diff --git a/plugins/php/index.html b/plugins/php/index.html index bf0e3d838..1d19a1c52 100755 --- a/plugins/php/index.html +++ b/plugins/php/index.html @@ -4,7 +4,7 @@

服务

安装扩展

-

配置修改

+

配置修改

上传限制

超时限制

配置文件

diff --git a/plugins/php/index.py b/plugins/php/index.py index 58a06071b..c2923b1ff 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -4,6 +4,10 @@ import sys import io import os import time +import re + +reload(sys) +sys.setdefaultencoding('utf8') sys.path.append(os.getcwd() + "/class/core") import public @@ -32,7 +36,7 @@ def getInitDFile(): def getArgs(): - args = sys.argv[2:] + args = sys.argv[3:] tmp = {} args_len = len(args) @@ -141,38 +145,59 @@ def reload(version): return phpOp(version, 'reload') -def runInfo(version): - path = os.path.dirname(os.getcwd()) - cmd = path + "/redis/bin/redis-cli info" - data = public.execShell(cmd)[0] - res = [ - 'tcp_port', - 'uptime_in_days', # 已运行天数 - 'connected_clients', # 连接的客户端数量 - 'used_memory', # Redis已分配的内存总量 - 'used_memory_rss', # Redis占用的系统内存总量 - 'used_memory_peak', # Redis所用内存的高峰值 - 'mem_fragmentation_ratio', # 内存碎片比率 - 'total_connections_received', # 运行以来连接过的客户端的总数量 - 'total_commands_processed', # 运行以来执行过的命令的总数量 - 'instantaneous_ops_per_sec', # 服务器每秒钟执行的命令数量 - 'keyspace_hits', # 查找数据库键成功的次数 - 'keyspace_misses', # 查找数据库键失败的次数 - 'latest_fork_usec' # 最近一次 fork() 操作耗费的毫秒数 +def getPhpConf(version): + gets = [ + {'name': 'short_open_tag', 'type': 1, 'ps': '短标签支持'}, + {'name': 'asp_tags', 'type': 1, 'ps': 'ASP标签支持'}, + {'name': 'max_execution_time', 'type': 2, 'ps': '最大脚本运行时间'}, + {'name': 'max_input_time', 'type': 2, 'ps': '最大输入时间'}, + {'name': 'memory_limit', 'type': 2, 'ps': '脚本内存限制'}, + {'name': 'post_max_size', 'type': 2, 'ps': 'POST数据最大尺寸'}, + {'name': 'file_uploads', 'type': 1, 'ps': '是否允许上传文件'}, + {'name': 'upload_max_filesize', 'type': 2, 'ps': '允许上传文件的最大尺寸'}, + {'name': 'max_file_uploads', 'type': 2, 'ps': '允许同时上传文件的最大数量'}, + {'name': 'default_socket_timeout', 'type': 2, 'ps': 'Socket超时时间'}, + {'name': 'error_reporting', 'type': 3, 'ps': '错误级别'}, + {'name': 'display_errors', 'type': 1, 'ps': '是否输出详细错误信息'}, + {'name': 'cgi.fix_pathinfo', 'type': 0, 'ps': '是否开启pathinfo'}, + {'name': 'date.timezone', 'type': 3, 'ps': '时区'} ] - data = data.split("\n") - result = {} - for d in data: - if len(d) < 3: - continue - t = d.strip().split(':') - if not t[0] in res: + phpini = public.readFile(getServerDir() + '/' + version + '/etc/php.ini') + result = [] + for g in gets: + rep = g['name'] + '\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)' + tmp = re.search(rep, phpini) + if not tmp: continue - result[t[0]] = t[1] + g['value'] = tmp.groups()[0] + result.append(g) return public.getJson(result) +def submitPhpConf(version): + gets = ['display_errors', 'cgi.fix_pathinfo', 'date.timezone', 'short_open_tag', + 'asp_tags', 'max_execution_time', 'max_input_time', 'memory_limit', + 'post_max_size', 'file_uploads', 'upload_max_filesize', 'max_file_uploads', + 'default_socket_timeout', 'error_reporting'] + args = getArgs() + filename = getServerDir() + '/' + version + '/etc/php.ini' + phpini = public.readFile(filename) + for g in gets: + if g in args: + rep = g + '\s*=\s*(.+)\r?\n' + val = g + ' = ' + args[g] + '\n' + phpini = re.sub(rep, val, phpini) + public.writeFile(filename, phpini) + public.execShell(getServerDir() + '/init.d/php' + version + ' reload') + return public.returnJson(True, '设置成功') + + if __name__ == "__main__": + + if len(sys.argv) < 3: + print 'missing parameters' + exit(0) + func = sys.argv[1] version = sys.argv[2] @@ -190,5 +215,9 @@ if __name__ == "__main__": print runInfo(version) elif func == 'conf': print getConf(version) + elif func == 'get_php_conf': + print getPhpConf(version) + elif func == 'submit_php_conf': + print submitPhpConf(version) else: print "fail" diff --git a/plugins/php/js/php.js b/plugins/php/js/php.js index 8412d95c7..3b32b133c 100755 --- a/plugins/php/js/php.js +++ b/plugins/php/js/php.js @@ -1,3 +1,92 @@ +function phpPost(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; + req_data['version'] = version; + + if (typeof(args) != 'undefined' && args!=''){ + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/run', 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) { + phpPost('get_php_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, + display_errors: $("select[name='display_errors']").val(), + 'cgi.fix_pathinfo': $("select[name='cgi.fix_pathinfo']").val(), + 'date.timezone': $("input[name='date.timezone']").val(), + short_open_tag: $("select[name='short_open_tag']").val(), + asp_tags: $("select[name='asp_tags']").val() || 'On', + safe_mode: $("select[name='safe_mode']").val(), + max_execution_time: $("input[name='max_execution_time']").val(), + max_input_time: $("input[name='max_input_time']").val(), + memory_limit: $("input[name='memory_limit']").val(), + post_max_size: $("input[name='post_max_size']").val(), + file_uploads: $("select[name='file_uploads']").val(), + upload_max_filesize: $("input[name='upload_max_filesize']").val(), + max_file_uploads: $("input[name='max_file_uploads']").val(), + default_socket_timeout: $("input[name='default_socket_timeout']").val(), + error_reporting: $("input[name='error_reporting']").val() || 'On' + }; + + phpPost('submit_php_conf', version, data, function(ret_data){ + var rdata = $.parseJSON(ret_data.data); + // console.log(rdata); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + + //软件管理 function phpSoftMain(name, key) { if (!isNaN(name)) { @@ -105,68 +194,6 @@ function GetFpmSlowLogs(phpversion) { } -//配置修改 -function SetPHPConf(version) { - var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.post('/config?action=GetPHPConf', 'version=' + version, function(rdata) { - layer.close(loadT); - 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 SubmitPHPConf(version) { - var data = { - version: version, - display_errors: $("select[name='display_errors']").val(), - 'cgi.fix_pathinfo': $("select[name='cgi.fix_pathinfo']").val(), - 'date.timezone': $("input[name='date.timezone']").val(), - short_open_tag: $("select[name='short_open_tag']").val(), - asp_tags: $("select[name='asp_tags']").val() || 'On', - safe_mode: $("select[name='safe_mode']").val(), - max_execution_time: $("input[name='max_execution_time']").val(), - max_input_time: $("input[name='max_input_time']").val(), - memory_limit: $("input[name='memory_limit']").val(), - post_max_size: $("input[name='post_max_size']").val(), - file_uploads: $("select[name='file_uploads']").val(), - upload_max_filesize: $("input[name='upload_max_filesize']").val(), - max_file_uploads: $("input[name='max_file_uploads']").val(), - default_socket_timeout: $("input[name='default_socket_timeout']").val(), - error_reporting: $("input[name='error_reporting']").val() || 'On' - } - - var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.post('/config?action=SetPHPConf', data, function(rdata) { - layer.close(loadT); - layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); - }); - -} - //php超时限制 function phpTimeLimit(version, max) {