Skip to content

Commit

Permalink
设置手动代理配置
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Dec 18, 2024
1 parent 36d604e commit 50ec1c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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('/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'])
Expand Down
19 changes: 19 additions & 0 deletions web/utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "必填项不能为空!")
Expand Down

0 comments on commit 50ec1c5

Please sign in to comment.