]> git.pld-linux.org Git - packages/lighttpd.git/blame - lighttpd-mod_evasive-status_code.patch
- up to r2505 (Fix evasive.silent option)
[packages/lighttpd.git] / lighttpd-mod_evasive-status_code.patch
CommitLineData
07541774
ER
1--- lighttpd-1.4.19/src/mod_evasive.c 2008-09-19 17:50:24.307245276 +0300
2+++ lighttpd-1.4.22/src/mod_evasive.c 2009-05-12 02:21:58.524447939 +0300
3@@ -28,11 +28,15 @@
53e13862
SP
4 typedef struct {
5 unsigned short max_conns;
07541774 6 unsigned short silent;
53e13862
SP
7+ unsigned short http_status_code;
8+ unsigned int retry_after;
9 } plugin_config;
10
11 typedef struct {
12 PLUGIN_DATA;
0315e022 13
53e13862 14+ buffer *evasive_rftmp;
0315e022 15+
53e13862 16 plugin_config **config_storage;
0315e022
ER
17
18 plugin_config conf;
07541774 19@@ -46,6 +50,10 @@
0315e022 20
53e13862 21 p = calloc(1, sizeof(*p));
0315e022 22
53e13862
SP
23+ p->evasive_rftmp = buffer_init();
24+
25+ buffer_prepare_copy(p->evasive_rftmp, 255);
0315e022 26+
53e13862
SP
27 return p;
28 }
29
07541774 30@@ -56,6 +64,8 @@
53e13862
SP
31
32 if (!p) return HANDLER_GO_ON;
0315e022 33
53e13862 34+ buffer_free(p->evasive_rftmp);
0315e022 35+
53e13862
SP
36 if (p->config_storage) {
37 size_t i;
38 for (i = 0; i < srv->config_context->used; i++) {
07541774
ER
39@@ -73,8 +83,10 @@
40 size_t i = 0;
41
42 config_values_t cv[] = {
43- { "evasive.max-conns-per-ip", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
44- { "evasive.silent", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
45+ { "evasive.max-conns-per-ip", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
46+ { "evasive.silent", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
47+ { "evasive.http-status-code", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
48+ { "evasive.retry-after", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 3 */
53e13862
SP
49 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
50 };
07541774
ER
51
52@@ -84,10 +96,14 @@
53e13862 53 plugin_config *s;
0315e022 54
53e13862
SP
55 s = calloc(1, sizeof(plugin_config));
56- s->max_conns = 0;
07541774 57- s->silent = 0;
53e13862 58+ s->max_conns = 0;
07541774 59+ s->silent = 0;
53e13862
SP
60+ s->http_status_code = 503;
61+ s->retry_after = 0;
0315e022 62
53e13862 63 cv[0].destination = &(s->max_conns);
07541774
ER
64+ cv[2].destination = &(s->http_status_code);
65+ cv[3].destination = &(s->retry_after);
0315e022 66
53e13862 67 p->config_storage[i] = s;
0315e022 68
07541774 69@@ -107,6 +123,8 @@
53e13862
SP
70
71 PATCH(max_conns);
07541774 72 PATCH(silent);
53e13862
SP
73+ PATCH(http_status_code);
74+ PATCH(retry_after);
0315e022 75
53e13862
SP
76 /* skip the first, the global context */
77 for (i = 1; i < srv->config_context->used; i++) {
07541774 78@@ -124,6 +142,10 @@
53e13862 79 PATCH(max_conns);
07541774
ER
80 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.silent"))) {
81 PATCH(silent);
53e13862
SP
82+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.http-status-code"))) {
83+ PATCH(http_status_code);
84+ } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.retry-after"))) {
85+ PATCH(retry_after);
86 }
87 }
88 }
07541774 89@@ -192,8 +214,10 @@
4fa4837c
ER
90 inet_ntop_cache_get_ip(srv, &(con->dst_addr)),
91 "turned away. Too many connections.");
92
93- con->http_status = 403;
94 con->mode = DIRECT;
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 return HANDLER_FINISHED;
53e13862 99 }
4fa4837c 100 }
This page took 0.071664 seconds and 4 git commands to generate.