diff --git a/class/public.py b/class/public.py index 863d69294..6dad7a2b5 100755 --- a/class/public.py +++ b/class/public.py @@ -4,6 +4,15 @@ import os import sys import time import string +import json +import hashlib +import shlex +import datetime +import subprocess +import re + +from random import Random +from flask import jsonify def getRunDir(): @@ -31,7 +40,7 @@ def GetFileMd5(filename): # 文件的MD5值 if not os.path.isfile(filename): return False - import hashlib + myhash = hashlib.md5() f = file(filename, 'rb') while True: @@ -45,7 +54,6 @@ def GetFileMd5(filename): def GetRandomString(length): # 取随机字符串 - from random import Random str = '' chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' chrlen = len(chars) - 1 @@ -57,7 +65,6 @@ def GetRandomString(length): def checkCode(code, outime=120): # 校验验证码 - import time import web try: if md5(code.lower()) != web.ctx.session.codeStr: @@ -72,6 +79,10 @@ def checkCode(code, outime=120): return False +def retJson(status, msg, data=()): + return jsonify({'status': status, 'msg': msg, 'data': data}) + + def returnJson(status, msg, args=()): # 取通用Json返回 return getJson(returnMsg(status, msg, args)) @@ -94,7 +105,6 @@ def returnMsg(status, msg, args=()): def getMsg(key, args=()): # 取提示消息 try: - import json logMessage = json.loads( readFile('static/language/' + get_language() + '/public.json')) keys = logMessage.keys() @@ -111,7 +121,7 @@ def getMsg(key, args=()): def getLan(key): # 取提示消息 - import json + logMessage = json.loads( readFile('static/language/' + get_language() + '/template.json')) keys = logMessage.keys() @@ -221,11 +231,9 @@ def httpPost(url, data, timeout=30): #WriteLog('网络诊断',str(ex) + '['+url+']'); return str(ex) -# 写进度 - def writeSpeed(title, used, total, speed=0): - import json + # 写进度 if not title: data = {'title': None, 'progress': 0, 'total': 0, 'used': 0, 'speed': 0} @@ -236,11 +244,9 @@ def writeSpeed(title, used, total, speed=0): writeFile('/tmp/panelSpeed.pl', json.dumps(data)) return True -# 取进度 - def getSpeed(): - import json + # 取进度 data = readFile('/tmp/panelSpeed.pl') if not data: data = json.dumps({'title': None, 'progress': 0, @@ -250,10 +256,6 @@ def getSpeed(): def ExecShell(cmdstring, cwd=None, timeout=None, shell=True): - import shlex - import datetime - import subprocess - import time if shell: cmdstring_list = cmdstring @@ -396,11 +398,9 @@ def getStrBetween(startStr, endStr, srcStr): return None return srcStr[start + 1:end] -# 取CPU类型 - def getCpuType(): - import re + # 取CPU类型 cpuinfo = open('/proc/cpuinfo', 'r').read() rep = "model\s+name\s+:\s+(.+)" tmp = re.search(rep, cpuinfo) diff --git a/data/type.json b/data/type.json index 1d0830249..0f3a4dc76 100755 --- a/data/type.json +++ b/data/type.json @@ -10,13 +10,23 @@ "ps":"" }, { - "title":"系统工具", + "title":"缓存软件", "type":2, "ps":"" }, { - "title":"其他插件", + "title":"代码管理", "type":3, "ps":"" + }, + { + "title":"系统工具", + "type":4, + "ps":"" + }, + { + "title":"其他插件", + "type":5, + "ps":"" } ] \ No newline at end of file diff --git a/plugins/nginx/info.json b/plugins/nginx/info.json index 6b9693d67..aa477b3da 100755 --- a/plugins/nginx/info.json +++ b/plugins/nginx/info.json @@ -5,7 +5,7 @@ "type":"其他插件", "ps":"轻量级,占有内存少,并发能力强", "shell":"install.sh", - "checks":"/www/server/panel/plugin/safelogin", + "checks":"/www/server/panel/plugin/nginx", "author":"伊戈尔·赛索耶夫", "home":"https://www.nginx.org", "path": "/www/server/nginx", diff --git a/plugins/php/info.json b/plugins/php/info.json index f90a31c66..c2599dff7 100755 --- a/plugins/php/info.json +++ b/plugins/php/info.json @@ -18,6 +18,12 @@ "versions": [ { "status": false, + "version": "5.2", + "no": "", + "task": "1" + }, + { + "status": false, "version": "5.3", "no": "", "task": "1" diff --git a/plugins/vpn/info.json b/plugins/vpn/info.json index 40e16ef5d..a7648e7c8 100755 --- a/plugins/vpn/info.json +++ b/plugins/vpn/info.json @@ -14,5 +14,5 @@ "date":"2017-11-24", "default":true, "display":1, - "pid": "3" + "pid": "5" } \ No newline at end of file diff --git a/views/plugins.py b/views/plugins.py index 017c12f17..5e5a4d863 100644 --- a/views/plugins.py +++ b/views/plugins.py @@ -69,23 +69,28 @@ def list(): return jsonify(ret) -@plugins.route("/install", methods=['POST']) +@plugins.route('/install', methods=['POST']) def install(): rundir = public.getRunDir() - name = request.form['name'] + name = request.form.get('name', '') + if name.strip() == '': - return '' + return public.retJson(-1, "123", ()) - infoJson = __plugin_name + "/" + name + "/info.json" - install = __plugin_name + "/" + name + "/install.sh" + infoJsonPos = __plugin_name + '/' + name + '/' + 'info.json' - pluginInfo = json.loads(public.readFile(infoJson)) + if not os.path.exists(infoJsonPos): + return public.retJson(-1, "1233", ()) + pluginInfo = json.loads(public.readFile(infoJsonPos)) - print pluginInfo - - print install - os.system('/bin/bash ' + install + ' install') + sh = __plugin_name + '/' + name + '/' + pluginInfo['shell'] + os.system('/bin/bash ' + sh + ' install') print request.args return '' + + +@plugins.route('/uninstall', methods=['POST']) +def uninstall(): + pass