Skip to content

Commit

Permalink
limit keys to 30 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Jul 13, 2011
1 parent bce70f8 commit 1c994bd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
6 changes: 5 additions & 1 deletion common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@


$redis = new Redis();
if (!$redis->connect($config['host'], $config['port'])) {

try {
$redis->connect($config['host'], $config['port']);
} catch (Exception $e) {
die('ERROR: Could not connect to Redis');
}


if (isset($config['auth'])) {
if (!$redis->auth($config['auth'])) {
die('ERROR: Authentication failed.');
Expand Down
2 changes: 1 addition & 1 deletion delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
require 'header.inc.php';
?>
<script>
top.location.href = top.location.pathname+'?view&key=<?=format_html($_GET['key'])?>';
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_GET['key'])?>';
</script>
<?
require 'footer.inc.php';
Expand Down
16 changes: 12 additions & 4 deletions edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@



if (isset($_POST['type'], $_POST['key'], $_POST['value'])) {
while (isset($_POST['type'], $_POST['key'], $_POST['value'])) {
if (strlen($_POST['key']) > 30) {
break;
}

if ($_POST['type'] == 'string') {
$redis->set($_POST['key'], $_POST['value']);
} else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) {
if (strlen($_POST['hkey']) > 30) {
break;
}

$redis->hSet($_POST['key'], $_POST['hkey'], $_POST['value']);
} else if (($_POST['type'] == 'list') && isset($_POST['index'])) {
$size = $redis->lSize($_POST['key']);
Expand All @@ -29,7 +37,7 @@
require 'header.inc.php';
?>
<script>
top.location.href = top.location.pathname+'?view&key=<?=format_html($_POST['key'])?>';
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_POST['key'])?>';
</script>
<?
require 'footer.inc.php';
Expand Down Expand Up @@ -74,12 +82,12 @@

<p>
<label for="key">Key:</label>
<input type="text" name="key" id="key" size="30" <?=isset($_GET['key']) ? 'value="'.format_html($_GET['key']).'"' : ''?>>
<input type="text" name="key" id="key" size="30" maxlength="30" <?=isset($_GET['key']) ? 'value="'.format_html($_GET['key']).'"' : ''?>>
</p>

<p id="hkeyp">
<label for="khey">Hash key:</label>
<input type="text" name="hkey" id="hkey" size="30" <?=isset($_GET['hkey']) ? 'value="'.format_html($_GET['hkey']).'"' : ''?>>
<input type="text" name="hkey" id="hkey" size="30" maxlength="30" <?=isset($_GET['hkey']) ? 'value="'.format_html($_GET['hkey']).'"' : ''?>>
</p>

<p id="indexp">
Expand Down
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
$dirs = array();

foreach ($keys as $key) {
if (strlen($key) > 30) {
continue;
}

$key = explode($config['seperator'], $key);

$a = &$dirs;
Expand Down Expand Up @@ -76,7 +80,7 @@ function print_tree($item, $key, $all, $last) {

?>
<li<?=empty($class) ? '' : ' class="'.implode(' ', $class).'"'?>>
<a href="?view&amp;key=<?=format_html($all)?>"><?=format_html($key)?><?
<a href="?view&amp;key=<?=urlencode($all)?>"><?=format_html($key)?><?

$len = false;

Expand Down
8 changes: 6 additions & 2 deletions rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@



if (isset($_POST['old'], $_POST['key'])) {
while (isset($_POST['old'], $_POST['key'])) {
if (strlen($_POST['key']) > 30) {
break;
}

$redis->rename($_POST['old'], $_POST['key']);

require 'header.inc.php';
?>
<script>
top.location.href = top.location.pathname+'?view&key=<?=format_html($_POST['key'])?>';
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_POST['key'])?>';
</script>
<?
require 'footer.inc.php';
Expand Down
30 changes: 15 additions & 15 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<?
if ($exists) {
?>
<a href="rename.php?key=<?=format_html($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
<a href="delete.php?key=<?=format_html($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="export.php?key=<?=format_html($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
<a href="rename.php?key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
<a href="delete.php?key=<?=urlencode($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="export.php?key=<?=urlencode($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
<?
}
?>
Expand Down Expand Up @@ -67,7 +67,7 @@

<tr><td><div>Type:</div></td><td><div><?=format_html($type)?></div></td></tr>

<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="ttl.php?key=<?=format_html($_GET['key'])?>&amp;ttl=<?=$ttl?>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>
<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="ttl.php?key=<?=urlencode($_GET['key'])?>&amp;ttl=<?=$ttl?>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>

<tr><td><div>Encoding:</div></td><td><div><?=format_html($encoding)?></div></td></tr>

Expand All @@ -82,9 +82,9 @@
?>
<table>
<tr><td><div><?=nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?type=string&amp;key=<?=format_html($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="edit.php?type=string&amp;key=<?=urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?type=string&amp;key=<?=format_html($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="delete.php?type=string&amp;key=<?=urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
</table>
<?
Expand All @@ -97,9 +97,9 @@
foreach ($values as $hkey => $value) {
?>
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=format_html($hkey)?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?type=hash&amp;key=<?=format_html($_GET['key'])?>&amp;hkey=<?=format_html($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="edit.php?type=hash&amp;key=<?=urlencode($_GET['key'])?>&amp;hkey=<?=urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?type=hash&amp;key=<?=format_html($_GET['key'])?>&amp;hkey=<?=format_html($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="delete.php?type=hash&amp;key=<?=urlencode($_GET['key'])?>&amp;hkey=<?=urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?

Expand All @@ -116,9 +116,9 @@

?>
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$i?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?type=list&amp;key=<?=format_html($_GET['key'])?>&amp;index=<?=$i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="edit.php?type=list&amp;key=<?=urlencode($_GET['key'])?>&amp;index=<?=$i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?type=list&amp;key=<?=format_html($_GET['key'])?>&amp;index=<?=$i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="delete.php?type=list&amp;key=<?=urlencode($_GET['key'])?>&amp;index=<?=$i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?

Expand All @@ -133,9 +133,9 @@
foreach ($values as $value) {
?>
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?type=set&amp;key=<?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="edit.php?type=set&amp;key=<?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?type=set&amp;key=<?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="delete.php?type=set&amp;key=<?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?

Expand All @@ -152,8 +152,8 @@

?>
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$score?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?type=zset&amp;key=<?=format_html($_GET['key'])?>&amp;score=<?=$score?>&amp;value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="delete.php?type=zset&amp;key=<?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="edit.php?type=zset&amp;key=<?=urlencode($_GET['key'])?>&amp;score=<?=$score?>&amp;value=<?=urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="delete.php?type=zset&amp;key=<?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?

Expand All @@ -166,7 +166,7 @@
</table>

<p>
<a href="edit.php?type=<?=$type?>&amp;key=<?=format_html($_GET['key'])?>" class="add">Add another value</a>
<a href="edit.php?type=<?=$type?>&amp;key=<?=urlencode($_GET['key'])?>" class="add">Add another value</a>
</p>
<?
}
Expand Down

0 comments on commit 1c994bd

Please sign in to comment.