From 36d604ec494b21eba03202e07e16314860cedd62 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 18 Dec 2024 22:47:21 +0800 Subject: [PATCH 1/4] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index 6ec5657482..248d3636f7 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1696,7 +1696,7 @@ def openRedirectByOpen(self, site_name): def getProxyConf(self, site_name, proxy_id): - if pid == '' or site_name == '': + if proxy_id == '' or site_name == '': return mw.returnData(False, "必填项不能为空!") conf_file = "{}/{}/{}.conf".format(self.proxyPath, site_name, proxy_id) From 50ec1c59d2dcb5ae3fac0ab4b3a43dc91dbd16a7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 18 Dec 2024 22:53:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/admin/site/proxy.py | 11 ++++++++++- web/utils/site.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/web/admin/site/proxy.py b/web/admin/site/proxy.py index 5c333845a7..65437b0b3f 100644 --- a/web/admin/site/proxy.py +++ b/web/admin/site/proxy.py @@ -47,7 +47,7 @@ def set_proxy(): proxy_id = request.form.get('id', '') return MwSites.instance().setProxy(site_name,site_from,to,host,name,open_proxy, open_cache,cache_time, proxy_id) -# 获取代理状态 +# 设置代理状态 @blueprint.route('/set_proxy_status', endpoint='set_proxy_status', methods=['POST']) @panel_login_required def set_proxy_status(): @@ -65,6 +65,15 @@ def get_proxy_conf(): rid = request.form.get("id", '') return MwSites.instance().getProxyConf(site_name, rid) +# 设置代理 +@blueprint.route('/get_proxy_conf', endpoint='get_proxy_conf', methods=['POST']) +@panel_login_required +def get_proxy_conf(): + site_name = request.form.get("siteName", '') + rid = request.form.get("id", '') + config = request.form.get("config", "") + return MwSites.instance().saveProxyConf(site_name, rid, config) + # 删除代理配置 @blueprint.route('/del_proxy', endpoint='del_proxy', methods=['POST']) diff --git a/web/utils/site.py b/web/utils/site.py index 248d3636f7..adbcc6fc20 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1709,6 +1709,25 @@ def getProxyConf(self, site_name, proxy_id): data = mw.readFile(conf_file) return mw.returnData(True, "ok", {"result": data}) + def saveProxyConf(self, site_name, proxy_id, config): + + if proxy_id == '' or site_name == '': + return mw.returnData(False, "必填项不能为空!") + + proxy_file = "{}/{}/{}.conf".format(self.proxyPath, site_name, proxy_id) + mw.backFile(proxy_file) + mw.writeFile(proxy_file, config) + rule_test = mw.checkWebConfig() + if rule_test != True: + mw.restoreFile(proxy_file) + mw.removeBackFile(proxy_file) + return mw.returnData(False, "OpenResty 配置测试不通过, 请重试: {}".format(rule_test)) + + mw.removeBackFile(proxy_file) + self.operateRedirectConf(site_name, 'start') + mw.restartWeb() + return mw.returnData(True, "ok") + def delProxy(self, site_name, proxy_id): if proxy_id == '' or site_name == '': return mw.returnData(False, "必填项不能为空!") From b1826a60d2330bdb59d7e8bdc4710e38f8211505 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 18 Dec 2024 22:54:46 +0800 Subject: [PATCH 3/4] Update proxy.py --- web/admin/site/proxy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/admin/site/proxy.py b/web/admin/site/proxy.py index 65437b0b3f..83d29f78de 100644 --- a/web/admin/site/proxy.py +++ b/web/admin/site/proxy.py @@ -66,9 +66,9 @@ def get_proxy_conf(): return MwSites.instance().getProxyConf(site_name, rid) # 设置代理 -@blueprint.route('/get_proxy_conf', endpoint='get_proxy_conf', methods=['POST']) +@blueprint.route('/save_proxy_conf', endpoint='save_proxy_conf', methods=['POST']) @panel_login_required -def get_proxy_conf(): +def save_proxy_conf(): site_name = request.form.get("siteName", '') rid = request.form.get("id", '') config = request.form.get("config", "") From 4cd620fe2b7e473c73926b8c7644c1c12de7d209 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 18 Dec 2024 23:01:38 +0800 Subject: [PATCH 4/4] update --- web/admin/site/redirect.py | 12 ++++++++++++ web/utils/site.py | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/web/admin/site/redirect.py b/web/admin/site/redirect.py index b8e641cd55..e02526bd80 100644 --- a/web/admin/site/redirect.py +++ b/web/admin/site/redirect.py @@ -61,6 +61,18 @@ def get_redirect_conf(): redirect_id = request.form.get("id", '') return MwSites.instance().getRedirectConf(site_name, redirect_id) +# 设置重定向配置 +@blueprint.route('/save_redirect_conf', endpoint='save_redirect_conf', methods=['POST']) +@panel_login_required +def save_redirect_conf(): + site_name = request.form.get("siteName", '') + redirect_id = request.form.get("id", '') + config = request.form.get("config", "") + return MwSites.instance().saveRedirectConf(site_name, redirect_id, config) + + + + # 删除重定向配置 @blueprint.route('/del_redirect', endpoint='del_redirect', methods=['POST']) @panel_login_required diff --git a/web/utils/site.py b/web/utils/site.py index adbcc6fc20..407b9a1505 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1694,6 +1694,24 @@ def openRedirectByOpen(self, site_name): self.close_redirect = [] return True + def saveRedirectConf(self, site_name, redirect_id, config): + if redirect_id == '' or site_name == '': + return mw.returnData(False, "必填项不能为空!") + + _old_config = mw.readFile("{}/{}/{}.conf".format(self.redirectPath, site_name, redirect_id)) + if _old_config == False: + return mw.returnData(False, "非法操作") + + mw.writeFile("{}/{}/{}.conf".format(self.redirectPath, site_name, redirect_id), config) + rule_test = mw.checkWebConfig() + if rule_test != True: + mw.writeFile("{}/{}/{}.conf".format(self.redirectPath,site_name, redirect_id), _old_config) + return mw.returnData(False, "OpenResty 配置测试不通过, 请重试: {}".format(rule_test)) + + self.operateRedirectConf(site_name, 'start') + mw.restartWeb() + return mw.returnData(True, "ok") + def getProxyConf(self, site_name, proxy_id): if proxy_id == '' or site_name == '':