]> git.sesse.net Git - remoteglot/blobdiff - www/manual-override.pl
Add a very crude function for manual overrides.
[remoteglot] / www / manual-override.pl
diff --git a/www/manual-override.pl b/www/manual-override.pl
new file mode 100755 (executable)
index 0000000..616e5ea
--- /dev/null
@@ -0,0 +1,33 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+use DBI;
+use DBD::Pg;
+use CGI;
+use Encode;
+use lib qw(..);
+require 'config.pm';
+
+my $dbh = DBI->connect($remoteglotconf::dbistr, $remoteglotconf::dbiuser, $remoteglotconf::dbipass)
+        or die DBI->errstr;
+$dbh->{RaiseError} = 1;
+
+my $cgi = CGI->new;
+my $password = Encode::decode_utf8($cgi->param('password'));
+if (!defined($password) || $password ne $remoteglotconf::adminpass) {
+       print CGI->header(-type=>'text/plain; charset=utf-8', -status=>'403 Denied');
+       print "Nope.\n";
+       exit;
+}
+
+$dbh->do('INSERT INTO game_extensions ( fen, history, player_w, player_b, ts, next_move ) VALUES ( ?, ?, ?, ?, CURRENT_TIMESTAMP, ? )',
+       undef,
+       Encode::decode_utf8($cgi->param('fen')),
+       Encode::decode_utf8($cgi->param('history')),
+       Encode::decode_utf8($cgi->param('player_w')),
+       Encode::decode_utf8($cgi->param('player_b')),
+       Encode::decode_utf8($cgi->param('move')));
+system("touch", $remoteglotconf::json_output);
+
+print CGI->header(-type=>'text/plain; charset=utf-8');
+print "OK\n";