From 913fac2159b922f0a9e335916fc6fa57606acd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E9=A2=97=E7=BA=A2=E5=BF=83?= Date: Mon, 19 Aug 2019 16:41:27 +0800 Subject: [PATCH 01/70] Add features: batch delete (#145) * Add features: batch delete --- delete.php | 13 +++++++++++++ index.php | 6 +++++- js/index.js | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/delete.php b/delete.php index df51bee..cde8539 100644 --- a/delete.php +++ b/delete.php @@ -60,4 +60,17 @@ die('?view&s='.$server['id'].'&d='.$server['db']); } +if (isset($_GET['batch_del'])) { + $keys = $_POST['selected_keys']; + $keys = trim($keys, ','); + if (empty($keys)) die('No keys to delete'); + + $keys = explode(',', $keys); + foreach ($keys as $key) { + $redis->del($key); + } + + die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0])); +} + ?> diff --git a/index.php b/index.php index 8e695e0..ae5ad90 100644 --- a/index.php +++ b/index.php @@ -102,6 +102,7 @@ function print_namespace($item, $name, $fullkey, $islast) { ?> > + ()

- + +
    diff --git a/js/index.js b/js/index.js index b440a77..de45790 100644 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,40 @@ $(function() { + $('#selected_all_keys').on('click', function () { + if ($(this).html()=='Select all'){ + $('input[name=checked_keys]').each(function () { + $(this).attr('checked', 'checked'); + }); + $(this).html('Select none'); + }else { + $('input[name=checked_keys]').each(function () { + $(this).removeAttr('checked'); + }); + $(this).html('Select all'); + } + }) + $('#sidebar').on('click', 'a', function(e) { - if (e.currentTarget.className.indexOf('deltree') !== -1) { + if (e.currentTarget.className.indexOf('batch_del') !== -1){ + e.preventDefault(); + var selected_keys = ''; + $('input[name=checked_keys]:checked').each(function () { + selected_keys += $(this).val() + ','; + }); + if (!selected_keys) { + alert('Please select the keys you want to delete.'); + return; + } + if (confirm('Are you sure you want to delete all selected keys?')) { + $.ajax({ + type: "POST", + url: this.href, + data: 'post=1&selected_keys=' + selected_keys, + success: function(url) { + top.location.href = top.location.pathname+url; + } + }); + } + }else if (e.currentTarget.className.indexOf('deltree') !== -1) { e.preventDefault(); if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) { From a858f60baea28405b0373ddf42fc77a56bc10820 Mon Sep 17 00:00:00 2001 From: Atef Ben Ali Date: Thu, 19 Sep 2019 12:04:45 +0100 Subject: [PATCH 02/70] style: remove `?>` php ending tag (#146) The `?>` ending tag is optional in a pure `php` file. --- includes/config.sample.inc.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 558f231..10e043d 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -81,5 +81,3 @@ // How many entries to fetch using each SCAN command. 'scansize' => 1000 ); - -?> From 0e8e4724be4016f75608aafd1c260b6f3350c490 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 27 Sep 2019 20:10:43 +0000 Subject: [PATCH 03/70] Make all paths relative --- edit.php | 2 +- export.php | 2 +- import.php | 2 +- includes/functions.inc.php | 3 +++ logout.php | 4 +--- rename.php | 2 +- ttl.php | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/edit.php b/edit.php index 4842655..0940503 100644 --- a/edit.php +++ b/edit.php @@ -144,7 +144,7 @@ ?>

    -
    +

    diff --git a/export.php b/export.php index ae1f0c3..c886e46 100644 --- a/export.php +++ b/export.php @@ -186,7 +186,7 @@ function export_json($key) { ?>

    Export

    - +

    diff --git a/import.php b/import.php index 9dbca76..1786164 100644 --- a/import.php +++ b/import.php @@ -91,7 +91,7 @@ ?>

    Import

    - +

    Edit Name of

    - + diff --git a/ttl.php b/ttl.php index b326823..6db0cb2 100644 --- a/ttl.php +++ b/ttl.php @@ -26,7 +26,7 @@ ?>

    Edit TTL

    - +

    From f20eda4baf6838a1b79379ee92e2669a5de197e2 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 27 Sep 2019 20:11:52 +0000 Subject: [PATCH 04/70] v1.11.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5199506..7d6cb26 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.11.4", + "version": "1.11.5", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 4a23c51c8b30409c57aa191cf74e29bae2b9c431 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Tue, 22 Oct 2019 06:56:15 +0200 Subject: [PATCH 05/70] Trying out github sponsorship --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a5fe8e7 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [erikdubbelboer] From 5e870a22a8dda82cc148656a6462305576b807d6 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sat, 16 Nov 2019 12:11:51 -0500 Subject: [PATCH 06/70] fix keys ending in :0 shown as (#148) --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index ae5ad90..cd96cd3 100644 --- a/index.php +++ b/index.php @@ -96,7 +96,7 @@ function print_namespace($item, $name, $fullkey, $islast) { } } - if (empty($name)) { + if (empty($name) && $name != '0') { $name = ''; } From 484714a25771e41b451bd2aaee068e5e0c07a0b5 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sun, 17 Nov 2019 15:27:11 -0500 Subject: [PATCH 07/70] show number of keys in database drop-down list (#150) also added an option to hide empty database the option can be set for all databases or on a database level the default is that empty database are shown closes #149 --- includes/common.inc.php | 4 ++++ includes/config.sample.inc.php | 3 +++ index.php | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/includes/common.inc.php b/includes/common.inc.php index 367c539..c50a2f3 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -111,6 +111,10 @@ } } +if (!isset($config['hideEmptyDBs'])) { + $config['hideEmptyDBs'] = false; +} + // Setup a connection to Redis. if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 10e043d..e24aa52 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -10,6 +10,7 @@ 'filter' => '*', 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket 'path' => '', // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock' + 'hide' => false, // Optional. Override global setting. Hide empty databases in the database list. // Optional Redis authentication. //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server. @@ -38,6 +39,8 @@ 'seperator' => ':', + // Hide empty databases in the database list (global, valid for all servers unless set at server level) + 'hideEmptyDBs' => false, // Uncomment to show less information and make phpRedisAdmin fire less commands to the Redis server. Recommended for a really busy Redis server. //'faster' => true, diff --git a/index.php b/index.php index cd96cd3..fc271b6 100644 --- a/index.php +++ b/index.php @@ -137,9 +137,30 @@ function print_namespace($item, $name, $fullkey, $islast) { } } + function getDbInfo($d, $info, $padding = '') { + global $config, $server; + $prefix = "database "; + $db = "db$d"; + + $dbHasData = array_key_exists("db$d", $info['Keyspace']); + + if (!$dbHasData && ((isset($server['hide']) && $server['hide']) || (!isset($server['hide']) && $config['hideEmptyDBs']))) { + return false; // we don't show empty dbs, so return false to tell the caller to continue the loop + } + + $dbinfo = sprintf("$prefix%'.-${padding}d", $d); + if ($dbHasData) { + $dbinfo = sprintf("%s (%d)", $dbinfo, $info['Keyspace'][$db]['keys']); + } + $dbinfo = str_replace('.', '  ', $dbinfo); // 2 spaces per character are needed to get the alignment right + + return $dbinfo; + } + } // if redis + // This is basically the same as the click code in index.js. // Just build the url for the frame based on our own url. if (count($_GET) == 0) { @@ -183,10 +204,11 @@ function print_namespace($item, $name, $fullkey, $islast) { $databases = $redis->config('GET', 'databases'); $databases = $databases['databases']; } +$info = $redis->info(); $len = strlen((string)($databases-1)); if ($databases > 1) { ?> From 65880d35bb745870f27a390e30ff98424cee16af Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Wed, 20 Nov 2019 16:20:57 -0500 Subject: [PATCH 08/70] fix reset stat code (#152) as mentioned earlier the method 'resetstat' does not exist and therefore the test will always be false. config resetstat is part of redis forever, so there's no reason for testing for this functionality. --- info.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/info.php b/info.php index 4d1f821..d657533 100644 --- a/info.php +++ b/info.php @@ -5,8 +5,8 @@ -if (isset($_GET['reset']) && method_exists($redis, 'resetStat')) { - $redis->resetStat(); +if (isset($_GET['reset'])) { + $redis->config('resetstat'); header('Location: info.php'); die; @@ -29,11 +29,9 @@ ?>

    Info

    -

    -Reset usage statistics +Reset usage statistics

    - From feed670bbdcb81b673de85f3327e0c232c915fd9 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Wed, 20 Nov 2019 16:22:52 -0500 Subject: [PATCH 09/70] fix switching server and database (#153) always show overview when switching - server, only keep var s (old database index might not exist on new server) - db, only keep vars s and d (whatever we are doing (show/edit key) won't be valid on new db) fixes #89, fixes #151 --- js/index.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/js/index.js b/js/index.js index de45790..3557014 100644 --- a/js/index.js +++ b/js/index.js @@ -12,7 +12,7 @@ $(function() { $(this).html('Select all'); } }) - + $('#sidebar').on('click', 'a', function(e) { if (e.currentTarget.className.indexOf('batch_del') !== -1){ e.preventDefault(); @@ -51,24 +51,24 @@ $(function() { if (e.currentTarget.href.indexOf('/?') == -1) { return; } - + e.preventDefault(); - + var href; - + if ((e.currentTarget.href.indexOf('?') == -1) || (e.currentTarget.href.indexOf('?') == (e.currentTarget.href.length - 1))) { href = 'overview.php'; } else { href = e.currentTarget.href.substr(e.currentTarget.href.indexOf('?') + 1); - + if (href.indexOf('&') != -1) { href = href.replace('&', '.php?'); } else { href += '.php'; } } - + if (href.indexOf('flush.php') == 0) { if (confirm('Are you sure you want to delete this key and all it\'s values?')) { $.ajax({ @@ -90,24 +90,17 @@ $(function() { }); $('#server').change(function(e) { - if (location.href.indexOf('?') == -1) { - location.href = location.href+'?s='+e.target.value; - } else if (location.href.indexOf('&s=') == -1) { - location.href = location.href+'&s='+e.target.value; - } else { - location.href = location.href.replace(/s=[0-9]*/, 's='+e.target.value); - } + // always show overview when switching server, only keep var s (old database index might not exist on new server) + const base = location.href.split('?', 1)[0]; + location.href = base + '?overview&s=' + e.target.value; }); $('#database').change(function(e) { - if (location.href.indexOf('?') == -1) { - location.href = location.href+'?d='+e.target.value; - } else if (location.href.indexOf('&d=') == -1) { - location.href = location.href+'&d='+e.target.value; - } else { - location.href = location.href.replace(/d=[0-9]*/, 'd='+e.target.value); - } + // always show overview when switching db, only keep vars s and d (whatever we are doing (show/edit key) won't be valid on new db) + const base = location.href.split('?', 1)[0]; + const s = location.href.match(/s=[0-9]*/); + location.href = base + '?overview&' + s + '&d=' + e.target.value; }); From c291de34a179faefa84ea53bee89176a5d380817 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 24 Nov 2019 16:43:06 +0000 Subject: [PATCH 10/70] Add showEmptyNamespaceAsKey and make grey --- css/index.css | 4 ++++ includes/config.sample.inc.php | 1 + index.php | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/css/index.css b/css/index.css index 80ceade..7b898e5 100644 --- a/css/index.css +++ b/css/index.css @@ -44,6 +44,10 @@ margin-top: .05em; cursor: pointer; } +#keys li.empty a { +color: #888; +} + #keys li.current a { background-color: #eee; } diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index e24aa52..10ed201 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -38,6 +38,7 @@ 'seperator' => ':', + 'showEmptyNamespaceAsKey' => false, // Hide empty databases in the database list (global, valid for all servers unless set at server level) 'hideEmptyDBs' => false, diff --git a/index.php b/index.php index fc271b6..fa0c51e 100644 --- a/index.php +++ b/index.php @@ -34,6 +34,10 @@ } $key = explode($server['seperator'], $key); + if ($key[count($key) - 1] == '' && $config['showEmptyNamespaceAsKey']) { + array_pop($key); + $key[count($key) - 1] .= ':'; + } // $d will be a reference to the current namespace. $d = &$namespaces; @@ -98,6 +102,7 @@ function print_namespace($item, $name, $fullkey, $islast) { if (empty($name) && $name != '0') { $name = ''; + $class[] = 'empty'; } ?> From 8c7bfcfe7a7bee5e2a0ede68eb95d29450682d93 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Mon, 25 Nov 2019 14:46:35 -0500 Subject: [PATCH 11/70] minor changes (#156) * change order of evaluation PHP evaluates conditions from left to right count needs more instructions thus should be on the right side (probably not necessary, but I'm a perf guy...) * set a default in case it is not set in confg (to avoid PHP warnings) --- includes/common.inc.php | 4 ++++ index.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/common.inc.php b/includes/common.inc.php index c50a2f3..ca63814 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -115,6 +115,10 @@ $config['hideEmptyDBs'] = false; } +if (!isset($config['showEmptyNamespaceAsKey'])) { + $config['showEmptyNamespaceAsKey'] = false; +} + // Setup a connection to Redis. if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); diff --git a/index.php b/index.php index fa0c51e..5ea3b25 100644 --- a/index.php +++ b/index.php @@ -34,7 +34,7 @@ } $key = explode($server['seperator'], $key); - if ($key[count($key) - 1] == '' && $config['showEmptyNamespaceAsKey']) { + if ($config['showEmptyNamespaceAsKey'] && $key[count($key) - 1] == '') { array_pop($key); $key[count($key) - 1] .= ':'; } From 756c4016130bb63a88e2eed07740d98fa5538a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 10 Jan 2020 09:39:02 +0100 Subject: [PATCH 12/70] Remove usage of get_magic_quotes_gpc method (#158) --- includes/common.inc.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/includes/common.inc.php b/includes/common.inc.php index ca63814..85dfe76 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -3,26 +3,6 @@ define('PHPREDIS_ADMIN_PATH', dirname(__DIR__)); -// Undo magic quotes (both in keys and values) -if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { - $process = array(&$_GET, &$_POST); - - foreach ($process as $key => $val) { - foreach ($val as $k => $v) { - unset($process[$key][$k]); - - if (is_array($v)) { - $process[$key][stripslashes($k)] = $v; - $process[] = &$process[$key][stripslashes($k)]; - } else { - $process[$key][stripslashes($k)] = stripslashes($v); - } - } - } - - unset($process); -} - From 7e4bc6cfedc02e045ef43936d615e07444c0de07 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 10 Jan 2020 08:48:08 +0000 Subject: [PATCH 13/70] v1.12.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7d6cb26..7198e92 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.11.5", + "version": "1.12.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 5752c5087023464e8f41161e77a87c3a8263ac95 Mon Sep 17 00:00:00 2001 From: Alex Stansfield Date: Sat, 1 Feb 2020 04:19:00 +0700 Subject: [PATCH 14/70] Allow 'databases' server config option to be set by ENV (#159) This is quite specific to my needs, but possibly useful for others. My setup is PhpRedisAdmin running in Docker on ECS Fargate connnecting to Redis Elasticache. AWS Elasticache has a restricted CONFIG command so you can't get the databases. This change allows me to set the databases in the Task Definition in ECS. --- includes/config.environment.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/config.environment.inc.php b/includes/config.environment.inc.php index 0522421..587899c 100644 --- a/includes/config.environment.inc.php +++ b/includes/config.environment.inc.php @@ -24,6 +24,7 @@ $server_host = getenv($prefix . 'HOST'); $server_port = getenv($prefix . 'PORT'); $server_auth = getenv($prefix . 'AUTH'); + $server_databases = getenv($prefix . 'DATABASES'); if (empty($server_host)) { break; @@ -51,6 +52,10 @@ if (!empty($server_auth)) { $config['servers'][$i-1]['auth'] = $server_auth; } + + if (!empty($server_databases)) { + $config['servers'][$i-1]['databases'] = $server_databases; + } $i++; } From 9eb60157dc13e660d6707af40835b8227b2ae3e9 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 31 Jan 2020 20:53:00 +0000 Subject: [PATCH 15/70] v1.13.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7198e92..0cfdc77 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.12.0", + "version": "1.13.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 4501c5d6500a926784fa32e7607065526f85e556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abra=C3=A3o=20Zaidan?= Date: Fri, 28 Feb 2020 10:24:17 -0300 Subject: [PATCH 16/70] Avoid unnecessary horizontal scrollbars (#160) * Avoid unnecessary horizontal scrollbars Fix long key values rendering with horizontal scrollbar; Fix keys folder with checkbox in one line and key name in another line. * Ellipsis replaced by horizontal scrollbar while keeping elements aligned https://github.com/erikdubbelboer/phpRedisAdmin/pull/160#issuecomment-589968360 * Fix missing padding on the right frame in Firefox for Mac https://github.com/erikdubbelboer/phpRedisAdmin/pull/160#issuecomment-590048242 --- css/common.css | 2 +- css/index.css | 15 ++++++++++++--- index.php | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/css/common.css b/css/common.css index b2a8431..9dc6276 100644 --- a/css/common.css +++ b/css/common.css @@ -52,6 +52,6 @@ background: url(http://github.com/images/add.png) left center no-repeat; .data { -white-space: pre; +white-space: pre-wrap; } diff --git a/css/index.css b/css/index.css index 7b898e5..4a56aa9 100644 --- a/css/index.css +++ b/css/index.css @@ -3,10 +3,14 @@ position: absolute; top: 0; bottom: 0; left: 0; +display: flex; +flex-direction: column; width: 290px; height: 100%; +} + +#header { padding-left: 10px; -border-right: 1px solid #000; } #sidebar a, #sidebar a:visited { @@ -23,7 +27,9 @@ text-decoration: underline; #keys { +flex-grow: 1; width: 290px; +margin-top: 10px; padding-left: 10px; overflow: auto; } @@ -36,6 +42,7 @@ padding: 0; #keys li { font-weight: normal; +white-space: nowrap; } #keys li.folder { @@ -115,6 +122,7 @@ background-color: #aaa; cursor: col-resize; padding: 0; margin: 0; +border-left: 1px solid #000; } #resize-layover { @@ -133,11 +141,12 @@ top: 0; left: 305px; right: 0; bottom: 0; -padding-left: 2em; } #frame iframe { -width: 100%; +width: calc(100% - 3em); height: 100%; +margin-left: 1.5em; +margin-right: 1.5em; } diff --git a/index.php b/index.php index 5ea3b25..933796a 100644 --- a/index.php +++ b/index.php @@ -108,7 +108,7 @@ function print_namespace($item, $name, $fullkey, $islast) { ?> > - () + () - +
    Key
    Value
    Encoding:
    Size:
    Size:
    + +
    From 175faa7f8f39e189eaeccb9cd556d7d3397fe696 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 11 Apr 2022 16:22:58 +0000 Subject: [PATCH 37/70] v1.17.1 * 0866ff2 Update view.php (#180) (diplopito) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3cc3fdd..69cf7ab 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.17.0", + "version": "1.17.1", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 7be7f0a27c0c732d4c1dad5f194c07c7e09dda50 Mon Sep 17 00:00:00 2001 From: suyar <296399959@qq.com> Date: Mon, 4 Jul 2022 03:03:29 +0800 Subject: [PATCH 38/70] Bring in tzdata so users could set the timezones through the environment (#182) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 16f313d..6a82667 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM composer:2.2 ENV TINI_VERSION 0.19.0-r0 -RUN apk add --no-cache tini=$TINI_VERSION +RUN apk add --no-cache tini=$TINI_VERSION tzdata ADD . /src/app/ From d8b24525562d8f6f2392a212242e094cdd9d8697 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 3 Jul 2022 21:09:48 +0200 Subject: [PATCH 39/70] v1.17.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 69cf7ab..75b1587 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.17.1", + "version": "1.17.2", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From e1f15392891d3648fafb3d2ec074db041a164faf Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Thu, 25 Aug 2022 08:15:13 +0200 Subject: [PATCH 40/70] Add support for REDIS_N_AUTH_FILE --- README.markdown | 1 + includes/config.environment.inc.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 15de6f7..6c90f58 100644 --- a/README.markdown +++ b/README.markdown @@ -56,6 +56,7 @@ Environment variables summary * ``REDIS_1_NAME`` - define name of the Redis server * ``REDIS_1_PORT`` - define port of the Redis server * ``REDIS_1_AUTH`` - define password of the Redis server +* ``REDIS_1_AUTH_FILE`` - define file containing the password of the Redis server * ``REDIS_1_DATABASES`` - You can modify you config to prevent phpRedisAdmin from using CONFIG command * ``ADMIN_USER`` - define username for user-facing Basic Auth * ``ADMIN_PASS`` - define password for user-facing Basic Auth diff --git a/includes/config.environment.inc.php b/includes/config.environment.inc.php index 587899c..798281f 100644 --- a/includes/config.environment.inc.php +++ b/includes/config.environment.inc.php @@ -23,7 +23,11 @@ $server_name = getenv($prefix . 'NAME'); $server_host = getenv($prefix . 'HOST'); $server_port = getenv($prefix . 'PORT'); - $server_auth = getenv($prefix . 'AUTH'); + if (getenv($prefix . 'AUTH_FILE') !== false) { + $server_auth = file_get_contents(getenv($prefix . 'AUTH_FILE')); + } else { + $server_auth = getenv($prefix . 'AUTH'); + } $server_databases = getenv($prefix . 'DATABASES'); if (empty($server_host)) { From d6786dc91bf77bf66e4ac5a2c8bc968ee55a5468 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Thu, 25 Aug 2022 08:15:49 +0200 Subject: [PATCH 41/70] v1.17.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 75b1587..50c18ee 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.17.2", + "version": "1.17.3", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From bccabce045071fbc2962496ec4f02ec3b30b45a6 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Wed, 28 Sep 2022 14:17:11 +0200 Subject: [PATCH 42/70] Update readme --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 6c90f58..6b525a4 100644 --- a/README.markdown +++ b/README.markdown @@ -41,7 +41,7 @@ git clone https://github.com/nrk/predis.git vendor Docker Image ============ -A public [phpRedisAdmin Docker image](https://hub.docker.com/r/erikdubbelboer/phpredisadmin/) is available on Docker Hub [automatically built](https://docs.docker.com/docker-hub/builds/) from latest source. +A public [phpRedisAdmin Docker image](https://hub.docker.com/r/erikdubbelboer/phpredisadmin/) is available on Docker Hub built from the latest tag. The file ```includes/config.environment.inc.php``` is used as the configuration file to allow environment variables to be used as configuration values. Example: ``` From e2348fdba7c124b5128684989ddb788ae388db52 Mon Sep 17 00:00:00 2001 From: Karel Wintersky Date: Sat, 29 Oct 2022 20:24:31 +0300 Subject: [PATCH 43/70] Fix #187 issue (comma in keys) (#188) * * [*] make all AJAX requrests recieve data as object * [*] JSON.Stringify() selected keys (fix issue #187) * * [*] add `ext-mbstring` and `ext-json` to composer.json * * [*] replaced `dirname(__FILE__)` to `__DIR__` (faster) * * [-] removed obsolete empty lines * [+] export `$redis, $config, $csrfToken, $server` to local env of any PHP file * [*] a little fixes --- composer.json | 2 ++ delete.php | 13 ++++++------- edit.php | 5 ++--- export.php | 1 + flush.php | 4 +--- import.php | 4 +--- includes/common.inc.php | 8 +------- includes/page.inc.php | 4 ---- index.php | 3 ++- info.php | 9 +-------- js/frame.js | 2 -- js/index.js | 26 ++++++++++++++++++-------- login.php | 1 + logout.php | 1 + overview.php | 6 ++---- rename.php | 4 +--- save.php | 4 +--- ttl.php | 7 +------ view.php | 10 +--------- 19 files changed, 43 insertions(+), 71 deletions(-) diff --git a/composer.json b/composer.json index 50c18ee..3136710 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,8 @@ } ], "require": { + "ext-mbstring": "*", + "ext-json": "*", "predis/predis": "v1.1.9", "paragonie/random_compat": ">=2" }, diff --git a/delete.php b/delete.php index cde8539..c329919 100644 --- a/delete.php +++ b/delete.php @@ -1,13 +1,13 @@ del($key); } @@ -73,4 +73,3 @@ die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0])); } -?> diff --git a/edit.php b/edit.php index 0e0b360..6f3fd20 100644 --- a/edit.php +++ b/edit.php @@ -2,8 +2,7 @@ require_once 'includes/common.inc.php'; - - +global $redis, $config, $csrfToken, $server; // Are we editing or creating a new key? $edit = false; @@ -192,4 +191,4 @@ require 'includes/footer.inc.php'; -?> +?> \ No newline at end of file diff --git a/export.php b/export.php index 2812705..d17839e 100644 --- a/export.php +++ b/export.php @@ -2,6 +2,7 @@ require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; // Export to redis-cli commands function export_redis($key, $filter = false, $transform = false) { diff --git a/flush.php b/flush.php index 4e74489..c8fc1f5 100644 --- a/flush.php +++ b/flush.php @@ -1,13 +1,11 @@ flushdb(); diff --git a/import.php b/import.php index e9176dc..5e5a89e 100644 --- a/import.php +++ b/import.php @@ -1,9 +1,7 @@ diff --git a/includes/page.inc.php b/includes/page.inc.php index 2f1a0e9..2941e68 100644 --- a/includes/page.inc.php +++ b/includes/page.inc.php @@ -1,6 +1,5 @@ array('common'), 'js' => array('jquery') diff --git a/index.php b/index.php index be7c9d8..94dd90a 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ config('resetstat'); @@ -12,15 +10,10 @@ die; } - - // Fetch the info $info = $redis->info(); $alt = false; - - - $page['css'][] = 'frame'; $page['js'][] = 'frame'; diff --git a/js/frame.js b/js/frame.js index 1a77e34..0196452 100644 --- a/js/frame.js +++ b/js/frame.js @@ -3,14 +3,12 @@ $(function() { window.parent.history.replaceState({}, '', document.location.href.replace('?', '&').replace(/\/([a-z]*)\.php/, '/?$1')); } - $('#type').change(function(e) { $('#hkeyp' ).css('display', e.target.value == 'hash' ? 'block' : 'none'); $('#indexp').css('display', e.target.value == 'list' ? 'block' : 'none'); $('#scorep').css('display', e.target.value == 'zset' ? 'block' : 'none'); }).change(); - $('.delkey, .delval').click(function(e) { e.preventDefault(); diff --git a/js/index.js b/js/index.js index a3ba627..a3f3414 100644 --- a/js/index.js +++ b/js/index.js @@ -14,13 +14,13 @@ $(function() { }) $('#sidebar').on('click', 'a', function(e) { - if (e.currentTarget.className.indexOf('batch_del') !== -1){ + if (e.currentTarget.className.indexOf('batch_del') !== -1) { e.preventDefault(); - var selected_keys = ''; + var selected_keys = []; $('input[name=checked_keys]:checked').each(function () { - selected_keys += $(this).val() + ','; + selected_keys.push($(this).val()); }); - if (!selected_keys) { + if (selected_keys.length == 0) { alert('Please select the keys you want to delete.'); return; } @@ -28,20 +28,27 @@ $(function() { $.ajax({ type: "POST", url: this.href, - data: 'post=1&selected_keys=' + selected_keys + '&csrf=' + phpRedisAdmin_csrfToken, + data: { + post: 1, + selected_keys: JSON.stringify(selected_keys), + csrf: phpRedisAdmin_csrfToken + }, success: function(url) { top.location.href = top.location.pathname+url; } }); } - }else if (e.currentTarget.className.indexOf('deltree') !== -1) { + } else if (e.currentTarget.className.indexOf('deltree') !== -1) { e.preventDefault(); if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) { $.ajax({ type: "POST", url: this.href, - data: 'post=1&csrf=' + phpRedisAdmin_csrfToken, + data: { + post: 1, + csrf: phpRedisAdmin_csrfToken + }, success: function(url) { top.location.href = top.location.pathname+url; } @@ -74,7 +81,10 @@ $(function() { $.ajax({ type: "POST", url: href, - data: 'post=1&csrf=' + phpRedisAdmin_csrfToken, + data: { + post: 1, + csrf: phpRedisAdmin_csrfToken + }, success: function() { window.location.reload(); } diff --git a/login.php b/login.php index 298b32f..a80a24c 100644 --- a/login.php +++ b/login.php @@ -2,6 +2,7 @@ define('LOGIN_PAGE', true); require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; $page['css'][] = 'login'; diff --git a/logout.php b/logout.php index 44b1785..12cc80b 100644 --- a/logout.php +++ b/logout.php @@ -1,6 +1,7 @@

    -Redis Documentation +Redis Documentation

    $config['maxkeylen']) { diff --git a/save.php b/save.php index 3154e8c..ef8b1d8 100644 --- a/save.php +++ b/save.php @@ -1,9 +1,7 @@ Invalid key @@ -18,8 +17,6 @@ die; } - - $type = $redis->type($_GET['key']); $exists = $redis->exists($_GET['key']); @@ -27,8 +24,6 @@ $page_num_request = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page_num_request = $page_num_request === 0 ? 1 : $page_num_request; - - ?>

    @@ -48,8 +43,6 @@ die; } - - $alt = false; $ttl = $redis->ttl($_GET['key']); @@ -59,7 +52,6 @@ $encoding = null; } - switch ($type) { case 'string': $value = $redis->get($_GET['key']); From 88b5d92c3d015d58be3aa346a23bbb457de6e64b Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 30 Oct 2022 09:55:07 +0100 Subject: [PATCH 44/70] v1.18.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3136710..e0251f6 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.17.3", + "version": "1.18.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 46be650827d65b51fc117b559dea6e059aa41547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=9B=E5=85=B5?= Date: Mon, 9 Jan 2023 11:49:47 +0800 Subject: [PATCH 45/70] Update Dockerfile to enable change listen port (#191) Docker can not change the exported port when in host mode, and port 80 open used by http server. So i made this to enable change the listening port by environment variables. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6a82667..73ea46e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,6 @@ RUN composer install RUN cp includes/config.environment.inc.php includes/config.inc.php +ENV PORT 80 EXPOSE 80 -ENTRYPOINT [ "tini", "--", "php", "-S", "0.0.0.0:80" ] +ENTRYPOINT [ "sh", "-c", "tini -- php -S 0.0.0.0:$PORT" ] From aeab4b0322eda72965ddbbc606fffef1163f89f0 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 9 Jan 2023 04:50:32 +0100 Subject: [PATCH 46/70] v1.19.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e0251f6..16a914d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.18.0", + "version": "1.19.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From bdc2e88160928fbd2e5fe49ddb6cf90cbd44be6e Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 9 Jan 2023 10:24:58 +0100 Subject: [PATCH 47/70] Use the latest version of tini --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 73ea46e..c9ff06c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM composer:2.2 -ENV TINI_VERSION 0.19.0-r0 - -RUN apk add --no-cache tini=$TINI_VERSION tzdata +RUN apk add --no-cache tini tzdata ADD . /src/app/ From 9221bfeb1cd01b7710ae84effc23194b382d85ff Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 9 Jan 2023 10:25:43 +0100 Subject: [PATCH 48/70] v1.19.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 16a914d..a7b3881 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.19.0", + "version": "1.19.1", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From bf71b74103b4aa506606f63344835f13ac42294d Mon Sep 17 00:00:00 2001 From: Sam Benskin <1180089+sambenskin@users.noreply.github.com> Date: Fri, 27 Jan 2023 05:36:20 +0000 Subject: [PATCH 49/70] Fix #194 Changed variable to {$var} syntax (#195) --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 94dd90a..44f7c85 100644 --- a/index.php +++ b/index.php @@ -154,7 +154,7 @@ function getDbInfo($d, $info, $padding = '') { return false; // we don't show empty dbs, so return false to tell the caller to continue the loop } - $dbinfo = sprintf("$prefix%'.-${padding}d", $d); + $dbinfo = sprintf("$prefix%'.-{$padding}d", $d); if ($dbHasData) { $dbinfo = sprintf("%s (%d)", $dbinfo, $info['Keyspace'][$db]['keys']); } From cb2d6a3e772948e6fec148a2ed0c76c8568ee386 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 3 Mar 2023 21:39:48 +0100 Subject: [PATCH 50/70] v1.19.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a7b3881..e1043de 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.19.1", + "version": "1.19.2", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From c7229f0ec3825b726f8074a3fbc4b2ea10301722 Mon Sep 17 00:00:00 2001 From: xiagw Date: Mon, 7 Aug 2023 23:44:14 +0800 Subject: [PATCH 51/70] fix Dockerfile (#201) --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9ff06c..610dbda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,13 @@ FROM composer:2.2 RUN apk add --no-cache tini tzdata -ADD . /src/app/ - WORKDIR /src/app -RUN composer install +COPY . . -RUN cp includes/config.environment.inc.php includes/config.inc.php +RUN set -xe; \ + composer install; \ + cp includes/config.environment.inc.php includes/config.inc.php ENV PORT 80 EXPOSE 80 From 0303c81abd6a73a37399229bbb6a9eb7b9dfbe10 Mon Sep 17 00:00:00 2001 From: Sachin Bahukhandi Date: Thu, 11 Apr 2024 00:09:16 +0530 Subject: [PATCH 52/70] Added a check for ZSET values (#204) --- edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edit.php b/edit.php index 6f3fd20..4424d24 100644 --- a/edit.php +++ b/edit.php @@ -82,7 +82,7 @@ } // ZSet - else if (($_POST['type'] == 'zset') && isset($_POST['score'])) { + else if (($_POST['type'] == 'zset') && isset($_POST['score']) && is_numeric($_POST['score'])) { // The only way to edit a ZSet value is to add it and remove the old value. $redis->zRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); $redis->zAdd($key, input_convert($_POST['score']), $value); From acc524865bb8e3c98bef2b0dec451f4c25712008 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Wed, 10 Apr 2024 20:40:01 +0200 Subject: [PATCH 53/70] 1.19.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e1043de..acb2515 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.19.2", + "version": "1.19.3", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 7bf33653b74e5419e9acef00b63c9c54e304765a Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Sun, 23 Jun 2024 21:24:14 +0800 Subject: [PATCH 54/70] Get more configs params from environment variables (#207) --- includes/config.environment.inc.php | 33 ++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/includes/config.environment.inc.php b/includes/config.environment.inc.php index 798281f..a35bf07 100644 --- a/includes/config.environment.inc.php +++ b/includes/config.environment.inc.php @@ -2,6 +2,18 @@ include 'config.sample.inc.php'; +// get configs from environment variables +$config['cookie_auth'] = getenv('COOKIE_AUTH') ?: false; +$config['count_elements_page'] = getenv('COUNT_ELEMENTS_PAGE') ?: 100; +$config['faster'] = getenv('FASTER') ?: true; +$config['filter'] = getenv('FILTER') ?: '*'; +$config['hideEmptyDBs'] = getenv('HIDE_EMPTY_DBS') ?: false; +$config['keys'] = getenv('KEYS') ?: false; +$config['maxkeylen'] = getenv('MAX_KEY_LEN') ?: 100; +$config['scansize'] = getenv('SCAN_SIZE') ?: 1000; +$config['seperator'] = getenv('SEPERATOR') ?: ':'; +$config['showEmptyNamespaceAsKey'] = getenv('SHOW_EMPTY_NAMESPACE_AS_KEY') ?: false; + $admin_user = getenv('ADMIN_USER'); $admin_pass = getenv('ADMIN_PASS'); @@ -37,29 +49,30 @@ if (empty($server_name)) { $server_name = $server_host; } - + if (empty($server_auth)) { $server_auth = ""; - } + } if (empty($server_port)) { $server_port = 6379; } $config['servers'][] = array( - 'name' => $server_name, - 'host' => $server_host, - 'port' => $server_port, - 'filter' => '*', + 'name' => $server_name, + 'host' => $server_host, + 'port' => $server_port, + 'filter' => $config['filter'], + 'scansize' => $config['scansize'], ); - + if (!empty($server_auth)) { $config['servers'][$i-1]['auth'] = $server_auth; - } - + } + if (!empty($server_databases)) { $config['servers'][$i-1]['databases'] = $server_databases; - } + } $i++; } From 092f83ff156b8f6b9355ca3ce5733172e7127297 Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Tue, 25 Jun 2024 01:14:38 +0800 Subject: [PATCH 55/70] Limit the max number of keys when scanning (#206) * Add parameter scan_max * Limit the max number of keys when scanning * Rename parameter scan_max to scanmax --- includes/config.environment.inc.php | 2 ++ includes/config.sample.inc.php | 3 ++- index.php | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/config.environment.inc.php b/includes/config.environment.inc.php index a35bf07..b987194 100644 --- a/includes/config.environment.inc.php +++ b/includes/config.environment.inc.php @@ -11,6 +11,7 @@ $config['keys'] = getenv('KEYS') ?: false; $config['maxkeylen'] = getenv('MAX_KEY_LEN') ?: 100; $config['scansize'] = getenv('SCAN_SIZE') ?: 1000; +$config['scanmax'] = getenv('SCAN_MAX') ?: 1000; $config['seperator'] = getenv('SEPERATOR') ?: ':'; $config['showEmptyNamespaceAsKey'] = getenv('SHOW_EMPTY_NAMESPACE_AS_KEY') ?: false; @@ -64,6 +65,7 @@ 'port' => $server_port, 'filter' => $config['filter'], 'scansize' => $config['scansize'], + 'scanmax' => $config['scanmax'], ); if (!empty($server_auth)) { diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 10ed201..13f4a2c 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -32,7 +32,8 @@ 'flush' => false, // Set to true to enable the flushdb button for this instance. 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8). 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default). - 'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default). + 'scansize' => 1000, // How many entries to fetch using each SCAN command for this server (default uses config default). + 'scanmax' => 1000, // In each query, SCAN command may be executed several times. To shorten the duration, it is recommended to limit the total number of entries to fetch. ),*/ ), diff --git a/index.php b/index.php index 44f7c85..8f99dd8 100644 --- a/index.php +++ b/index.php @@ -17,6 +17,10 @@ $next = $r[0]; $keys = array_merge($keys, $r[1]); + if (count($keys) >= $server['scanmax']) { + break; + } + if ($next == 0) { break; } From 3dcd016ae259dbe0836a04d7907905cb078640db Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 24 Jun 2024 19:16:11 +0200 Subject: [PATCH 56/70] 1.20.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index acb2515..5c707cf 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.19.3", + "version": "1.20.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 4f1544459395892741ebcabec498680e544742f2 Mon Sep 17 00:00:00 2001 From: arielectron Date: Sun, 18 Aug 2024 14:28:06 -0300 Subject: [PATCH 57/70] Allow scheme config from env vars (#209) * Allow scheme config from env vars * Fix condition * Add new config to readme file * Update includes/common.inc.php --------- Co-authored-by: Erik Dubbelboer --- README.markdown | 1 + includes/common.inc.php | 8 ++++++-- includes/config.environment.inc.php | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 6b525a4..0938c08 100644 --- a/README.markdown +++ b/README.markdown @@ -55,6 +55,7 @@ Environment variables summary * ``REDIS_1_HOST`` - define host of the Redis server * ``REDIS_1_NAME`` - define name of the Redis server * ``REDIS_1_PORT`` - define port of the Redis server +* ``REDIS_1_SCHEME`` - define scheme of the Redis server (tcp or tls) * ``REDIS_1_AUTH`` - define password of the Redis server * ``REDIS_1_AUTH_FILE`` - define file containing the password of the Redis server * ``REDIS_1_DATABASES`` - You can modify you config to prevent phpRedisAdmin from using CONFIG command diff --git a/includes/common.inc.php b/includes/common.inc.php index ae0bd52..075ca16 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -113,11 +113,15 @@ $config['showEmptyNamespaceAsKey'] = false; } +if (!isset($config['scheme']) || empty($config['scheme'])) { + $config['scheme'] = 'tcp'; +} + // Setup a connection to Redis. -if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { +if ($server['scheme'] === 'unix' && $server['path']) { $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); } else { - $redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client('tcp://'.$server['host'].':'.$server['port']); + $redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client($server['scheme'].'://'.$server['host'].':'.$server['port']); } try { diff --git a/includes/config.environment.inc.php b/includes/config.environment.inc.php index b987194..06a06fe 100644 --- a/includes/config.environment.inc.php +++ b/includes/config.environment.inc.php @@ -36,6 +36,7 @@ $server_name = getenv($prefix . 'NAME'); $server_host = getenv($prefix . 'HOST'); $server_port = getenv($prefix . 'PORT'); + $server_scheme = getenv($prefix . 'SCHEME'); if (getenv($prefix . 'AUTH_FILE') !== false) { $server_auth = file_get_contents(getenv($prefix . 'AUTH_FILE')); } else { @@ -55,10 +56,14 @@ $server_auth = ""; } - if (empty($server_port)) { + if (empty($server_port) && strpos($server_host, ':') === false) { $server_port = 6379; } + if (empty($server_scheme)) { + $server_scheme = 'tcp'; + } + $config['servers'][] = array( 'name' => $server_name, 'host' => $server_host, @@ -66,6 +71,7 @@ 'filter' => $config['filter'], 'scansize' => $config['scansize'], 'scanmax' => $config['scanmax'], + 'scheme' => $server_scheme, ); if (!empty($server_auth)) { From 5d8756c0863cfbf7f95206520be6d101f4f67079 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 18 Aug 2024 19:29:01 +0200 Subject: [PATCH 58/70] 1.21.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c707cf..1052799 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.20.0", + "version": "1.21.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From fed29bf9dac74ce0eb37a89ebeae014c290bd3de Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Sat, 21 Sep 2024 22:09:23 +0800 Subject: [PATCH 59/70] Display the number of keys scanned (#210) * Display the number of keys scanned and the limit * Reduce scansize according to scanmax * Simplify info about scanmax --- index.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 8f99dd8..056abeb 100644 --- a/index.php +++ b/index.php @@ -10,20 +10,18 @@ } else { $next = 0; $keys = array(); - + $scansize = $server['scansize']; while (true) { - $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $server['scansize']); - + $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $scansize); $next = $r[0]; $keys = array_merge($keys, $r[1]); - - if (count($keys) >= $server['scanmax']) { + if ($next == 0) { break; } - - if ($next == 0) { + if (count($keys) >= $server['scanmax']) { break; } + $scansize = min($server['scanmax'] - count($keys), $server['scansize']); } } @@ -256,6 +254,9 @@ function getDbInfo($d, $info, $padding = '') {

+
+ scaned keys= $server['scanmax']) ? ', reached scanmax' : '' ?> +
From 47f4c678f0cca20709a2587c2704c0ec612de189 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sat, 21 Sep 2024 16:10:00 +0200 Subject: [PATCH 60/70] v1.21.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1052799..29d6261 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.21.0", + "version": "1.21.1", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From c8fc6a08e4f05c710daa9c8a695f54b7aba498f2 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sun, 8 Dec 2024 10:35:59 +0100 Subject: [PATCH 61/70] fix: scanmax behavior (#212) * fix: typo * fix: scanmax behavior --- includes/common.inc.php | 12 ++++++++++++ includes/config.sample.inc.php | 5 ++++- index.php | 8 +++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/includes/common.inc.php b/includes/common.inc.php index 075ca16..c13424b 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -95,10 +95,22 @@ $server['keys'] = $config['keys']; } +if (!isset($config['scansize'])) { + $config['scansize'] = 1000; +} + +if (!isset($config['scanmax'])) { + $config['scanmax'] = 0; +} + if (!isset($server['scansize'])) { $server['scansize'] = $config['scansize']; } +if (!isset($server['scanmax'])) { + $server['scanmax'] = $config['scanmax']; +} + if (!isset($server['serialization'])) { if (isset($config['serialization'])) { $server['serialization'] = $config['serialization']; diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 13f4a2c..2732d97 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -33,7 +33,7 @@ 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8). 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default). 'scansize' => 1000, // How many entries to fetch using each SCAN command for this server (default uses config default). - 'scanmax' => 1000, // In each query, SCAN command may be executed several times. To shorten the duration, it is recommended to limit the total number of entries to fetch. + 'scanmax' => 1000, // In each query, SCAN command may be executed several times. To shorten the duration, it is recommended to limit the total number of entries to fetch (default uses config default). ),*/ ), @@ -85,4 +85,7 @@ // How many entries to fetch using each SCAN command. 'scansize' => 1000 + + // The total number of entries to fetch. Set to 0 or -1 for no limit. + 'scanmax' => 0 ); diff --git a/index.php b/index.php index 056abeb..b513947 100644 --- a/index.php +++ b/index.php @@ -10,18 +10,16 @@ } else { $next = 0; $keys = array(); - $scansize = $server['scansize']; while (true) { - $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $scansize); + $r = $redis->scan($next, 'MATCH', $server['filter'], 'COUNT', $server['scansize']); $next = $r[0]; $keys = array_merge($keys, $r[1]); if ($next == 0) { break; } - if (count($keys) >= $server['scanmax']) { + if ($server['scanmax'] > 0 && count($keys) >= $server['scanmax']) { break; } - $scansize = min($server['scanmax'] - count($keys), $server['scansize']); } } @@ -255,7 +253,7 @@ function getDbInfo($d, $info, $padding = '') {
- scaned keys= $server['scanmax']) ? ', reached scanmax' : '' ?> + scanned keys 0 && count($keys) >= $server['scanmax']) ? ', reached scanmax' : '' ?>
    From 644162e932230d8eef642ebce327260a4dd54b0a Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sun, 8 Dec 2024 10:41:43 +0100 Subject: [PATCH 62/70] v1.22.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 29d6261..475fd18 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.21.1", + "version": "1.22.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 5e8c6ecb19e68988994ac20a1dff30b3fa65cf3e Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 9 Dec 2024 13:04:25 +0100 Subject: [PATCH 63/70] Add missing , Fixes: https://github.com/erikdubbelboer/phpRedisAdmin/issues/202 --- includes/config.sample.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index 2732d97..cca5b81 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -84,7 +84,7 @@ 'keys' => false, // How many entries to fetch using each SCAN command. - 'scansize' => 1000 + 'scansize' => 1000, // The total number of entries to fetch. Set to 0 or -1 for no limit. 'scanmax' => 0 From 3e60b217dae70e0be700202c2fb3d4cf46ac02fe Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 9 Dec 2024 13:05:05 +0100 Subject: [PATCH 64/70] v1.22.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 475fd18..a851fe6 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.22.0", + "version": "1.22.1", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From 543cbc7997874fae7967aaaa85bf190a6b24d0b4 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 20 Dec 2024 07:28:42 +0000 Subject: [PATCH 65/70] Upgrade predis to v2.3.0 Fixes a bug with $server['scheme'] and simplifies some of the config code. Fixes https://github.com/erikdubbelboer/phpRedisAdmin/issues/214 --- composer.json | 2 +- composer.lock | 42 ++++++++++++++++++++--------------------- includes/common.inc.php | 24 +++++++++++------------ 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index a851fe6..5c6d433 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "ext-mbstring": "*", "ext-json": "*", - "predis/predis": "v1.1.9", + "predis/predis": "v2.3.0", "paragonie/random_compat": ">=2" }, "minimum-stability": "stable", diff --git a/composer.lock b/composer.lock index 41f9438..f724f31 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ad3fb9bfb043b086870b317dc9eff9b7", + "content-hash": "401ff61cebe5223d003a47192d7c3d6a", "packages": [ { "name": "paragonie/random_compat", @@ -58,27 +58,28 @@ }, { "name": "predis/predis", - "version": "v1.1.9", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/predis/predis.git", - "reference": "c50c3393bb9f47fa012d0cdfb727a266b0818259" + "reference": "bac46bfdb78cd6e9c7926c697012aae740cb9ec9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/predis/predis/zipball/c50c3393bb9f47fa012d0cdfb727a266b0818259", - "reference": "c50c3393bb9f47fa012d0cdfb727a266b0818259", + "url": "https://api.github.com/repos/predis/predis/zipball/bac46bfdb78cd6e9c7926c697012aae740cb9ec9", + "reference": "bac46bfdb78cd6e9c7926c697012aae740cb9ec9", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": "^7.2 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "friendsofphp/php-cs-fixer": "^3.3", + "phpstan/phpstan": "^1.9", + "phpunit/phpunit": "^8.0 || ^9.4" }, "suggest": { - "ext-curl": "Allows access to Webdis when paired with phpiredis", - "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol" + "ext-relay": "Faster connection with in-memory caching (>=0.6.2)" }, "type": "library", "autoload": { @@ -91,19 +92,13 @@ "MIT" ], "authors": [ - { - "name": "Daniele Alessandri", - "email": "suppakilla@gmail.com", - "homepage": "http://clorophilla.net/", - "role": "Creator & Maintainer" - }, { "name": "Till Krüss", "homepage": "https://till.im/", "role": "Maintainer" } ], - "description": "Flexible and feature-complete Redis client for PHP and HHVM", + "description": "A flexible and feature-complete Redis client for PHP.", "homepage": "http://github.com/predis/predis", "keywords": [ "nosql", @@ -112,7 +107,7 @@ ], "support": { "issues": "https://github.com/predis/predis/issues", - "source": "https://github.com/predis/predis/tree/v1.1.9" + "source": "https://github.com/predis/predis/tree/v2.3.0" }, "funding": [ { @@ -120,16 +115,19 @@ "type": "github" } ], - "time": "2021-10-05T19:02:38+00:00" + "time": "2024-11-21T20:00:02+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.1.0" + "platform": { + "ext-mbstring": "*", + "ext-json": "*" + }, + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/includes/common.inc.php b/includes/common.inc.php index c13424b..a92a3ed 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -95,20 +95,20 @@ $server['keys'] = $config['keys']; } -if (!isset($config['scansize'])) { - $config['scansize'] = 1000; -} - -if (!isset($config['scanmax'])) { - $config['scanmax'] = 0; -} - if (!isset($server['scansize'])) { - $server['scansize'] = $config['scansize']; + if (isset($config['scansize'])) { + $server['scansize'] = $config['scansize']; + } else { + $server['scansize'] = 1000; + } } if (!isset($server['scanmax'])) { - $server['scanmax'] = $config['scanmax']; + if (isset($config['scanmax'])) { + $server['scanmax'] = $config['scanmax']; + } else { + $server['scanmax'] = 0; + } } if (!isset($server['serialization'])) { @@ -125,8 +125,8 @@ $config['showEmptyNamespaceAsKey'] = false; } -if (!isset($config['scheme']) || empty($config['scheme'])) { - $config['scheme'] = 'tcp'; +if (!isset($server['scheme']) || empty($server['scheme'])) { + $server['scheme'] = 'tcp'; } // Setup a connection to Redis. From 6f9fae06b4edeaa758113407d90b4a3d2915ad76 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 20 Dec 2024 08:31:12 +0100 Subject: [PATCH 66/70] v1.23.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c6d433..fb69cc8 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.22.1", + "version": "1.23.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [ From dc8fce6df5385c7e3c12e8f10ed40a6d9bd5fb01 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Wed, 26 Mar 2025 11:03:53 +0700 Subject: [PATCH 67/70] Handle permission access errors (#216) --- css/frame.css | 10 +++++ edit.php | 115 +++++++++++++++++++++++++++----------------------- index.php | 8 +++- view.php | 14 +++++- 4 files changed, 92 insertions(+), 55 deletions(-) diff --git a/css/frame.css b/css/frame.css index 8969e10..7cf935d 100644 --- a/css/frame.css +++ b/css/frame.css @@ -52,3 +52,13 @@ float: left; margin: 1em; } + +.exception { +border: 1px solid #ff0000; +background-color: rgba(255, 0, 0, 0.2); +color: #880000; +padding: 10px; +border-radius: 5px; +margin: 20px; +} + diff --git a/edit.php b/edit.php index 4424d24..998012c 100644 --- a/edit.php +++ b/edit.php @@ -34,72 +34,83 @@ die('ERROR: could not encode value'); } - // String - if ($_POST['type'] == 'string') { - $redis->set($key, $value); - } - - // Hash - else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) { - if (strlen($_POST['hkey']) > $config['maxkeylen']) { - die('ERROR: Your hash key is to long (max length is '.$config['maxkeylen'].')'); + try { + // String + if ($_POST['type'] == 'string') { + $redis->set($key, $value); } - if ($edit && !$redis->hExists($key, input_convert($_POST['hkey']))) { - $redis->hDel($key, input_convert($_GET['hkey'])); + // Hash + else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) { + if (strlen($_POST['hkey']) > $config['maxkeylen']) { + die('ERROR: Your hash key is to long (max length is '.$config['maxkeylen'].')'); + } + + if ($edit && !$redis->hExists($key, input_convert($_POST['hkey']))) { + $redis->hDel($key, input_convert($_GET['hkey'])); + } + + $redis->hSet($key, input_convert($_POST['hkey']), $value); } - $redis->hSet($key, input_convert($_POST['hkey']), $value); - } + // List + else if (($_POST['type'] == 'list') && isset($_POST['index'])) { + $size = $redis->lLen($key); + + if (($_POST['index'] == '') || + ($_POST['index'] == $size)) { + // Push it at the end + $redis->rPush($key, $value); + } else if ($_POST['index'] == -1) { + // Push it at the start + $redis->lPush($key, $value); + } else if (($_POST['index'] >= 0) && + ($_POST['index'] < $size)) { + // Overwrite an index + $redis->lSet($key, input_convert($_POST['index']), $value); + } else { + die('ERROR: Out of bounds index'); + } + } - // List - else if (($_POST['type'] == 'list') && isset($_POST['index'])) { - $size = $redis->lLen($key); - - if (($_POST['index'] == '') || - ($_POST['index'] == $size)) { - // Push it at the end - $redis->rPush($key, $value); - } else if ($_POST['index'] == -1) { - // Push it at the start - $redis->lPush($key, $value); - } else if (($_POST['index'] >= 0) && - ($_POST['index'] < $size)) { - // Overwrite an index - $redis->lSet($key, input_convert($_POST['index']), $value); - } else { - die('ERROR: Out of bounds index'); + // Set + else if ($_POST['type'] == 'set') { + if ($_POST['value'] != $_POST['oldvalue']) { + // The only way to edit a Set value is to add it and remove the old value. + $redis->sRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); + $redis->sAdd($key, $value); + } } - } - // Set - else if ($_POST['type'] == 'set') { - if ($_POST['value'] != $_POST['oldvalue']) { - // The only way to edit a Set value is to add it and remove the old value. - $redis->sRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); - $redis->sAdd($key, $value); + // ZSet + else if (($_POST['type'] == 'zset') && isset($_POST['score']) && is_numeric($_POST['score'])) { + // The only way to edit a ZSet value is to add it and remove the old value. + $redis->zRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); + $redis->zAdd($key, input_convert($_POST['score']), $value); } - } - // ZSet - else if (($_POST['type'] == 'zset') && isset($_POST['score']) && is_numeric($_POST['score'])) { - // The only way to edit a ZSet value is to add it and remove the old value. - $redis->zRem($key, encodeOrDecode('save', $key, input_convert($_POST['oldvalue']))); - $redis->zAdd($key, input_convert($_POST['score']), $value); - } + // Refresh the top so the key tree is updated. + require 'includes/header.inc.php'; - // Refresh the top so the key tree is updated. - require 'includes/header.inc.php'; + ?> + + - - +
    +

    getMessage() ?>

    +
    + type($fullkey)) { + $type = ''; + try { + $type = $redis->type($fullkey); + } catch (\Predis\Response\ServerException $th) { + $class[] = 'empty'; + } + switch ($type) { case 'hash': $len = $redis->hLen($fullkey); break; diff --git a/view.php b/view.php index 1836979..0fdb1b5 100644 --- a/view.php +++ b/view.php @@ -17,8 +17,18 @@ die; } -$type = $redis->type($_GET['key']); -$exists = $redis->exists($_GET['key']); +$type = ''; +$exists = false; +try { + $type = $redis->type($_GET['key']); + $exists = $redis->exists($_GET['key']); +} catch (\Predis\Response\ServerException $th) { + ?> +
    +

    getMessage() ?>

    +
    + Date: Sat, 29 Mar 2025 12:04:03 +0700 Subject: [PATCH 68/70] Change TTL input type (#217) --- ttl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttl.php b/ttl.php index 92e6cca..c5d7a88 100644 --- a/ttl.php +++ b/ttl.php @@ -31,7 +31,7 @@

    -> (-1 to remove the TTL) +> (-1 to remove the TTL)

    From 2d977bce2a3225bacf9ab04ba0ca27c5d58324ab Mon Sep 17 00:00:00 2001 From: Wildan M Date: Mon, 31 Mar 2025 11:33:09 +0700 Subject: [PATCH 69/70] Implement ACL login (#218) * Implement ACL login * Make password form optional --- includes/common.inc.php | 3 + includes/config.sample.inc.php | 6 ++ includes/login_acl.inc.php | 100 +++++++++++++++++++++++++++++++++ login.php | 2 +- logout.php | 4 ++ overview.php | 33 ++++++++--- 6 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 includes/login_acl.inc.php diff --git a/includes/common.inc.php b/includes/common.inc.php index a92a3ed..78e791f 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -148,6 +148,9 @@ } } +if (!isset($config['login']) && !empty($config['login_as_acl_auth'])) { + require_once PHPREDIS_ADMIN_PATH . '/includes/login_acl.inc.php'; +} if ($server['db'] != 0) { if (!$redis->select($server['db'])) { diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php index cca5b81..923a60c 100644 --- a/includes/config.sample.inc.php +++ b/includes/config.sample.inc.php @@ -61,6 +61,12 @@ ) ),*/ + // Uncomment to enable login as ACL authentication (won't work if 'login' or 'auth' is also used) + // Only support using one server at this moment. + // If you set the default user off, browsers will be redirected to login page. + // The user and password will be stored in browser as plaintext so using HTTPS is strongly recommended. + // 'login_as_acl_auth' => true, + // Use HTML form/cookie-based auth instead of HTTP Basic/Digest auth 'cookie_auth' => false, diff --git a/includes/login_acl.inc.php b/includes/login_acl.inc.php new file mode 100644 index 0000000..e8b7d72 --- /dev/null +++ b/includes/login_acl.inc.php @@ -0,0 +1,100 @@ +auth($login['username'], $login['password']); + } catch (Predis\Response\ServerException $exception) { + return false; + } + return true; +} + +// This fill will perform HTTP basic authentication. The authentication data will be sent and stored as plaintext +// Please make sure to use HTTPS proxy such as Apache or Nginx to prevent traffic eavesdropping. +function authHttpBasic() +{ + $realm = 'phpRedisAdmin'; + + if (!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { + try { + global $redis; + $redis->ping(); + } catch (Predis\Response\ServerException $exception) { + header('HTTP/1.1 401 Unauthorized'); + header('WWW-Authenticate: Basic realm="' . $realm . '"'); + die('NOAUTH -- Authentication required'); + } + } + + $login = [ + 'username' => $_SERVER['PHP_AUTH_USER'], + 'password' => $_SERVER['PHP_AUTH_PW'], + ]; + + if (!authCheck($login)) { + header('HTTP/1.1 401 Unauthorized'); + header('WWW-Authenticate: Basic realm="' . $realm . '"'); + die('NOAUTH -- Authentication required'); + } + + return $login; +} + +// Perform auth using a standard HTML
    submission and cookies to save login state +function authCookie() +{ + if (!empty($_COOKIE['phpRedisAdminLogin'])) { + // We have a cookie; is it correct? + // Cookie value looks like "username:password-hash" + $login = explode(':', $_COOKIE['phpRedisAdminLogin'], 2); + if (count($login) === 2) { + $login = [ + 'username' => $login[0], + 'password' => $login[1], + ]; + if (authCheck($login)) { + return $login; + } + } + } + + if (isset($_POST['username'], $_POST['password'])) { + // Login form submitted; correctly? + $login = [ + 'username' => $_POST['username'], + 'password' => $_POST['password'], + ]; + + if (authCheck($login)) { + setcookie('phpRedisAdminLogin', $login['username'] . ':' . $login['password']); + // This should be an absolute URL, but that's a bit of a pain to generate; this will work + header("Location: index.php"); + die(); + } + } + + try { + global $redis; + $redis->ping(); + } catch (Predis\Response\ServerException $exception) { + // If we're here, we don't have a valid login cookie and we don't have a + // valid form submission, so redirect to the login page if we aren't + // already on that page + if (!defined('LOGIN_PAGE')) { + header("Location: login.php"); + die(); + } + } + + // We must be on the login page without a valid cookie or submission + return null; +} + +if (!empty($config['cookie_auth'])) { + $login = authCookie(); +} else { + $login = authHttpBasic(); +} diff --git a/login.php b/login.php index a80a24c..5c12301 100644 --- a/login.php +++ b/login.php @@ -33,7 +33,7 @@ > + >
    diff --git a/logout.php b/logout.php index 12cc80b..07e10ae 100644 --- a/logout.php +++ b/logout.php @@ -8,6 +8,10 @@ setcookie('phpRedisAdminLogin', '', 1); header("Location: login.php"); die(); +} else if (isset($config['login_as_acl_auth'])) { + // HTTP Basic auth + header('HTTP/1.1 401 Unauthorized'); + die(''); } else { // HTTP Digest auth $needed_parts = array( diff --git a/overview.php b/overview.php index 3e426db..5c67370 100644 --- a/overview.php +++ b/overview.php @@ -10,16 +10,24 @@ $server['db'] = 0; } - // Setup a connection to Redis. - if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { - $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); + + if (isset($config['login_as_acl_auth'])) { + // Currently only support one server at a time + if ($i > 0) { + break; + } } else { - $redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client('tcp://'.$server['host'].':'.$server['port']); - } - try { - $redis->connect(); - } catch (Predis\CommunicationException $exception) { - $redis = false; + // Setup a connection to Redis. + if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) { + $redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path'])); + } else { + $redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client('tcp://'.$server['host'].':'.$server['port']); + } + try { + $redis->connect(); + } catch (Predis\CommunicationException $exception) { + $redis = false; + } } if(!$redis) { @@ -38,6 +46,9 @@ $info[$i] = $redis->info(); $info[$i]['size'] = $redis->dbSize(); + if (isset($config['login_as_acl_auth'])) { + $info[$i]['username'] = $redis->acl->whoami(); + } if (!isset($info[$i]['Server'])) { $info[$i]['Server'] = array( @@ -83,6 +94,10 @@
    Uptime:
    + +
    Username:
    + +
    Last save:
    Date: Mon, 31 Mar 2025 06:36:23 +0200 Subject: [PATCH 70/70] v1.24.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fb69cc8..3b3ab81 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "erik-dubbelboer/php-redis-admin", "description": "Simple web interface to manage Redis databases.", - "version": "1.23.0", + "version": "1.24.0", "license": "CC-BY-3.0", "homepage": "https://github.com/ErikDubbelboer/phpRedisAdmin", "authors": [