]> git.sesse.net Git - remoteglot/blob - www/manual-override.pl
Handle streaming PGNs, like from Lichess (although this might break non-streaming...
[remoteglot] / www / manual-override.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 use DBI;
5 use DBD::Pg;
6 use CGI;
7 use Encode;
8 use lib qw(..);
9 require 'config.pm';
10
11 my $dbh = DBI->connect($remoteglotconf::dbistr, $remoteglotconf::dbiuser, $remoteglotconf::dbipass)
12         or die DBI->errstr;
13 $dbh->{RaiseError} = 1;
14
15 my $cgi = CGI->new;
16 my $password = Encode::decode_utf8($cgi->param('password'));
17 if (!defined($password) || $password ne $remoteglotconf::adminpass) {
18         print CGI->header(-type=>'text/plain; charset=utf-8', -status=>'403 Denied');
19         print "Nope.\n";
20         exit;
21 }
22
23 if ($cgi->param('move') eq 'null') {
24         $dbh->do('DELETE FROM game_extensions WHERE fen=? AND history=? AND player_w=? AND player_b=?',
25                 undef,
26                 Encode::decode_utf8($cgi->param('fen')),
27                 Encode::decode_utf8($cgi->param('history')),
28                 Encode::decode_utf8($cgi->param('player_w')),
29                 Encode::decode_utf8($cgi->param('player_b')));
30 } else {
31         $dbh->do('INSERT INTO game_extensions ( fen, history, player_w, player_b, ts, next_move ) VALUES ( ?, ?, ?, ?, CURRENT_TIMESTAMP, ? )',
32                 undef,
33                 Encode::decode_utf8($cgi->param('fen')),
34                 Encode::decode_utf8($cgi->param('history')),
35                 Encode::decode_utf8($cgi->param('player_w')),
36                 Encode::decode_utf8($cgi->param('player_b')),
37                 Encode::decode_utf8($cgi->param('move')));
38 }
39 system("sudo", "/usr/bin/touch", $remoteglotconf::target);
40
41 print CGI->header(-type=>'text/plain; charset=utf-8');
42 print "OK\n";