diff options
author | Karel Wintersky <KarelWintersky@users.noreply.github.com> | 2022-10-29 20:24:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-29 20:24:31 +0300 |
commit | e2348fdba7c124b5128684989ddb788ae388db52 (patch) | |
tree | 071e1f8d8f79c32d3de978b86b37754af1e03c62 | |
parent | bccabce045071fbc2962496ec4f02ec3b30b45a6 (diff) |
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
-rw-r--r-- | composer.json | 2 | ||||
-rw-r--r-- | delete.php | 13 | ||||
-rw-r--r-- | edit.php | 5 | ||||
-rw-r--r-- | export.php | 1 | ||||
-rw-r--r-- | flush.php | 4 | ||||
-rw-r--r-- | import.php | 4 | ||||
-rw-r--r-- | includes/common.inc.php | 8 | ||||
-rw-r--r-- | includes/page.inc.php | 4 | ||||
-rw-r--r-- | index.php | 3 | ||||
-rw-r--r-- | info.php | 9 | ||||
-rw-r--r-- | js/frame.js | 2 | ||||
-rw-r--r-- | js/index.js | 26 | ||||
-rw-r--r-- | login.php | 1 | ||||
-rw-r--r-- | logout.php | 1 | ||||
-rw-r--r-- | overview.php | 6 | ||||
-rw-r--r-- | rename.php | 4 | ||||
-rw-r--r-- | save.php | 4 | ||||
-rw-r--r-- | ttl.php | 7 | ||||
-rw-r--r-- | 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" }, @@ -1,13 +1,13 @@ <?php - if (!isset($_POST['post'])) { die('Javascript needs to be enabled for you to delete keys.'); } - require_once 'includes/common.inc.php'; +global $redis; +global $server; if (isset($_GET['key'])) { // String @@ -61,11 +61,11 @@ if (isset($_GET['tree'])) { } if (isset($_GET['batch_del'])) { - $keys = $_POST['selected_keys']; - $keys = trim($keys, ','); - if (empty($keys)) die('No keys to delete'); + if (empty($_POST['selected_keys'])) { + die('No keys to delete'); + } + $keys = json_decode($_POST['selected_keys']); - $keys = explode(',', $keys); foreach ($keys as $key) { $redis->del($key); } @@ -73,4 +73,3 @@ if (isset($_GET['batch_del'])) { die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0])); } -?> @@ -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/header.inc.php'; require 'includes/footer.inc.php'; -?> +?>
\ No newline at end of file @@ -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) { @@ -1,13 +1,11 @@ <?php - if (!isset($_POST['post'])) { die('Javascript needs to be enabled for you to flush a database.'); } - require_once 'includes/common.inc.php'; - +global $redis, $config, $csrfToken, $server; $redis->flushdb(); @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; // This mess could need some cleanup! if (isset($_POST['commands'])) { diff --git a/includes/common.inc.php b/includes/common.inc.php index cfa5059..ae0bd52 100644 --- a/includes/common.inc.php +++ b/includes/common.inc.php @@ -1,9 +1,8 @@ <?php -require dirname(__FILE__) . '/../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; define('PHPREDIS_ADMIN_PATH', dirname(__DIR__)); - if (session_status() !== PHP_SESSION_DISABLED) { session_start(); @@ -44,7 +43,6 @@ if (isset($login['servers'])) { $i = 0; } - if (isset($_GET['s']) && is_numeric($_GET['s']) && ($_GET['s'] < count($config['servers']))) { $i = $_GET['s']; } @@ -53,10 +51,8 @@ $server = $config['servers'][$i]; $server['id'] = $i; $server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : false; - mb_internal_encoding('utf-8'); - if (isset($login, $login['servers'])) { if (array_search($i, $login['servers']) === false) { die('You are not allowed to access this database.'); @@ -142,5 +138,3 @@ if ($server['db'] != 0) { die('ERROR: Selecting database failed ('.$server['host'].':'.$server['port'].','.$server['db'].')'); } } - -?> 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 @@ <?php - // Returns true when the user is using IE function is_ie() { if (isset($_SERVER['HTTP_USER_AGENT']) && @@ -11,9 +10,6 @@ function is_ie() { } } - - - $page = array( 'css' => array('common'), 'js' => array('jquery') @@ -1,6 +1,7 @@ <?php require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; if($redis) { @@ -33,7 +34,7 @@ if($redis) { continue; } - $key = explode($server['seperator'], $key); + $key = explode($server['seperator'], $key); //@todo: may be separator ? if ($config['showEmptyNamespaceAsKey'] && $key[count($key) - 1] == '') { array_pop($key); $key[count($key) - 1] .= ':'; @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; if (isset($_GET['reset'])) { $redis->config('resetstat'); @@ -12,15 +10,10 @@ if (isset($_GET['reset'])) { 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(); } @@ -2,6 +2,7 @@ define('LOGIN_PAGE', true); require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; $page['css'][] = 'login'; @@ -1,6 +1,7 @@ <?php require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; if (!empty($config['cookie_auth'])) { // Cookie-based auth diff --git a/overview.php b/overview.php index 007e2d6..3e426db 100644 --- a/overview.php +++ b/overview.php @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; $info = array(); @@ -109,7 +107,7 @@ require 'includes/header.inc.php'; </p> <p> -<a href="http://redis.io/documentation" target="_blank">Redis Documentation</a> +<a href="https://redis.io/documentation" target="_blank">Redis Documentation</a> </p> <?php @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; if (isset($_POST['old'], $_POST['key'])) { if (strlen($_POST['key']) > $config['maxkeylen']) { @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; $page['css'][] = 'frame'; $page['js'][] = 'frame'; @@ -1,9 +1,7 @@ <?php require_once 'includes/common.inc.php'; - - - +global $redis, $config, $csrfToken, $server; if (isset($_POST['key'], $_POST['ttl'])) { if ($_POST['ttl'] == -1) { @@ -16,9 +14,6 @@ if (isset($_POST['key'], $_POST['ttl'])) { die; } - - - $page['css'][] = 'frame'; $page['js'][] = 'frame'; @@ -1,14 +1,13 @@ <?php require_once 'includes/common.inc.php'; +global $redis, $config, $csrfToken, $server; $page['css'][] = 'frame'; $page['js'][] = 'frame'; require 'includes/header.inc.php'; - - if (!isset($_GET['key'])) { ?> Invalid key @@ -18,8 +17,6 @@ if (!isset($_GET['key'])) { die; } - - $type = $redis->type($_GET['key']); $exists = $redis->exists($_GET['key']); @@ -27,8 +24,6 @@ $count_elements_page = isset($config['count_elements_page']) ? $config['count_el $page_num_request = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page_num_request = $page_num_request === 0 ? 1 : $page_num_request; - - ?> <h2><?php echo format_html($_GET['key'])?> <?php if ($exists) { ?> @@ -48,8 +43,6 @@ if (!$exists) { die; } - - $alt = false; $ttl = $redis->ttl($_GET['key']); @@ -59,7 +52,6 @@ try { $encoding = null; } - switch ($type) { case 'string': $value = $redis->get($_GET['key']); |