From f5fd840211ff5c8f6ed22ed9b7b9fb79029df5b1 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 18 Dec 2018 18:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E6=97=B6=E9=99=90=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/php/conf/php-fpm.conf | 1 + plugins/php/index.html | 4 +- plugins/php/index.py | 95 ++++++++++++++++ plugins/php/js/php.js | 205 +++++----------------------------- 4 files changed, 128 insertions(+), 177 deletions(-) diff --git a/plugins/php/conf/php-fpm.conf b/plugins/php/conf/php-fpm.conf index 520a62edf..e451c6e9d 100644 --- a/plugins/php/conf/php-fpm.conf +++ b/plugins/php/conf/php-fpm.conf @@ -1,5 +1,6 @@ [global] +request_terminate_timeout = 30 include={$SERVER_PATH}/php/{$PHP_VERSION}/etc/php-fpm.d/*.conf ;php_value[auto_prepend_file]={$SERVER_PATH}/md_start.php ;php_value[auto_append_file]={$SERVER_PATH}/md_end.php \ No newline at end of file diff --git a/plugins/php/index.html b/plugins/php/index.html index fa5bc54fa..b6a757cc0 100755 --- a/plugins/php/index.html +++ b/plugins/php/index.html @@ -5,8 +5,8 @@

服务

安装扩展

配置修改

-

上传限制

-

超时限制

+

上传限制

+

超时限制

配置文件

禁用函数

性能调整

diff --git a/plugins/php/index.py b/plugins/php/index.py index fe46fa648..06a597358 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -200,6 +200,95 @@ def submitPhpConf(version): return public.returnJson(True, '设置成功') +def getLimitConf(version): + fileini = getServerDir() + "/" + version + "/etc/php.ini" + phpini = public.readFile(fileini) + filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf" + phpfpm = public.readFile(filefpm) + + # print fileini, filefpm + data = {} + try: + rep = "upload_max_filesize\s*=\s*([0-9]+)M" + tmp = re.search(rep, phpini).groups() + data['max'] = tmp[0] + except: + data['max'] = '50' + + try: + rep = "request_terminate_timeout\s*=\s*([0-9]+)\n" + tmp = re.search(rep, phpfpm).groups() + data['maxTime'] = tmp[0] + except: + data['maxTime'] = 0 + + try: + rep = r"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n" + tmp = re.search(rep, phpini).groups() + + if tmp[0] == '1': + data['pathinfo'] = True + else: + data['pathinfo'] = False + except: + data['pathinfo'] = False + + return public.getJson(data) + + +def setMaxTime(version): + args = getArgs() + if not 'time' in args: + return 'missing time args!' + time = args['time'] + if int(time) < 30 or int(time) > 86400: + return public.returnJson(False, '请填写30-86400间的值!') + + filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf" + conf = public.readFile(filefpm) + rep = "request_terminate_timeout\s*=\s*([0-9]+)\n" + conf = re.sub(rep, "request_terminate_timeout = " + time + "\n", conf) + public.writeFile(filefpm, conf) + + fileini = getServerDir() + "/" + version + "/etc/php.ini" + phpini = public.readFile(fileini) + rep = "max_execution_time\s*=\s*([0-9]+)\r?\n" + phpini = re.sub(rep, "max_execution_time = " + time + "\n", phpini) + rep = "max_input_time\s*=\s*([0-9]+)\r?\n" + phpini = re.sub(rep, "max_input_time = " + time + "\n", phpini) + public.writeFile(fileini, phpini) + return public.returnJson(True, '设置成功!') + + +def setMaxSize(version): + args = getArgs() + if not 'max' in args: + return 'missing time args!' + max = args['max'] + if int(max) < 2: + return public.returnJson(False, '上传大小限制不能小于2MB!') + + path = getServerDir() + '/' + version + '/etc/php.ini' + conf = public.readFile(path) + rep = u"\nupload_max_filesize\s*=\s*[0-9]+M" + conf = re.sub(rep, u'\nupload_max_filesize = ' + max + 'M', conf) + rep = u"\npost_max_size\s*=\s*[0-9]+M" + conf = re.sub(rep, u'\npost_max_size = ' + max + 'M', conf) + public.writeFile(path, conf) + + # if public.get_webserver() == 'nginx': + # path = web.ctx.session.setupPath + '/nginx/conf/nginx.conf' + # conf = public.readFile(path) + # rep = "client_max_body_size\s+([0-9]+)m" + # tmp = re.search(rep, conf).groups() + # if int(tmp[0]) < int(max): + # conf = re.sub(rep, 'client_max_body_size ' + max + 'm', conf) + # public.writeFile(path, conf) + + public.writeLog("TYPE_PHP", "PHP_UPLOAD_MAX", (version, max)) + return public.returnJson(True, '设置成功!') + + if __name__ == "__main__": if len(sys.argv) < 3: @@ -229,5 +318,11 @@ if __name__ == "__main__": print getPhpConf(version) elif func == 'submit_php_conf': print submitPhpConf(version) + elif func == 'get_limit_conf': + print getLimitConf(version) + elif func == 'set_max_time': + print setMaxTime(version) + elif func == 'set_max_size': + print setMaxSize(version) else: print "fail" diff --git a/plugins/php/js/php.js b/plugins/php/js/php.js index 42c9fbd93..d530408c5 100755 --- a/plugins/php/js/php.js +++ b/plugins/php/js/php.js @@ -87,203 +87,62 @@ function submitConf(version) { } -//软件管理 -function phpSoftMain(name, key) { - if (!isNaN(name)) { - var nametext = "php" + name; - name = name.replace(".", ""); - } - - var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.get('/plugins?action=getPluginInfo&name=php', function(rdata) { - layer.close(loadT); - nameA = rdata.versions[key]; - bodys = [ - '

' + lan.soft.php_main1 + '

', - '

' + lan.soft.php_main5 + '

', - '

' + lan.soft.config_edit + '

', - '

' + lan.soft.php_main2 + '

', - '

' + lan.soft.php_main3 + '

', - '

' + lan.soft.php_main4 + '

', - '

' + lan.soft.php_main6 + '

', - '

' + lan.soft.php_main7 + '

', - '

' + lan.soft.php_main8 + '

', - '

FPM日志

', - '

慢日志

', - '

phpinfo

' - ] - - var sdata = ''; - if (rdata.phpSort == false) { - rdata.phpSort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; - } else { - rdata.phpSort = rdata.phpSort.split('|'); - } - for (var i = 0; i < rdata.phpSort.length; i++) { - sdata += bodys[rdata.phpSort[i]]; - } - - layer.open({ - type: 1, - area: '640px', - title: nametext + lan.soft.admin, - closeBtn: 2, - shift: 0, - content: '
\ - \ -
\ - ' + sdata + '\ -
\ -
\ -
\ -
\ -
' - }); - if (name == "52") { - $(".phphide").hide(); - } - - if (rdata.versions.length < 5) { - $(".phphide").hide(); - $(".pstate").hide(); - SetPHPConfig(name, nameA.pathinfo); - $("p[data-id='4']").addClass('bgw'); - } else { - service(name, nameA.run); - } - $(".bt-w-menu p a").click(function() { - var txt = $(this).text(); - $(this).parent().addClass("bgw").siblings().removeClass("bgw"); - if (txt != lan.soft.php_menu_ext) $(".soft-man-con").removeAttr("style"); - }); - $(".soft-man-menu").dragsort({ dragSelector: ".spanmove", dragEnd: MenusaveOrder }); +//php上传限制 +function phpUploadLimitReq(version){ + phpPost('get_limit_conf', version, '', function(ret_data){ + var rdata = $.parseJSON(ret_data.data); + phpUploadLimit(version,rdata['max']); }); } -//FPM日志 -function GetFpmLogs(phpversion) { - var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.get('/ajax?action=GetFpmLogs&version=' + phpversion, function(logs) { - layer.close(loadT); - if (logs.status !== true) { - logs.msg = ''; - } - if (logs.msg == '') logs.msg = '当前没有fpm日志.'; - var phpCon = ''; - $(".soft-man-con").html(phpCon); - var ob = document.getElementById('error_log'); - ob.scrollTop = ob.scrollHeight; - }); +function phpUploadLimit(version,max){ + var LimitCon = '

MB

'; + $(".soft-man-con").html(LimitCon); } -//FPM-Slow日志 -function GetFpmSlowLogs(phpversion) { - var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.get('/ajax?action=GetFpmSlowLogs&version=' + phpversion, function(logs) { - layer.close(loadT); - if (logs.status !== true) { - logs.msg = ''; - } - if (logs.msg == '') logs.msg = '当前没有慢日志.'; - var phpCon = ''; - $(".soft-man-con").html(phpCon); - var ob = document.getElementById('error_log'); - ob.scrollTop = ob.scrollHeight; + +//php超时限制 +function phpTimeLimitReq(version){ + phpPost('get_limit_conf', version, '', function(ret_data){ + var rdata = $.parseJSON(ret_data.data); + phpTimeLimit(version,rdata['maxTime']); }); } - - -//php超时限制 function phpTimeLimit(version, max) { - var LimitCon = '

' + lan.bt.s + '

'; + var LimitCon = '

'; $(".soft-man-con").html(LimitCon); } + //设置超时限制 -function SetPHPMaxTime(version) { +function setPHPMaxTime(version) { var max = $(".phpTimeLimit").val(); - var loadT = layer.msg(lan.soft.the_save, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.post('/config?action=setPHPMaxTime', 'version=' + version + '&time=' + max, function(rdata) { - $(".bt-w-menu .active").attr('onclick', "phpTimeLimit('" + version + "'," + max + ")"); - $(".bt-w-menu .active a").attr('href', "javascript:phpTimeLimit('" + version + "'," + max + ");"); - layer.close(loadT); + phpPost('set_max_time',version,{'time':max},function(data){ + var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); }); } //设置PHP上传限制 -function SetPHPMaxSize(version) { +function setPHPMaxSize(version) { max = $(".phpUploadLimit").val(); if (max < 2) { alert(max); - layer.msg(lan.soft.php_upload_size, { icon: 2 }); + layer.msg('上传大小限制不能小于2M', { icon: 2 }); return; } - var loadT = layer.msg(lan.soft.the_save, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.post('/config?action=setPHPMaxSize', '&version=' + version + '&max=' + max, function(rdata) { - $(".bt-w-menu .active").attr('onclick', "phpUploadLimit('" + version + "'," + max + ")"); - $(".bt-w-menu .active a").attr('href', "javascript:phpUploadLimit('" + version + "'," + max + ");"); - layer.close(loadT); + + phpPost('set_max_size',version,{'max':max},function(data){ + var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); - }) -} -//配置修改 -function configChange(type) { - var con = '

' + lan.bt.edit_ps + '

\ - \ - '; - $(".soft-man-con").html(con); - var fileName = ''; - switch (type) { - case 'mysqld': - fileName = '/etc/my.cnf'; - break; - case 'nginx': - fileName = '/www/server/nginx/conf/nginx.conf'; - break; - case 'pure-ftpd': - fileName = '/www/server/pure-ftpd/etc/pure-ftpd.conf'; - break; - case 'apache': - fileName = '/www/server/apache/conf/httpd.conf'; - break; - case 'tomcat': - fileName = '/www/server/tomcat/conf/server.xml'; - break; - case 'memcached': - fileName = '/etc/init.d/memcached'; - break; - case 'redis': - fileName = '/www/server/redis/redis.conf'; - break; - default: - fileName = '/www/server/php/' + type + '/etc/php.ini'; - break; - } - var loadT = layer.msg(lan.soft.get, { icon: 16, time: 0, shade: [0.3, '#000'] }); - $.post('/files?action=GetFileBody', 'path=' + fileName, function(rdata) { - layer.close(loadT); - $("#textBody").empty().text(rdata.data); - $(".CodeMirror").remove(); - var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { - extraKeys: { "Ctrl-Space": "autocomplete" }, - lineNumbers: true, - matchBrackets: true, - }); - editor.focus(); - $(".CodeMirror-scroll").css({ "height": "300px", "margin": 0, "padding": 0 }); - $("#OnlineEditFileBtn").click(function() { - $("#textBody").text(editor.getValue()); - confSafe(fileName); - }); }); } //设置PATHINFO -function SetPathInfo(version, type) { +function setPathInfo(version, type) { var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); $.post('/config?action=setPathInfo', 'version=' + version + '&type=' + type, function(rdata) { var pathinfo = (type == 'on') ? true : false; @@ -301,7 +160,7 @@ function SetPathInfo(version, type) { //PHP扩展配置 -function SetPHPConfig(version, pathinfo, go) { +function setPHPConfig(version, pathinfo, go) { $.get('/ajax?action=GetPHPConfig&version=' + version, function(rdata) { var body = "" var opt = "" @@ -636,11 +495,7 @@ function GetPHPStatus(version) { } -//php上传限制 -function phpUploadLimit(version, max) { - var LimitCon = '

MB

'; - $(".soft-man-con").html(LimitCon); -} + function GetPHPStatus(a) { if(a == "52") { @@ -657,7 +512,7 @@ function GetPHPStatus(a) { closeBtn: 2, shift: 5, shadeClose: true, - content: "
"+lan.bt.php_pool+"" + b.pool + "
"+lan.bt.php_manager+"" + ((b["process manager"] == "dynamic") ? lan.bt.dynamic : lan.bt.static) + "
"+lan.bt.php_start+"" + b["start time"] + "
"+lan.bt.php_accepted+"" + b["accepted conn"] + "
"+lan.bt.php_queue+"" + b["listen queue"] + "
"+lan.bt.php_max_queue+"" + b["max listen queue"] + "
"+lan.bt.php_len_queue+"" + b["listen queue len"] + "
"+lan.bt.php_idle+"" + b["idle processes"] + "
"+lan.bt.php_active+"" + b["active processes"] + "
"+lan.bt.php_total+"" + b["total processes"] + "
"+lan.bt.php_max_active+"" + b["max active processes"] + "
"+lan.bt.php_max_children+"" + b["max children reached"] + "
"+lan.bt.php_slow+"" + b["slow requests"] + "
" + content: "
"+lan.bt.php_pool+"" + b.pool + "
"+lan.bt.php_manager+"" + ((b["process manager"] == "dynamic") ? lan.bt.dynamic : lan.bt.static) + "
"+lan.bt.php_start+"" + b["start time"] + "
"+lan.bt.php_accepted+"" + b["accepted conn"] + "
"+lan.bt.php_queue+"" + b["listen queue"] + "
"+lan.bt.php_max_queue+"" + b["max listen queue"] + "
"+lan.bt.php_len_queue+"" + b["listen queue len"] + "
"+lan.bt.php_idle+"" + b["idle processes"] + "
"+lan.bt.php_active+"" + b["active processes"] + "
"+lan.bt.php_total+"" + b["total processes"] + "
"+lan.bt.php_max_active+"" + b["max active processes"] + "
"+lan.bt.php_max_children+"" + b["max children reached"] + "
"+lan.bt.php_slow+"" + b["slow requests"] + "
" }) }) } \ No newline at end of file