]> TLD Linux GIT Repositories - packages/lighttpd.git/blob - lighttpd-mod_evasive-status_code.patch
- updated to 1.4.40, partial PLD merge
[packages/lighttpd.git] / lighttpd-mod_evasive-status_code.patch
1 --- lighttpd-1.4.40/src/mod_evasive.c   2016-07-16 10:06:16.000000000 +0000
2 +++ lighttpd-1.4.40/src/mod_evasive.c   2016-07-26 12:11:56.730554000 +0000
3 @@ -31,12 +31,16 @@
4  typedef struct {
5         unsigned short max_conns;
6         unsigned short silent;
7 +       unsigned short http_status_code;
8 +       unsigned int retry_after;
9         buffer *location;
10  } plugin_config;
11  
12  typedef struct {
13         PLUGIN_DATA;
14  
15 +       buffer *evasive_rftmp;
16 +
17         plugin_config **config_storage;
18  
19         plugin_config conf;
20 @@ -47,6 +51,10 @@
21  
22         p = calloc(1, sizeof(*p));
23  
24 +       p->evasive_rftmp = buffer_init();
25 +       
26 +       buffer_prepare_copy(p->evasive_rftmp, 255);
27 +
28         return p;
29  }
30  
31 @@ -57,6 +65,8 @@
32  
33         if (!p) return HANDLER_GO_ON;
34  
35 +       buffer_free(p->evasive_rftmp);
36 +
37         if (p->config_storage) {
38                 size_t i;
39                 for (i = 0; i < srv->config_context->used; i++) {
40 @@ -84,6 +94,8 @@
41                 { "evasive.max-conns-per-ip",    NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 0 */
42                 { "evasive.silent",              NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
43                 { "evasive.location",            NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 2 */
44 +               { "evasive.http-status-code",    NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 3 */
45 +               { "evasive.retry-after",         NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },   /* 4 */
46                 { NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
47         };
48  
49 @@ -94,13 +106,17 @@
50                 plugin_config *s;
51  
52                 s = calloc(1, sizeof(plugin_config));
53 -               s->max_conns       = 0;
54 -               s->silent          = 0;
55 -               s->location        = buffer_init();
56 +               s->max_conns        = 0;
57 +               s->silent           = 0;
58 +               s->location         = buffer_init();
59 +               s->http_status_code = 503;
60 +               s->retry_after      = 0;
61  
62                 cv[0].destination = &(s->max_conns);
63                 cv[1].destination = &(s->silent);
64                 cv[2].destination = s->location;
65 +               cv[2].destination = &(s->http_status_code);
66 +               cv[3].destination = &(s->retry_after);
67  
68                 p->config_storage[i] = s;
69  
70 @@ -121,6 +137,8 @@
71         PATCH(max_conns);
72         PATCH(silent);
73         PATCH(location);
74 +       PATCH(http_status_code);
75 +       PATCH(retry_after);
76  
77         /* skip the first, the global context */
78         for (i = 1; i < srv->config_context->used; i++) {
79 @@ -140,6 +158,10 @@
80                                 PATCH(silent);
81                         } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.location"))) {
82                                 PATCH(location);
83 +                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.http-status-code"))) {
84 +                               PATCH(http_status_code);
85 +                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.retry-after"))) {
86 +                               PATCH(retry_after);
87                         }
88                 }
89         }
90 @@ -205,7 +227,9 @@
91                                 con->http_status = 302;
92                                 con->file_finished = 1;
93                         } else {
94 -                               con->http_status = 403;
95 +                               con->http_status = p->conf.http_status_code;
96 +                               buffer_copy_long(p->evasive_rftmp, p->conf.retry_after);
97 +                               response_header_overwrite(srv, con, CONST_STR_LEN("Retry-After"), CONST_BUF_LEN(p->evasive_rftmp));
98                         }
99                         con->mode = DIRECT;
100                         return HANDLER_FINISHED;