From 256dfb3ced422bd20d9c55c97b839fae158ce3a3 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 5 Mar 2019 10:42:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=81=B5=E6=B4=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.php显示phpinfo优化 2.插件接口新增方法 --- class/core/config_api.py | 2 +- class/core/plugins_api.py | 46 ++++++++++++++++++++++++++++++--------- plugins/php/index.py | 4 ++++ plugins/php/js/php.js | 39 +++++++++++++++++++++++++++++---- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 5d9400fbd..4f850ebb9 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -15,7 +15,7 @@ from flask import request class config_api: - __version = '0.1.0' + __version = '0.1.2' def __init__(self): pass diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py index 9fc0aa3ac..17bbb97de 100755 --- a/class/core/plugins_api.py +++ b/class/core/plugins_api.py @@ -177,6 +177,17 @@ class plugins_api: return public.returnJson(True, "OK", data[0].strip()) return public.returnJson(False, data[1].strip()) + def callbackApi(self): + name = request.form.get('name', '') + func = request.form.get('func', '') + args = request.form.get('args', '') + script = request.form.get('script', 'index') + + data = self.callback(name, func, args, script) + if data[0]: + return public.returnJson(True, "OK", data[1]) + return public.returnJson(False, data[1]) + def updateZipApi(self): tmp_path = public.getRootDir() + '/temp' if not os.path.exists(tmp_path): @@ -251,15 +262,6 @@ class plugins_api: return public.returnJson(True, '安装成功!') public.execShell("rm -rf " + plugin_path) return public.returnJson(False, '安装失败!') - - # 由于内容太大无法shell输出,暂时移动的插件模块中 - def phpinfoApi(self): - v = request.form.get('v', '') - sys.path.append("plugins/php") - - import index - content = index.getPhpinfo(v) - return content ##### ----- end ----- ### # 进程是否存在 @@ -750,6 +752,7 @@ class plugins_api: public.writeFile(self.__index, json.dumps(indexList)) return public.returnJson(True, '删除成功!') + # shell 调用 def run(self, name, func, version, args='', script='index'): path = public.getRunDir() + '/' + self.__plugin_dir + \ '/' + name + '/' + script + '.py' @@ -766,6 +769,29 @@ class plugins_api: # data = os.popen(py_cmd).read() if public.isAppleSystem(): - print py_cmd + print 'run', py_cmd # print os.path.exists(py_cmd) return (data[0].strip(), data[1].strip()) + + # 映射包调用 + def callback(self, name, func, args='', script='index'): + package = public.getRunDir() + '/plugins/' + name + if not os.path.exists(package): + return (False, "插件不存在!") + + sys.path.append(package) + eval_str = "__import__('" + script + "')." + func + '(' + args + ')' + newRet = eval(eval_str) + if public.isAppleSystem(): + print 'callback', eval_str, newRet + + return (True, newRet) + + # 由于内容太大无法shell输出,暂时移动的插件模块中 + def phpinfoApi(self): + v = request.form.get('v', '') + sys.path.append("plugins/php") + + import index + content = index.getPhpinfo(v) + return content diff --git a/plugins/php/index.py b/plugins/php/index.py index 7e178f57d..32f571141 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -506,6 +506,10 @@ def getPhpinfo(v): return phpinfo +def get_php_info(args): + return getPhpinfo(args['version']) + + def getLibConf(version): fname = public.getServerDir() + '/php/' + version + '/etc/php.ini' if not os.path.exists(fname): diff --git a/plugins/php/js/php.js b/plugins/php/js/php.js index 04c634bac..c352c8037 100755 --- a/plugins/php/js/php.js +++ b/plugins/php/js/php.js @@ -36,6 +36,33 @@ function phpPost(method, version, args,callback){ },'json'); } +function phpPostCallbak(method, version, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'php'; + 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'); +} + //配置修改 function phpSetConfig(version) { @@ -392,20 +419,24 @@ function getPHPInfo_old(version) { }); } -//获取PHPInfo function getPHPInfo(version) { - $.post('/plugins/phpinfo', {v:version}, function(data) { + phpPostCallbak('get_php_info', version, {}, function(data){ + if (!data.status){ + layer.msg(rdata.msg, { icon: 2 }); + } + layer.open({ type: 1, title: "PHP-" + version + "-PHPINFO", area: ['90%', '90%'], closeBtn: 2, shadeClose: true, - content: data + content: data.data }); - }); + }) } + function phpLibConfig(version){ phpPost('get_lib_conf', version, '', function(data){