pull/119/head
midoks 3 years ago
parent c7fc9e2069
commit 1eb4908370
  1. 73
      class/core/site_api.py
  2. 68
      route/static/app/site.js

@ -135,7 +135,7 @@ class site_api:
mid = request.form.get('id', '')
name = request.form.get('name', '')
return self.stop(self, mid, name)
return self.stop(mid, name)
def stop(self, mid, name):
path = self.setupPath + '/stop'
@ -1219,13 +1219,13 @@ class site_api:
content = mw.readFile(vhost_file)
cnf_301 = '''
#301-START
# 301-START
include %s/*.conf;
#301-END
# 301-END
''' % (self.getRedirectPath( siteName))
cnf_301_source = '''
#301-START
# 301-START
'''
# print('operateRedirectConf', content.find('#301-END'))
if content.find('#301-END') != -1:
@ -1411,13 +1411,13 @@ class site_api:
content = mw.readFile(vhost_file)
proxy_cnf = '''
#PROXY-START
# PROXY-START
include %s/*.conf;
#PROXY-END
# PROXY-END
''' % (self.getProxyPath(siteName))
proxy_cnf_source = '''
#PROXY-START
# PROXY-START
'''
if content.find('#PROXY-END') != -1:
@ -1436,12 +1436,34 @@ class site_api:
if _id == '' or _siteName == '':
return mw.returnJson(False, "必填项不能为空!")
data = mw.readFile(
"{}/{}/{}.conf".format(self.proxyPath, _siteName, _id))
conf_file = "{}/{}/{}.conf".format(self.proxyPath, _siteName, _id)
if not os.path.exists(conf_file):
conf_file = "{}/{}/{}.conf.txt".format(
self.proxyPath, _siteName, _id)
data = mw.readFile(conf_file)
if data == False:
return mw.returnJson(False, "获取失败!")
return mw.returnJson(True, "ok", {"result": data})
def setProxyStatusApi(self):
_siteName = request.form.get("siteName", '')
_status = request.form.get("status", '')
_id = request.form.get("id", '')
if _status == '' or _siteName == '' or _id == '':
return mw.returnJson(False, "必填项不能为空!")
conf_file = "{}/{}/{}.conf".format(self.proxyPath, _siteName, _id)
conf_txt = "{}/{}/{}.conf.txt".format(self.proxyPath, _siteName, _id)
if _status == '1':
mw.execShell('mv ' + conf_txt + ' ' + conf_file)
else:
mw.execShell('mv ' + conf_file + ' ' + conf_txt)
mw.restartWeb()
return mw.returnJson(True, "OK")
def saveProxyConfApi(self):
_siteName = request.form.get("siteName", '')
_id = request.form.get("id", '')
@ -1484,6 +1506,16 @@ class site_api:
mw.execShell("rm -rf {}/{}".format(self.proxyPath, _siteName))
return mw.returnJson(True, "", {"result": [], "count": 0})
tmp = []
for proxy in data:
proxy_dir = "{}/{}".format(self.proxyPath, _siteName)
proxy_dir_file = proxy_dir + '/' + proxy['id'] + '.conf'
if os.path.exists(proxy_dir_file):
proxy['status'] = True
else:
proxy['status'] = False
tmp.append(proxy)
return mw.returnJson(True, "ok", {"result": data, "count": len(data)})
# 设置 网站 反向代理列表
@ -1492,6 +1524,7 @@ class site_api:
_from = request.form.get('from', '')
_to = request.form.get('to', '')
_host = request.form.get('host', '')
_open_proxy = request.form.get('open_proxy', '')
if _siteName == "" or _from == "" or _to == "" or _host == "":
return mw.returnJson(False, "必填项不能为空")
@ -1514,7 +1547,7 @@ class site_api:
return mw.returnJson(False, "错误的目标地址")
tpl = """
#PROXY-START/
# PROXY-START/
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
proxy_pass {to};
@ -1535,7 +1568,7 @@ location ~* ^{from}(.*)$ {
proxy_ignore_headers Set-Cookie Cache-Control expires;
add_header Cache-Control no-cache;
}
#PROXY-END/
# PROXY-END/
"""
# replace
@ -1550,16 +1583,21 @@ location ~* ^{from}(.*)$ {
if item["id"] == _id:
return mw.returnJson(False, "已存在该规则!")
if item["from"] == _from:
return mw.returnJson(False, "已存在该规则!")
return mw.returnJson(False, "代理目录已存在!")
data.append({
"from": _from,
"to": _to,
"host": _host,
"id": _id
})
conf_file = "{}/{}.conf".format(self.getProxyPath(_siteName), _id)
if _open_proxy != 'on':
conf_file = "{}/{}.conf.txt".format(
self.getProxyPath(_siteName), _id)
mw.writeFile(data_path, json.dumps(data))
mw.writeFile(
"{}/{}.conf".format(self.getProxyPath(_siteName), _id), tpl)
mw.writeFile(conf_file, tpl)
self.operateProxyConf(_siteName, 'start')
mw.restartWeb()
@ -1587,8 +1625,9 @@ location ~* ^{from}(.*)$ {
if len(data) == 0:
self.operateProxyConf(_siteName, 'stop')
# remove conf file
mw.execShell(
"rm -rf {}/{}.conf".format(self.getProxyPath(_siteName), _id))
cmd = "rm -rf {}/{}.conf*".format(
self.getProxyPath(_siteName), _id)
mw.execShell(cmd)
except:
return mw.returnJson(False, "删除失败!")
@ -1970,7 +2009,7 @@ location ~* ^{from}(.*)$ {
return 404;
}
}
#SECURITY-END
# SECURITY-END
include %s/enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace(',', ' '), pre_path)
conf = re.sub(re_path, rconf, conf)
mw.writeLog('网站管理', '站点[' + name + ']已开启防盗链!')

