forked from erikdubbelboer/phpRedisAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.inc.php
115 lines (76 loc) · 2.34 KB
/
common.inc.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
<?php
if (!class_exists('Redis')) {
die('ERROR: phpredis is required. You can find phpredis at <a href="https://github.com/nicolasff/phpredis">https://github.com/nicolasff/phpredis</a>');
}
// Undo magic quotes (both in keys and values)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
// These includes are needed by each script.
require_once 'config.inc.php';
require_once 'functions.inc.php';
require_once 'page.inc.php';
if (isset($config['login'])) {
require_once 'login.inc.php';
}
// phpredis types to string conversion array.
$redistypes = array(
Redis::REDIS_STRING => 'string',
Redis::REDIS_SET => 'set',
Redis::REDIS_LIST => 'list',
Redis::REDIS_ZSET => 'zset',
Redis::REDIS_HASH => 'hash',
);
if (isset($login['servers'])) {
$i = current($login['servers']);
} else {
$i = 0;
}
if (isset($_GET['s']) && is_numeric($_GET['s']) && ($_GET['s'] < count($config['servers']))) {
$i = $_GET['s'];
}
$server = $config['servers'][$i];
$server['id'] = $i;
if (isset($login, $login['servers'])) {
if (array_search($i, $login['servers']) === false) {
die('You are not allowed to access this database.');
}
foreach ($config['servers'] as $key => $ignore) {
if (array_search($key, $login['servers']) === false) {
unset($config['servers'][$key]);
}
}
}
if (!isset($server['db'])) {
$server['db'] = 0;
}
// Setup a connection to Redis.
$redis = new Redis();
try {
$redis->connect($server['host'], $server['port']);
} catch (Exception $e) {
die('ERROR: Could not connect to Redis ('.$server['host'].':'.$server['port'].')');
}
if (isset($server['auth'])) {
if (!$redis->auth($server['auth'])) {
die('ERROR: Authentication failed ('.$server['host'].':'.$server['port'].')');
}
}
if ($server['db'] != 0) {
if (!$redis->select($server['db'])) {
die('ERROR: Selecting database failed ('.$server['host'].':'.$server['port'].','.$server['db'].')');
}
}
?>