feta: add proxy conf nginx.conf

pull/117/head
soxft 3 years ago
parent e3fb8e3db7
commit 4a6c881018
  1. 28
      class/core/site_api.py
  2. 6
      data/tpl/nginx.conf
  3. 70
      route/static/app/site.js

@ -44,6 +44,11 @@ class site_api:
mw.execShell("mkdir -p " + self.redirectPath + mw.execShell("mkdir -p " + self.redirectPath +
" && chmod -R 755 " + 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' self.logsPath = mw.getRootDir() + '/wwwlogs'
# ssl conf # ssl conf
if mw.isAppleSystem(): if mw.isAppleSystem():
@ -1337,21 +1342,15 @@ class site_api:
return mw.returnJson(False, "删除失败!") return mw.returnJson(False, "删除失败!")
return mw.returnJson(True, "删除成功!") return mw.returnJson(True, "删除成功!")
# 读取 网站 反向代理列表
def getProxyListApi(self): def getProxyListApi(self):
siteName = request.form.get('siteName', '') siteName = request.form.get('siteName', '')
conf_path = self.getHostConf(siteName) conf_path = self.getHostConf(siteName)
old_conf = mw.readFile(conf_path) old_conf = mw.readFile(conf_path)
rep = "(#PROXY-START(\n|.)+#PROXY-END)"
url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);" return mw.returnJson(True, "ok", {
host_rep = "Host\s(.*);" "conf_content": old_conf
})
proxyUrl = self.__read_config(self.__proxyfile)
sitename = sitename
proxylist = []
for i in proxyUrl:
if i["sitename"] == sitename:
proxylist.append(i)
return mw.getJson(proxylist)
def getSiteTypesApi(self): def getSiteTypesApi(self):
# 取网站分类 # 取网站分类
@ -1510,6 +1509,12 @@ class site_api:
def getRedirectPath(self, siteName): def getRedirectPath(self, siteName):
return "{}/{}/".format(self.redirectPath, 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): def getDirBindRewrite(self, siteName, dirname):
return self.rewritePath + '/' + siteName + '_' + dirname + '.conf' return self.rewritePath + '/' + siteName + '_' + dirname + '.conf'
@ -1808,6 +1813,7 @@ class site_api:
content = content.replace('{$PHPVER}', self.phpVersion) content = content.replace('{$PHPVER}', self.phpVersion)
content = content.replace('{$OR_REWRITE}', self.rewritePath) content = content.replace('{$OR_REWRITE}', self.rewritePath)
content = content.replace('{$OR_REDIRECT}', self.redirectPath) content = content.replace('{$OR_REDIRECT}', self.redirectPath)
content = content.replace('{$OR_PROXY}', self.proxyPath)
logsPath = mw.getLogsDir() logsPath = mw.getLogsDir()
content = content.replace('{$LOGPATH}', logsPath) content = content.replace('{$LOGPATH}', logsPath)

