From 99a15ffc8295d5c77f2645d9a84f8a6feb898589 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 17 Jan 2023 03:46:04 +0800 Subject: [PATCH 01/63] Update mw.py --- class/core/mw.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/class/core/mw.py b/class/core/mw.py index a111c912cc..3ebfba4df3 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -454,6 +454,12 @@ def getDate(): return time.strftime('%Y-%m-%d %X', time.localtime()) +def getDataFromInt(val): + time_format = '%Y-%m-%d %H:%M:%S' + time_str = time.localtime(val) + return time.strftime(time_format, time_str) + + def writeLog(stype, msg, args=()): # 写日志 try: From 1558e93f33e2cb1d9317abd0ad964994d0246a05 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 17 Jan 2023 15:37:22 +0800 Subject: [PATCH 02/63] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 73b5a21507..292b5ddd39 100644 --- a/.gitignore +++ b/.gitignore @@ -157,6 +157,7 @@ data/bind_domain.pl plugins/l2tp plugins/openlitespeed plugins/system_safe +plugins/tamper_proof plugins/gdrive plugins/mtproxy plugins/zimg From ec78197317ac67094f359e2ee81d66d7271cfcb6 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 17 Jan 2023 15:58:27 +0800 Subject: [PATCH 03/63] Update plugins_api.py --- class/core/plugins_api.py | 42 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py index 54641a6f6a..4005de3184 100755 --- a/class/core/plugins_api.py +++ b/class/core/plugins_api.py @@ -214,10 +214,7 @@ def hookInstallFile(self, hook_name, info): isNeedAdd = False if isNeedAdd: - tmp = {} - tmp['title'] = info['title'] - tmp['name'] = info['name'] - data.append(tmp) + data.append(info) mw.writeFile(hookPath, json.dumps(data)) def hookUninstallFile(self, hook_name, info): @@ -233,21 +230,40 @@ def hookUninstallFile(self, hook_name, info): mw.writeFile(hookPath, json.dumps(data)) def hookInstall(self, info): + valid_hook = ['backup', 'database'] + valid_list_hook = ['menu'] if 'hook' in info: hooks = info['hook'] - for x in hooks: - if x in ['backup', 'database']: - self.hookInstallFile(x, info) - return True + hooks_type = type(hooks) + if hooks_type == list: + for h in hooks: + tag = h['tag'] + if tag in valid_list_hook: + self.hookInstallFile(tag, h[tag]) + + elif hooks_type == str: + for x in hooks: + if x in valid_hook: + self.hookInstallFile(x, info) + return True return False def hookUninstall(self, info): + valid_hook = ['backup', 'database'] + valid_list_hook = ['menu'] if 'hook' in info: - hooks = info['hook'] - for x in hooks: - if x in ['backup', 'database']: - self.hookUninstallFile(x, info) - return True + ooks = info['hook'] + hooks_type = type(hooks) + if hooks_type == list: + for h in hooks: + tag = h['tag'] + if tag in valid_list_hook: + self.hookUninstallFile(tag, h[tag]) + elif hooks_type == str: + for x in hooks: + if x in valid_hook: + self.hookUninstallFile(x, info) + return True return False def uninstallOldApi(self): From b35ae736a377b9321895395375f44c5ce8e2c723 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 18 Jan 2023 00:57:25 +0800 Subject: [PATCH 04/63] up --- class/core/config_api.py | 15 +++++++++++--- class/core/mw.py | 4 ++++ class/core/plugins_api.py | 41 +++++++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index b8d0c54493..df0342f639 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -781,12 +781,21 @@ def get(self): "id=?", (1,)).getField('username') # databases hook 获取 - database_file = 'data/hook_database.json' - if os.path.exists(database_file): - df = mw.readFile(database_file) + database_hook_file = 'data/hook_database.json' + if os.path.exists(database_hook_file): + df = mw.readFile(database_hook_file) df = json.loads(df) data['hook_database'] = df else: data['hook_database'] = [] + # menu hook 获取 + menu_hook_file = 'data/hook_menu.json' + if os.path.exists(menu_hook_file): + df = mw.readFile(menu_hook_file) + df = json.loads(df) + data['hook_menu'] = df + else: + data['hook_menu'] = [] + return data diff --git a/class/core/mw.py b/class/core/mw.py index 3ebfba4df3..c1a25626a1 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1281,6 +1281,10 @@ def toSize(size): return str(round(size, 2)) + ' ' + b +def getPathSuffix(path): + return os.path.splitext(path)[-1] + + def getMacAddress(): # 获取mac import uuid diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py index 4005de3184..89a99f2209 100755 --- a/class/core/plugins_api.py +++ b/class/core/plugins_api.py @@ -27,7 +27,7 @@ import threading import multiprocessing - +from flask import render_template from flask import request @@ -75,12 +75,35 @@ def listApi(self): data = self.getPluginList(sType, int(sPage)) return mw.getJson(data) + def menuGetAbsPath(self, tag, path): + if path[0:1] == '/': + return path + else: + return mw.getPluginDir() + '/' + tag + '/' + path + + def menuApi(self): + import config_api + data = config_api.config_api().get() + tag = request.args.get('tag', '') + menu_file = 'data/hook_menu.json' + content = '' + if os.path.exists(menu_file): + t = mw.readFile(menu_file) + tlist = json.loads(t) + for menu_data in tlist: + if 'path' in menu_data: + tpath = self.menuGetAbsPath(tag, menu_data['path']) + content = mw.readFile(tpath) + data['plugin_content'] = content + return render_template('plugin_menu.html', data=data) + def fileApi(self): name = request.args.get('name', '') if name.strip() == '': return '' f = request.args.get('f', '') + if f.strip() == '': return '' @@ -88,8 +111,18 @@ def fileApi(self): if not os.path.exists(file): return '' - c = open(file, 'rb').read() - return c + suffix = mw.getPathSuffix(file) + # c = open(file, 'rb').read() + content = mw.readFile(file) + print("ddd:", suffix) + if suffix == '.css': + + from flask import Response + from flask import make_response + v = Response(content, headers={'Content-Type': 'css/text'}) + return make_response(v) + + return content def indexListApi(self): data = self.getIndexList() @@ -252,7 +285,7 @@ def hookUninstall(self, info): valid_hook = ['backup', 'database'] valid_list_hook = ['menu'] if 'hook' in info: - ooks = info['hook'] + hooks = info['hook'] hooks_type = type(hooks) if hooks_type == list: for h in hooks: From b4b9b6eb1f80b52daf612b502d05b91a64bca63f Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 18 Jan 2023 00:57:30 +0800 Subject: [PATCH 05/63] Create plugin_menu.html --- route/templates/default/plugin_menu.html | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 route/templates/default/plugin_menu.html diff --git a/route/templates/default/plugin_menu.html b/route/templates/default/plugin_menu.html new file mode 100644 index 0000000000..2e4ca72df4 --- /dev/null +++ b/route/templates/default/plugin_menu.html @@ -0,0 +1,4 @@ +{% extends "layout.html" %} +{% block content %} +{{data['plugin_content']}} +{% endblock %} \ No newline at end of file From 4e16773ed82f71a2b6d6f36056d255a10bc45458 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 18 Jan 2023 00:57:38 +0800 Subject: [PATCH 06/63] Update layout.html --- route/templates/default/layout.html | 51 ++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/route/templates/default/layout.html b/route/templates/default/layout.html index 3f3b5831b2..830a2bdbdb 100755 --- a/route/templates/default/layout.html +++ b/route/templates/default/layout.html @@ -23,6 +23,14 @@ gtag('js', new Date()); gtag('config', 'G-FC74BB2RGD'); + + + {% for menu in data['hook_menu'] %} + {% if menu['js_path'] %} + + + {% endif %} + {% endfor %} @@ -33,12 +41,18 @@

{{data['ip']}}