5 $ENV{PATH} = "/usr/bin:/bin";
8 # if we are suid, set uid := euid
23 print "Content-type: text/plain\n\nd0er $err";
30 my $ip = $ENV{REMOTE_ADDR};
31 return 0 if -f "$dir/$ip";
37 my ($goodpatterns, $badpatterns, $list) = @_;
39 my $name = $ENV{REMOTE_HOST} . ".";
40 my $addr = $ENV{REMOTE_ADDR};
45 if($name =~ /^(??{$_})$/ || $addr =~ /^(??{$_})$/)
53 if($name =~ /^(??{$_})$/ || $addr =~ /^(??{$_})$/)
55 warn "$addr/$name blocked by $_";
61 my $h = gethostbyname $addr;
64 warn "$addr blocked by gethostbyname()";
68 my $blprefix = join '.', reverse unpack 'C4', $h;
73 my $hn = "$blprefix.$_.";
74 my $h2 = gethostbyname $hn;
77 my $h2_text = join '.', reverse unpack 'C4', $h2;
78 warn "$addr blocked by $hn -> $h2_text";
85 # create table ip ( id INT AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(64), t DATETIME, error BOOLEAN, INDEX(ip), INDEX(t), INDEX(error) );
90 my ($DBH, $tbl, $ip) = @_;
91 my $status = $DBH->selectrow_arrayref("select count(*) from $tbl where ip=? and error=false and t>date_sub(now(), interval 7 day)", undef, $ip)
97 my ($DBH, $tbl, $ip) = @_;
98 my $status = $DBH->selectall_arrayref("select error, t>date_sub(now(), interval 7 day) from $tbl where ip=?", undef, $ip)
102 if($status->[0][0] || !$status->[0][1]) # error, or after interval
104 $DBH->do("update $tbl set error=false, t=now() where ip=?", undef, $ip);
114 $DBH->do("insert into $tbl(ip, error, t) values(?, false, now())", undef, $ip);
120 my ($DBH, $tbl, $ip) = @_;
121 $DBH->do("update $tbl set error=true where ip=?", undef, $ip);
124 sub check_sql($$$$$$$$$)
126 my ($dsn, $u, $p, $tbl, $per32, $per24, $per16, $per8, $inc) = @_;
127 my $ip = $ENV{REMOTE_ADDR};
128 my $DBH = ($__CACHED_DBH__ ? $__CACHED_DBH__ : ($__CACHED_DBH__ = DBI->connect($dsn, $u, $p, { RaiseError => 1, AutoCommit => 0 })))
129 or die "DBI/DBD: $!";
131 $DBH->do("set character set utf8");
132 $DBH->do("set names utf8");
133 $DBH->do("set time_zone = '+0:00'");
135 undef $__CACHED_DBH__;
140 delete_ip_record($DBH, $tbl, $ip);
147 my $status = check_ip_record($DBH, $tbl, $ip);
151 warn "$ip blocked by SQL";
157 my $status = insert_ip_record($DBH, $tbl, $ip);
162 warn "$ip blocked by SQL";
171 my $ip = $ENV{REMOTE_ADDR};
172 my @s = split /\n/, get $s;
176 if("$ip." =~ /^\Q$i\E\./)
178 warn "$ip blocked by SQL";
190 if((my $key = $cgi->param('key')))
195 my $ca = $cgi->param('ca');
196 $ca = $default_ca if not defined $ca;
197 error "Invalid CA" if not defined $ca{$ca};
198 error "Not allowed" if not $ca{$ca}->{check}->(1);
202 $tempfh = File::Temp->new();
204 my $fh = $cgi->upload('key');
208 print $tempfh $_ for <$fh>;
213 $key = decode_base64($key);
218 $ENV{REQUESTFILE} = $tempfh->filename;
219 $ENV{RESPONSEFILE} = $tempfh->filename;
220 $ENV{SECRET} = "key_$ca.d0sk";
221 open my $errfh, '-|', './crypto-keygen-standalone -P "$SECRET" -j "$REQUESTFILE" -o "$RESPONSEFILE" 2>&1'
222 or die "cannot start crypto-keygen-standalone";
225 or die "crypto-keygen-standalone failed: $err";
230 $ca{$ca}->{check}->(-1);
234 print "Content-type: application/octet-stream\n\n";
241 Content-type: text/html
246 <title>Xonotic keygen</title>
249 <h1>Xonotic keygen</h1>
250 <form action="response.d0ir" method="post" enctype="multipart/form-data">
251 To generate and sign a key IN GAME, follow these steps on the console:
253 <li>crypto_keygen $default_ca http://ca.xonotic.org/?ca=$default_ca&key=</li>
255 To generate and sign a key MANUALLY, follow these steps on a UNIX command line:
257 <li>./crypto-keygen-standalone -p key_$default_ca.d0pk -o key_$default_ca.d0si</li>
258 <li>./crypto-keygen-standalone -p key_$default_ca.d0pk -I key_$default_ca.d0si -o request.d0iq -O camouflage.d0ic
259 <li>Upload the request.d0iq file: <input type="file" name="key"><input type="submit"></li>
260 <li>Save the response.d0ir file you are getting</li>
261 <li>./crypto-keygen-standalone -p key_$default_ca.d0pk -I key_$default_ca.d0si -c camouflage.d0ic -J response.d0ir -o key_$default_ca.d0si</li>
262 <li>Delete request.d0iq, camouflage.d0ic, response.d0ir</li>
264 Your key_$default_ca.d0si key is now signed.
266 To use another CA, please enter its number here before using this page:
267 <input type="text" name="ca" value="$default_ca" size="2">
269 REMOTE_HOST=$ENV{REMOTE_HOST}<br>
270 REMOTE_ADDR=$ENV{REMOTE_ADDR}