Skip to content

Commit

Permalink
Merge pull request #651 from midoks/dev
Browse files Browse the repository at this point in the history
代理/重定向功能修复
  • Loading branch information
midoks authored Dec 18, 2024
2 parents 7d6407a + 4cd620f commit a5a7f40
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
11 changes: 10 additions & 1 deletion web/admin/site/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -65,6 +65,15 @@ def get_proxy_conf():
rid = request.form.get("id", '')
return MwSites.instance().getProxyConf(site_name, rid)

# 设置代理
@blueprint.route('/save_proxy_conf', endpoint='save_proxy_conf', methods=['POST'])
@panel_login_required
def save_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'])
Expand Down
12 changes: 12 additions & 0 deletions web/admin/site/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion web/utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,27 @@ 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 pid == '' or site_name == '':
if proxy_id == '' or site_name == '':
return mw.returnData(False, "必填项不能为空!")

conf_file = "{}/{}/{}.conf".format(self.proxyPath, site_name, proxy_id)
Expand All @@ -1709,6 +1727,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, "必填项不能为空!")
Expand Down

0 comments on commit a5a7f40

Please sign in to comment.