From ea3033e22af9f532bb1677ebb61453e97c66217f Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:07:29 +0800 Subject: [PATCH 01/11] Update site.py --- web/utils/site.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 97c5316900..2f72610060 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1513,8 +1513,9 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, if item["from"] == site_from: return mw.returnData(False, "代理目录已存在!!") - tpl = "#PROXY-START\n \ + tpl = "#PROXY-START\n\ location ^~ {from} {\n \ + {cors}\n\ proxy_pass {to};\n \ proxy_set_header Host {host};\n \ proxy_ssl_server_name on;\n \ @@ -1526,13 +1527,12 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, 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 \ + tpl_proxy_cache = "\n\ if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \ {\n \ expires {cache_time}m;\n \ @@ -1540,10 +1540,10 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, 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 \ + proxy_cache_valid 200 304 301 302 {cache_time}m;\n\ " - tpl_proxy_nocache = "\n \ + tpl_proxy_nocache = "\n\ set $static_files_app 0; \n \ if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n \ {\n \ @@ -1553,13 +1553,16 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, if ( $static_files_app = 0 )\n \ {\n \ add_header Cache-Control no-cache;\n \ - }\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 \ + tpl_proxy_cors = "\n\ + add_header Access-Control-Allow-Origin *;\ + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\ + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';\ + add_header X-Cache $upstream_cache_status;\ + if ($request_method = 'OPTIONS') {\ + return 204;\ + }\ " # replace @@ -1579,7 +1582,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, if open_cors == 'on': tpl = tpl.replace("{cors}", tpl_proxy_cors, 999) else: - tpl = tpl.replace("{cors}", tpl_proxy_cors, 999) + tpl = tpl.replace("{cors}", '', 999) conf_proxy = "{}/{}.conf".format(self.getProxyPath(site_name), proxy_id) From 8b391f03c26a43cce61db442eacceb599a0741ec Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:08:59 +0800 Subject: [PATCH 02/11] Update site.py --- web/utils/site.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 2f72610060..93864f46bc 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1515,6 +1515,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, tpl = "#PROXY-START\n\ location ^~ {from} {\n \ + add_header X-Cache $upstream_cache_status;\n \ {cors}\n\ proxy_pass {to};\n \ proxy_set_header Host {host};\n \ @@ -1522,13 +1523,11 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, 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 \ + proxy_set_header Upgrade $http_upgrade;\n\ + proxy_set_header Connection $connection_upgrade;\n\ + proxy_http_version 1.1;\n\ + \n\ + {proxy_cache}\n\ }\n\ # PROXY-END" From 27fd93f590f16dd5d0f32edefbc4c628f97bf9fd Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:09:25 +0800 Subject: [PATCH 03/11] Update site.py --- web/utils/site.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 93864f46bc..8ba331085e 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1555,13 +1555,12 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, }\n\ " tpl_proxy_cors = "\n\ - add_header Access-Control-Allow-Origin *;\ - add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\ - add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';\ - add_header X-Cache $upstream_cache_status;\ - if ($request_method = 'OPTIONS') {\ - return 204;\ - }\ + add_header Access-Control-Allow-Origin *;\n\ + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\n\ + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';\n\ + if ($request_method = 'OPTIONS') {\n\ + return 204;\n\ + }\n\ " # replace From 88c6abb53c020111e02a24c334aed1fb36599cd8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:14:13 +0800 Subject: [PATCH 04/11] Update site.py --- web/utils/site.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 8ba331085e..31f2fd23e0 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1514,15 +1514,15 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, return mw.returnData(False, "代理目录已存在!!") tpl = "#PROXY-START\n\ -location ^~ {from} {\n \ - add_header X-Cache $upstream_cache_status;\n \ +location ^~ {from} {\n\ + add_header X-Cache $upstream_cache_status;\n\ {cors}\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_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\ @@ -1532,26 +1532,26 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, # 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 \ + 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_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 \ + 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\ + if ( $static_files_app = 0 )\n\ + {\n\ + add_header Cache-Control no-cache;\n\ }\n\ " tpl_proxy_cors = "\n\ From 6e44452807e442a327cbeb962c9342a07b988394 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:17:12 +0800 Subject: [PATCH 05/11] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index 31f2fd23e0..ad25358086 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1544,7 +1544,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, tpl_proxy_nocache = "\n\ set $static_files_app 0; \n \ - if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n\ + if ( $uri ~* \\.(gif|png|jpg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ set $static_files_app 1;\n\ expires 12h;\n\ From cf72ebdfd8dc249236db318d465fbb0ec96a166b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:17:22 +0800 Subject: [PATCH 06/11] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index ad25358086..d5f178c57b 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1532,7 +1532,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, # PROXY-END" tpl_proxy_cache = "\n\ - if ( $uri ~* \\.(gif|png|jpg|css|js|woff|woff2)$\" )\n\ + if ( $uri ~* \\.(gif|png|jpg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ expires {cache_time}m;\n\ }\n\ From de6fd60f41ec73391527c7c49490594d4b2554ae Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:19:17 +0800 Subject: [PATCH 07/11] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index d5f178c57b..4fca154ee9 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1543,7 +1543,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, " tpl_proxy_nocache = "\n\ - set $static_files_app 0; \n \ + set $static_files_app 0; \n\ if ( $uri ~* \\.(gif|png|jpg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ set $static_files_app 1;\n\ From 3bf1573e36de1aca2ea16cf519a37d444aeb600d Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:20:39 +0800 Subject: [PATCH 08/11] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index 4fca154ee9..e364c94305 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1537,7 +1537,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, expires {cache_time}m;\n\ }\n\ proxy_ignore_headers Set-Cookie Cache-Control expires;\n\ - proxy_cache mw_cache;\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\ " From a9bc4fe9147278ef5790a743fe46b270058189ca Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:21:39 +0800 Subject: [PATCH 09/11] Update site.py --- web/utils/site.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index e364c94305..5ed12a1963 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1532,7 +1532,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, # PROXY-END" tpl_proxy_cache = "\n\ - if ( $uri ~* \\.(gif|png|jpg|css|js|ttf|woff|woff2)$\" )\n\ + if ( $uri ~* \\.(gif|png|jpg|jpeg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ expires {cache_time}m;\n\ }\n\ @@ -1544,7 +1544,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, tpl_proxy_nocache = "\n\ set $static_files_app 0; \n\ - if ( $uri ~* \\.(gif|png|jpg|css|js|ttf|woff|woff2)$\" )\n\ + if ( $uri ~* \\.(gif|png|jpg|jpeg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ set $static_files_app 1;\n\ expires 12h;\n\ From eb480c88387286d022f05b0abd874c8f0a8684e5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 14:43:59 +0800 Subject: [PATCH 10/11] update --- web/static/app/public.js | 8 +++---- web/static/app/site.js | 49 +++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/web/static/app/public.js b/web/static/app/public.js index dd3436f0f1..fcaef965cf 100755 --- a/web/static/app/public.js +++ b/web/static/app/public.js @@ -2186,19 +2186,19 @@ function pluginConfig(_name, version, func){ } editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { + lineNumbers: true, + matchBrackets:true, extraKeys: { "Ctrl-Space": "autocomplete", "Ctrl-F": "findPersistent", "Ctrl-H": "replaceAll", "Ctrl-S": function() { - saveDataFunc() + saveDataFunc(); }, "Cmd-S":function() { saveDataFunc(); } - }, - lineNumbers: true, - matchBrackets:true, + } }); editor.focus(); $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); diff --git a/web/static/app/site.js b/web/static/app/site.js index 00ac4d4fec..d40251dbb9 100755 --- a/web/static/app/site.js +++ b/web/static/app/site.js @@ -1805,6 +1805,25 @@ function toProxy(siteName, type, obj) { \ "; var editor; + function saveDataFunc(){ + $("#configProxyBody").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) + if (res.status == true) { + layer.msg('保存成功', {icon: 1}); + layer.close(index); + } else { + layer.msg(res.msg, {time: 3000,icon: 2}); + } + },'json'); + } var index = layer.open({ type: 1, title: '编辑配置文件', @@ -1815,32 +1834,26 @@ function toProxy(siteName, type, obj) { content: mBody, success: function () { editor = CodeMirror.fromTextArea(document.getElementById("configProxyBody"), { - extraKeys: {"Ctrl-Space": "autocomplete"}, lineNumbers: true, matchBrackets:true, + extraKeys: { + "Ctrl-Space": "autocomplete", + "Ctrl-F": "findPersistent", + "Ctrl-H": "replaceAll", + "Ctrl-S": function() { + saveDataFunc(); + }, + "Cmd-S":function() { + saveDataFunc(); + } + } }); editor.focus(); $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); $("#onlineEditFileBtn").unbind('click'); }, yes:function(index,layero){ - $("#configProxyBody").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) - if (res.status == true) { - layer.msg('保存成功', {icon: 1}); - layer.close(index); - } else { - layer.msg(res.msg, {time: 3000,icon: 2}); - } - },'json'); + saveDataFunc(); return true; }, }); From 3e9e7922b4f8138a2a7d6d680d88be9fe410c0c4 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 19 Dec 2024 15:01:19 +0800 Subject: [PATCH 11/11] Update site.py --- web/utils/site.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 5ed12a1963..9f94627ab7 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1541,8 +1541,7 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, proxy_cache_key \"$host$uri$is_args$args\";\n\ proxy_cache_valid 200 304 301 302 {cache_time}m;\n\ " - - tpl_proxy_nocache = "\n\ + tpl_proxy_nocache_bak = "\n\ set $static_files_app 0; \n\ if ( $uri ~* \\.(gif|png|jpg|jpeg|css|js|ttf|woff|woff2)$\" )\n\ {\n\ @@ -1554,6 +1553,10 @@ def setProxy(self, site_name, site_from, to, host, name, open_proxy, open_cors, add_header Cache-Control no-cache;\n\ }\n\ " + + tpl_proxy_nocache = "\n\ + add_header Cache-Control no-cache;\n\ +" tpl_proxy_cors = "\n\ add_header Access-Control-Allow-Origin *;\n\ add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';\n\