Skip to content

Commit e2348fd

Browse files
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
1 parent bccabce commit e2348fd

19 files changed

+43
-71
lines changed

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
}
1414
],
1515
"require": {
16+
"ext-mbstring": "*",
17+
"ext-json": "*",
1618
"predis/predis": "v1.1.9",
1719
"paragonie/random_compat": ">=2"
1820
},

delete.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
43
if (!isset($_POST['post'])) {
54
die('Javascript needs to be enabled for you to delete keys.');
65
}
76

8-
97
require_once 'includes/common.inc.php';
108

9+
global $redis;
10+
global $server;
1111

1212
if (isset($_GET['key'])) {
1313
// String
@@ -61,16 +61,15 @@
6161
}
6262

6363
if (isset($_GET['batch_del'])) {
64-
$keys = $_POST['selected_keys'];
65-
$keys = trim($keys, ',');
66-
if (empty($keys)) die('No keys to delete');
64+
if (empty($_POST['selected_keys'])) {
65+
die('No keys to delete');
66+
}
67+
$keys = json_decode($_POST['selected_keys']);
6768

68-
$keys = explode(',', $keys);
6969
foreach ($keys as $key) {
7070
$redis->del($key);
7171
}
7272

7373
die('?view&s=' . $server['id'] . '&d=' . $server['db'] . '&key=' . urlencode($keys[0]));
7474
}
7575

76-
?>

edit.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
require_once 'includes/common.inc.php';
44

5-
6-
5+
global $redis, $config, $csrfToken, $server;
76

87
// Are we editing or creating a new key?
98
$edit = false;
@@ -192,4 +191,4 @@
192191

193192
require 'includes/footer.inc.php';
194193

195-
?>
194+
?>

export.php

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require_once 'includes/common.inc.php';
44

5+
global $redis, $config, $csrfToken, $server;
56