@ -24,7 +24,11 @@ server
#301-START #301-START
include {$OR_REDIRECT}/{$SERVER_NAME}/*.conf; 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) location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)

@ -994,7 +994,7 @@ function webEdit(id,website,endTime,addtime){
+"<p onclick=\"setSSL("+id+",'"+website+"')\" title='SSL'>SSL</p>" +"<p onclick=\"setSSL("+id+",'"+website+"')\" title='SSL'>SSL</p>"
+"<p onclick=\"phpVersion('"+website+"')\" title='PHP版本'>PHP版本</p>" +"<p onclick=\"phpVersion('"+website+"')\" title='PHP版本'>PHP版本</p>"
+"<p onclick=\"to301('"+website+"')\" title='重定向'>重定向</p>" +"<p onclick=\"to301('"+website+"')\" title='重定向'>重定向</p>"
+"<p onclick=\"proxyList('"+website+"')\" title='反向代理'>反向代理</p>" +"<p onclick=\"toProxy('"+website+"')\" title='反向代理'>反向代理</p>"
+"<p id='site_"+id+"' onclick=\"security('"+id+"','"+website+"')\" title='防盗链'>防盗链</p>" +"<p id='site_"+id+"' onclick=\"security('"+id+"','"+website+"')\" title='防盗链'>防盗链</p>"
+"<p id='site_"+id+"' onclick=\"getSiteLogs('"+website+"')\" title='查看站点请求日志'>响应日志</p>"; +"<p id='site_"+id+"' onclick=\"getSiteLogs('"+website+"')\" title='查看站点请求日志'>响应日志</p>";
layer.open({ layer.open({
@ -1367,48 +1367,38 @@ function delDirBind(id,siteId){
} }
//反向代理 //反向代理
function proxyList(siteName,type){ function toProxy(siteName, type, obj) {
if(type == 1){ 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});
});
return; 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){ var body = '<div id="redirect_list" class="bt_table">\
layer.close(loadT); <div style="padding-bottom: 10px">\
if(rdata.proxyUrl == null) rdata.proxyUrl = ''; <button type="button" title="添加反向代理" class="btn btn-success btn-sm mr5" onclick="toProxy(\''+siteName+'\',1)" ><span>添加反向代理</span></button>\
var status_selected = rdata.status?'checked':''; </div>\
var disabled = rdata.status?'disabled':''; <div class="divtable" style="max-height:200px;">\
var body = "<div>" <table class="table table-hover" >\
+"<p style='margin-bottom:8px'><span style='display: inline-block; width: 104px;'>"+lan.site.proxy_url+"</span><input "+disabled+" class='bt-input-text' type='text' name='toUrl' value='"+rdata.proxyUrl+"' style='margin-left: 5px;width: 380px;height: 30px;margin-right:10px;' placeholder='"+lan.site.proxy_url_info+"' /></p>" <thead style="position: relative;z-index: 1;">\
+"<p style='margin-bottom:8px'><span style='display: inline-block; width: 104px;'>"+lan.site.proxy_domain+"</span><input "+disabled+" class='bt-input-text' type='text' name='toDomain' value='"+rdata.toDomain+"' style='margin-left: 5px;width: 380px;height: 30px;margin-right:10px;' placeholder='"+lan.site.proxy_domian_info+"' /></p>" <tr>\
+"<p style='margin-bottom:8px'><span style='display: inline-block; width: 104px;'>"+lan.site.con_rep+"</span><input "+disabled+" class='bt-input-text' type='text' name='sub1' value='"+rdata.sub1+"' style='margin-left: 5px;width: 182px;height: 30px;margin-right:10px;' placeholder='"+lan.site.con_rep_info+"' />" <th><span data-index="1"><span>代理目录</span></span></th>\
+"<input class='bt-input-text' type='text' name='sub2' "+disabled+" value='"+rdata.sub2+"' style='margin-left: 5px;width: 183px;height: 30px;margin-right:10px;' placeholder='"+lan.site.to_con+"' /></p>" <th><span data-index="2"><span>目标地址</span></span></th>\
+'<div class="label-input-group ptb10"><label style="font-weight:normal"><input type="checkbox" name="status" '+status_selected+' onclick="Proxy(\''+siteName+'\',1)" />'+lan.site.proxy_enable+'</label><label style="margin-left: 18px;"><input '+(rdata.cache?'checked':'')+' type="checkbox" name="status" onclick="OpenCache(\''+siteName+'\',1)" />'+lan.site.proxy_cache+'</label></div>' <th><span data-index="3"><span>操作</span></span></th>\
+'<ul class="help-info-text c7 ptb10">' </tr>\
+'<li>'+lan.site.proxy_help_1+'</li>' </thead>\
+'<li>'+lan.site.proxy_help_2+'</li>' <tbody id="md-301-body">\
+'<li>'+lan.site.proxy_help_3+'</li>' </tbody>\
+'<li>'+lan.site.proxy_help_4+'</li>' </table>\
+'<li>'+lan.site.proxy_help_5+'</li>' </div>\
+'</ul>' </div>';
+"</div>";
$("#webedit-con").html(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)
})
} }
//开启缓存 //开启缓存

Loading…
Cancel
Save