From 2dcb8b257e2db770aaa516feb943c8335e0308da Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 29 Nov 2024 21:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/data_query/nosql_memcached.py | 4 +- web/admin/plugins/__init__.py | 17 +++++++ web/utils/plugin.py | 70 +++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/plugins/data_query/nosql_memcached.py b/plugins/data_query/nosql_memcached.py index 18b844edf..b32ef5690 100755 --- a/plugins/data_query/nosql_memcached.py +++ b/plugins/data_query/nosql_memcached.py @@ -69,7 +69,7 @@ class nosqlMemcached(): if not mem_content: return False keys = ["bind", "PORT"] - rep = 'PORT\s*=\s*(.*)' + rep = r'PORT\s*=\s*(.*)' port_re = re.search(rep, mem_content) if port_re: result['port'] = int(port_re.groups()[0].strip()) @@ -106,7 +106,7 @@ class nosqlMemcachedCtr(): item_no = [] for i in m_items: - item_match = b'items:(\d*?):number' + item_match = rb'items:(\d*?):number' item_match_re = re.search(item_match, i) if item_match_re: v = item_match_re.groups()[0].strip() diff --git a/web/admin/plugins/__init__.py b/web/admin/plugins/__init__.py index 8d7c72fb5..d152ae3e3 100644 --- a/web/admin/plugins/__init__.py +++ b/web/admin/plugins/__init__.py @@ -148,6 +148,23 @@ def file(): content = open(file, 'rb').read() return content + +# 插件上传 +@blueprint.route('/update_zip', endpoint='update_zip', methods=['POST']) +@panel_login_required +def update_zip(): + request_zip = request.files['plugin_zip'] + return MwPlugin.instance().updateZip(request_zip) + + +@blueprint.route('/input_zip', endpoint='input_zip', methods=['POST']) +@panel_login_required +def input_zip(): + plugin_name = request.form.get('plugin_name', '') + tmp_path = request.form.get('tmp_path', '') + return MwPlugin.instance().inputZipApi(plugin_name,tmp_path) + + # 插件设置页 @blueprint.route('/setting', endpoint='setting', methods=['GET']) @panel_login_required diff --git a/web/utils/plugin.py b/web/utils/plugin.py index 57ccc1a6f..24c2cea02 100644 --- a/web/utils/plugin.py +++ b/web/utils/plugin.py @@ -634,6 +634,76 @@ class plugin(object): rdata['list'] = mw.getPage({'count':data[1],'p':page,'tojs':'getSList','row':size}) return rdata + def updateZip(self, request_zip): + tmp_path = mw.getPanelDir() + '/temp' + if not os.path.exists(tmp_path): + os.makedirs(tmp_path) + mw.execShell("rm -rf " + tmp_path + '/*') + + tmp_file = tmp_path + '/plugin_tmp.zip' + if request_zip.filename[-4:] != '.zip': + return mw.returnData(False, '仅支持zip文件!') + + request_zip.save(tmp_file) + mw.execShell('cd ' + tmp_path + ' && unzip ' + tmp_file) + os.remove(tmp_file) + + p_info = tmp_path + '/info.json' + if not os.path.exists(p_info): + d_path = None + for df in os.walk(tmp_path): + if len(df[2]) < 3: + continue + if not 'info.json' in df[2]: + continue + if not 'install.sh' in df[2]: + continue + if not os.path.exists(df[0] + '/info.json'): + continue + d_path = df[0] + if d_path: + tmp_path = d_path + p_info = tmp_path + '/info.json' + try: + data = json.loads(mw.readFile(p_info)) + data['size'] = mw.getPathSize(tmp_path) + if not 'author' in data: + data['author'] = '未知' + if not 'home' in data: + data['home'] = 'https://github.com/midoks/mdserver-web' + plugin_path = mw.getPluginDir() + data['name'] + '/info.json' + data['old_version'] = '0' + data['tmp_path'] = tmp_path + if os.path.exists(plugin_path): + try: + old_info = json.loads(mw.readFile(plugin_path)) + data['old_version'] = old_info['versions'] + except: + pass + except: + mw.execShell("rm -rf " + tmp_path) + return mw.returnData(False, '在压缩包中没有找到插件信息,请检查插件包!') + protectPlist = ('openresty', 'mysql', 'php', 'redis', 'memcached' + 'mongodb', 'swap', 'gogs', 'pureftp') + if data['name'] in protectPlist: + return mw.returnData(False, '[' + data['name'] + '],重要插件不可修改!') + return data + + def inputZipApi(self, plugin_name,tmp_path): + if not os.path.exists(tmp_path): + return mw.returnData(False, '临时文件不存在,请重新上传!') + plugin_path = mw.getPluginDir() + '/' + plugin_name + if not os.path.exists(plugin_path): + print(mw.execShell('mkdir -p ' + plugin_path)) + mw.execShell("cp -rf " + tmp_path + '/* ' + plugin_path + '/') + mw.execShell('chmod -R 755 ' + plugin_path) + p_info = mw.readFile(plugin_path + '/info.json') + if p_info: + mw.writeLog('软件管理', '安装第三方插件[%s]' %json.loads(p_info)['title']) + return mw.returnData(True, '安装成功!') + mw.execShell("rm -rf " + plugin_path) + return mw.returnData(False, '安装失败!') + # shell/bash方式调用 def run(self, name, func, version = '',