pull/109/head
midoks 6 years ago
parent ea88243c72
commit f87f018952
  1. 4
      plugins/openresty/conf/nginx.conf
  2. 2
      plugins/openresty/conf/nginx_status.conf
  3. 2
      plugins/openresty/index.html
  4. 43
      plugins/openresty/index.py
  5. 169
      plugins/openresty/js/openresty.js
  6. 5
      plugins/openresty/versions/1.13.6/install.sh
  7. 4
      static/app/public.js

@ -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;

@ -1,5 +1,5 @@
server {
listen 6666;
listen 80;
server_name 127.0.0.1;
allow 127.0.0.1;
location /nginx_status {

@ -1,7 +1,7 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('openresty');">服务</p>
<p class="bgw" onclick="orPluginService('openresty');">服务</p>
<p onclick="pluginInitD('openresty');">自启动</p>
<p onclick="pluginConfig('openresty');">配置修改</p>
<p onclick="getOpenrestyStatus();">负载状态</p>

@ -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':

@ -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 ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+
'</span><span style="color: '+
(status?'#20a53a;':'red;')+
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\''+(status?'stop':'start')+'\',\''+version+'\')">'+(status?'停止':'启动')+'</button>\
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'restart\',\''+version+'\')">重启</button>\
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'reload\',\''+version+'\')">重载配置</button>\
</div>';
$(".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 = "<div><table class='table table-hover table-bordered'>\
<tr><th>活动连接(Active connections)</th><td>" + rdata.active + "</td></tr>\
<tr><th>总连接次数(accepts)</th><td>" + rdata.accepts + "</td></tr>\
<tr><th>总握手次数(handled)</th><td>" + rdata.handled + "</td></tr>\
<tr><th>总请求数(requests)</th><td>" + rdata.requests + "</td></tr>\
<tr><th>请求数(Reading)</th><td>" + rdata.Reading + "</td></tr>\
<tr><th>响应数(Writing)</th><td>" + rdata.Writing + "</td></tr>\
<tr><th>驻留进程(Waiting)</th><td>" + rdata.Waiting + "</td></tr>\
</table></div>";
$(".soft-man-con").html(con);
}catch(err){
showMsg(data.data, function(){}, null,3000);
}
},'json');
}
//nginx
function nginxSoftMain(name, version) {
@ -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() {
@ -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 = "<div><table class='table table-hover table-bordered'>\
<tr><th>活动连接(Active connections)</th><td>" + rdata.active + "</td></tr>\
<tr><th>总连接次数(accepts)</th><td>" + rdata.accepts + "</td></tr>\
<tr><th>总握手次数(handled)</th><td>" + rdata.handled + "</td></tr>\
<tr><th>总请求数(requests)</th><td>" + rdata.requests + "</td></tr>\
<tr><th>请求数(Reading)</th><td>" + rdata.Reading + "</td></tr>\
<tr><th>响应数(Writing)</th><td>" + rdata.Writing + "</td></tr>\
<tr><th>驻留进程(Waiting)</th><td>" + rdata.Waiting + "</td></tr>\
</table></div>";
$(".soft-man-con").html(con);
}catch(err){
showMsg(data.data, function(){}, null,3000);
}
},'json');
}
pluginService('openresty');

@ -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

@ -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;

Loading…
Cancel
Save