ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/err.pl
Revision: 1.9
Committed: Fri Oct 12 12:34:31 2007 UTC (16 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-4_22, rel-4_21, rel-4_3, rel-4_13, rel-4_2, rel-4_31
Changes since 1.8: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 use HTTP::Date;
2    
3     use Coro::Event;
4    
5     sub conn::err_block_country {
6     my $self = shift;
7     my $whois = shift;
8    
9     $whois =~ s/&/&/g;
10     $whois =~ s/</&lt;/g;
11     $self->err(403, "forbidden", { "Content-Type" => "text/html", Connection => "close" }, <<EOF);
12     <html>
13     <head>
14     <title>This material is licensed in your country!</title>
15     </head>
16     <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
17    
18     <h1>This material is licensed in your country!</h1>
19    
20     <p>My research has shown that your IP address
21     (<b>$self->{remote_addr}</b>) most probably is located in this country:
22     <b>$self->{country}</b> (ISO-3166-2 code, XX == unknown). The full record is:</p>
23    
24     <pre>
25     $whois
26     </pre>
27    
28     <p>My database says that the material you are trying to access is licensed
29     in your country. If I would distribute these files to your country I would
30     actively <em>hurt</em> the industry behind it, which includes the artists
31     and authors of these videos/mangas. So I hope you understand that I try to
32     avoid this.</p>
33    
34     <div align="right">Thanks a lot for understanding.</div>
35    
36     </body>
37     </html>
38     EOF
39     }
40    
41     sub conn::err_block_referer {
42     my $self = shift;
43    
44     my $uri = $self->{uri};
45     $uri =~ s/\/[^\/]+$/\//;
46    
47     $self->slog(6, "REFERER($self->{uri},$self->{h}{referer})");
48    
49     $whois =~ s/&/&amp;/g;
50     $whois =~ s/</&lt;/g;
51     $self->err(203, "non-authoritative", { "Content-Type" => "text/html" }, <<EOF);
52     <html>
53     <head>
54     <title>Unallowed Referral</title>
55     </head>
56     <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
57    
58     <h1>The site which referred you has done something bad!</h1>
59    
60     <p>It seems that you are coming from this URL:</p>
61    
62     <pre>$self->{h}{referer}</pre>
63    
64     <p>This site has been blocked, either because it required you to pay
65     money, forced you to click on banners, claimed these files were theirs
66     or something very similar. Please note that you can download these files
67     <em>without</em> having to pay, <em>without</em> clicking banners or jump
68     through other hoops.</p>
69    
70     <p><b>Sites like the one you came from actively hurt the distribution of
71     these files and the service quality for you since I can't move or correct
72     files and you will likely not be able to see the full archive.</b></p>
73    
74     <p>Having that this, you can find the original content (if it is still
75     there) by <b>following <a href="$uri">this link</a>.</b></p>
76    
77     <div align="right">Thanks a lot for understanding.</div>
78    
79     </body>
80     </html>
81     EOF
82     }
83    
84     sub conn::err_blocked {
85     my $self = shift;
86 root 1.4 my $id = $self->{remote_id};
87 root 1.5 my $block = $conn::blocked{$id};
88    
89     $block->[2]++;
90    
91     if ($block->[0] < $::NOW + $::BLOCKTIME) {
92     $block->[0] = $::NOW + $::BLOCKTIME;
93     }
94    
95     my $status = 403;
96     my $hdr = {
97     "Content-Type" => "text/html",
98     "Retry-After" => $block->[0] - $::NOW,
99     "Connection" => "close",
100     };
101    
102 root 1.2 my $ctime = $HTTP_NOW;
103 root 1.5 my $etime = time2str $block->[0];
104    
105     my $limit = $block->[3];
106     $block->[3] = $::NOW + 10;
107 root 1.1
108 root 1.5 if ($limit > $::NOW) {
109     Coro::Event::do_timer(after => $limit - $::NOW);
110 root 1.1
111 root 1.8 if ($block->[2] > 20) {
112     $block->[3] = $::NOW + $::DYNABLOCK + 360;
113 root 1.5 $status = 401;
114 root 1.8 $hdr->{Warning} = "Please do NOT retry, your IP has been blocked due to excessive hammering. Press Cancel instead.";
115     $hdr->{"WWW-Authenticate"} = "Basic realm=\"Please do NOT retry, you IP has been blocked due to excessive hammering. Press Cancel instead.\"";
116    
117     if ($block->[2] > 40) {
118 root 1.9 system "/root/s/dynablock --add $self->{remote_addr} $::DYNABLOCK &";
119 root 1.8 }
120 root 1.5 }
121     }
122    
123     $self->err($status, $block->[1], $hdr,
124 root 1.1 <<EOF);
125     <html>
126     <head>
127 root 1.5 <title>$block->[1]</title>
128 root 1.1 </head>
129     <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
130    
131 root 1.5 <p>You have been blocked because you didn't behave. The exact reason was:</p>
132    
133     <h1><blockquote>"$block->[1]"</blockquote></h1>
134    
135     <p>You may retry not earlier than:</p>
136 root 1.1
137 root 1.2 <p><blockquote>$etime.</blockquote></p>
138    
139 root 1.7 <p>Until then, each access will renew the block.</p>
140 root 1.5
141     <p>For your reference, the current time and your connection ID is:</p>
142 root 1.2
143 root 1.3 <p><blockquote>$ctime | $id</blockquote></p>
144 root 1.1
145     </body></html>
146     EOF
147     }
148    
149     sub conn::err_segmented_download {
150     my $self = shift;
151     $self->err(400, "segmented downloads are not allowed",
152     { "Content-Type" => "text/html", Connection => "close" }, <<EOF);
153     <html>
154     <head>
155     <title>Segmented downloads are not allowed</title>
156     </head>
157     <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
158    
159 root 1.7 <p>Segmented downloads are not allowed on this server.</p>
160 root 1.1
161     </body></html>
162     EOF
163     }
164    
165     1;
166