… | |
… | |
188 | $self->response($code, $msg, $hdr, $content); |
188 | $self->response($code, $msg, $hdr, $content); |
189 | |
189 | |
190 | die bless {}, err::; |
190 | die bless {}, err::; |
191 | } |
191 | } |
192 | |
192 | |
193 | sub err_blocked { |
|
|
194 | my $self = shift; |
|
|
195 | my $ip = $self->{remote_addr}; |
|
|
196 | my $time = time2str $blocked{$ip} = $::NOW + $::BLOCKTIME; |
|
|
197 | |
|
|
198 | Coro::Event::do_timer(after => 20*rand); |
|
|
199 | |
|
|
200 | $self->err(401, "too many connections", |
|
|
201 | { |
|
|
202 | "Content-Type" => "text/html", |
|
|
203 | "Retry-After" => $::BLOCKTIME, |
|
|
204 | "Warning" => "Please do NOT retry, you have been blocked", |
|
|
205 | "WWW-Authenticate" => "Basic realm=\"Please do NOT retry, you have been blocked\"", |
|
|
206 | "Connection" => "close", |
|
|
207 | }, |
|
|
208 | <<EOF); |
|
|
209 | <html> |
|
|
210 | <head> |
|
|
211 | <title>Too many connections</title> |
|
|
212 | </head> |
|
|
213 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
|
|
214 | |
|
|
215 | <p>You have been blocked because you opened too many connections. You |
|
|
216 | may retry at</p> |
|
|
217 | |
|
|
218 | <p><blockquote>$time.</blockquote></p> |
|
|
219 | |
|
|
220 | <p>Until then, each new access will renew the block. You might want to have a |
|
|
221 | look at the <a href="http://www.goof.com/pcg/marc/animefaq.html#connectionlimit">FAQ</a>.</p> |
|
|
222 | |
|
|
223 | </body></html> |
|
|
224 | EOF |
|
|
225 | } |
|
|
226 | |
|
|
227 | sub handle { |
193 | sub handle { |
228 | my $self = shift; |
194 | my $self = shift; |
229 | my $fh = $self->{fh}; |
195 | my $fh = $self->{fh}; |
230 | |
196 | |
231 | my $host; |
197 | my $host; |
… | |
… | |
467 | $self->err(416, "not satisfiable", $hdr, ""); |
433 | $self->err(416, "not satisfiable", $hdr, ""); |
468 | |
434 | |
469 | satisfiable: |
435 | satisfiable: |
470 | # check for segmented downloads |
436 | # check for segmented downloads |
471 | if ($l && $::NO_SEGMENTED) { |
437 | if ($l && $::NO_SEGMENTED) { |
472 | my $delay = 60; |
438 | my $delay = 180; |
473 | while (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
439 | while (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { |
474 | if ($delay <= 0) { |
440 | if ($delay <= 0) { |
475 | $self->err(400, "segmented downloads are not allowed", |
441 | $self->err_segmented_download; |
476 | { "Content-Type" => "text/html", Connection => "close" }, <<EOF); |
|
|
477 | <html> |
|
|
478 | <head> |
|
|
479 | <title>Segmented downloads are not allowed</title> |
|
|
480 | </head> |
|
|
481 | <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000"> |
|
|
482 | |
|
|
483 | <p>Segmented downloads are not allowed on this server. Please refer to the |
|
|
484 | <a href="http://www.goof.com/pcg/marc/animefaq.html#segmented_downloads">FAQ</a>.</p> |
|
|
485 | |
|
|
486 | </body></html> |
|
|
487 | EOF |
|
|
488 | } else { |
442 | } else { |
489 | Coro::Event::do_timer(after => 3); $delay -= 3; |
443 | Coro::Event::do_timer(after => 3); $delay -= 3; |
490 | } |
444 | } |
491 | } |
445 | } |
492 | } |
446 | } |