pull/632/head
Mr Chen 6 months ago
parent d83e7b6905
commit 82ee20b1a9
  1. 2
      plugins/openresty/index.html
  2. 38
      plugins/openresty/index.py
  3. 108
      web/core/mw.py

@ -1,5 +1,5 @@
<div class="bt-form"> <div class="bt-form">
<div class='plugin_version'></div> <!-- <div class='plugin_version'></div> -->
<div class="bt-w-main"> <div class="bt-w-main">
<div class="bt-w-menu"> <div class="bt-w-menu">
<p class="bgw" onclick="orPluginService('openresty',$('.plugin_version').attr('version'));">服务</p> <p class="bgw" onclick="orPluginService('openresty',$('.plugin_version').attr('version'));">服务</p>

@ -8,8 +8,12 @@ import threading
import subprocess import subprocess
import re import re
sys.path.append(os.getcwd() + "/class/core")
import mw web_dir = os.getcwd() + "/web"
sys.path.append(web_dir)
os.chdir(web_dir)
import core.mw as mw
app_debug = False app_debug = False
if mw.isAppleSystem(): if mw.isAppleSystem():
@ -41,18 +45,19 @@ def getInitDFile():
def getArgs(): def getArgs():
args = sys.argv[2:] args = sys.argv[2:]
# print(args)
tmp = {} tmp = {}
args_len = len(args) args_len = len(args)
if args_len == 1: if args_len == 1:
t = args[0].strip('{').strip('}') t = args[0].strip('{').strip('}')
t = t.split(':') t = t.split(':',2)
tmp[t[0]] = t[1] tmp[t[0]] = t[1]
elif args_len > 1: elif args_len > 1:
for i in range(len(args)): for i in range(len(args)):
t = args[i].split(':') t = args[i].split(':',2)
tmp[t[0]] = t[1] tmp[t[0]] = t[1]
# print(tmp)
return tmp return tmp
@ -398,16 +403,25 @@ def initdUinstall():
mw.execShell('systemctl disable openresty') mw.execShell('systemctl disable openresty')
return 'ok' return 'ok'
def getNgxStatusPort():
ngx_status_file = mw.getServerDir() + '/web_conf/nginx/vhost/0.nginx_status.conf'
content = mw.readFile(ngx_status_file)
rep = r'listen\s*(.*);'
tmp = re.search(rep, content)
port = tmp.groups()[0].strip()
return port
def runInfo(): def runInfo():
op_status = status() op_status = status()
if op_status == 'stop': if op_status == 'stop':
return mw.returnJson(False, "未启动!") return mw.returnJson(False, "未启动!")
port = getNgxStatusPort()
# 取Openresty负载状态 # 取Openresty负载状态
try: try:
url = 'http://127.0.0.1/nginx_status' url = 'http://127.0.0.1:%s/nginx_status' % port
result = mw.httpGet(url, timeout=1) result = mw.httpGet(url, timeout=3)
tmp = result.split() tmp = result.split()
data = {} data = {}
data['active'] = tmp[2] data['active'] = tmp[2]
@ -419,8 +433,7 @@ def runInfo():
data['Waiting'] = tmp[15] data['Waiting'] = tmp[15]
return mw.getJson(data) return mw.getJson(data)
except Exception as e: except Exception as e:
url = 'http://' + mw.getHostAddr() + ':%s/nginx_status' % port
url = 'http://' + mw.getHostAddr() + '/nginx_status'
result = mw.httpGet(url) result = mw.httpGet(url)
tmp = result.split() tmp = result.split()
data = {} data = {}
@ -550,6 +563,13 @@ def installPreInspection():
if __name__ == "__main__": if __name__ == "__main__":
version_pl = getServerDir() + "/version.pl"
if not os.path.exists(version_pl):
print('error')
exit(-1)
version = mw.readFile(version_pl)
func = sys.argv[1] func = sys.argv[1]
if func == 'status': if func == 'status':
print(status()) print(status())

@ -199,7 +199,7 @@ def readFile(filename):
fp.close() fp.close()
return fBody return fBody
except Exception as e: except Exception as e:
# print(e) print(e)
return False return False
def writeFile(filename, content, mode='w+'): def writeFile(filename, content, mode='w+'):
@ -764,6 +764,112 @@ def deDoubleCrypt(key, strings):
writeFileLog(getTracebackInfo()) writeFileLog(getTracebackInfo())
return strings return strings
# ------------------------------ network start -----------------------------
def HttpGet(url, timeout=10):
"""
发送GET请求
@url 被请求的URL地址(必需)
@timeout 超时时间默认60秒
return string
"""
if sys.version_info[0] == 2:
try:
import urllib2
import ssl
if sys.version_info[0] == 2:
reload(urllib2)
reload(ssl)
try:
ssl._create_default_https_context = ssl._create_unverified_context
except:
pass
response = urllib2.urlopen(url, timeout=timeout)
return response.read()
except Exception as ex:
return str(ex)
else:
try:
import urllib.request
import ssl
try:
ssl._create_default_https_context = ssl._create_unverified_context
except:
pass
response = urllib.request.urlopen(url, timeout=timeout)
result = response.read()
if type(result) == bytes:
result = result.decode('utf-8')
return result
except Exception as ex:
return str(ex)
def HttpGet2(url, timeout):
import urllib.request
try:
import ssl
try:
ssl._create_default_https_context = ssl._create_unverified_context
except:
pass
req = urllib.request.urlopen(url, timeout=timeout)
result = req.read().decode('utf-8')
return result
except Exception as e:
return str(e)
def httpGet(url, timeout=10):
return HttpGet2(url, timeout)
def HttpPost(url, data, timeout=10):
"""
发送POST请求
@url 被请求的URL地址(必需)
@data POST参数可以是字符串或字典(必需)
@timeout 超时时间默认60秒
return string
"""
if sys.version_info[0] == 2:
try:
import urllib
import urllib2
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
data = urllib.urlencode(data)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req, timeout=timeout)
return response.read()
except Exception as ex:
return str(ex)
else:
try:
import urllib.request
import ssl
try:
ssl._create_default_https_context = ssl._create_unverified_context
except:
pass
data = urllib.parse.urlencode(data).encode('utf-8')
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req, timeout=timeout)
result = response.read()
if type(result) == bytes:
result = result.decode('utf-8')
return result
except Exception as ex:
return str(ex)
def httpPost(url, data, timeout=10):
return HttpPost(url, data, timeout)
# ------------------------------ network end -----------------------------
# ------------------------------ panel start ----------------------------- # ------------------------------ panel start -----------------------------
def isRestart(): def isRestart():

Loading…
Cancel
Save