From 7d7d18e27b3916a9b0c0f18ff78d63033bb4de2f Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 4 Jul 2022 14:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/site_api.py | 40 +++++++++++++++++++++-- route/static/app/site.js | 68 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/class/core/site_api.py b/class/core/site_api.py index dcf46424e..2c9e01968 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -1430,6 +1430,42 @@ class site_api: mw.writeFile(vhost_file, content) + def getProxyConfApi(self): + _siteName = request.form.get("siteName", '') + _id = request.form.get("id", '') + if _id == '' or _siteName == '': + return mw.returnJson(False, "必填项不能为空!") + + data = mw.readFile( + "{}/{}/{}.conf".format(self.proxyPath, _siteName, _id)) + if data == False: + return mw.returnJson(False, "获取失败!") + return mw.returnJson(True, "ok", {"result": data}) + + def saveProxyConfApi(self): + _siteName = request.form.get("siteName", '') + _id = request.form.get("id", '') + _config = request.form.get("config", "") + if _id == '' or _siteName == '': + return mw.returnJson(False, "必填项不能为空!") + + _old_config = mw.readFile( + "{}/{}/{}.conf".format(self.proxyPath, _siteName, _id)) + if _old_config == False: + return mw.returnJson(False, "非法操作") + + mw.writeFile("{}/{}/{}.conf".format(self.proxyPath, + _siteName, _id), _config) + rule_test = mw.checkWebConfig() + if rule_test != True: + mw.writeFile("{}/{}/{}.conf".format(self.proxyPath, + _siteName, _id), _old_config) + return mw.returnJson(False, "OpenResty 配置测试不通过, 请重试: {}".format(rule_test)) + + self.operateRedirectConf(_siteName, 'start') + mw.restartWeb() + return mw.returnJson(True, "ok") + # 读取 网站 反向代理列表 def getProxyListApi(self): _siteName = request.form.get('siteName', '') @@ -1527,9 +1563,7 @@ location ~* ^{from}(.*)$ { self.operateProxyConf(_siteName, 'start') mw.restartWeb() - return mw.returnJson(True, "ok", { - "hash": _id - }) + return mw.returnJson(True, "ok", {"hash": _id}) def delProxyApi(self): _siteName = request.form.get("siteName", '') diff --git a/route/static/app/site.js b/route/static/app/site.js index f20137106..c5072888c 100755 --- a/route/static/app/site.js +++ b/route/static/app/site.js @@ -1696,6 +1696,69 @@ function toProxy(siteName, type, obj) { } + if (type == 3) { + var laoding = layer.load(); + var data = {siteName: siteName,id: obj}; + $.post('/site/get_proxy_conf', data, function(res) { + layer.close(laoding); + res = JSON.parse(res); + if (res.status == true) { + var mBody = "
\ + \ +
\ +
    \ +
  • 此处为反向代理配置文件,若您不了解配置规则,请勿随意修改.
  • \ +
\ +
\ +
"; + var editor; + var index = layer.open({ + type: 1, + title: '编辑配置文件', + closeBtn: 1, + shadeClose: true, + area: ['500px', '500px'], + btn: ['提交','关闭'], + content: mBody, + success: function () { + editor = CodeMirror.fromTextArea(document.getElementById("configRedirectBody"), { + extraKeys: {"Ctrl-Space": "autocomplete"}, + lineNumbers: true, + matchBrackets:true, + }); + editor.focus(); + $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); + $("#onlineEditFileBtn").unbind('click'); + }, + yes:function(index,layero){ + $("#configRedirectBody").empty().text(editor.getValue()); + var load = layer.load(); + var data = { + siteName: siteName, + id: obj, + config: editor.getValue(), + }; + $.post('/site/save_proxy_conf', data, function(res) { + layer.close(load) + var res = JSON.parse(res); + if (res.status == true) { + layer.msg('保存成功', {icon: 1}); + layer.close(index); + } else { + layer.msg(res.msg, {time: 3000,icon: 2}); + } + }); + return true; + }, + }); + } else { + layer.msg('请求错误!!', {time: 3000,icon: 2}); + } + }); + return + } + + var body = '
\
\ \ @@ -1729,7 +1792,10 @@ function toProxy(siteName, type, obj) { let tmp = '\ '+item.from+'\ '+item.to+'\ - 删除\ + \ + 详情 |\ + 删除\ + \ '; $("#md-301-body").append(tmp); })