From e443b88ad93b96e69f48c2ca56c3e7654cdee33c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Sat, 30 Dec 2023 04:12:15 +0800 Subject: [PATCH] phpredisadmin --- plugins/mysql/js/mysql.js | 4 +- plugins/phpmyadmin/index.py | 7 +- plugins/phpredisadmin/conf/config.inc.php | 87 +++ plugins/phpredisadmin/conf/phpredisadmin.conf | 38 ++ plugins/phpredisadmin/ico.png | Bin 0 -> 1426 bytes plugins/phpredisadmin/index.html | 24 + plugins/phpredisadmin/index.py | 520 ++++++++++++++++++ plugins/phpredisadmin/info.json | 16 + plugins/phpredisadmin/install.sh | 90 +++ plugins/phpredisadmin/js/phpredisadmin.js | 172 ++++++ 10 files changed, 954 insertions(+), 4 deletions(-) create mode 100644 plugins/phpredisadmin/conf/config.inc.php create mode 100755 plugins/phpredisadmin/conf/phpredisadmin.conf create mode 100755 plugins/phpredisadmin/ico.png create mode 100755 plugins/phpredisadmin/index.html create mode 100755 plugins/phpredisadmin/index.py create mode 100755 plugins/phpredisadmin/info.json create mode 100755 plugins/phpredisadmin/install.sh create mode 100755 plugins/phpredisadmin/js/phpredisadmin.js diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index bc33dba8f..23fea49fd 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -904,7 +904,7 @@ function openPhpmyadmin(name,username,password){ setTimeout(function(){ $("#toPHPMyAdmin").submit(); - },3000); + },2000); layer.msg('phpMyAdmin['+data.data+']需要手动登录😭',{icon:16,shade: [0.3, '#000'],time:4000}); } else{ @@ -917,7 +917,7 @@ function openPhpmyadmin(name,username,password){ setTimeout(function(){ $("#toPHPMyAdmin").submit(); - },3000); + },2000); } } diff --git a/plugins/phpmyadmin/index.py b/plugins/phpmyadmin/index.py index 4fae2ce15..6ea24e805 100755 --- a/plugins/phpmyadmin/index.py +++ b/plugins/phpmyadmin/index.py @@ -74,8 +74,11 @@ def getHomePage(): ip = '127.0.0.1' if not mw.isAppleSystem(): ip = mw.getLocalIp() - url = 'http://' + ip + ':' + port + \ - '/' + getCfg()['path'] + '/index.php' + + cfg = getCfg() + auth = cfg['username']+':'+cfg['password'] + rand_path = cfg['path'] + url = 'http://' + auth + '@' + ip + ':' + port + '/' + rand_path + '/index.php' return mw.returnJson(True, 'OK', url) except Exception as e: return mw.returnJson(False, '插件未启动!') diff --git a/plugins/phpredisadmin/conf/config.inc.php b/plugins/phpredisadmin/conf/config.inc.php new file mode 100644 index 000000000..ef9c0fea4 --- /dev/null +++ b/plugins/phpredisadmin/conf/config.inc.php @@ -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' => '{$REDIS_PASS}' // 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/plugins/phpredisadmin/conf/phpredisadmin.conf b/plugins/phpredisadmin/conf/phpredisadmin.conf new file mode 100755 index 000000000..d609b249f --- /dev/null +++ b/plugins/phpredisadmin/conf/phpredisadmin.conf @@ -0,0 +1,38 @@ +server +{ + listen 6390; + server_name 127.0.0.1; + index index.html index.htm index.php; + root {$SERVER_PATH}/phpredisadmin; + + #error_page 404 /404.html; + include {$PHP_CONF_PATH}/enable-php-{$PHP_VER}.conf; + + #AUTH_START + auth_basic "Authorization"; + auth_basic_user_file {$SERVER_PATH}/phpredisadmin/app.pass; + #AUTH_END + + location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ + { + expires 30d; + } + + location ~ .*\.(js|css)?$ + { + expires 12h; + } + + location ~ /.*\.(log|pass|json|pl)$ { + deny all; + } + + + location ~ /\. + { + deny all; + } + + access_log {$SERVER_PATH}/phpredisadmin/access.log; + error_log {$SERVER_PATH}/phpredisadmin/error.log; +} \ No newline at end of file diff --git a/plugins/phpredisadmin/ico.png b/plugins/phpredisadmin/ico.png new file mode 100755 index 0000000000000000000000000000000000000000..804758d8e86d818b6c532d2ea911c9500318a48d GIT binary patch literal 1426 zcmV;D1#S9?P)@gyi8n%)#7CLcpFI zjs8sbb|%z{5zC+*QT~+p?rW4kd@#ko{InpaV{6*?*uAt<7YZQ&=HfTEpN*I^Cw|9u zdN|20&t;$@iWspVO8@g`I&4%|QNpXwN*Zb&r$O;I>ItcAyIzM>^ygIooZ5Y><#s0A zid~Ln(2nRpfxHg&5`r0x{-e@WE2wFFs1(bJ(X=( zOUD}cJmtI3Xj`BwZS%4h(n+7bC+TePbED-kfi%Y$MHBR4G)5ar&BOfYOMefl7vf9Z zqk?FGDGCA=AZT66jm9U=NC3OCju%kzinDOFWcd<0(LhxofDgC`-X82pdzsu?HeiY| zLR=rgm+~xK08t`KCBRe6r?(Ey>E07>Llx@-E71&=7G4RG$1;t z_ZbP`AI1*U1Y;vChDAk4Y=o~QvG=}PDelE5al6QK?ESYB-%dCmxJKnB%I@5bil$DY zihaAKN-#k6e1la3$org|O(1_5@qwBUMlcdPGXWfP9^%F#SPYB8xsALDZW0JVx8X1< zgXnYn_mV{Fs;lYHfm;d5sB08+mE+uTT5F9#eNZjzrvUOmt20gDZ^k+X7E?lG6Lfi{ zRdZNh@fv?ta31GCjjEJnihbxVh&}TD#~SKf97cS9d**TE1QZ0(6!3REH(Ux_IVuHG zP)T3MQo5RTdKhr&awb;ZC;HSVZFA;e8=4|rXL>0Jq^gYU7$c~VQeYc((mkMWctxA+J<-fJQXxlB%T7Vt^FiQ6R5$@#Q1 zw!O1PV2m8=8I<9{oC|c2EWGq6&)frCea~w?lV~{Twoz)b>jW~y<|e>1D(T@)jeK7^ zKIx3Odsyy5qhu=y#6m{7UC5|>tT>x|?L2lN&Y`=>62aXNTkArvpFVgx2KN|_{wydA zX5ryU3J-8hTRaLlyOiJY8lr$}o!Jn)b3Au8O9UpY$99A6AlDT9N&%<$K0w4SLP|vn#FE!1dz>7304PPr;zT z>_Q2=yO26fy#(&$U+zK&y{s|-IU6MMDG&GiOf}OhiXR&Z+@jvD64;C!p$JiVPt67b zNl8N>Yb4Lt$}HIgzQ4e*)P*E*Yvct)P^$6-)^*~NW*17LMhr3nw-yRGHgA2eKk6ld zH+E?(i;)xnc-D!pk*=8rj_&sOcO#&neB>F^(HcRztGId~?)rT$CoMYB{WE{qGAdis zO9{`$+_=%ekGb1v@-qo^R5s+U06!teo!`HlKoNP$_894<9GTyL#IMsAM0U|pF8}}k gz<&b&34DKf2hqS7L5RiDJOBUy07*qoM6N<$g3~&v4gdfE literal 0 HcmV?d00001 diff --git a/plugins/phpredisadmin/index.html b/plugins/phpredisadmin/index.html new file mode 100755 index 000000000..184df5c68 --- /dev/null +++ b/plugins/phpredisadmin/index.html @@ -0,0 +1,24 @@ +
+
+
+

