Showing
1 changed file
with
28 additions
and
3 deletions
@@ -35,6 +35,8 @@ function rate_limit() | @@ -35,6 +35,8 @@ function rate_limit() | ||
35 | -- read config | 35 | -- read config |
36 | local common_config=lua_context.configs["common_conf"] | 36 | local common_config=lua_context.configs["common_conf"] |
37 | local limit_config=lua_context.configs["api_rate_limit_conf"] | 37 | local limit_config=lua_context.configs["api_rate_limit_conf"] |
38 | + local limit_ip_config=lua_context.configs["limit_ip_access"] | ||
39 | + | ||
38 | if (not common_config) or (not limit_config) then | 40 | if (not common_config) or (not limit_config) then |
39 | return | 41 | return |
40 | end | 42 | end |
@@ -79,6 +81,21 @@ function rate_limit() | @@ -79,6 +81,21 @@ function rate_limit() | ||
79 | end | 81 | end |
80 | end | 82 | end |
81 | 83 | ||
84 | + --check is in white ip list | ||
85 | +function is_white() | ||
86 | + if limit_ip_config then | ||
87 | + local white_ips_length=#limit_ip_config.white_ips | ||
88 | + if white_ips_length >0 then | ||
89 | + for i=1,white_ips_length do | ||
90 | + local is_in_white_ips=iptool:pcall_check_ip_in_ipblock(ngx.var.real_ip,limit_ip_config.white_ips[i],false) | ||
91 | + if is_in_white_ips then | ||
92 | + return true | ||
93 | + end | ||
94 | + end | ||
95 | + end | ||
96 | + end | ||
97 | + return false | ||
98 | +end | ||
82 | 99 | ||
83 | ----- check weather ip is in black list | 100 | ----- check weather ip is in black list |
84 | function check_malIp() | 101 | function check_malIp() |
@@ -100,8 +117,16 @@ function init_read_body() | @@ -100,8 +117,16 @@ function init_read_body() | ||
100 | end | 117 | end |
101 | end | 118 | end |
102 | 119 | ||
103 | -init_read_body() | ||
104 | -check_malIp() | ||
105 | -rate_limit() | 120 | +function main() |
121 | + if is_white() then | ||
122 | + return | ||
123 | + else | ||
124 | + init_read_body() | ||
125 | + check_malIp() | ||
126 | + rate_limit() | ||
127 | + end | ||
128 | +end | ||
106 | 129 | ||
130 | +----- running ---- | ||
131 | +main() | ||
107 | 132 |
-
Please register or login to post a comment