ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/err.pl
Revision: 1.12
Committed: Sat Aug 13 23:42:05 2011 UTC (12 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-6_5, rel-6_10, rel-6_09, rel-6_08, rel-6_07, rel-6_512, rel-6_513, rel-6_511, rel-6_514, rel-6_32, rel-6_33, rel-6_31, rel-6_36, rel-6_37, rel-6_38, rel-6_39, rel-6_23, rel-6_29, rel-6_28, rel-6_46, rel-6_45, rel-6_51, rel-6_52, rel-6_53, rel-6_54, rel-6_55, rel-6_56, rel-6_57, rel-6_43, rel-6_42, rel-6_41, rel-6_47, rel-6_44, rel-6_49, rel-6_48, HEAD
Changes since 1.11: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 use HTTP::Date;
2
3 use Coro::EV;
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 my $id = $self->{remote_id};
87 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 my $ctime = $HTTP_NOW;
103 my $etime = time2str $block->[0];
104
105 my $limit = $block->[3];
106 $block->[3] = $::NOW + 10;
107
108 if ($limit > $::NOW) {
109 Coro::AnyEvent::sleep $limit - $::NOW;
110
111 if ($block->[2] > 20) {
112 $block->[3] = $::NOW + $::DYNABLOCK + 360;
113 $status = 401;
114 $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 system "/root/s/dynablock --dur $::DYNABLOCK --add $self->{remote_addr} &";
119 }
120 }
121 }
122
123 $self->err($status, $block->[1], $hdr,
124 <<EOF);
125 <html>
126 <head>
127 <title>$block->[1]</title>
128 </head>
129 <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
130
131 <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
137 <p><blockquote>$etime.</blockquote></p>
138
139 <p>Until then, each access will renew the block.</p>
140
141 <p>For your reference, the current time and your connection ID is:</p>
142
143 <p><blockquote>$ctime | $id</blockquote></p>
144
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 <p>Segmented downloads are not allowed on this server.</p>
160
161 </body></html>
162 EOF
163 }
164
165 1;
166