From a7eb0b351ab22c5f8dd1d9545b36fa32bc7a6912 Mon Sep 17 00:00:00 2001 From: vndroid Date: Fri, 15 Jul 2022 15:34:55 +0800 Subject: [PATCH 1/2] Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加 JSON 返回伪装 --- ss_whitelist/nginx.conf | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ss_whitelist/nginx.conf b/ss_whitelist/nginx.conf index 8f4b79d..b20df26 100644 --- a/ss_whitelist/nginx.conf +++ b/ss_whitelist/nginx.conf @@ -87,15 +87,17 @@ http { listen [::]:80 ipv6only=on; charset utf-8; + charset_types text/xml application/json; - location / { - auth_basic ""; - auth_basic_user_file /etc/openresty/auth; - add_header Content-Type text/plain; + location / { + default_type "application/json"; + return 401 '{"code":401,"status":"Unauthorized","server":"openresty","info":"Please log in again or clear cookies."}'; + access_log off; } location = /auth { - auth_basic ""; + default_type "application/json"; + auth_basic "Please enter your username and password"; auth_basic_user_file /etc/openresty/auth; add_header Content-Type "text/plain; charset=utf-8"; proxy_set_header X-Real-IP $remote_addr; @@ -109,7 +111,9 @@ http { for line in file:lines() do if string.find(line,clientIP) then m = string.find(line,clientIP) - ngx.print("当前IP:"..clientIP.."已存在,无需添加\n\n") + ngx.status = 202 + ngx.print('{"code":202,"status":"Accepted","ip":"'..clientIP..'","server":"openresty","info":"Current IP already exists, no operation."}') + ngx.exit(202) for k, v in pairs(headers) do ngx.print(k..":"..v.."\n") end @@ -117,7 +121,7 @@ http { end if m == nil then io.write("allow "..clientIP..";\n") - ngx.print("当前IP:"..clientIP.."已添加至白名单") + ngx.print('{"code":200,"status":"OK","ip":"'..clientIP..'","server":"openresty","info":"Current IP added to whitelist."}') end io.close(file) os.execute("/usr/local/openresty/nginx/sbin/nginx -s reload") @@ -125,12 +129,13 @@ http { } location = /purge { - auth_basic ""; + default_type 'application/json'; + auth_basic "Please enter your username and password"; auth_basic_user_file /etc/openresty/auth; add_header Content-Type "text/plain; charset=utf-8"; content_by_lua_block { file = io.open("/etc/openresty/allow.list","w+") - ngx.print("IP列表已被清空") + ngx.print('{"code":200,"status":"OK","server":"openresty","info":"IP list has been cleared."}') io.close(file) os.execute("/usr/local/openresty/nginx/sbin/nginx -s reload") } From 22a689179f17f8c38c0a708dfda3baf30d5c08b8 Mon Sep 17 00:00:00 2001 From: vndroid Date: Fri, 15 Jul 2022 15:50:04 +0800 Subject: [PATCH 2/2] Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除冲突选项 --- ss_whitelist/nginx.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/ss_whitelist/nginx.conf b/ss_whitelist/nginx.conf index b20df26..b1d0cbc 100644 --- a/ss_whitelist/nginx.conf +++ b/ss_whitelist/nginx.conf @@ -99,7 +99,6 @@ http { default_type "application/json"; auth_basic "Please enter your username and password"; auth_basic_user_file /etc/openresty/auth; - add_header Content-Type "text/plain; charset=utf-8"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; content_by_lua_block { @@ -132,7 +131,6 @@ http { default_type 'application/json'; auth_basic "Please enter your username and password"; auth_basic_user_file /etc/openresty/auth; - add_header Content-Type "text/plain; charset=utf-8"; content_by_lua_block { file = io.open("/etc/openresty/allow.list","w+") ngx.print('{"code":200,"status":"OK","server":"openresty","info":"IP list has been cleared."}')