|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once 'common.inc.php'; |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +if (isset($_POST['commands'])) { |
| 9 | + $commands = explode("\n", $_POST['commands']); |
| 10 | + |
| 11 | + foreach ($commands as $command) { |
| 12 | + // The command and it's arguments are always seperated by a space |
| 13 | + $command = explode(' ', trim($command), 2); |
| 14 | + |
| 15 | + if (!isset($command[1])) { |
| 16 | + // It's just an empty line or simple command which we don't support. |
| 17 | + continue; |
| 18 | + } |
| 19 | + |
| 20 | + // Is the key enclosed in ""? |
| 21 | + if ($command[1][0] == '"') { |
| 22 | + // We can't just explode since we might have \" inside the key. So do a preg_split on " with a negative lookbehind assertions to make sure it isn't a \". |
| 23 | + $key = preg_split('/(?<!\\\\)"/', substr($command[1], 1), 2); |
| 24 | + |
| 25 | + // Strip the seperating space |
| 26 | + $key[1] = substr($key[1], 1); |
| 27 | + } else { |
| 28 | + $key = explode(' ', $command[1], 2); |
| 29 | + } |
| 30 | + |
| 31 | + switch ($command[0]) { |
| 32 | + case 'SET': { |
| 33 | + // Trim the optional "" acount th value. |
| 34 | + $redis->set($key[0], trim($key[1], '"')); |
| 35 | + break; |
| 36 | + } |
| 37 | + |
| 38 | + case 'HSET': { |
| 39 | + if ($key[1][0] == '"') { |
| 40 | + // See preg_split above. |
| 41 | + $hkey = preg_split('/(?<!\\\\)"/', substr($key[1], 1), 2); |
| 42 | + |
| 43 | + // Strip the seperating space |
| 44 | + $hkey[1] = substr($hkey[1], 1); |
| 45 | + } else { |
| 46 | + $hkey = explode(' ', $key[1], 2); |
| 47 | + } |
| 48 | + |
| 49 | + $redis->hSet($key[0], $hkey[0], trim($hkey[1], '"')); |
| 50 | + break; |
| 51 | + } |
| 52 | + |
| 53 | + case 'RPUSH': { |
| 54 | + $redis->rPush($key[0], trim($key[1], '"')); |
| 55 | + break; |
| 56 | + } |
| 57 | + |
| 58 | + case 'SADD': { |
| 59 | + $redis->sAdd($key[0], trim($key[1], '"')); |
| 60 | + break; |
| 61 | + } |
| 62 | + |
| 63 | + case 'ZADD': { |
| 64 | + if ($key[1][0] == '"') { |
| 65 | + // See preg_split ebove. |
| 66 | + $score = preg_split('/(?<!\\\\)"/', substr($key[1], 1), 2); |
| 67 | + |
| 68 | + // Strip the seperating space |
| 69 | + $score[1] = substr($score[1], 1); |
| 70 | + } else { |
| 71 | + $score = explode(' ', $key[1], 2); |
| 72 | + } |
| 73 | + |
| 74 | + $redis->zAdd($key[0], $score[0], trim($score[1], '"')); |
| 75 | + break; |
| 76 | + } |
| 77 | + |
| 78 | + // We ignore commands we don't know (Could produce a warning). |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + // Refresh the top so the key tree is updated. |
| 85 | + require 'header.inc.php'; |
| 86 | + |
| 87 | + ?> |
| 88 | + <script> |
| 89 | + top.location.href = top.location.pathname+'?overview&s=<?php echo $server['id']?>'; |
| 90 | + </script> |
| 91 | + <?php |
| 92 | + |
| 93 | + require 'footer.inc.php'; |
| 94 | + die; |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +$page['css'][] = 'frame'; |
| 101 | +$page['js'][] = 'frame'; |
| 102 | + |
| 103 | +require 'header.inc.php'; |
| 104 | + |
| 105 | +?> |
| 106 | +<h2>Import</h2> |
| 107 | +<form action="<?php echo format_html($_SERVER['REQUEST_URI'])?>" method="post"> |
| 108 | + |
| 109 | +<p> |
| 110 | +<label for="commands">Commands:<br> |
| 111 | +<br> |
| 112 | +<span class="info"> |
| 113 | +Valid are:<br> |
| 114 | +SET<br> |
| 115 | +HSET<br> |
| 116 | +RPUSH<br> |
| 117 | +SADD<br> |
| 118 | +ZADD |
| 119 | +</span> |
| 120 | +</label> |
| 121 | +<textarea name="commands" id="commands" cols="80" rows="20"></textarea> |
| 122 | +</p> |
| 123 | + |
| 124 | +<p> |
| 125 | +<input type="submit" class="button" value="Import"> |
| 126 | +</p> |
| 127 | + |
| 128 | +</form> |
| 129 | +<?php |
| 130 | + |
| 131 | +require 'footer.inc.php'; |
| 132 | + |
| 133 | +?> |
0 commit comments