mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-11 03:19:26 +08:00
@@ -42,10 +42,11 @@ def set_proxy():
|
||||
host = request.form.get('host', '')
|
||||
name = request.form.get('name', '')
|
||||
open_proxy = request.form.get('open_proxy', '')
|
||||
open_cors = request.form.get('open_cors','')
|
||||
open_cache = request.form.get('open_cache', '')
|
||||
cache_time = request.form.get('cache_time', '')
|
||||
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)
|
||||
return MwSites.instance().setProxy(site_name,site_from,to,host,name,open_proxy,open_cors,open_cache,cache_time, proxy_id)
|
||||
|
||||
# 设置代理状态
|
||||
@blueprint.route('/set_proxy_status', endpoint='set_proxy_status', methods=['POST'])
|
||||
|
||||
+26
-4
@@ -1617,15 +1617,20 @@ function toProxy(siteName, type, obj) {
|
||||
btn: ['提交','关闭'],
|
||||
content: "<form id='form_proxy' class='divtable pd15' style='padding-bottom: 10px'>\
|
||||
<div class='line'>\
|
||||
<span class='tname'>开启代理</span>\
|
||||
<span class='tname' style='line-height:20px;'>开启代理</span>\
|
||||
<div class='info-r ml0 mt5'>\
|
||||
<input name='open_proxy' class='btswitch btswitch-ios' type='checkbox' checked>\
|
||||
<label id='open_proxy' class='btswitch-btn' for='openProxy' style='float:left'></label>\
|
||||
<div style='display: inline-block'>\
|
||||
<span class='tname' style='margin-left:15px;position: relative;top: -5px;'>是否缓存</span>\
|
||||
<span class='tname' style='position: relative;top: -5px;'>是否缓存</span>\
|
||||
<input class='btswitch btswitch-ios' type='checkbox' name='open_cache'>\
|
||||
<label class='btswitch-btn' id='open_cache' for='openCache' style='float:left'></label>\
|
||||
</div>\
|
||||
<div style='display: inline-block'>\
|
||||
<span class='tname' style='position: relative;top: -5px;'>是否跨域</span>\
|
||||
<input class='btswitch btswitch-ios' type='checkbox' name='open_cors'>\
|
||||
<label class='btswitch-btn' id='open_cors' for='open_cors' style='float:left'></label>\
|
||||
</div>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
@@ -1637,7 +1642,7 @@ function toProxy(siteName, type, obj) {
|
||||
<div class='line' style='display:none' id='cache_time'>\
|
||||
<span class='tname'>缓存时间</span>\
|
||||
<div class='info-r ml0'>\
|
||||
<input name='cache_time' value='1' class='bt-input-text mr5' type='text' style='width:200px''>分钟\
|
||||
<input name='cache_time' value='1' class='bt-input-text mr5' type='number' style='width:200px''>分钟\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='line'>\
|
||||
@@ -1666,13 +1671,21 @@ function toProxy(siteName, type, obj) {
|
||||
success:function(){
|
||||
|
||||
if (typeof(obj) != 'undefined'){
|
||||
// console.log(obj);
|
||||
console.log(obj);
|
||||
$('input[name="name"]').val(obj['name']).attr('readonly','readonly').addClass('disabled');
|
||||
if (obj['open_cache'] == 'on'){
|
||||
$("input[name='open_cache']").prop("checked",true);
|
||||
$('#cache_time').show();
|
||||
}
|
||||
|
||||
if (obj['open_cors'] == 'on'){
|
||||
$("input[name='open_cors']").prop("checked",true);
|
||||
}
|
||||
|
||||
if (obj['open_proxy'] == 'on'){
|
||||
$("input[name='open_proxy']").prop("checked",true);
|
||||
}
|
||||
|
||||
$('input[name="from"]').val(obj['from']);
|
||||
$('input[name="to"]').val(obj['to']);
|
||||
|
||||
@@ -1722,6 +1735,15 @@ function toProxy(siteName, type, obj) {
|
||||
$("input[name='open_cache']").prop("checked",true);
|
||||
}
|
||||
});
|
||||
|
||||
$('#open_cors').click(function(){
|
||||
var status = $("input[name='open_cors']").prop("checked")==true?1:0;
|
||||
if(status==1){
|
||||
$("input[name='open_cors']").prop("checked",false);
|
||||
}else{
|
||||
$("input[name='open_cors']").prop("checked",true);
|
||||
}
|
||||
});
|
||||
},
|
||||
yes:function(index,layer_ro){
|
||||
var data = $('#form_proxy').serializeArray();
|
||||
|
||||
+50
-36
@@ -1479,7 +1479,7 @@ class sites(object):
|
||||
mw.writeFile(vhost_file, content)
|
||||
|
||||
# 设置 网站 反向代理列表
|
||||
def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cache, cache_time, proxy_id):
|
||||
def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, open_cache, cache_time, proxy_id):
|
||||
from urllib.parse import urlparse
|
||||
if site_name == "" or site_from == "" or to == "" or host == "" or name == "":
|
||||
return mw.returnData(False, "必填项不能为空")
|
||||
@@ -1513,46 +1513,53 @@ class sites(object):
|
||||
if item["from"] == site_from:
|
||||
return mw.returnData(False, "代理目录已存在!!")
|
||||
|
||||
tpl = "#PROXY-START\n\
|
||||
location ^~ {from} {\n\
|
||||
proxy_pass {to};\n\
|
||||
proxy_set_header Host {host};\n\
|
||||
proxy_ssl_server_name on;\n\
|
||||
proxy_set_header X-Real-IP $remote_addr;\n\
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
||||
proxy_set_header REMOTE-HOST $remote_addr;\n\
|
||||
proxy_set_header Upgrade $http_upgrade;\n\
|
||||
proxy_set_header Connection $connection_upgrade;\n\
|
||||
proxy_http_version 1.1;\n\
|
||||
\n\
|
||||
add_header X-Cache $upstream_cache_status;\n\
|
||||
\n\
|
||||
{proxy_cache}\n\
|
||||
tpl = "#PROXY-START\n \
|
||||
location ^~ {from} {\n \
|
||||
proxy_pass {to};\n \
|
||||
proxy_set_header Host {host};\n \
|
||||
proxy_ssl_server_name on;\n \
|
||||
proxy_set_header X-Real-IP $remote_addr;\n \
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n \
|
||||
proxy_set_header REMOTE-HOST $remote_addr;\n \
|
||||
proxy_set_header Upgrade $http_upgrade;\n \
|
||||
proxy_set_header Connection $connection_upgrade;\n \
|
||||
proxy_http_version 1.1;\n \
|
||||
\n \
|
||||
add_header X-Cache $upstream_cache_status;\n \
|
||||
{cors}\n \
|
||||
\n \
|
||||
{proxy_cache}\n \
|
||||
}\n\
|
||||
# PROXY-END"
|
||||
|
||||
tpl_proxy_cache = "\n\
|
||||
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n\
|
||||
{\n\
|
||||
expires {cache_time}m;\n\
|
||||
}\n\
|
||||
proxy_ignore_headers Set-Cookie Cache-Control expires;\n\
|
||||
proxy_cache mw_cache;\n\
|
||||
proxy_cache_key \"$host$uri$is_args$args\";\n\
|
||||
proxy_cache_valid 200 304 301 302 {cache_time}m;\n\
|
||||
tpl_proxy_cache = "\n \
|
||||
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \
|
||||
{\n \
|
||||
expires {cache_time}m;\n \
|
||||
}\n \
|
||||
proxy_ignore_headers Set-Cookie Cache-Control expires;\n \
|
||||
proxy_cache mw_cache;\n \
|
||||
proxy_cache_key \"$host$uri$is_args$args\";\n \
|
||||
proxy_cache_valid 200 304 301 302 {cache_time}m;\n \
|
||||
"
|
||||
|
||||
tpl_proxy_nocache = "\n\
|
||||
set $static_files_app 0; \n\
|
||||
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n\
|
||||
{\n\
|
||||
tpl_proxy_nocache = "\n \
|
||||
set $static_files_app 0; \n \
|
||||
if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \
|
||||
{\n \
|
||||
set $static_files_app 1;\n\
|
||||
expires 12h;\n\
|
||||
}\n\
|
||||
if ( $static_files_app = 0 )\n\
|
||||
{\n\
|
||||
add_header Cache-Control no-cache;\n\
|
||||
}\n\
|
||||
}\n \
|
||||
if ( $static_files_app = 0 )\n \
|
||||
{\n \
|
||||
add_header Cache-Control no-cache;\n \
|
||||
}\n \
|
||||
"
|
||||
tpl_proxy_cors = "\n \
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,OPTIONS,POST' always;\n \
|
||||
add_header 'Access-Control-Allow-Credentials' 'true';\n \
|
||||
add_header 'Access-Control-Allow-Origin' *;\n \
|
||||
add_header 'Access-Control-Allow-Headers' *;\n \
|
||||
"
|
||||
|
||||
# replace
|
||||
@@ -1569,6 +1576,11 @@ location ^~ {from} {\n\
|
||||
else:
|
||||
tpl = tpl.replace("{proxy_cache}", tpl_proxy_nocache, 999)
|
||||
|
||||
if open_cors == 'on':
|
||||
tpl = tpl.replace("{cors}", tpl_proxy_cors, 999)
|
||||
else:
|
||||
tpl = tpl.replace("{cors}", tpl_proxy_cors, 999)
|
||||
|
||||
|
||||
conf_proxy = "{}/{}.conf".format(self.getProxyPath(site_name), proxy_id)
|
||||
conf_bk = "{}/{}.conf.txt".format(self.getProxyPath(site_name), proxy_id)
|
||||
@@ -1593,8 +1605,9 @@ location ^~ {from} {\n\
|
||||
"to": to,
|
||||
"host": host,
|
||||
"open_cache": open_cache,
|
||||
"open_proxy": open_proxy,
|
||||
"cache_time": cache_time,
|
||||
"open_proxy": open_proxy,
|
||||
"open_cors": open_cors,
|
||||
"id": proxy_id,
|
||||
})
|
||||
else:
|
||||
@@ -1610,8 +1623,9 @@ location ^~ {from} {\n\
|
||||
data[dindex]['to'] = to
|
||||
data[dindex]['host'] = host
|
||||
data[dindex]['open_cache'] = open_cache
|
||||
data[dindex]['open_proxy'] = open_proxy
|
||||
data[dindex]['cache_time'] = cache_time
|
||||
data[dindex]['open_proxy'] = open_proxy
|
||||
data[dindex]['open_cors'] = open_cors
|
||||
|
||||
if open_proxy != 'on':
|
||||
os.rename(conf_proxy, conf_bk)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
# 应用程序版本号组件
|
||||
APP_RELEASE = 0
|
||||
APP_REVISION = 18
|
||||
APP_SMALL_VERSION = 0
|
||||
APP_SMALL_VERSION = 0.1
|
||||
|
||||
# 应用程序版本后缀,例如“beta1”、“dev”。通常为空字符串GA发布
|
||||
APP_SUFFIX = ''
|
||||
|
||||
Reference in New Issue
Block a user