From 4a087ef10cbd7abc4ca8861e8bff1c2515aa9fde Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 21 Nov 2018 18:18:17 +0800 Subject: [PATCH] u --- class/core/plugin.py | 139 ++++++++++++++++++++++++++++++++++++ plugins/csvn/info.json | 3 +- plugins/mysql/info.json | 1 + plugins/nginx/info.json | 5 +- plugins/php/info.json | 80 +-------------------- plugins/redis/info.json | 1 + plugins/redis/install.sh | 2 +- route/plugins.py | 38 ++-------- static/js/soft.js | 75 ++++++++++--------- task.py | 6 +- templates/default/soft.html | 2 +- 11 files changed, 198 insertions(+), 154 deletions(-) create mode 100755 class/core/plugin.py diff --git a/class/core/plugin.py b/class/core/plugin.py new file mode 100755 index 000000000..11ce662c3 --- /dev/null +++ b/class/core/plugin.py @@ -0,0 +1,139 @@ +# coding: utf-8 + +import psutil +import time +import os +import public +import re +import json + + +class plugin: + __tasks = None + __plugin_dir = "plugins" + __type = "data/type.json" + setupPath = None + + def __init__(self): + self.setupPath = 'server' + + # 进程是否存在 + def processExists(self, pname, exe=None): + try: + if not self.pids: + self.pids = psutil.pids() + for pid in self.pids: + try: + p = psutil.Process(pid) + if p.name() == pname: + if not exe: + return True + else: + if p.exe() == exe: + return True + except: + pass + return False + except: + return True + + # 检查是否正在安装 + def checkSetupTask(self, sName): + if not self.__tasks: + self.__tasks = public.M('tasks').where( + "status!=?", ('1',)).field('status,name').select() + if sName.find('php-') != -1: + tmp = sName.split('-') + sName = tmp[0] + version = tmp[1] + isTask = '1' + for task in self.__tasks: + tmpt = public.getStrBetween('[', ']', task['name']) + if not tmpt: + continue + tmp1 = tmpt.split('-') + name1 = tmp1[0].lower() + if sName == 'php': + if name1 == sName and tmp1[1] == version: + isTask = task['status'] + else: + if name1 == 'pure': + name1 = 'pure-ftpd' + if name1 == sName: + isTask = task['status'] + return isTask + + def checkStatus(self, info): + pass + + # 构造本地插件信息 + def getPluginInfo(self, info): + print info["checks"] + + checks = "" + if info["checks"][0:1] == "/": + checks = info["checks"] + else: + checks = public.getRootDir() + "/" + info['checks'] + + pluginInfo = { + "id": 10000, + "pid": info['pid'], + "type": 1000, + "name": info['name'], + "title": info['title'], + "ps": info['ps'], + "dependnet": "", + "mutex": "", + "install_checks": checks, + "uninsatll_checks": checks, + "versions": info['versions'], + # "updates": info['updates'], + "setup": False, + "status": False, + } + + pluginInfo['task'] = self.checkSetupTask(pluginInfo['name']) + pluginInfo['setup'] = os.path.exists(pluginInfo['install_checks']) + pluginInfo['status'] = os.path.exists(pluginInfo['install_checks']) + return pluginInfo + + def getPluginList(self, sType, sPage=1, sPageSize=15): + + ret = {} + ret['type'] = json.loads(public.readFile(self.__type)) + plugins_info = [] + for dirinfo in os.listdir(self.__plugin_dir): + path = self.__plugin_dir + '/' + dirinfo + if os.path.isdir(path): + jsonFile = path + '/info.json' + if os.path.exists(jsonFile): + try: + tmp = json.loads(public.readFile(jsonFile)) + if tmp['name'] == 'php': + for v in tmp['versions']: + pg = self.getPluginInfo(tmp) + pg['versions'] = v + # print "sss:", i, v + # pg['updates'] = tmp["updates"][v] + if sType == "0": + plugins_info.append(pg) + else: + if pg['pid'] == sType: + plugins_info.append(pg) + else: + pg = self.getPluginInfo(tmp) + if sType == "0": + plugins_info.append(pg) + else: + if pg['pid'] == sType: + plugins_info.append(pg) + except BaseException, e: + print e + args = {} + args['count'] = len(plugins_info) + args['p1'] = sPage + + ret['data'] = plugins_info + ret['list'] = public.getPage(args) + return ret diff --git a/plugins/csvn/info.json b/plugins/csvn/info.json index ad4503f8c..3ec65ac12 100755 --- a/plugins/csvn/info.json +++ b/plugins/csvn/info.json @@ -5,8 +5,9 @@ "name": "csvn", "title": "CSVN", "versions": ["5.1"], + "updates":["5.1.4"], "tip": "soft", - "checks": "server/csvn/VERSION/", + "checks": "server/csvn", "author": "midoks", "date": "2017-04-01", "home": "https://www.collab.net", diff --git a/plugins/mysql/info.json b/plugins/mysql/info.json index 6f22edb01..e6c3be31a 100755 --- a/plugins/mysql/info.json +++ b/plugins/mysql/info.json @@ -5,6 +5,7 @@ "type":"运行环境", "ps":"MySQL是一种关系数据库管理系统!", "versions":["5.5"], + "updates":["5.5"], "shell":"install.sh", "checks":"/www/server/panel/plugin/safelogin", "author":"midoks", diff --git a/plugins/nginx/info.json b/plugins/nginx/info.json index 0134d45ce..5cf3cc061 100755 --- a/plugins/nginx/info.json +++ b/plugins/nginx/info.json @@ -8,8 +8,9 @@ "checks":"server/nginx", "author":"伊戈尔·赛索耶夫", "home":"https://www.nginx.org", - "path": "server/nginx", + "checks": "server/nginx", "date":"2017-11-24", "pid": "1", - "versions": ["1.14.0", "1.12.2", "1.8.1", "1.15.3", "-Tengine2.2.2", "openresty"] + "versions": ["1.14.0", "1.12.2", "1.8.1", "1.15.3", "-Tengine2.2.2", "openresty"], + "updates": ["1.14.0", "1.12.2", "1.8.1", "1.15.3", "-Tengine2.2.2", "openresty"] } \ No newline at end of file diff --git a/plugins/php/info.json b/plugins/php/info.json index c2599dff7..682e48aaa 100755 --- a/plugins/php/info.json +++ b/plugins/php/info.json @@ -5,8 +5,8 @@ "name": "php", "title": "PHP", "default": false, - "versions": "5.2,5.3,5.4,5.5,5.6,7.0,7.1,7.2", - "update": "5.2.17p1,5.3.29,5.4.45,5.5.38,5.6.32,7.0.26,7.1.12,7.2.0", + "versions": ["5.2","5.3","5.4","5.5","5.6","7.0","7.1","7.2"], + "updates": ["5.2.17p1","5.3.29","5.4.45","5.5.38","5.6.32","7.0.26","7.1.12","7.2.0"], "tip": "soft", "checks": "/www/server/php/VERSION/bin/php", "display": 1, @@ -14,79 +14,5 @@ "date": "2017-04-01", "home": "https://www.php.net", "type": "语言解释器", - "pid": "1", - "versions": [ - { - "status": false, - "version": "5.2", - "no": "", - "task": "1" - }, - { - "status": false, - "version": "5.3", - "no": "", - "task": "1" - }, - { - "status": true, - "task": "1", - "run": true, - "no": "5.4.45", - "fpm": true, - "max": "50", - "version": "5.4", - "pathinfo": true, - "maxTime": "100", - "display": false - }, - { - "status": false, - "version": "5.5", - "no": "", - "task": "1" - }, - { - "status": true, - "task": "1", - "run": true, - "no": "5.6.30", - "fpm": true, - "max": "50", - "version": "5.6", - "pathinfo": true, - "maxTime": "100", - "display": false - }, - { - "status": true, - "task": "1", - "run": true, - "no": "7.0.19", - "fpm": true, - "max": "50", - "version": "7.0", - "pathinfo": true, - "maxTime": "100", - "display": false - }, - { - "status": true, - "task": "1", - "run": true, - "no": "7.1.5", - "fpm": true, - "max": "50", - "version": "7.1", - "pathinfo": true, - "maxTime": "100", - "display": false - }, - { - "status": false, - "version": "7.2", - "no": "", - "task": "1" - } - ] + "pid": "1" } \ No newline at end of file diff --git a/plugins/redis/info.json b/plugins/redis/info.json index 945f5b7cb..0b3cb00c9 100755 --- a/plugins/redis/info.json +++ b/plugins/redis/info.json @@ -6,6 +6,7 @@ "shell": "install.sh", "default": false, "versions":["4.0"], + "updates":["4.0.11"], "tip": "soft", "checks": "server/redis", "display": 1, diff --git a/plugins/redis/install.sh b/plugins/redis/install.sh index 4b166bded..d4f75cc9c 100755 --- a/plugins/redis/install.sh +++ b/plugins/redis/install.sh @@ -26,7 +26,7 @@ Install_redis() echo '安装完成' > $install_tmp - # rm -rf $serverPath/tmp + rm -rf $serverPath/tmp } Uninstall_redis() diff --git a/route/plugins.py b/route/plugins.py index 36ab7d604..6e3302d04 100644 --- a/route/plugins.py +++ b/route/plugins.py @@ -12,6 +12,7 @@ import json sys.path.append("class/core") import public +import plugin plugins = Blueprint('plugins', __name__, template_folder='templates') @@ -39,40 +40,9 @@ def file(): @plugins.route("/list", methods=['GET', 'POST']) def list(): - - data = json.loads(public.readFile("data/type.json")) - ret = {} - ret["type"] = data - - plugins_info = [] - - typeVal = request.args.get('type', '') - if typeVal == "": - typeVal = "0" - - for dirinfo in os.listdir(__plugin_name): - path = __plugin_name + "/" + dirinfo - if os.path.isdir(path): - jsonFile = path + "/info.json" - if os.path.exists(jsonFile): - try: - tmp = json.loads(public.readFile(jsonFile)) - if typeVal == "0": - plugins_info.append(tmp) - else: - if tmp['pid'] == typeVal: - plugins_info.append(tmp) - except: - pass - - ret['data'] = plugins_info - - args = {} - args['count'] = len(plugins_info) - args['p1'] = 1 - - ret['list'] = public.getPage(args) - return jsonify(ret) + typeVal = request.args.get('type', '0') + data = plugin.plugin().getPluginList(typeVal, 1) + return public.getJson(data) @plugins.route('/install', methods=['POST']) diff --git a/static/js/soft.js b/static/js/soft.js index 5c7f01057..bb0f52f11 100755 --- a/static/js/soft.js +++ b/static/js/soft.js @@ -1784,6 +1784,7 @@ function GetSList(isdisplay) { $(".task").text(rdata.data[rdata.length - 1]); for (var i = 0; i < rdata.data.length; i++) { + var plugin = rdata.data[i]; var len = rdata.data[i].versions.length; var version_info = ''; var version = ''; @@ -1793,50 +1794,54 @@ function GetSList(isdisplay) { var indexshow = ''; var checked = ''; - checked = rdata.data[i].display ? 'checked' : ''; + checked = plugin.display ? 'checked' : ''; - if (typeof rdata.data[i].versions == "string"){ - version_info += rdata.data[i].versions + '|'; + if (typeof plugin.versions == "string"){ + version_info += plugin.versions + '|'; } else { for (var j = 0; j < len; j++) { - version_info += rdata.data[i].versions[j] + '|'; + version_info += plugin.versions[j] + '|'; } } if (version_info != '') { version_info = version_info.substring(0, version_info.length - 1); } - var handle = '' + lan.soft.install + ''; + var handle = '安装'; var isSetup = false; - if (rdata.data[i].name != 'php') { + + if (plugin.name != 'php') { for (var n = 0; n < len; n++) { - if (rdata.data[i].versions[n].status == true) { + if (plugin.status == true) { isSetup = true; - if (rdata.data[i].tip == 'lib') { - var mupdate = (rdata.data[i].versions[n].no == rdata.data[i].versions[n].version) ? '' : '更新 | '; - handle = mupdate + '' + lan.soft.setup + ' | ' + lan.soft.uninstall + ''; - titleClick = 'onclick="PluginMan(\'' + rdata.data[i].name + '\',\'' + rdata.data[i].title + '\')" style="cursor:pointer"'; + if (plugin.tip == 'lib') { + var mupdate = (plugin.versions[n].no == plugin.versions[n].version) ? '' : '更新 | '; + handle = mupdate + '' + lan.soft.setup + ' | 卸载'; + titleClick = 'onclick="PluginMan(\'' + plugin.name + '\',\'' + plugin.title + '\')" style="cursor:pointer"'; } else { - var mupdate = (rdata.data[i].versions[n].no == rdata.data[i].update[n]) ? '' : '更新 | '; - if (rdata.data[i].versions[n].no == '') mupdate = ''; - handle = mupdate + '' + lan.soft.setup + ' | ' + lan.soft.uninstall + ''; - titleClick = 'onclick="SoftMan(\'' + rdata.data[i].name + '\',\'' + version_info + '\')" style="cursor:pointer"'; + console.log(plugin, n); + + + var mupdate = '';//(plugin.versions[n] == plugin.updates[n]) '' : '更新 | '; + if (plugin.versions[n] == '') mupdate = ''; + handle = mupdate + '' + lan.soft.setup + ' | 卸载'; + titleClick = 'onclick="SoftMan(\'' + plugin.name + '\',\'' + version_info + '\')" style="cursor:pointer"'; } - version = rdata.data[i].versions[n].version; + version = plugin.version; softPath = ''; - indexshow = '
'; + indexshow = '
'; if (rdata.data[i].versions[n].run == true) { state = '' } else { state = '' } } - var isTask = rdata.data[i].versions[n].task; + var isTask = plugin.task; if (isTask == '-1') { - handle = '' + lan.soft.the_install + '' + handle = '正在安装...'; } else if (isTask == '0') { - handle = '' + lan.soft.sleep_install + '' + handle = '等待安装...'; } } @@ -1853,18 +1858,18 @@ function GetSList(isdisplay) { } else { var pnum = 0; for (var n = 0; n < len; n++) { - if (rdata.data[i].versions[n].status == true) { - checked = rdata.data[i].versions[n]['display'] ? "checked" : ""; - var mupdate = (rdata.data[i].versions[n].no == rdata.data[i].update[n]) ? '' : '更新 | '; - handle = mupdate + '' + lan.soft.setup + ' | ' + lan.soft.uninstall + ''; - softPath = ''; - titleClick = 'onclick="phpSoftMain(\'' + rdata.data[i].versions[n].version + '\',' + n + ')" style="cursor:pointer"'; - indexshow = '
'; - if (rdata.data[i].versions[n].run == true) { - state = '' - } else { - state = '' - } + if (plugin.status == true) { + // checked = plugin.versions[n]['display'] ? "checked" : ""; + // var mupdate = (plugin.versions[n] == plugin.updates[n]) ? '' : '更新 | '; + // handle = mupdate + '' + lan.soft.setup + ' | 卸载'; + // softPath = ''; + // titleClick = 'onclick="phpSoftMain(\'' + plugin.versions[n] + '\',' + n + ')" style="cursor:pointer"'; + // indexshow = '
'; + // if (plugin.run == true) { + // state = '' + // } else { + // state = '' + // } } else { handle = '' + lan.soft.install + ''; softPath = ''; @@ -1922,7 +1927,7 @@ function GetSList(isdisplay) { $(this).addClass("on").siblings().removeClass("on"); GetSList(); }) - }) + },'json'); } //刷新状态 function FPStatus() { @@ -2327,7 +2332,7 @@ function toIndexDisplay(name, version) { status = $("#index_" + name + verinfo).prop("checked") ? "0" : "1"; } var data = "name=" + name + "&status=" + status + "&version=" + version; - $.post("/plugins?action=setPluginStatus", data, function(rdata) { + $.post("/plugins/set_plugin_status", data, function(rdata) { if (rdata.status) { layer.msg(rdata.msg, { icon: 1 }) } @@ -2345,7 +2350,7 @@ function flush_cache() { $(function() { - if (window.document.location.pathname == '/soft') { + if (window.document.location.pathname == '/soft/') { setInterval(function() { GetSList(true); }, 5000); } }); \ No newline at end of file diff --git a/task.py b/task.py index 08685ea27..edd4e7c18 100755 --- a/task.py +++ b/task.py @@ -9,7 +9,7 @@ import json # import psutil import time -sys.path.append(os.getcwd() + "/class/") +sys.path.append(os.getcwd() + "/class/core") reload(sys) sys.setdefaultencoding('utf-8') import db @@ -113,13 +113,13 @@ def startTask(): while True: try: if os.path.exists(isTask): - print "run --- !" + # print "run --- !" sql = db.Sql() sql.table('tasks').where( "status=?", ('-1',)).setField('status', '0') taskArr = sql.table('tasks').where("status=?", ('0',)).field( 'id,type,execstr').order("id asc").select() - print sql + # print sql for value in taskArr: start = int(time.time()) if not sql.table('tasks').where("id=?", (value['id'],)).count(): diff --git a/templates/default/soft.html b/templates/default/soft.html index a0e28d660..d883e12e1 100755 --- a/templates/default/soft.html +++ b/templates/default/soft.html @@ -28,8 +28,8 @@ 软件名称 说明 - 状态 位置 + 状态 首页显示 操作