67
// Export to redis-cli commands
78
function export_redis($key, $filter = false, $transform = false) {

flush.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
43
if (!isset($_POST['post'])) {
54
die('Javascript needs to be enabled for you to flush a database.');
65
}
76

8-
97
require_once 'includes/common.inc.php';
10-
8+
global $redis, $config, $csrfToken, $server;
119

1210
$redis->flushdb();
1311

import.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
// This mess could need some cleanup!
97
if (isset($_POST['commands'])) {

includes/common.inc.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
2-
require dirname(__FILE__) . '/../vendor/autoload.php';
2+
require __DIR__ . '/../vendor/autoload.php';
33

44
define('PHPREDIS_ADMIN_PATH', dirname(__DIR__));
55

6-
76
if (session_status() !== PHP_SESSION_DISABLED) {
87
session_start();
98

@@ -44,7 +43,6 @@
4443
$i = 0;
4544
}
4645

47-
4846
if (isset($_GET['s']) && is_numeric($_GET['s']) && ($_GET['s'] < count($config['servers']))) {
4947
$i = $_GET['s'];
5048
}
@@ -53,10 +51,8 @@
5351
$server['id'] = $i;
5452
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : false;
5553

56-
5754
mb_internal_encoding('utf-8');
5855

59-
6056
if (isset($login, $login['servers'])) {
6157
if (array_search($i, $login['servers']) === false) {
6258
die('You are not allowed to access this database.');
@@ -142,5 +138,3 @@
142138
die('ERROR: Selecting database failed ('.$server['host'].':'.$server['port'].','.$server['db'].')');
143139
}
144140
}
145-
146-
?>

includes/page.inc.php

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
// Returns true when the user is using IE
54
function is_ie() {
65
if (isset($_SERVER['HTTP_USER_AGENT']) &&
@@ -11,9 +10,6 @@ function is_ie() {
1110
}
1211
}
1312

14-
15-
16-
1713
$page = array(
1814
'css' => array('common'),
1915
'js' => array('jquery')

index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4+
global $redis, $config, $csrfToken, $server;
45

56
if($redis) {
67

@@ -33,7 +34,7 @@
3334
continue;
3435
}
3536

36-
$key = explode($server['seperator'], $key);
37+
$key = explode($server['seperator'], $key); //@todo: may be separator ?
3738
if ($config['showEmptyNamespaceAsKey'] && $key[count($key) - 1] == '') {
3839
array_pop($key);
3940
$key[count($key) - 1] .= ':';

info.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
if (isset($_GET['reset'])) {
97
$redis->config('resetstat');
@@ -12,15 +10,10 @@
1210
die;
1311
}
1412

15-
16-
1713
// Fetch the info
1814
$info = $redis->info();
1915
$alt = false;
2016

21-
22-
23-
2417
$page['css'][] = 'frame';
2518
$page['js'][] = 'frame';
2619

js/frame.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ $(function() {
33
window.parent.history.replaceState({}, '', document.location.href.replace('?', '&').replace(/\/([a-z]*)\.php/, '/?$1'));
44
}
55

6-
76
$('#type').change(function(e) {
87
$('#hkeyp' ).css('display', e.target.value == 'hash' ? 'block' : 'none');
98
$('#indexp').css('display', e.target.value == 'list' ? 'block' : 'none');
109
$('#scorep').css('display', e.target.value == 'zset' ? 'block' : 'none');
1110
}).change();
1211

13-
1412
$('.delkey, .delval').click(function(e) {
1513
e.preventDefault();
1614

js/index.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,41 @@ $(function() {
1414
})
1515

1616
$('#sidebar').on('click', 'a', function(e) {
17-
if (e.currentTarget.className.indexOf('batch_del') !== -1){
17+
if (e.currentTarget.className.indexOf('batch_del') !== -1) {
1818
e.preventDefault();
19-
var selected_keys = '';
19+
var selected_keys = [];
2020
$('input[name=checked_keys]:checked').each(function () {
21-
selected_keys += $(this).val() + ',';
21+
selected_keys.push($(this).val());
2222
});
23-
if (!selected_keys) {
23+
if (selected_keys.length == 0) {
2424
alert('Please select the keys you want to delete.');
2525
return;
2626
}
2727
if (confirm('Are you sure you want to delete all selected keys?')) {
2828
$.ajax({
2929
type: "POST",
3030
url: this.href,
31-
data: 'post=1&selected_keys=' + selected_keys + '&csrf=' + phpRedisAdmin_csrfToken,
31+
data: {
32+
post: 1,
33+
selected_keys: JSON.stringify(selected_keys),
34+
csrf: phpRedisAdmin_csrfToken
35+
},
3236
success: function(url) {
3337
top.location.href = top.location.pathname+url;
3438
}
3539
});
3640
}
37-
}else if (e.currentTarget.className.indexOf('deltree') !== -1) {
41+
} else if (e.currentTarget.className.indexOf('deltree') !== -1) {
3842
e.preventDefault();
3943

4044
if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) {
4145
$.ajax({
4246
type: "POST",
4347
url: this.href,
44-
data: 'post=1&csrf=' + phpRedisAdmin_csrfToken,
48+
data: {
49+
post: 1,
50+
csrf: phpRedisAdmin_csrfToken
51+
},
4552
success: function(url) {
4653
top.location.href = top.location.pathname+url;
4754
}
@@ -74,7 +81,10 @@ $(function() {
7481
$.ajax({
7582
type: "POST",
7683
url: href,
77-
data: 'post=1&csrf=' + phpRedisAdmin_csrfToken,
84+
data: {
85+
post: 1,
86+
csrf: phpRedisAdmin_csrfToken
87+
},
7888
success: function() {
7989
window.location.reload();
8090
}

login.php

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
define('LOGIN_PAGE', true);
33

44
require_once 'includes/common.inc.php';
5+
global $redis, $config, $csrfToken, $server;
56

67
$page['css'][] = 'login';
78

logout.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4+
global $redis, $config, $csrfToken, $server;
45

56
if (!empty($config['cookie_auth'])) {
67
// Cookie-based auth

overview.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
$info = array();
97

@@ -109,7 +107,7 @@
109107
</p>
110108

111109
<p>
112-
<a href="http://redis.io/documentation" target="_blank">Redis Documentation</a>
110+
<a href="https://redis.io/documentation" target="_blank">Redis Documentation</a>
113111
</p>
114112
<?php
115113

rename.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
if (isset($_POST['old'], $_POST['key'])) {
97
if (strlen($_POST['key']) > $config['maxkeylen']) {

save.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
$page['css'][] = 'frame';
97
$page['js'][] = 'frame';

ttl.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4-
5-
6-
4+
global $redis, $config, $csrfToken, $server;
75

86
if (isset($_POST['key'], $_POST['ttl'])) {
97
if ($_POST['ttl'] == -1) {
@@ -16,9 +14,6 @@
1614
die;
1715
}
1816

19-
20-
21-
2217
$page['css'][] = 'frame';
2318
$page['js'][] = 'frame';
2419

view.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

33
require_once 'includes/common.inc.php';
4+
global $redis, $config, $csrfToken, $server;
45

56
$page['css'][] = 'frame';
67
$page['js'][] = 'frame';
78

89
require 'includes/header.inc.php';
910

10-
11-
1211
if (!isset($_GET['key'])) {
1312
?>
1413
Invalid key
@@ -18,17 +17,13 @@
1817
die;
1918
}
2019

21-
22-
2320
$type = $redis->type($_GET['key']);
2421
$exists = $redis->exists($_GET['key']);
2522

2623
$count_elements_page = isset($config['count_elements_page']) ? $config['count_elements_page'] : false;
2724
$page_num_request = isset($_GET['page']) ? (int)$_GET['page'] : 1;
2825
$page_num_request = $page_num_request === 0 ? 1 : $page_num_request;
2926

30-
31-
3227
?>
3328
<h2><?php echo format_html($_GET['key'])?>
3429
<?php if ($exists) { ?>
@@ -48,8 +43,6 @@
4843
die;
4944
}
5045

51-
52-
5346
$alt = false;
5447
$ttl = $redis->ttl($_GET['key']);
5548

@@ -59,7 +52,6 @@
5952
$encoding = null;
6053
}
6154

62-
6355
switch ($type) {
6456
case 'string':
6557
$value = $redis->get($_GET['key']);

0 commit comments

Comments
 (0)