diff --git a/plugins/mail/index.html b/plugins/mail/index.html
index b257f933f..7804682f8 100755
--- a/plugins/mail/index.html
+++ b/plugins/mail/index.html
@@ -12,5 +12,5 @@
\ No newline at end of file
diff --git a/plugins/redis/config/redis.conf b/plugins/redis/config/redis.conf
index 30c63fff0..fae7a8a76 100644
--- a/plugins/redis/config/redis.conf
+++ b/plugins/redis/config/redis.conf
@@ -1,6 +1,9 @@
daemonize yes
pidfile {$SERVER_PATH}/redis/redis_6379.pid
+
+bind 127.0.0.1
port 6379
+requirepass admin
timeout 0
tcp-keepalive 0
diff --git a/plugins/redis/index.html b/plugins/redis/index.html
index dfa65bf45..f7eb39a90 100755
--- a/plugins/redis/index.html
+++ b/plugins/redis/index.html
@@ -1,10 +1,12 @@
+
\ No newline at end of file
diff --git a/plugins/redis/index.py b/plugins/redis/index.py
index 671d9b98d..f3664256f 100755
--- a/plugins/redis/index.py
+++ b/plugins/redis/index.py
@@ -4,6 +4,7 @@ import sys
import io
import os
import time
+import re
sys.path.append(os.getcwd() + "/class/core")
import mw
@@ -47,7 +48,7 @@ def getInitDTpl():
def getArgs():
- args = sys.argv[2:]
+ args = sys.argv[3:]
tmp = {}
args_len = len(args)
@@ -153,7 +154,19 @@ def reload():
def runInfo():
+ requirepass = ""
+
+ conf = getServerDir() + '/redis.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]
+
cmd = getServerDir() + "/bin/redis-cli info"
+ if requirepass != "":
+ cmd = getServerDir() + '/bin/redis-cli -a "' + requirepass + '" info'
+
data = mw.execShell(cmd)[0]
res = [
'tcp_port',
@@ -202,7 +215,6 @@ def initdInstall():
def initdUinstall():
-
if mw.isAppleSystem():
return "Apple Computer does not support"
@@ -213,6 +225,69 @@ def initdUinstall():
def runLog():
return getServerDir() + '/data/redis.log'
+
+def getRedisConfInfo():
+ conf = getServerDir() + '/redis.conf'
+ content = mw.readFile(conf)
+
+ gets = [
+ {'name': 'bind', 'type': 2, 'ps': '绑定IP(修改绑定IP可能会存在安全隐患)'},
+ {'name': 'port', 'type': 2, 'ps': '绑定端口'},
+ {'name': 'timeout', 'type': 2, 'ps': '空闲链接超时时间,0表示不断开'},
+ {'name': 'maxclients', 'type': 2, 'ps': '最大输入时间'},
+ {'name': 'databases', 'type': 2, 'ps': '数据库数量'},
+ {'name': 'requirepass', 'type': 2, 'ps': 'redis密码,留空代表没有设置密码'},
+ {'name': 'maxmemory', 'type': 2, 'ps': 'MB,最大使用内存,0表示不限制'}
+ ]
+ content = mw.readFile(conf)
+
+ result = []
+ for g in gets:
+ rep = "^(" + g['name'] + ')\s*([.0-9A-Za-z_& ~]+)'
+ tmp = re.search(rep, content, re.M)
+ if not tmp:
+ g['value'] = ''
+ result.append(g)
+ continue
+ g['value'] = tmp.groups()[1]
+ if g['name'] == 'maxmemory':
+ g['value'] = g['value'].strip("mb")
+ result.append(g)
+
+ return result
+
+
+def getRedisConf():
+ data = getRedisConfInfo()
+ return mw.getJson(data)
+
+
+def submitRedisConf():
+ gets = ['bind', 'port', 'timeout', 'maxclients',
+ 'databases', 'requirepass', 'maxmemory']
+ args = getArgs()
+ conf = getServerDir() + '/redis.conf'
+ content = mw.readFile(conf)
+ for g in gets:
+ if g in args:
+ rep = g + '\s*([.0-9A-Za-z_& ~]+)'
+ val = g + ' ' + args[g]
+
+ if g == 'maxmemory':
+ val = g + ' ' + args[g] + "mb"
+
+ if g == 'requirepass' and args[g] == '':
+ content = re.sub('requirepass', '#requirepass', content)
+ if g == 'requirepass' and args[g] != '':
+ content = re.sub('#requirepass', 'requirepass', content)
+ content = re.sub(rep, val, content)
+
+ if g != 'requirepass':
+ content = re.sub(rep, val, content)
+ mw.writeFile(conf, content)
+ reload()
+ return mw.returnJson(True, '设置成功')
+
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
@@ -237,5 +312,9 @@ if __name__ == "__main__":
print(getConf())
elif func == 'run_log':
print(runLog())
+ elif func == 'get_redis_conf':
+ print(getRedisConf())
+ elif func == 'submit_redis_conf':
+ print(submitRedisConf())
else:
print('error')
diff --git a/plugins/redis/js/redis.js b/plugins/redis/js/redis.js
new file mode 100755
index 000000000..63b3d73e0
--- /dev/null
+++ b/plugins/redis/js/redis.js
@@ -0,0 +1,149 @@
+
+function str2Obj(str){
+ var data = {};
+ kv = str.split('&');
+ for(i in kv){
+ v = kv[i].split('=');
+ data[v[0]] = v[1];
+ }
+ return data;
+}
+
+function redisPost(method, version, args,callback){
+ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
+
+ var req_data = {};
+ req_data['name'] = 'redis';
+ req_data['func'] = method;
+ req_data['version'] = version;
+
+ if (typeof(args) == 'string'){
+ req_data['args'] = JSON.stringify(str2Obj(args));
+ } else {
+ req_data['args'] = JSON.stringify(args);
+ }
+
+ $.post('/plugins/run', req_data, function(data) {
+ layer.close(loadT);
+ if (!data.status){
+ //错误展示10S
+ layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']});
+ return;
+ }
+
+ if(typeof(callback) == 'function'){
+ callback(data);
+ }
+ },'json');
+}
+
+function redisPostCallbak(method, version, args,callback){
+ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
+
+ var req_data = {};
+ req_data['name'] = 'redis';
+ req_data['func'] = method;
+ args['version'] = version;
+
+ if (typeof(args) == 'string'){
+ req_data['args'] = JSON.stringify(str2Obj(args));
+ } else {
+ req_data['args'] = JSON.stringify(args);
+ }
+
+ $.post('/plugins/callback', req_data, 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');
+}
+
+//redis负载状态 start
+function redisStatus(version) {
+
+ redisPost('run_info',version, {},function(data){
+ var rdata = $.parseJSON(data.data);
+ hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2);
+ var con = '
\
+
\
+ | 字段 | 当前值 | 说明 | \
+ \
+ | uptime_in_days | ' + rdata.uptime_in_days + ' | 已运行天数 |
\
+ | tcp_port | ' + rdata.tcp_port + ' | 当前监听端口 |
\
+ | connected_clients | ' + rdata.connected_clients + ' | 连接的客户端数量 |
\
+ | used_memory_rss | ' + toSize(rdata.used_memory_rss) + ' | Redis当前占用的系统内存总量 |
\
+ | used_memory | ' + toSize(rdata.used_memory) + ' | Redis当前已分配的内存总量 |
\
+ | used_memory_peak | ' + toSize(rdata.used_memory_peak) + ' | Redis历史分配内存的峰值 |
\
+ | mem_fragmentation_ratio | ' + rdata.mem_fragmentation_ratio + '% | 内存碎片比率 |
\
+ | total_connections_received | ' + rdata.total_connections_received + ' | 运行以来连接过的客户端的总数量 |
\
+ | total_commands_processed | ' + rdata.total_commands_processed + ' | 运行以来执行过的命令的总数量 |
\
+ | instantaneous_ops_per_sec | ' + rdata.instantaneous_ops_per_sec + ' | 服务器每秒钟执行的命令数量 |
\
+ | keyspace_hits | ' + rdata.keyspace_hits + ' | 查找数据库键成功的次数 |
\
+ | keyspace_misses | ' + rdata.keyspace_misses + ' | 查找数据库键失败的次数 |
\
+ | hit | ' + hit + '% | 查找数据库键命中率 |
\
+ | latest_fork_usec | ' + rdata.latest_fork_usec + ' | 最近一次 fork() 操作耗费的微秒数 |
\
+ \
+
';
+ $(".soft-man-con").html(con);
+ });
+}
+//redis负载状态 end
+
+//配置修改
+function getRedisConfig(version) {
+ redisPost('get_redis_conf', version,'',function(data){
+ // console.log(data);
+ var rdata = $.parseJSON(data.data);
+ // console.log(rdata);
+ var mlist = '';
+ for (var i = 0; i < rdata.length; i++) {
+ var w = '70'
+ if (rdata[i].name == 'error_reporting') w = '250';
+ var ibody = '
';
+ switch (rdata[i].type) {
+ case 0:
+ var selected_1 = (rdata[i].value == 1) ? 'selected' : '';
+ var selected_0 = (rdata[i].value == 0) ? 'selected' : '';
+ ibody = '
'
+ break;
+ case 1:
+ var selected_1 = (rdata[i].value == 'On') ? 'selected' : '';
+ var selected_0 = (rdata[i].value == 'Off') ? 'selected' : '';
+ ibody = '
'
+ break;
+ }
+ mlist += '
' + rdata[i].name + '' + ibody + ', ' + rdata[i].ps + '
'
+ }
+ var phpCon = '
' + mlist + '\
+
\
+
\
+
'
+ $(".soft-man-con").html(phpCon);
+ });
+}
+
+//提交PHP配置
+function submitConf(version) {
+ var data = {
+ version: version,
+ bind: $("input[name='bind']").val(),
+ 'port': $("input[name='port']").val(),
+ 'timeout': $("input[name='timeout']").val(),
+ maxclients: $("input[name='maxclients']").val(),
+ databases: $("input[name='databases']").val(),
+ requirepass: $("input[name='requirepass']").val(),
+ maxmemory: $("input[name='maxmemory']").val(),
+ };
+
+ redisPost('submit_redis_conf', version, data, function(ret_data){
+ var rdata = $.parseJSON(ret_data.data);
+ layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
+ });
+}
+