5 $ENV{PATH} = "/usr/bin:/bin";
8 # if we are suid, set uid := euid
23 print "Content-type: text/plain\n\nd0er $err";
29 my ($goodpatterns, $badpatterns, $list) = @_;
31 my $name = $ENV{REMOTE_HOST} . ".";
32 my $addr = $ENV{REMOTE_ADDR};
38 if $name =~ /^(??{$_})$/ || $addr =~ /^(??{$_})$/;
44 if $name =~ /^(??{$_})$/ || $addr =~ /^(??{$_})$/;
48 my $h = gethostbyname $addr;
52 my $blprefix = join '.', reverse unpack 'C4', $h;
57 my $hn = "$blprefix.$_.";
58 my $h2 = gethostbyname $hn;
67 # create table ip ( id INT AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(64), t DATETIME, error BOOLEAN, INDEX(ip), INDEX(t), INDEX(error) );
72 my ($dsn, $u, $p, $tbl, $inc) = @_;
73 my $ip = $ENV{REMOTE_ADDR};
74 my $DBH = ($__CACHED_DBH__ ? $__CACHED_DBH__ : ($__CACHED_DBH__ = DBI->connect($dsn, $u, $p, { RaiseError => 1, AutoCommit => 0 })))
76 $DBH->do("set character set utf8");
77 $DBH->do("set names utf8");
80 $DBH->do("update $tbl set error=true where ip=?", undef, $ip);
87 my $status = $DBH->selectrow_arrayref("select count(*) from $tbl where ip=? and error=false and t>date_sub(now(), interval 7 day)", undef, $ip)
90 return $status->[0] ? -1 : 0;
94 my $status = $DBH->selectall_arrayref("select error, t>date_sub(now(), interval 7 day) from $tbl where ip=?", undef, $ip)
98 if($status->[0][0] || !$status->[0][1]) # error, or after interval
100 $DBH->do("update $tbl set error=false, t=now() where ip=?", undef, $ip);
113 $DBH->do("insert into $tbl(ip, error, t) values(?, false, now())", undef, $ip);
124 my $ip = $ENV{REMOTE_ADDR};
125 my @s = split /\n/, get $s;
129 return 1 if "$ip." =~ /^\Q$i\E\./;
139 if((my $key = $cgi->param('key')))
144 my $ca = $cgi->param('ca');
145 $ca = $default_ca if not defined $ca;
146 error "Invalid CA" if not defined $ca{$ca};
147 error "Not allowed" if not $ca{$ca}->{check}->(1);
151 $tempfh = File::Temp->new();
153 my $fh = $cgi->upload('key');
157 print $tempfh $_ for <$fh>;
162 $key = decode_base64($key);
167 $ENV{REQUESTFILE} = $tempfh->filename;
168 $ENV{RESPONSEFILE} = $tempfh->filename;
169 $ENV{SECRET} = "key_$ca.d0sk";
170 open my $errfh, '-|', './crypto-keygen-standalone -P "$SECRET" -j "$REQUESTFILE" -o "$RESPONSEFILE" 2>&1'
171 or die "cannot start crypto-keygen-standalone";
174 or die "crypto-keygen-standalone failed: $err";
179 $ca{$ca}->{check}->(-1);
183 print "Content-type: application/octet-stream\n\n";
190 Content-type: text/html
195 <title>Xonotic keygen</title>
198 <h1>Xonotic keygen</h1>
199 <form action="response.d0ir" method="post" enctype="multipart/form-data">
200 To generate and sign a key IN GAME, follow these steps on the console:
202 <li>crypto_keygen $default_ca http://ca.xonotic.org/?ca=$default_ca&key=</li>
204 To generate and sign a key MANUALLY, follow these steps on a UNIX command line:
206 <li>./crypto-keygen-standalone -p key_$default_ca.d0pk -o key_$default_ca.d0si</li>
207 <li>./crypto-keygen-standalone -p key_$default_ca.d0pk -I key_$default_ca.d0si -o request.d0iq -O camouflage.d0ic
208 <li>Upload the request.d0iq file: <input type="file" name="key"><input type="submit"></li>
209 <li>Save the response.d0ir file you are getting</li>
210 <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>
211 <li>Delete request.d0iq, camouflage.d0ic, response.d0ir</li>
213 Your key_$default_ca.d0si key is now signed.
215 To use another CA, please enter its number here before using this page:
216 <input type="text" name="ca" value="$default_ca" size="2">