服务

+

重写模版

+

主页

+

PHP版本

+

安全设置

+

访问日志

+

错误日志

+

配置

+
+
+
+
+
+ +
+ \ No newline at end of file diff --git a/plugins/phpredisadmin/index.py b/plugins/phpredisadmin/index.py new file mode 100755 index 000000000..fec686545 --- /dev/null +++ b/plugins/phpredisadmin/index.py @@ -0,0 +1,520 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re +import json + +sys.path.append(os.getcwd() + "/class/core") +import mw +import site_api + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'phpredisadmin' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':') + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + + return tmp + + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + + +def getConf(): + return mw.getServerDir() + '/web_conf/nginx/vhost/phpredisadmin.conf' + + +def getConfInc(): + return getServerDir() + "/" + getCfg()['path'] + '/includes/config.inc.php' + + +def getPort(): + file = getConf() + content = mw.readFile(file) + rep = 'listen\s*(.*);' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def getHomePage(): + try: + port = getPort() + ip = '127.0.0.1' + if not mw.isAppleSystem(): + ip = mw.getLocalIp() + + cfg = getCfg() + auth = cfg['username']+':'+cfg['password'] + rand_path = cfg['path'] + url = 'http://' + auth + '@' + ip + ':' + port + '/' + rand_path + '/index.php' + return mw.returnJson(True, 'OK', url) + except Exception as e: + return mw.returnJson(False, '插件未启动!') + + +def getPhpVer(expect=55): + v = site_api.site_api().getPhpVersion() + is_find = False + for i in range(len(v)): + t = str(v[i]['version']) + if (t == expect): + is_find = True + return str(t) + if not is_find: + if len(v) > 1: + return v[1]['version'] + return v[0]['version'] + return str(expect) + + +def getCachePhpVer(): + cacheFile = getServerDir() + '/php.pl' + v = '' + if os.path.exists(cacheFile): + v = mw.readFile(cacheFile) + else: + v = getPhpVer() + mw.writeFile(cacheFile, v) + return v + + +def getRedisPass(): + requirepass = "" + conf = mw.getServerDir() + '/redis/redis.conf' + if os.path.exists(conf): + content = mw.readFile(conf) + rep = "^(requirepass" + ')\s*([.0-9A-Za-z_& ~]+)' + tmp = re.search(rep, content, re.M) + if tmp: + requirepass = tmp.groups()[1] + + return requirepass + +def contentReplace(content): + service_path = mw.getServerDir() + php_ver = getCachePhpVer() + tmp = mw.execShell( + 'cat /dev/urandom | head -n 32 | md5sum | head -c 16') + blowfish_secret = tmp[0].strip() + # print php_ver + php_conf_dir = mw.getServerDir() + '/web_conf/php/conf' + content = content.replace('{$ROOT_PATH}', mw.getRootDir()) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$PHP_CONF_PATH}', php_conf_dir) + content = content.replace('{$PHP_VER}', php_ver) + content = content.replace('{$BLOWFISH_SECRET}', blowfish_secret) + + # REDIS_PASS + rd_pass = getRedisPass() + content = content.replace('{$REDIS_PASS}', rd_pass) + + cfg = getCfg() + + if cfg['choose'] == "mysql": + content = content.replace('{$CHOOSE_DB}', 'mysql') + content = content.replace('{$CHOOSE_DB_DIR}', 'mysql') + elif cfg['choose'] == "mysql-apt": + content = content.replace('{$CHOOSE_DB}', 'mysql') + content = content.replace('{$CHOOSE_DB_DIR}', 'mysql-apt') + elif cfg['choose'] == "mysql-yum": + content = content.replace('{$CHOOSE_DB}', 'mysql') + content = content.replace('{$CHOOSE_DB_DIR}', 'mysql-yum') + else: + content = content.replace('{$CHOOSE_DB}', 'MariaDB') + content = content.replace('{$CHOOSE_DB_DIR}', 'mariadb') + + content = content.replace('{$PMA_PATH}', cfg['path']) + + port = cfg["port"] + rep = 'listen\s*(.*);' + content = re.sub(rep, "listen " + port + ';', content) + return content + + +def initCfg(): + cfg = getServerDir() + "/cfg.json" + if not os.path.exists(cfg): + data = {} + data['port'] = '6390' + data['choose'] = 'mysql' + data['path'] = '' + data['username'] = 'admin' + data['password'] = 'admin' + mw.writeFile(cfg, json.dumps(data)) + + +def setCfg(key, val): + cfg = getServerDir() + "/cfg.json" + data = mw.readFile(cfg) + data = json.loads(data) + data[key] = val + mw.writeFile(cfg, json.dumps(data)) + + +def getCfg(): + cfg = getServerDir() + "/cfg.json" + data = mw.readFile(cfg) + data = json.loads(data) + return data + + +def returnCfg(): + cfg = getServerDir() + "/cfg.json" + data = mw.readFile(cfg) + return data + + +def status(): + conf = getConf() + conf_inc = getConfInc() + # 两个文件都在,才算启动成功 + if os.path.exists(conf) and os.path.exists(conf_inc): + return 'start' + return 'stop' + + +def __release_port(port): + from collections import namedtuple + try: + import firewall_api + firewall_api.firewall_api().addAcceptPortArgs(port, 'phpRedisAdmin默认端口', 'port') + return port + except Exception as e: + return "Release failed {}".format(e) + + +def __delete_port(port): + from collections import namedtuple + try: + import firewall_api + firewall_api.firewall_api().delAcceptPortArgs(port, 'tcp') + return port + except Exception as e: + return "Release failed {}".format(e) + + +def openPort(): + for i in ["6390"]: + __release_port(i) + return True + + +def delPort(): + for i in ["6390"]: + __delete_port(i) + return True + + +def opRestart(): + mw.opWeb('stop') + mw.opWeb('start') + + +def start(): + initCfg() + openPort() + + pra_dir = getServerDir() + "/phpredisadmin" + if os.path.exists(pra_dir): + rand_str = mw.getRandomString(6) + rand_str = rand_str.lower() + pma_dir_dst = pra_dir + "_" + rand_str + mw.execShell("mv " + pra_dir + " " + pma_dir_dst) + setCfg('path', 'phpredisadmin_' + rand_str) + + file_tpl = getPluginDir() + '/conf/phpredisadmin.conf' + file_run = getConf() + if not os.path.exists(file_run): + centent = mw.readFile(file_tpl) + centent = contentReplace(centent) + mw.writeFile(file_run, centent) + + pma_path = getServerDir() + '/app.pass' + if not os.path.exists(pma_path): + username = mw.getRandomString(8) + password = mw.getRandomString(10) + pass_cmd = username + ':' + mw.hasPwd(password) + setCfg('username', username) + setCfg('password', password) + mw.writeFile(pma_path, pass_cmd) + + tmp = getServerDir() + "/" + getCfg()["path"] + '/tmp' + if not os.path.exists(tmp): + os.mkdir(tmp) + mw.execShell("chown -R www:www " + tmp) + + conf_run = getConfInc() + if not os.path.exists(conf_run): + conf_tpl = getPluginDir() + '/conf/config.inc.php' + centent = mw.readFile(conf_tpl) + centent = contentReplace(centent) + mw.writeFile(conf_run, centent) + + log_a = accessLog() + log_e = errorLog() + + for i in [log_a, log_e]: + if os.path.exists(i): + cmd = "echo '' > " + i + mw.execShell(cmd) + + opRestart() + return 'ok' + + +def stop(): + conf = getConf() + if os.path.exists(conf): + os.remove(conf) + delPort() + + opRestart() + return 'ok' + + +def restart(): + return start() + + +def reload(): + file_tpl = getPluginDir() + '/conf/phpredisadmin.conf' + file_run = getConf() + if os.path.exists(file_run): + centent = mw.readFile(file_tpl) + centent = contentReplace(centent) + mw.writeFile(file_run, centent) + return start() + + +def setPhpVer(): + args = getArgs() + + if not 'phpver' in args: + return 'phpver missing' + + cacheFile = getServerDir() + '/php.pl' + mw.writeFile(cacheFile, args['phpver']) + + file_tpl = getPluginDir() + '/conf/phpredisadmin.conf' + file_run = getConf() + + content = mw.readFile(file_tpl) + content = contentReplace(content) + mw.writeFile(file_run, content) + + opRestart() + return 'ok' + + +def getSetPhpVer(): + cacheFile = getServerDir() + '/php.pl' + if os.path.exists(cacheFile): + return mw.readFile(cacheFile).strip() + return '' + + +def getPmaOption(): + data = getCfg() + return mw.returnJson(True, 'ok', data) + + +def getPmaPort(): + try: + port = getPort() + return mw.returnJson(True, 'OK', port) + except Exception as e: + # print(e) + return mw.returnJson(False, '插件未启动!') + + +def setPmaPort(): + args = getArgs() + data = checkArgs(args, ['port']) + if not data[0]: + return data[1] + + port = args['port'] + if port == '80': + return mw.returnJson(False, '80端不能使用!') + + file = getConf() + if not os.path.exists(file): + return mw.returnJson(False, '插件未启动!') + content = mw.readFile(file) + rep = 'listen\s*(.*);' + content = re.sub(rep, "listen " + port + ';', content) + mw.writeFile(file, content) + + setCfg("port", port) + mw.restartWeb() + return mw.returnJson(True, '修改成功!') + + +def setPmaChoose(): + args = getArgs() + data = checkArgs(args, ['choose']) + if not data[0]: + return data[1] + + choose = args['choose'] + setCfg('choose', choose) + + pma_path = getCfg()['path'] + conf_run = getServerDir() + "/" + pma_path + '/config.inc.php' + + conf_tpl = getPluginDir() + '/conf/config.inc.php' + content = mw.readFile(conf_tpl) + content = contentReplace(content) + mw.writeFile(conf_run, content) + + opRestart() + return mw.returnJson(True, '修改成功!') + + +def setPmaUsername(): + args = getArgs() + data = checkArgs(args, ['username']) + if not data[0]: + return data[1] + + username = args['username'] + setCfg('username', username) + + cfg = getCfg() + pma_path = getServerDir() + '/app.pass' + username = mw.getRandomString(10) + pass_cmd = cfg['username'] + ':' + mw.hasPwd(cfg['password']) + mw.writeFile(pma_path, pass_cmd) + + opRestart() + return mw.returnJson(True, '修改成功!') + + +def setPmaPassword(): + args = getArgs() + data = checkArgs(args, ['password']) + if not data[0]: + return data[1] + + password = args['password'] + setCfg('password', password) + + cfg = getCfg() + pma_path = getServerDir() + '/app.pass' + username = mw.getRandomString(10) + pass_cmd = cfg['username'] + ':' + mw.hasPwd(cfg['password']) + mw.writeFile(pma_path, pass_cmd) + + opRestart() + return mw.returnJson(True, '修改成功!') + + +def setPmaPath(): + args = getArgs() + data = checkArgs(args, ['path']) + if not data[0]: + return data[1] + + path = args['path'] + + if len(path) < 5: + return mw.returnJson(False, '不能小于5位!') + + old_path = getServerDir() + "/" + getCfg()['path'] + new_path = getServerDir() + "/" + path + + mw.execShell("mv " + old_path + " " + new_path) + setCfg('path', path) + return mw.returnJson(True, '修改成功!') + + +def accessLog(): + return getServerDir() + '/access.log' + + +def errorLog(): + return getServerDir() + '/error.log' + + +def Version(): + return mw.readFile(getServerDir() + '/version.pl') + + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print(status()) + elif func == 'start': + print(start()) + elif func == 'stop': + print(stop()) + elif func == 'restart': + print(restart()) + elif func == 'reload': + print(reload()) + elif func == 'conf': + print(getConf()) + elif func == 'version': + print(Version()) + elif func == 'get_cfg': + print(returnCfg()) + elif func == 'config_inc': + print(getConfInc()) + elif func == 'get_home_page': + print(getHomePage()) + elif func == 'set_php_ver': + print(setPhpVer()) + elif func == 'get_set_php_ver': + print(getSetPhpVer()) + elif func == 'get_pma_port': + print(getPmaPort()) + elif func == 'set_pma_port': + print(setPmaPort()) + elif func == 'get_pma_option': + print(getPmaOption()) + elif func == 'set_pma_choose': + print(setPmaChoose()) + elif func == 'set_pma_username': + print(setPmaUsername()) + elif func == 'set_pma_password': + print(setPmaPassword()) + elif func == 'set_pma_path': + print(setPmaPath()) + elif func == 'access_log': + print(accessLog()) + elif func == 'error_log': + print(errorLog()) + else: + print('error') diff --git a/plugins/phpredisadmin/info.json b/plugins/phpredisadmin/info.json new file mode 100755 index 000000000..8145858cc --- /dev/null +++ b/plugins/phpredisadmin/info.json @@ -0,0 +1,16 @@ +{ + "title":"phpRedisAdmin", + "tip":"soft", + "name":"phpRedisAdmin", + "type":"运行环境", + "ps":"常用的Redis后台管理", + "versions":["1.19.0"], + "updates":["1.19.0"], + "shell":"install.sh", + "checks":"server/phpredisadmin", + "path": "server/phpredisadmin", + "author":"phpredisadmin", + "home":"https://github.com/ErikDubbelboer/phpRedisAdmin", + "date":"2023-12-30", + "pid": "2" +} \ No newline at end of file diff --git a/plugins/phpredisadmin/install.sh b/plugins/phpredisadmin/install.sh new file mode 100755 index 000000000..bf15eb0d6 --- /dev/null +++ b/plugins/phpredisadmin/install.sh @@ -0,0 +1,90 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + +install_tmp=${rootPath}/tmp/mw_install.pl + + +if [ -f ${rootPath}/bin/activate ];then + source ${rootPath}/bin/activate +fi + +if [ "$sys_os" == "Darwin" ];then + BAK='_bak' +else + BAK='' +fi + +sysName=`uname` +echo "use system: ${sysName}" + +if [ "${sysName}" == "Darwin" ]; then + OSNAME='macos' +elif grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then + OSNAME='centos' +elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then + OSNAME='fedora' +elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then + OSNAME='debian' +elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then + OSNAME='ubuntu' +elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then + OSNAME='raspbian' +else + OSNAME='unknow' +fi + +Install_App() +{ + if [ -d $serverPath/phpredisadmin ];then + exit 0 + fi + + mkdir -p ${serverPath}/phpredisadmin + mkdir -p ${serverPath}/source/phpredisadmin + echo "${1}" > ${serverPath}/phpredisadmin/version.pl + + VER=$1 + + FDIR=phpRedisAdmin-${VER} + FILE=v${VER}.tar.gz + DOWNLOAD=https://github.com/erikdubbelboer/phpRedisAdmin/archive/refs/tags/v${VER}.tar.gz + + + if [ ! -f $serverPath/source/phpredisadmin/$FILE ];then + wget --no-check-certificate -O $serverPath/source/phpredisadmin/$FILE $DOWNLOAD + fi + + if [ ! -d $serverPath/source/phpredisadmin/$FDIR ];then + cd $serverPath/source/phpredisadmin && tar zxvf $FILE + fi + + cp -r $serverPath/source/phpredisadmin/$FDIR $serverPath/phpredisadmin/ + cd $serverPath/phpredisadmin/ && mv $FDIR phpredisadmin + rm -rf $serverPath/source/phpredisadmin/$FDIR + + cd $serverPath/phpredisadmin/phpredisadmin && composer install + + cd ${rootPath} && python3 ${rootPath}/plugins/phpredisadmin/index.py start + echo '安装完成' +} + +Uninstall_App() +{ + cd ${rootPath} && python3 ${rootPath}/plugins/phpredisadmin/index.py stop + + rm -rf ${serverPath}/phpredisadmin + echo '卸载完成' +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App $2 +else + Uninstall_App $2 +fi diff --git a/plugins/phpredisadmin/js/phpredisadmin.js b/plugins/phpredisadmin/js/phpredisadmin.js new file mode 100755 index 000000000..2936c12df --- /dev/null +++ b/plugins/phpredisadmin/js/phpredisadmin.js @@ -0,0 +1,172 @@ +function str2Obj(str){ + var data = {}; + kv = str.split('&'); + for(i in kv){ + v = kv[i].split('='); + data[v[0]] = v[1]; + } + return data; +} + +function pmaPost(method,args,callback){ + + var _args = null; + if (typeof(args) == 'string'){ + _args = JSON.stringify(str2Obj(args)); + } else { + _args = JSON.stringify(args); + } + + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + $.post('/plugins/run', {name:'phpredisadmin', func:method, args:_args}, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + + +function pmaAsyncPost(method,args){ + + var _args = null; + if (typeof(args) == 'string'){ + _args = JSON.stringify(str2Obj(args)); + } else { + _args = JSON.stringify(args); + } + return syncPost('/plugins/run', {name:'phpredisadmin', func:method, args:_args}); +} + +function homePage(){ + pmaPost('get_home_page', '', function(data){ + var rdata = $.parseJSON(data.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + var con = ''; + $(".soft-man-con").html(con); + }); +} + +//phpmyadmin切换php版本 +function phpVer(version) { + + var _version = pmaAsyncPost('get_set_php_ver','') + if (_version['data'] != ''){ + version = _version['data']; + } + + $.post('/site/get_php_version', function(rdata) { + // console.log(rdata); + var body = "
PHP版本
'; + $(".soft-man-con").html(body); + },'json'); +} + +function phpVerChange(type, msg) { + var phpver = $("#phpver").val(); + pmaPost('set_php_ver', 'phpver='+phpver, function(data){ + if ( data.data == 'ok' ){ + layer.msg('设置成功!',{icon:1,time:2000,shade: [0.3, '#000']}); + } else { + layer.msg('设置失败!',{icon:2,time:2000,shade: [0.3, '#000']}); + } + }); +} + + +//phpmyadmin安全设置 +function safeConf() { + pmaPost('get_pma_option', {}, function(rdata){ + var rdata = $.parseJSON(rdata.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:2,time:2000,shade: [0.3, '#000']}); + return; + } + + var cfg = rdata.data; + var con = '
\ + 访问端口\ + \ + \ +
\ +
\ + 用户名\ + \ + \ +
\ +
\ + 密码\ + \ + \ +
\ +
\ +
\ + 路径名\ + \ + \ +
'; + $(".soft-man-con").html(con); + }); +} + + +function setPmaChoose(){ + var choose = $("#access_choose").val(); + pmaPost('set_pma_choose',{'choose':choose}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function setPmaUsername(){ + var username = $("input[name=username]").val(); + pmaPost('set_pma_username',{'username':username}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function setPmaPassword(){ + var password = $("input[name=password]").val(); + pmaPost('set_pma_password',{'password':password}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function setPmaPath(){ + var path = $("input[name=path]").val(); + pmaPost('set_pma_path',{'path':path}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +//修改phpmyadmin端口 +function setPamPort() { + var pmport = $("#pmport").val(); + if (pmport < 80 || pmport > 65535) { + layer.msg('端口范围不合法!', { icon: 2 }); + return; + } + var data = 'port=' + pmport; + + pmaPost('set_pma_port',data, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} \ No newline at end of file