forked from erikdubbelboer/phpRedisAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
249 lines (175 loc) · 8.53 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
require_once 'includes/common.inc.php';
$page['css'][] = 'frame';
$page['js'][] = 'frame';
require 'includes/header.inc.php';
if (!isset($_GET['key'])) {
?>
Invalid key
<?php
require 'includes/footer.inc.php';
die;
}
$type = $redis->type($_GET['key']);
$exists = $redis->exists($_GET['key']);
$count_elements_page = isset($config['count_elements_page']) ? $config['count_elements_page'] : false;
$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) { ?>
<a href="rename.php?s=<?php echo $server['id']?>&key=<?php echo urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
<a href="delete.php?s=<?php echo $server['id']?>&key=<?php echo urlencode($_GET['key'])?>" class="delkey"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
<a href="export.php?s=<?php echo $server['id']?>&key=<?php echo urlencode($_GET['key'])?>"><img src="images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
<?php } ?>
</h2>
<?php
if (!$exists) {
?>
This key does not exist.
<?php
require 'includes/footer.inc.php';
die;
}
$alt = false;
$ttl = $redis->ttl($_GET['key']);
try {
$encoding = $redis->object('encoding', $_GET['key']);
} catch (Exception $e) {
$encoding = null;
}
switch ($type) {
case 'string':
$value = $redis->get($_GET['key']);
$size = strlen($value);
break;
case 'hash':
$values = $redis->hGetAll($_GET['key']);
$size = count($values);
break;
case 'list':
$size = $redis->lLen($_GET['key']);
break;
case 'set':
$values = $redis->sMembers($_GET['key']);
$size = count($values);
break;
case 'zset':
$values = $redis->zRange($_GET['key'], 0, -1);
$size = count($values);
break;
}
if (isset($values) && ($count_elements_page !== false)) {
$values = array_slice($values, $count_elements_page * ($page_num_request - 1), $count_elements_page,true);
}
?>
<table>
<tr><td><div>Type:</div></td><td><div><?php echo format_html($type)?></div></td></tr>
<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?php echo ($ttl == -1) ? 'does not expire' : $ttl?> <a href="ttl.php?s=<?php echo $server['id']?>&key=<?php echo urlencode($_GET['key'])?>&ttl=<?php echo $ttl?>"><img src="images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>
<?php if (!is_null($encoding)) { ?>
<tr><td><div>Encoding:</div></td><td><div><?php echo format_html($encoding)?></div></td></tr>
<?php } ?>
<tr><td><div>Size:</div></td><td><div><?php echo $size?> <?php echo ($type == 'string') ? 'characters' : 'items'?></div></td></tr>
</table>
<p>
<?php
// Build pagination div.
if (($count_elements_page !== false) && in_array($type, array('hash', 'list', 'set', 'zset')) && ($size > $count_elements_page)) {
$pagination = '<div style="width: inherit; word-wrap: break-word;">';
$url = preg_replace('/&page=(\d+)/i', '', $_SERVER['REQUEST_URI']);
for ($i = 0; $i < ceil($size / $count_elements_page); ++$i) {
$page_num = $i + 1;
if ($page_num === $page_num_request) {
$pagination .= $page_num . ' ';
} else {
$pagination .= '<a href="' . $url . '&page=' . $page_num . '">' . $page_num . "</a> ";
}
}
$pagination .= '</div>';
}
if (isset($pagination)) {
echo $pagination;
}
// String
if ($type == 'string') { ?>
<table>
<tr><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
<a href="edit.php?s=<?php echo $server['id']?>&type=string&key=<?php echo 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?s=<?php echo $server['id']?>&type=string&key=<?php echo urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
</table>
<?php }
// Hash
else if ($type == 'hash') { ?>
<table>
<tr><th><div>Key</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr>
<?php foreach ($values as $hkey => $value) { ?>
<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>
<a href="edit.php?s=<?php echo $server['id']?>&type=hash&key=<?php echo urlencode($_GET['key'])?>&hkey=<?php echo urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?s=<?php echo $server['id']?>&type=hash&key=<?php echo urlencode($_GET['key'])?>&hkey=<?php echo urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?php $alt = !$alt; } ?>
<?php }
// List
else if ($type == 'list') { ?>
<table>
<tr><th><div>Index</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr>
<?php
if (($count_elements_page === false) && ($size > $count_elements_page)) {
$start = 0;
$end = $size;
} else {
$start = $count_elements_page * ($page_num_request - 1);
$end = min($start + $count_elements_page, $size);
}
for ($i = $start; $i < $end; ++$i) {
$value = $redis->lIndex($_GET['key'], $i);
?>
<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>
<a href="edit.php?s=<?php echo $server['id']?>&type=list&key=<?php echo urlencode($_GET['key'])?>&index=<?php echo $i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?s=<?php echo $server['id']?>&type=list&key=<?php echo urlencode($_GET['key'])?>&index=<?php echo $i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?php $alt = !$alt; } ?>
<?php }
// Set
else if ($type == 'set') {
?>
<table>
<tr><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr>
<?php foreach ($values as $value) {
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
?>
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $display_value ?></div></td><td><div>
<a href="edit.php?s=<?php echo $server['id']?>&type=set&key=<?php echo urlencode($_GET['key'])?>&value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
</div></td><td><div>
<a href="delete.php?s=<?php echo $server['id']?>&type=set&key=<?php echo urlencode($_GET['key'])?>&value=<?php echo urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?php $alt = !$alt; } ?>
<?php }
// ZSet
else if ($type == 'zset') { ?>
<table>
<tr><th><div>Score</div></th><th><div>Value</div></th><th><div> </div></th><th><div> </div></th></tr>
<?php foreach ($values as $value) {
$score = $redis->zScore($_GET['key'], $value);
$display_value = $redis->exists($value) ? '<a href="view.php?s='.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
?>
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $score?></div></td><td><div><?php echo $display_value ?></div></td><td><div>
<a href="edit.php?s=<?php echo $server['id']?>&type=zset&key=<?php echo urlencode($_GET['key'])?>&score=<?php echo $score?>&value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
<a href="delete.php?s=<?php echo $server['id']?>&type=zset&key=<?php echo urlencode($_GET['key'])?>&value=<?php echo urlencode($value)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
</div></td></tr>
<?php $alt = !$alt; } ?>
<?php }
if ($type != 'string') { ?>
</table>
<p>
<a href="edit.php?s=<?php echo $server['id']?>&type=<?php echo $type?>&key=<?php echo urlencode($_GET['key'])?>" class="add">Add another value</a>
</p>
<?php }
if (isset($pagination)) {
echo $pagination;
}
require 'includes/footer.inc.php';