diff --git a/includes/common.inc.php b/includes/common.inc.php
index 85dfe76..6956521 100644
--- a/includes/common.inc.php
+++ b/includes/common.inc.php
@@ -1,11 +1,10 @@
";
+
+$servername = $config['db_host'];
+$username = $config['db_user'];
+$password = $config['db_pass'];
+$dbname = $config['db_name'];
+
+$conn = new mysqli($servername, $username, $password, $dbname);
+if ($conn->connect_error) {
+ die("获取服务列表失败,联系运维!");
+}
+
+$sql = "SELECT * FROM servers";
+$result = $conn->query($sql);
+
+$c_servers = array();
+$sum = array();
+$n = array();
+
+if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ $c_servers['name'] = $row['name'];
+ $c_servers['host'] = $row['host'];
+ $c_servers['port'] = (int)$row['port'];
+ $c_servers['filter'] = $row['filter'];
+ $c_servers['server_id'] = $row['server_id'];
+ array_push($n, $c_servers['server_id']);
+ //array_push($sum, $c_servers);
+ $sum[$c_servers['server_id']] = $c_servers;
+ $c_servers = array();
+ }
+} else {
+ die("服务列表为空,请联系管理员!");
+}
+$conn->close();
+
+$config['servers'] = $sum;
+
+//var_dump($config['servers']);
+//echo "
";
+//die();
if (isset($login['servers'])) {
$i = current($login['servers']);
} else {
- $i = 0;
+ //$i = 0;
+ $i = min($n);
}
-
if (isset($_GET['s']) && is_numeric($_GET['s']) && ($_GET['s'] < count($config['servers']))) {
$i = $_GET['s'];
}
@@ -35,7 +76,6 @@
$server['id'] = $i;
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : false;
-
mb_internal_encoding('utf-8');
diff --git a/includes/config.sample.inc.php b/includes/config.sample.inc.php
index 10ed201..698bf0e 100644
--- a/includes/config.sample.inc.php
+++ b/includes/config.sample.inc.php
@@ -2,39 +2,45 @@
//Copy this file to config.inc.php and make changes to that file to customize your configuration.
$config = array(
- 'servers' => array(
- array(
- 'name' => 'local server', // Optional name.
- 'host' => '127.0.0.1',
- 'port' => 6379,
- 'filter' => '*',
- 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket
- 'path' => '', // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock'
- 'hide' => false, // Optional. Override global setting. Hide empty databases in the database list.
-
- // Optional Redis authentication.
- //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server.
- ),
- /*array(
- 'host' => 'localhost',
- 'port' => 6380
- ),*/
-
- /*array(
- 'name' => 'local db 2',
- 'host' => 'localhost',
- 'port' => 6379,
- 'db' => 1, // Optional database number, see http://redis.io/commands/select
- 'databases' => 1, // Optional number of databases (prevents use of CONFIG command).
- 'filter' => 'something:*', // Show only parts of database for speed or security reasons.
- 'seperator' => '/', // Use a different seperator on this database (default uses config default).
- 'flush' => false, // Set to true to enable the flushdb button for this instance.
- 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
- 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default).
- 'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default).
- ),*/
- ),
+ 'db_host' => 'localhost',
+ 'db_user' => 'tang',
+ 'db_pass' => '123456',
+ 'db_name' => 'phpredis',
+
+ //'servers' => array(
+ // array(
+ // 'name' => 'local server', // Optional name.
+ // 'host' => '127.0.0.1',
+ // 'port' => 6379,
+ // 'filter' => '*',
+ // 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket
+ // 'path' => '', // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock'
+ // 'hide' => false, // Optional. Override global setting. Hide empty databases in the database list.
+
+ // // Optional Redis authentication.
+ // //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server.
+ // ),
+
+ // /*array(
+ // 'host' => 'localhost',
+ // 'port' => 6380
+ // ),*/
+
+ // /*array(
+ // 'name' => 'local db 2',
+ // 'host' => 'localhost',
+ // 'port' => 6379,
+ // 'db' => 1, // Optional database number, see http://redis.io/commands/select
+ // 'databases' => 1, // Optional number of databases (prevents use of CONFIG command).
+ // 'filter' => 'something:*', // Show only parts of database for speed or security reasons.
+ // 'seperator' => '/', // Use a different seperator on this database (default uses config default).
+ // 'flush' => false, // Set to true to enable the flushdb button for this instance.
+ // 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
+ // 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default).
+ // 'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default).
+ // ),*/
+ //),
'seperator' => ':',
@@ -60,6 +66,18 @@
)
),*/
+ 'login' => array(
+ // Username => Password
+ // Multiple combinations can be used
+ 'amin' => array(
+ 'password' => 'adminpassword',
+ ),
+ 'guest' => array(
+ 'password' => 'adminpassword',
+ 'servers' => array(0,1) // Optional list of servers this user can access.
+ )
+ ),
+
// Use HTML form/cookie-based auth instead of HTTP Basic/Digest auth
'cookie_auth' => false,
diff --git a/includes/config.sample.inc.php.old b/includes/config.sample.inc.php.old
new file mode 100644
index 0000000..10ed201
--- /dev/null
+++ b/includes/config.sample.inc.php.old
@@ -0,0 +1,87 @@
+ array(
+ array(
+ 'name' => 'local server', // Optional name.
+ 'host' => '127.0.0.1',
+ 'port' => 6379,
+ 'filter' => '*',
+ 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket
+ 'path' => '', // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock'
+ 'hide' => false, // Optional. Override global setting. Hide empty databases in the database list.
+
+ // Optional Redis authentication.
+ //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server.
+ ),
+
+ /*array(
+ 'host' => 'localhost',
+ 'port' => 6380
+ ),*/
+
+ /*array(
+ 'name' => 'local db 2',
+ 'host' => 'localhost',
+ 'port' => 6379,
+ 'db' => 1, // Optional database number, see http://redis.io/commands/select
+ 'databases' => 1, // Optional number of databases (prevents use of CONFIG command).
+ 'filter' => 'something:*', // Show only parts of database for speed or security reasons.
+ 'seperator' => '/', // Use a different seperator on this database (default uses config default).
+ 'flush' => false, // Set to true to enable the flushdb button for this instance.
+ 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8).
+ 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default).
+ 'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default).
+ ),*/
+ ),
+
+
+ 'seperator' => ':',
+ 'showEmptyNamespaceAsKey' => false,
+
+ // Hide empty databases in the database list (global, valid for all servers unless set at server level)
+ 'hideEmptyDBs' => false,
+
+ // Uncomment to show less information and make phpRedisAdmin fire less commands to the Redis server. Recommended for a really busy Redis server.
+ //'faster' => true,
+
+
+ // Uncomment to enable HTTP authentication
+ /*'login' => array(
+ // Username => Password
+ // Multiple combinations can be used
+ 'admin' => array(
+ 'password' => 'adminpassword',
+ ),
+ 'guest' => array(
+ 'password' => '',
+ 'servers' => array(1) // Optional list of servers this user can access.
+ )
+ ),*/
+
+ // Use HTML form/cookie-based auth instead of HTTP Basic/Digest auth
+ 'cookie_auth' => false,
+
+
+ /*'serialization' => array(
+ 'foo*' => array( // Match like KEYS
+ // Function called when saving to redis.
+ 'save' => function($data) { return json_encode(json_decode($data)); },
+ // Function called when loading from redis.
+ 'load' => function($data) { return json_encode(json_decode($data), JSON_PRETTY_PRINT); },
+ ),
+ ),*/
+
+
+ // You can ignore settings below this point.
+
+ 'maxkeylen' => 100,
+ 'count_elements_page' => 100,
+
+ // Use the old KEYS command instead of SCAN to fetch all keys.
+ 'keys' => false,
+
+ // How many entries to fetch using each SCAN command.
+ 'scansize' => 1000
+);
diff --git a/includes/login.inc.php b/includes/login.inc.php
index 75ed28d..e2b7243 100644
--- a/includes/login.inc.php
+++ b/includes/login.inc.php
@@ -1,5 +1,7 @@
connect_error) {
+ die("获取用户失败,联系运维!");
+ }
+
+ //$conn = new mysqli($servername, $username, $password, $dbname);
+ //if ($conn->connect_error) {
+ // die("连接数据库失败: " . $conn->connect_error);
+ //}
+
+ $sql = "SELECT * FROM users";
+ $result = $conn->query($sql);
+
+ $c_login = array();
+ $c_user = array();
+
+ if ($result->num_rows > 0) {
+ while($row = $result->fetch_assoc()) {
+ $c_users['username'] = $row['username'];
+ $c_users['password'] = $row['password'];
+ $c_servers['servers'] = $row['servers'];
+
+ if (!empty($c_servers['servers'])) {
+ $c_user['password'] = $c_users['password'];
+ $c_user['servers'] = explode(',',$c_servers['servers']);
+ } else {
+ $c_user['password'] = $c_users['password'];
+ }
+ $c_login[$c_users['username']] = $c_user;
+ }
+ } else {
+ die("用户列表为空,请联系管理员!");
+ }
+ $conn->close();
+
+ $config['login'] = $c_login;
+
if (!isset($config['login'][$data['username']])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.uniqid().'",opaque="'.$opaque.'"');
diff --git a/index.php b/index.php
index 933796a..8d75667 100644
--- a/index.php
+++ b/index.php
@@ -192,6 +192,7 @@ function getDbInfo($d, $info, $padding = '') {