… | |
… | |
92 | } |
92 | } |
93 | |
93 | |
94 | sub conn::err_blocked { |
94 | sub conn::err_blocked { |
95 | my $self = shift; |
95 | my $self = shift; |
96 | my $id = $self->{remote_id}; |
96 | my $id = $self->{remote_id}; |
|
|
97 | my $block = $conn::blocked{$id}; |
|
|
98 | |
|
|
99 | $block->[2]++; |
|
|
100 | |
|
|
101 | if ($block->[0] < $::NOW + $::BLOCKTIME) { |
|
|
102 | $block->[0] = $::NOW + $::BLOCKTIME; |
|
|
103 | } |
|
|
104 | |
|
|
105 | my $status = 403; |
|
|
106 | my $hdr = { |
|
|
107 | "Content-Type" => "text/html", |
|
|
108 | "Retry-After" => $block->[0] - $::NOW, |
|
|
109 | "Connection" => "close", |
|
|
110 | }; |
|
|
111 | |
97 | my $ctime = $HTTP_NOW; |
112 | my $ctime = $HTTP_NOW; |
98 | my $etime = time2str $conn::blocked{$ip} = $::NOW + $::BLOCKTIME; |
113 | my $etime = time2str $block->[0]; |
99 | |
114 | |
100 | Coro::Event::do_timer(after => 20*rand); |
115 | my $limit = $block->[3]; |
|
|
116 | $block->[3] = $::NOW + 10; |
101 | |
117 | |
102 | $self->err(401, "too many connections", |
118 | if ($limit > $::NOW) { |
103 | { |
119 | Coro::Event::do_timer(after => $limit - $::NOW); |
104 | "Content-Type" => "text/html", |
120 | |
105 | "Retry-After" => $::BLOCKTIME, |
121 | if ($block->[2] > 30) { |
|
|
122 | $status = 401; |
106 | "Warning" => "Please do NOT retry, you have been blocked. Press Cancel instead.", |
123 | $hdr->{Warning} = "Please do NOT retry, you have been blocked. Press Cancel instead."; |
107 | "WWW-Authenticate" => "Basic realm=\"Please do NOT retry, you have been blocked. Press Cancel instead.\"", |
124 | $hdr->{"WWW-Authenticate"} = "Basic realm=\"Please do NOT retry, you have been blocked. Press Cancel instead.\""; |
108 | "Connection" => "close", |
125 | } |
109 | }, |
126 | } |
|
|
127 | |
|
|
128 | $self->err($status, $block->[1], $hdr, |
110 | <<EOF); |
129 | <<EOF); |
111 | <html> |
130 | <html> |
112 | <head> |
131 | <head> |
113 | <title>Too many connections</title> |
132 | <title>$block->[1]</title> |
114 | </head> |
133 | </head> |
115 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
134 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
116 | |
135 | |
117 | <p>You have been blocked because you didn't behave. You may retry at</p> |
136 | <p>You have been blocked because you didn't behave. The exact reason was:</p> |
|
|
137 | |
|
|
138 | <h1><blockquote>"$block->[1]"</blockquote></h1> |
|
|
139 | |
|
|
140 | <p>You may retry not earlier than:</p> |
118 | |
141 | |
119 | <p><blockquote>$etime.</blockquote></p> |
142 | <p><blockquote>$etime.</blockquote></p> |
120 | |
143 | |
|
|
144 | <p>Until then, each access will renew the block. This should give |
|
|
145 | you ample time to look at the <a href="http://www.goof.com/pcg/marc/animefaq.html#blocked">FAQ</a>.</p> |
|
|
146 | |
121 | <p>For your reference, the current time and your identifier is:</p> |
147 | <p>For your reference, the current time and your connection ID is:</p> |
122 | |
148 | |
123 | <p><blockquote>$ctime | $id</blockquote></p> |
149 | <p><blockquote>$ctime | $id</blockquote></p> |
124 | |
150 | |
125 | <p>Until then, each access will renew the block. This should give |
|
|
126 | you ample time to look at the <a href="http://www.goof.com/pcg/marc/animefaq.html#blocked">FAQ</a>.</p> |
|
|
127 | |
|
|
128 | </body></html> |
151 | </body></html> |
129 | EOF |
152 | EOF |
130 | } |
153 | } |
131 | |
154 | |
132 | sub conn::err_segmented_download { |
155 | sub conn::err_segmented_download { |