From f87f0189520c6a7f90048d3b385065099439cc0d Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 16 Dec 2018 23:29:35 +0800 Subject: [PATCH] update --- plugins/openresty/conf/nginx.conf | 4 +- plugins/openresty/conf/nginx_status.conf | 2 +- plugins/openresty/index.html | 2 +- plugins/openresty/index.py | 43 ++- plugins/openresty/js/openresty.js | 275 +++++++++++++------ plugins/openresty/versions/1.13.6/install.sh | 5 +- static/app/public.js | 4 + 7 files changed, 234 insertions(+), 101 deletions(-) diff --git a/plugins/openresty/conf/nginx.conf b/plugins/openresty/conf/nginx.conf index b2740bcd2..b61a02d11 100644 --- a/plugins/openresty/conf/nginx.conf +++ b/plugins/openresty/conf/nginx.conf @@ -60,8 +60,8 @@ http server { - listen 8088; - server_name www.bt.cn; + listen 80; + server_name 0.0.0.0; index index.html index.htm index.php; root /www/server/phpmyadmin; diff --git a/plugins/openresty/conf/nginx_status.conf b/plugins/openresty/conf/nginx_status.conf index 1f9cdc9a2..e8dd05cef 100644 --- a/plugins/openresty/conf/nginx_status.conf +++ b/plugins/openresty/conf/nginx_status.conf @@ -1,5 +1,5 @@ server { - listen 6666; + listen 80; server_name 127.0.0.1; allow 127.0.0.1; location /nginx_status { diff --git a/plugins/openresty/index.html b/plugins/openresty/index.html index 36566c1de..96eef2317 100755 --- a/plugins/openresty/index.html +++ b/plugins/openresty/index.html @@ -1,7 +1,7 @@
-

服务

+

服务

自启动

配置修改

负载状态

diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index 8d9881648..e4f9e651a 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -4,6 +4,7 @@ import sys import io import os import time +import subprocess sys.path.append(os.getcwd() + "/class/core") import public @@ -32,6 +33,23 @@ def getInitDFile(): return '/etc/init.d/' + 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 clearTemp(): path_bin = getServerDir() + "/nginx" public.execShell('rm -rf ' + path_bin + '/client_body_temp') @@ -87,15 +105,22 @@ def confReplace(): public.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content) - exe_bin = getServerDir() + "/bin/openresty" - public.execShell('chown -R ' + user + ':' + user_group + ' ' + exe_bin) - public.execShell('chmod 755 ' + exe_bin) - public.execShell('chmod u+s ' + exe_bin) + # exe_bin = getServerDir() + "/bin/openresty" + # print 'chown -R ' + user + ':' + user_group + ' ' + exe_bin + # print public.execShell('chown -R ' + user + ':' + user_group + ' ' + exe_bin) + # public.execShell('chmod 755 ' + exe_bin) + # public.execShell('chmod u+s ' + exe_bin) ng_exe_bin = getServerDir() + "/nginx/sbin/nginx" - public.execShell('chown -R ' + user + ':' + user_group + ' ' + ng_exe_bin) - public.execShell('chmod 755 ' + ng_exe_bin) - public.execShell('chmod u+s ' + ng_exe_bin) + + # args = getArgs() + # print args['pwd'] + # sudoPassword = args['pwd'] + # command = 'chown -R ' + 'root:' + user_group + ' ' + ng_exe_bin + # print os.system('echo %s|sudo -S %s' % (args['pwd'], command)) + # print os.system('echo %s|sudo -S %s' % (sudoPassword, 'chmod 755 ' + ng_exe_bin)) + # print os.system('echo %s|sudo -S %s' % (sudoPassword, 'chmod u+s ' + + # ng_exe_bin)) def initDreplace(): @@ -204,7 +229,7 @@ def initdUinstall(): def runInfo(): # 取Openresty负载状态 try: - result = public.httpGet('http://127.0.0.1:6666/nginx_status') + result = public.httpGet('http://127.0.0.1:80/nginx_status') tmp = result.split() data = {} data['active'] = tmp[2] @@ -243,6 +268,8 @@ if __name__ == "__main__": print initdUinstall() elif func == 'conf': print getConf() + elif func == 'get_os': + print public.getOs() elif func == 'run_info': print runInfo() elif func == 'error_log': diff --git a/plugins/openresty/js/openresty.js b/plugins/openresty/js/openresty.js index b444f9e57..729349f87 100755 --- a/plugins/openresty/js/openresty.js +++ b/plugins/openresty/js/openresty.js @@ -1,3 +1,133 @@ +orPluginService('openresty'); + + +function orPost(method, args, callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + $.post('/plugins/run', {name:'openresty', func:method, args:JSON.stringify(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 orPluginService(_name, version){ + var data = {name:_name, func:'status'} + if ( typeof(version) != 'undefined' ){ + data['version'] = version; + } else { + version = ''; + } + + orPost('status', data, function(data){ + if (data.data == 'start'){ + orPluginSetService(_name, true, version); + } else { + orPluginSetService(_name, false, version); + } + }); +} + +function orPluginSetService(_name ,status, version){ + var serviceCon ='

当前状态:'+(status ? '开启' : '关闭' )+ + '

\ + \ + \ + \ +
'; + $(".soft-man-con").html(serviceCon); +} + + +function orPluginOpService(a, b, v) { + + var c = "name=" + a + "&func=" + b; + if(v != ''){ + c = c + '&version='+v; + } + + var d = ""; + + switch(b) { + case "stop":d = '停止';break; + case "start":d = '启动';break; + case "restart":d = '重启';break; + case "reload":d = '重载';break; + } + layer.confirm( msgTpl('您真的要{1}{2}{3}服务吗?', [d,a,v]), {icon:3,closeBtn: 2}, function() { + orPost('get_os',{},function(data){ + if (data.data == 'darwin'){ + layer.prompt({title: '检查到权限不足,需要输入密码!', formType: 1},function(pwd, index){ + + layer.close(index); + var data = {'pwd':pwd}; + c += '&args='+JSON.stringify(data); + orPluginOpServiceOp(a,c,d,a,v); + }); + } else { + orPluginOpServiceOp(a,c,d,a,v); + } + }); + }) +} + +function orPluginOpServiceOp(a,c,d,a,v){ + var e = layer.msg(msgTpl('正在{1}{2}{3}服务,请稍候...',[d,a,v]), {icon: 16,time: 0}); + $.post("/plugins/run", c, function(g) { + layer.close(e); + + var f = g.data == 'ok' ? msgTpl('{1}{2}服务已{3}',[a,v,d]) : msgTpl('{1}{2}服务{3}失败!',[a,v,d]); + layer.msg(f, {icon: g.data == 'ok' ? 1 : 2}); + + if( b != "reload" && g.data == 'ok' ) { + if ( b == 'start' ) { + orPluginSetService(a, true, v); + } else if ( b == 'stop' ){ + orPluginSetService(a, false, v); + } + } + + if( g.status && g.data != 'ok' ) { + layer.msg(g.data, {icon: 2,time: 3000,shade: 0.3,shadeClose: true}); + } + },'json').error(function() { + layer.close(e); + layer.msg('操作异常!', {icon: 2}); + }); +} + + +//查看Nginx负载状态 +function getOpenrestyStatus() { + $.post('/plugins/run', {name:'openresty', func:'run_info'}, function(data) { + if (!data.status){ + showMsg(data.msg, function(){}, null,3000); + return; + } + try { + var rdata = $.parseJSON(data.data); + var con = "
\ + \ + \ + \ + \ + \ + \ + \ +
活动连接(Active connections)" + rdata.active + "
总连接次数(accepts)" + rdata.accepts + "
总握手次数(handled)" + rdata.handled + "
总请求数(requests)" + rdata.requests + "
请求数(Reading)" + rdata.Reading + "
响应数(Writing)" + rdata.Writing + "
驻留进程(Waiting)" + rdata.Waiting + "
"; + $(".soft-man-con").html(con); + }catch(err){ + showMsg(data.data, function(){}, null,3000); + } + },'json'); +} //nginx function nginxSoftMain(name, version) { @@ -24,18 +154,18 @@ function nginxSoftMain(name, version) { closeBtn: 2, shift: 0, content: '
\ -
\ -

' + lan.soft.web_service + '

\ -

' + lan.soft.config_edit + '

\ - ' + waf + '\ - ' + menu + '\ - ' + status + '\ -

错误日志

\ -
\ -
\ -
\ -
\ -
' +
\ +

' + lan.soft.web_service + '

\ +

' + lan.soft.config_edit + '

\ + ' + waf + '\ + ' + menu + '\ + ' + status + '\ +

错误日志

\ +
\ +
\ +
\ +
\ +
' }); service(name, nameA.status); $(".bt-w-menu p").click(function() { @@ -83,42 +213,42 @@ function waf() { var cc = rdata.CCrate.split('/') var con = "
\ -
\ - " + lan.soft.waf_title + "
\ +
\ + " + lan.soft.waf_title + "
\ \ \ -
\ -
\ - \ - \ -
\ -
\ -
\ - \ - \ - \ - \ - \ - \ -
\ -
\ - " + lan.soft.waf_input6 + "\ - " + lan.soft.waf_input7 + "(" + lan.bt.s + ")\ - \ -
\ -
\ -
\ - " + lan.soft.waf_input8 + "\ - \ -
" + whiteList + "
\ -
\ -
\ - " + lan.soft.waf_input9 + "\ - \ -
" + blackList + "
\ -
\ -
\ -
" +
\ +
\ + \ + \ +
\ +
\ +
\ + \ + \ + \ + \ + \ + \ +
\ +
\ + " + lan.soft.waf_input6 + "\ + " + lan.soft.waf_input7 + "(" + lan.bt.s + ")\ + \ +
\ +
\ +
\ + " + lan.soft.waf_input8 + "\ + \ +
" + whiteList + "
\ +
\ +
\ + " + lan.soft.waf_input9 + "\ + \ +
" + blackList + "
\ +
\ +
\ +
" $(".soft-man-con").html(con); }); } @@ -158,7 +288,7 @@ function upLimit() { } //设置waf状态 -function CloseWaf() { +function closeWaf() { var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] }); $.post('/waf?action=SetStatus', '', function(rdata) { layer.close(loadT) @@ -168,8 +298,8 @@ function CloseWaf() { } //取规则文件 -function GetWafFile(name) { - OnlineEditFile(0, '/www/server/panel/vhost/wafconf/' + name); +function getWafFile(name) { + onlineEditFile(0, '/www/server/panel/vhost/wafconf/' + name); } //规则编辑 function gzEdit() { @@ -180,13 +310,13 @@ function gzEdit() { closeBtn: 2, shift: 0, content: "
\ - \ - \ - \ - \ - \ - \ -
" + \ + \ + \ + \ + \ + \ +
" }); } @@ -200,7 +330,7 @@ function updateWaf() { } //设置WAF配置值 -function SetWafConfig(name, value) { +function setWafConfig(name, value) { if (name == 'CCrate') { var CCrate_1 = $("#CCrate_1").val(); var CCrate_2 = $("#CCrate_2").val(); @@ -242,34 +372,3 @@ function addWafKey(name) { if (name == 'black_fileExt') upLimit(); }); } - - - -//查看Nginx负载状态 -function getOpenrestyStatus() { - - $.post('/plugins/run', {name:'openresty', func:'run_info'}, function(data) { - if (!data.status){ - showMsg(data.msg, function(){}, null,3000); - return; - } - - try { - var rdata = $.parseJSON(data.data); - var con = "
\ - \ - \ - \ - \ - \ - \ - \ -
活动连接(Active connections)" + rdata.active + "
总连接次数(accepts)" + rdata.accepts + "
总握手次数(handled)" + rdata.handled + "
总请求数(requests)" + rdata.requests + "
请求数(Reading)" + rdata.Reading + "
响应数(Writing)" + rdata.Writing + "
驻留进程(Waiting)" + rdata.Waiting + "
"; - $(".soft-man-con").html(con); - }catch(err){ - showMsg(data.data, function(){}, null,3000); - } - },'json'); -} - -pluginService('openresty'); \ No newline at end of file diff --git a/plugins/openresty/versions/1.13.6/install.sh b/plugins/openresty/versions/1.13.6/install.sh index 3752ddbe9..dbce740f7 100755 --- a/plugins/openresty/versions/1.13.6/install.sh +++ b/plugins/openresty/versions/1.13.6/install.sh @@ -24,7 +24,10 @@ Install_openresty() cd ${openrestyDir}/openresty-1.13.6.2 && ./configure --prefix=$serverPath/openresty \ --with-openssl=$serverPath/source/lib/openssl-1.0.2q \ - --with-http_stub_status_module && make && make install && \ + --with-http_stub_status_module \ + --user=www \ + --group=www \ + && make && make install && \ echo '1.13.6' > $serverPath/openresty/version.pl echo '安装完成' > $install_tmp diff --git a/static/app/public.js b/static/app/public.js index 4d9ea2543..83433de18 100755 --- a/static/app/public.js +++ b/static/app/public.js @@ -1518,7 +1518,9 @@ function pluginService(_name, version){ } // console.log(version); + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); $.post('/plugins/run', data, function(data) { + layer.close(loadT); if(!data.status){ layer.msg(data.msg,{icon:0,time:3000,shade: [0.3, '#000']}); return; @@ -1661,7 +1663,9 @@ function pluginConfigSave(fileName) { function pluginInitD(_name){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); $.post('/plugins/run', {name:_name, func:'initd_status'}, function(data) { + layer.close(loadT); if( !data.status ){ layer.msg(data.msg,{icon:0,time:3000,shade: [0.3, '#000']}); return;