Skip to content

Commit d979128

Browse files
1 parent 20ba940 commit d979128

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

edit.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
// String
3131
if ($_POST['type'] == 'string') {
32-
$redis->set($_POST['key'], $_POST['value']);
32+
$redis->set(input_convert($_POST['key']), input_convert($_POST['value']));
3333
}
3434

3535
// Hash
@@ -38,26 +38,26 @@
3838
die('ERROR: Your hash key is to long (max length is '.$config['maxkeylen'].')');
3939
}
4040

41-
if ($edit && !$redis->hExists($_POST['key'], $_POST['hkey'])) {
42-
$redis->hDel($_POST['key'], $_GET['hkey']);
41+
if ($edit && !$redis->hExists(input_convert($_POST['key']), input_convert($_POST['hkey']))) {
42+
$redis->hDel(input_convert($_POST['key']), input_convert($_GET['hkey']));
4343
}
4444

45-
$redis->hSet($_POST['key'], $_POST['hkey'], $_POST['value']);
45+
$redis->hSet(input_convert($_POST['key']), input_convert($_POST['hkey']), input_convert($_POST['value']));
4646
}
4747

4848
// List
4949
else if (($_POST['type'] == 'list') && isset($_POST['index'])) {
50-
$size = $redis->lLen($_POST['key']);
50+
$size = $redis->lLen(input_convert($_POST['key']));
5151

5252
if (($_POST['index'] == '') ||
5353
($_POST['index'] == $size) ||
5454
($_POST['index'] == -1)) {
5555
// Push it at the end
56-
$redis->rPush($_POST['key'], $_POST['value']);
56+
$redis->rPush(input_convert($_POST['key']), input_convert($_POST['value']));
5757
} else if (($_POST['index'] >= 0) &&
5858
($_POST['index'] < $size)) {
5959
// Overwrite an index
60-
$redis->lSet($_POST['key'], $_POST['index'], $_POST['value']);
60+
$redis->lSet(input_convert($_POST['key']), input_convert($_POST['index']), input_convert($_POST['value']));
6161
} else {
6262
die('ERROR: Out of bounds index');
6363
}
@@ -67,17 +67,17 @@
6767
else if ($_POST['type'] == 'set') {
6868
if ($_POST['value'] != $_POST['oldvalue']) {
6969
// The only way to edit a Set value is to add it and remove the old value.
70-
$redis->sRem($_POST['key'], $_POST['oldvalue']);
71-
$redis->sAdd($_POST['key'], $_POST['value']);
70+
$redis->sRem(input_convert($_POST['key']), input_convert($_POST['oldvalue']));
71+
$redis->sAdd(input_convert($_POST['key']), input_convert($_POST['value']));
7272
}
7373
}
7474

7575
// ZSet
7676
else if (($_POST['type'] == 'zset') && isset($_POST['score'])) {
7777
if ($_POST['value'] != $_POST['oldvalue']) {
7878
// The only way to edit a ZSet value is to add it and remove the old value.
79-
$redis->zRem($_POST['key'], $_POST['oldvalue']);
80-
$redis->zAdd($_POST['key'], $_POST['score'], $_POST['value']);
79+
$redis->zRem(input_convert($_POST['key']), input_convert($_POST['oldvalue']));
80+
$redis->zAdd(input_convert($_POST['key']), input_convert($_POST['score']), input_convert($_POST['value']));
8181
}
8282
}
8383

includes/common.inc.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555

5656
$server = $config['servers'][$i];
5757
$server['id'] = $i;
58-
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : mb_internal_encoding();
58+
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : false;
59+
60+
61+
mb_internal_encoding('utf-8');
5962

6063

6164
if (isset($login, $login['servers'])) {

includes/config.sample.inc.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
$config = array(
55
'servers' => array(
66
array(
7-
'name' => 'local server', // Optional name.
8-
'host' => '127.0.0.1',
9-
'port' => 6379,
7+
'name' => 'local server', // Optional name.
8+
'host' => '127.0.0.1',
9+
'port' => 6379,
1010
'filter' => '*',
1111

1212
// Optional Redis authentication.
@@ -19,14 +19,14 @@
1919
),*/
2020

2121
/*array(
22-
'name' => 'local db 2',
23-
'host' => 'localhost',
24-
'port' => 6379,
25-
'db' => 1, // Optional database number, see http://redis.io/commands/select
26-
'filter' => 'something:*', // Show only parts of database for speed or security reasons
27-
'seperator' => '/', // Use a different seperator on this database
28-
'flush' => false, // Set to true to enable the flushdb button for this instance.
29-
'encoding' => 'cp1251', // Set for view values in other encoding
22+
'name' => 'local db 2',
23+
'host' => 'localhost',
24+
'port' => 6379,
25+
'db' => 1, // Optional database number, see http://redis.io/commands/select
26+
'filter' => 'something:*', // Show only parts of database for speed or security reasons.
27+
'seperator' => '/', // Use a different seperator on this database.
28+
'flush' => false, // Set to true to enable the flushdb button for this instance.
29+
'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
3030
),*/
3131
),
3232

includes/functions.inc.php

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

3-
function format_html($str, $from_encoding = FALSE) {
4-
$res = $from_encoding ? mb_convert_encoding($str, 'utf-8', $from_encoding) : $str;
3+
function format_html($str) {
4+
global $server;
5+
6+
if (isset($server['charset']) && $server['charset']) {
7+
$res = mb_convert_encoding($str, 'utf-8', $server['charset']);
8+
} else {
9+
$res = $str;
10+
}
11+
512
$res = htmlentities($res, defined('ENT_SUBSTITUTE') ? (ENT_QUOTES | ENT_SUBSTITUTE) : ENT_QUOTES, 'utf-8');
13+
614
return ($res || !$str) ? $res : '(' . strlen($str) . ' bytes)';
715
}
816

17+
18+
function input_convert($str) {
19+
if (isset($server['charset']) && $server['charset']) {
20+
return mb_convert_encoding($str, $server['charset'], 'utf-8');
21+
} else {
22+
return $str;
23+
}
24+
}
25+
26+
927
function format_ago($time, $ago = false) {
1028
$minute = 60;
1129
$hour = $minute * 60;

view.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
if ($type == 'string') { ?>
138138

139139
<table>
140-
<tr><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
140+
<tr><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
141141
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=string&amp;key=<?php echo urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
142142
</div></td><td><div>
143143
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=string&amp;key=<?php echo urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -155,7 +155,7 @@
155155
<tr><th><div>Key</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
156156

157157
<?php foreach ($values as $hkey => $value) { ?>
158-
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($hkey, $server['charset'])?></div></td><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
158+
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($hkey)?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
159159
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=hash&amp;key=<?php echo urlencode($_GET['key'])?>&amp;hkey=<?php echo urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
160160
</div></td><td><div>
161161
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=hash&amp;key=<?php echo urlencode($_GET['key'])?>&amp;hkey=<?php echo urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -183,7 +183,7 @@
183183
for ($i = $start; $i < $end; ++$i) {
184184
$value = $redis->lIndex($_GET['key'], $i);
185185
?>
186-
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
186+
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
187187
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
188188
</div></td><td><div>
189189
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -202,7 +202,7 @@
202202
<tr><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
203203

204204
<?php foreach ($values as $value) {
205-
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value, $server['charset'])).'</a>' : nl2br(format_html($value, $server['charset']));
205+
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
206206
?>
207207
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $display_value ?></div></td><td><div>
208208
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=set&amp;key=<?php echo urlencode($_GET['key'])?>&amp;value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
@@ -223,7 +223,7 @@
223223

224224
<?php foreach ($values as $value) {
225225
$score = $redis->zScore($_GET['key'], $value);
226-
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value, $server['charset'])).'</a>' : nl2br(format_html($value, $server['charset']));
226+
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
227227
?>
228228
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $score?></div></td><td><div><?php echo $display_value ?></div></td><td><div>
229229
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=zset&amp;key=<?php echo urlencode($_GET['key'])?>&amp;score=<?php echo $score?>&amp;value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>

0 commit comments

Comments
 (0)