@ -1611,9 +1611,17 @@ function to301(siteName, type, obj){
}
function toProxySwitch(){
var status = $("input[name='open_proxy']").prop("checked")==true?1:0;
if(status==1){
$("input[name='open_proxy']").prop("checked",false);
}else{
$("input[name='open_proxy']").prop("checked",true);
}
}
//反向代理
function toProxy(siteName, type, obj) {
// 设置 页面展示
if(type == 1) {
var proxy_form = layer.open({
@ -1625,34 +1633,44 @@ function toProxy(siteName, type, obj) {
shadeClose: false,
btn: ['提交','关闭'],
content: "<form id='form_redirect' class='divtable pd15' style='padding-bottom: 10px'>" +
"<div class='line'>" +
'<span class="tname">开启代理</span>'+
"<div class='info-r ml0'>" +
"<input name='open_proxy' class='btswitch btswitch-ios' type='checkbox' checked><label id='open_proxy' class='btswitch-btn' for='openProxy' onclick='toProxySwitch();'></label>" +
"</div>" +
"</div>" +
"<div class='line'>"+
"<span class='tname'>目标URL</span>" +
"<span class='tname'>代理目录</span>" +
"<div class='info-r ml0'>" +
"<input name='to' class='bt-input-text mr5' type='text' style='width:200px''>" +
"<input name='from' value='/' placeholder='/' class='bt-input-text mr5' type='text' style='width:200px''>" +
"</div>" +
"</div>" +
"<div class='line'>" +
"<span class='tname'>代理目录</span>" +
"<span class='tname'>目标URL</span>" +
"<div class='info-r ml0'>" +
"<input name='from' value='/' placeholder='/' class='bt-input-text mr5' type='text' style='width:200px;float: left;margin-right:0px''>" +
"<input name='to' class='bt-input-text mr5' type='text' style='width:200px;float: left;margin-right:0px''>" +
"<span class='tname' style='width:90px'>发送域名</span>" +
"<input name='host' value='$host' class='bt-input-text mr5' type='text' style='width:200px'>" +
"</div>" +
"</div>" +
"<div class='help-info-text c7'>" +
"<ul class='help-info-text c7'>" +
"<li>代理目录:访问这个目录时将会把目标URL的内容返回并显示(需要开启高级功能)</li>" +
"<li>代理目录:访问这个目录时将会把目标URL的内容返回并显示</li>" +
"<li>目标URL:可以填写你需要代理的站点,目标URL必须为可正常访问的URL,否则将返回错误</li>" +
"<li>发送域名:将域名添加到请求头传递到代理服务器,默认为目标URL域名,若设置不当可能导致代理无法正常运行</li>" +
"</ul>" +
"</div>" +
"</form>",
yes:function(){
var to = $('[name="to"]').val();
var from = $('[name="from"]').val();
var host = $('[name="host"]').val();
$.post('/site/set_proxy', {siteName: siteName,from: from,to: to,host: host}, function(res) {
var data = $('#form_redirect').serializeArray();
var t = {};
t['name'] = 'siteName';
t['value'] = siteName;
data.push(t);
var loading = layer.msg('添加中...',{icon:16,time:0,shade: [0.3, '#000']});
$.post('/site/set_proxy',data, function(res) {
layer.close(loading);
if (res.status) {
layer.close(proxy_form);
toProxy(siteName)
@ -1683,7 +1701,6 @@ function toProxy(siteName, type, obj) {
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 = "<div class='webEdit-box' style='padding: 20px'>\
<textarea style='height: 320px; width: 445px; margin-left: 20px; line-height:18px' id='configProxyBody'>"+res.data.result+"</textarea>\
@ -1720,6 +1737,7 @@ function toProxy(siteName, type, obj) {
id: obj,
config: editor.getValue(),
};
$.post('/site/save_proxy_conf', data, function(res) {
layer.close(load)
if (res.status == true) {
@ -1735,10 +1753,25 @@ function toProxy(siteName, type, obj) {
} else {
layer.msg('请求错误!!', {time: 3000,icon: 2});
}
});
},'json');
return
}
if (type == 10 || type == 11) {
//[11]启动 或 停止[10]
status = type==10 ? '0' : '1';
var loading = layer.msg(lan.site.the_msg,{icon:16,time:0,shade: [0.3, '#000']});
$.post('/site/set_proxy_status', {siteName: siteName,'status':status,'id':obj}, function(res) {
layer.close(loading);
if (res.status == true) {
layer.msg('设置成功', {icon: 1,time: 1000});
setTimeout(function(){toProxy(siteName);},1000);
} else {
layer.msg(res.msg, {time: 3000,icon: 2});
}
},'json');
}
var body = '<div id="proxy_list" class="bt_table">\
<div style="padding-bottom: 10px">\
<button type="button" title="添加反向代理" class="btn btn-success btn-sm mr5" onclick="toProxy(\''+siteName+'\',1)" ><span>添加反向代理</span></button>\
@ -1749,6 +1782,7 @@ function toProxy(siteName, type, obj) {
<tr>\
<th><span data-index="1"><span>代理目录</span></span></th>\
<th><span data-index="2"><span>目标地址</span></span></th>\
<th><span data-index="2"><span>状态</span></span></th>\
<th><span data-index="3"><span>操作</span></span></th>\
</tr>\
</thead>\
@ -1761,13 +1795,19 @@ function toProxy(siteName, type, obj) {
var loadT = layer.msg(lan.site.the_msg,{icon:16,time:0,shade: [0.3, '#000']});
$.post("/site/get_proxy_list", {siteName: siteName},function (res) {
layer.close(loadT);
$("#md-301-loading").remove();
if (res.status === true) {
let data = res.data.result;
data.forEach(function(item){
// console.log(item);
var switchProxy = '<span onclick="toProxy(\''+siteName+'\', 10, \''+ item.id +'\')" style="color:rgb(92, 184, 92);" class="btlink glyphicon glyphicon-play"></span>';
if (!item['status']){
switchProxy = '<span onclick="toProxy(\''+siteName+'\', 11, \''+ item.id +'\')" style="color:rgb(255, 0, 0);" class="btlink glyphicon glyphicon-pause"></span>';
}
let tmp = '<tr>\
<td><span data-index="1"><span>'+item.from+'</span></span></td>\
<td><span data-index="2"><span>'+item.to+'</span></span></td>\
<td>'+switchProxy+'</td>\
<td>\
<span data-index="4" onclick="toProxy(\''+siteName+'\', 3, \''+ item.id +'\')" class="btlink">详细</span> |\
<span data-index="4" onclick="toProxy(\''+siteName+'\', 2, \''+ item.id +'\')" class="btlink">删除</span>\

Loading…
Cancel
Save