diff --git a/ss_whitelist/config/nginx.conf b/ss_whitelist/config/nginx.conf index 83bb092..5fdfa43 100644 --- a/ss_whitelist/config/nginx.conf +++ b/ss_whitelist/config/nginx.conf @@ -97,11 +97,19 @@ http { file = io.open("/etc/openresty/allow.list","a+") io.input(file) io.output(file) - io.write("allow "..clientIP..";\n") - ngx.print("当前IP:"..clientIP.."已添加至白名单") + for line in file:lines() do + if string.find(line,clientIP) then + m = string.find(line,clientIP) + ngx.print("当前IP:"..clientIP.."已存在,无需添加") + end + end + if m == nil then + io.write("allow "..clientIP..";\n") + ngx.print("当前IP:"..clientIP.."已添加至白名单") + end io.close(file) + os.execute("/usr/local/openresty/nginx/sbin/nginx -s reload") } - } } }