Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代理/重定向功能修复 #651

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading