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 == '':