From 4a6c88101888029a3176e85dedb31d56c6ab4814 Mon Sep 17 00:00:00 2001 From: soxft Date: Thu, 30 Jun 2022 07:26:13 +0000 Subject: [PATCH] feta: add proxy conf nginx.conf --- class/core/site_api.py | 28 ++++++++++------ data/tpl/nginx.conf | 6 +++- route/static/app/site.js | 72 +++++++++++++++++----------------------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/class/core/site_api.py b/class/core/site_api.py index 1f8c7a7f5..4de502389 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -43,6 +43,11 @@ class site_api: if not os.path.exists(self.redirectPath): mw.execShell("mkdir -p " + self.redirectPath + " && chmod -R 755 " + self.redirectPath) + + self.proxyPath = self.setupPath + '/nginx/proxy' + if not os.path.exists(self.proxyPath): + mw.execShell("mkdir -p " + self.proxyPath + + " && chmod -R 755 " + self.proxyPath) self.logsPath = mw.getRootDir() + '/wwwlogs' # ssl conf @@ -1337,21 +1342,15 @@ class site_api: return mw.returnJson(False, "删除失败!") return mw.returnJson(True, "删除成功!") + # 读取 网站 反向代理列表 def getProxyListApi(self): siteName = request.form.get('siteName', '') conf_path = self.getHostConf(siteName) old_conf = mw.readFile(conf_path) - rep = "(#PROXY-START(\n|.)+#PROXY-END)" - url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);" - host_rep = "Host\s(.*);" - - proxyUrl = self.__read_config(self.__proxyfile) - sitename = sitename - proxylist = [] - for i in proxyUrl: - if i["sitename"] == sitename: - proxylist.append(i) - return mw.getJson(proxylist) + + return mw.returnJson(True, "ok", { + "conf_content": old_conf + }) def getSiteTypesApi(self): # 取网站分类 @@ -1509,6 +1508,12 @@ class site_api: def getRedirectPath(self, siteName): return "{}/{}/".format(self.redirectPath, siteName) + + def getProxytDataPath(self, siteName): + return "{}/{}/data.json".format(self.proxyPath, siteName) + + def getProxyDataPath(self, siteName): + return "{}/{}/data.json".format(self.proxyPath, siteName) def getDirBindRewrite(self, siteName, dirname): return self.rewritePath + '/' + siteName + '_' + dirname + '.conf' @@ -1808,6 +1813,7 @@ class site_api: content = content.replace('{$PHPVER}', self.phpVersion) content = content.replace('{$OR_REWRITE}', self.rewritePath) content = content.replace('{$OR_REDIRECT}', self.redirectPath) + content = content.replace('{$OR_PROXY}', self.proxyPath) logsPath = mw.getLogsDir() content = content.replace('{$LOGPATH}', logsPath) diff --git a/data/tpl/nginx.conf b/data/tpl/nginx.conf index 504cc6e8b..cb7c79ad3 100755 --- a/data/tpl/nginx.conf +++ b/data/tpl/nginx.conf @@ -24,7 +24,11 @@ server #301-START include {$OR_REDIRECT}/{$SERVER_NAME}/*.conf; - ##301-END + #301-END + + #PROXY-START + include {$OR_PROXY}/{$SERVER_NAME}/*.conf; + #PROXY-END #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) diff --git a/route/static/app/site.js b/route/static/app/site.js index 02e7866b8..9ad7e4432 100755 --- a/route/static/app/site.js +++ b/route/static/app/site.js @@ -994,7 +994,7 @@ function webEdit(id,website,endTime,addtime){ +"

SSL

" +"

PHP版本

" +"

重定向

" - +"

反向代理

" + +"

反向代理

" +"

防盗链

" +"

响应日志

"; layer.open({ @@ -1367,48 +1367,38 @@ function delDirBind(id,siteId){ } //反向代理 -function proxyList(siteName,type){ - if(type == 1){ - type = $("input[name='status']").attr('checked')?'0':'1'; - toUrl = encodeURIComponent($("input[name='toUrl']").val()); - toDomain = encodeURIComponent($("input[name='toDomain']").val()); - var sub1 = encodeURIComponent($("input[name='sub1']").val()); - var sub2 = encodeURIComponent($("input[name='sub2']").val()); - var data = 'name='+siteName+'&type='+type+'&proxyUrl='+toUrl+'&toDomain=' + toDomain + '&sub1=' + sub1 + '&sub2=' + sub2; - var loadT = layer.msg(lan.public.the,{icon:16,time:0,shade: [0.3, '#000']}); - $.post('/site?action=SetProxy',data,function(rdata){ - layer.close(loadT); - if(rdata.status) { - Proxy(siteName); - }else{ - $("input[name='status']").attr('checked',false) - } - layer.msg(rdata.msg,{icon:rdata.status?1:2}); - }); +function toProxy(siteName, type, obj) { + if (type == 1) { + return; } - var loadT = layer.msg(lan.site.the_msg,{icon:16,time:0,shade: [0.3, '#000']}); - $.post('/site?action=GetProxy','name='+siteName,function(rdata){ - layer.close(loadT); - if(rdata.proxyUrl == null) rdata.proxyUrl = ''; - var status_selected = rdata.status?'checked':''; - var disabled = rdata.status?'disabled':''; - var body = "
" - +"

"+lan.site.proxy_url+"

" - +"

"+lan.site.proxy_domain+"

" - +"

"+lan.site.con_rep+"" - +"

" - +'
' - +'' - +"
"; - $("#webedit-con").html(body); - }); + + var body = '
\ +
\ + \ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
代理目录目标地址操作
\ +
\ +
'; + $("#webedit-con").html(body); + var loading = layer.load() + $.post("/site/get_proxy_list", { + siteName: siteName + },function (res) { + var res = JSON.parse(res) + console.log(res) + }) } //开启缓存