Skip to content

Commit 3214fc8

Browse files
committed
🔧 Change syntax of config file
1 parent d5a8344 commit 3214fc8

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

inc/ngx_http_waf_module_core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ static char* ngx_http_waf_cc_deny_limit_conf(ngx_conf_t* cf, ngx_command_t* cmd,
2929
static ngx_int_t ngx_http_waf_init_after_load_config(ngx_conf_t* cf);
3030

3131

32-
static void* ngx_http_waf_create_main_conf(ngx_conf_t* cf);
33-
34-
3532
static void* ngx_http_waf_create_srv_conf(ngx_conf_t* cf);
3633

3734

inc/ngx_http_waf_module_type.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ typedef struct {
1919
UT_hash_handle hh;
2020
} hash_table_item_int_ulong_t;
2121

22-
typedef struct {
23-
ngx_int_t waf_mult_mount;
24-
} ngx_http_waf_main_conf_t;
25-
2622
typedef struct {
2723
ngx_int_t blocked; /* 是否拦截了本次请求 */
2824
u_char rule_type[128]; /* 触发的规则类型 */
@@ -36,6 +32,7 @@ typedef struct {
3632
ngx_uint_t alloc_times; /* 当前已经从内存池中申请过多少次内存 */
3733
ngx_int_t waf; /* 是否启用本模块 */
3834
ngx_str_t waf_rule_path; /* 配置文件所在目录 */
35+
ngx_int_t waf_mult_mount;
3936
ngx_int_t waf_cc_deny; /* 是否启用 CC 防御 */
4037
ngx_int_t waf_cc_deny_limit; /* CC 防御的限制频率 */
4138
ngx_int_t waf_cc_deny_duration; /* CC 防御的拉黑时长 */

src/ngx_http_waf_module_core.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
#endif
1212
#include "../inc/ngx_http_waf_module_check.h"
1313

14-
static ngx_int_t ngx_waf_mult_mount = 0;
15-
1614
static ngx_command_t ngx_http_waf_commands[] = {
1715

1816
{
1917
ngx_string("waf_mult_mount"),
20-
NGX_HTTP_MAIN_CONF | NGX_CONF_FLAG,
18+
NGX_HTTP_SRV_CONF | NGX_CONF_FLAG,
2119
ngx_http_waf_mult_mount,
22-
NGX_HTTP_MAIN_CONF_OFFSET,
23-
offsetof(ngx_http_waf_main_conf_t, waf_mult_mount),
20+
NGX_HTTP_SRV_CONF_OFFSET,
21+
offsetof(ngx_http_waf_srv_conf_t, waf_mult_mount),
2422
NULL
2523
},
2624
{
@@ -62,7 +60,7 @@ static ngx_command_t ngx_http_waf_commands[] = {
6260
static ngx_http_module_t ngx_http_waf_module_ctx = {
6361
NULL,
6462
ngx_http_waf_init_after_load_config,
65-
ngx_http_waf_create_main_conf,
63+
NULL,
6664
NULL,
6765
ngx_http_waf_create_srv_conf,
6866
NULL,
@@ -88,11 +86,9 @@ ngx_module_t ngx_http_waf_module = {
8886

8987

9088
static char* ngx_http_waf_mult_mount(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
91-
ngx_http_waf_main_conf_t* main_conf = conf;
9289
if (ngx_conf_set_flag_slot(cf, cmd, conf) != NGX_CONF_OK) {
9390
return NGX_CONF_ERROR;
9491
}
95-
ngx_waf_mult_mount = main_conf->waf_mult_mount;
9692
return NGX_CONF_OK;
9793
}
9894

@@ -154,17 +150,6 @@ static char* ngx_http_waf_cc_deny_limit_conf(ngx_conf_t* cf, ngx_command_t* cmd,
154150
}
155151

156152

157-
static void* ngx_http_waf_create_main_conf(ngx_conf_t* cf) {
158-
ngx_http_waf_main_conf_t* main_conf = NULL;
159-
main_conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_waf_main_conf_t));
160-
if (main_conf == NULL) {
161-
return NULL;
162-
}
163-
main_conf->waf_mult_mount = NGX_CONF_UNSET;
164-
return main_conf;
165-
}
166-
167-
168153
static void* ngx_http_waf_create_srv_conf(ngx_conf_t* cf) {
169154
ngx_http_waf_srv_conf_t* srv_conf = NULL;
170155
srv_conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_waf_srv_conf_t));
@@ -176,6 +161,7 @@ static void* ngx_http_waf_create_srv_conf(ngx_conf_t* cf) {
176161
srv_conf->ngx_pool = ngx_create_pool(sizeof(ngx_pool_t) + INITIAL_SIZE, srv_conf->ngx_log);
177162
srv_conf->alloc_times = 0;
178163
srv_conf->waf = NGX_CONF_UNSET;
164+
srv_conf->waf_mult_mount = NGX_CONF_UNSET;
179165
srv_conf->waf_cc_deny = NGX_CONF_UNSET;
180166
srv_conf->waf_cc_deny_limit = NGX_CONF_UNSET;
181167
srv_conf->waf_cc_deny_duration = NGX_CONF_UNSET;
@@ -220,10 +206,8 @@ static ngx_int_t ngx_http_waf_init_after_load_config(ngx_conf_t* cf) {
220206
}
221207
*h = ngx_http_waf_handler_ip_url_referer_ua_args_cookie_post;
222208

223-
if (ngx_waf_mult_mount != 0) {
224-
h = ngx_array_push(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers);
225-
*h = ngx_http_waf_handler_url_args;
226-
}
209+
h = ngx_array_push(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers);
210+
*h = ngx_http_waf_handler_url_args;
227211

228212
ngx_str_t waf_blocked_name = ngx_string("waf_blocked");
229213
ngx_http_variable_t* waf_blocked = ngx_http_add_variable(cf, &waf_blocked_name, NGX_HTTP_VAR_NOCACHEABLE);
@@ -356,6 +340,9 @@ static ngx_int_t ngx_http_waf_handler_url_args(ngx_http_request_t* r) {
356340
if (srv_conf->waf == 0 || srv_conf->waf == NGX_CONF_UNSET) {
357341
http_status = NGX_DECLINED;
358342
}
343+
else if (srv_conf->waf_mult_mount == 0 || srv_conf->waf_mult_mount == NGX_CONF_UNSET) {
344+
http_status = NGX_DECLINED;
345+
}
359346
else if (!(r->method & (NGX_HTTP_GET | NGX_HTTP_POST))) {
360347
http_status = NGX_DECLINED;
361348
}
@@ -422,6 +409,9 @@ static ngx_int_t ngx_http_waf_handler_ip_url_referer_ua_args_cookie_post(ngx_htt
422409
if (srv_conf->waf == 0 || srv_conf->waf == NGX_CONF_UNSET) {
423410
http_status = NGX_DECLINED;
424411
}
412+
else if (srv_conf->waf_mult_mount == 0 || srv_conf->waf_mult_mount == NGX_CONF_UNSET) {
413+
http_status = NGX_DECLINED;
414+
}
425415
else if (!(r->method & (NGX_HTTP_GET | NGX_HTTP_POST))) {
426416
http_status = NGX_DECLINED;
427417
}

0 commit comments

Comments
 (0)