]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
Add PostgreSQL support to CA scripts
authorbones_was_here <bones_was_here@xa.org.au>
Wed, 16 Mar 2022 11:25:07 +0000 (21:25 +1000)
committerbones_was_here <bones_was_here@xa.org.au>
Wed, 16 Mar 2022 11:25:07 +0000 (21:25 +1000)
misc/infrastructure/keygen/config.pl
misc/infrastructure/keygen/response.d0ir

index 65108fd794e28e975c2eef6665f0ad91b89726f8..97da9e13db6c37cd2cdd622ea7291e81520805ad 100644 (file)
@@ -7,7 +7,8 @@
                        my ($inc) = @_;
                        return 0 if ($inc >= 0) && check_dnsbl([qr/.*:.*:.*/], [], ['torexit.dan.me.uk', 'aspews.ext.sorbs.net']);
                        return 0 if ($inc >= 0) && check_banlist('http://rm.sudo.rm-f.org/~xonotic/bans/?action=list&servers=*');
-                       return 0 if check_sql('dbi:mysql:dbname=xonotic-ca', 'xonotic-ca', '************', 'ip', 0.2, 1, 20, 1000, $inc);
+                       #return 0 if check_sql('dbi:mysql:dbname=xonotic-ca', 'xonotic-ca', '************', 'ip', 0.2, 1, 20, 1000, $inc);
+                       return 0 if check_sql('dbi:Pg:dbname=xonotic-ca', '', '', 'ip', 0.2, 1, 20, 1000, $inc);
                        1;
                }
        },
index 3396ce1e97905d9dda5013eb6d30a24f452e603d..044611551b9e060e8f1758021effe99213fe7550 100755 (executable)
@@ -82,20 +82,30 @@ sub check_dnsbl($$@)
        return 0;
 }
 
+# MySQL
 # create table ip ( id INT AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(64), t DATETIME, error BOOLEAN, INDEX(ip), INDEX(t), INDEX(error) );
+# standard SQL
+# CREATE TABLE ip ( id INT PRIMARY KEY generated always as identity, ip VARCHAR(64), t TIMESTAMP, error BOOLEAN );
+# CREATE INDEX ip_index ON ip ( ip, t, error );
 our $__CACHED_DBH__;
 
 sub check_ip_record
 {
        my ($DBH, $tbl, $ip) = @_;
-       my $status = $DBH->selectrow_arrayref("select count(*) from $tbl where ip=? and error=false and t>date_sub(now(), interval 7 day)", undef, $ip)
+       # MySQL
+       #my $status = $DBH->selectrow_arrayref("select count(*) from $tbl where ip=? and error=false and t>date_sub(now(), interval 7 day)", undef, $ip)
+       # standard SQL
+       my $status = $DBH->selectrow_arrayref("select count(*) from $tbl where ip=? and error=false and t>(now() - interval '7' day)", undef, $ip)
                or die "DBI/DBD: $!";
        return $status->[0];
 }
 sub insert_ip_record
 {
        my ($DBH, $tbl, $ip) = @_;
-       my $status = $DBH->selectall_arrayref("select error, t>date_sub(now(), interval 7 day) from $tbl where ip=?", undef, $ip)
+       # MySQL
+       #my $status = $DBH->selectall_arrayref("select error, t>date_sub(now(), interval 7 day) from $tbl where ip=?", undef, $ip)
+       # standard SQL
+       my $status = $DBH->selectall_arrayref("select error, t>(now() - interval '7' day) from $tbl where ip=?", undef, $ip)
                or die "DBI/DBD: $!";
        if(@$status)
        {
@@ -128,9 +138,13 @@ sub check_sql($$$$$$$$$)
        my $DBH = ($__CACHED_DBH__ ? $__CACHED_DBH__ : ($__CACHED_DBH__ = DBI->connect($dsn, $u, $p, { RaiseError => 1, AutoCommit => 0 })))
                or die "DBI/DBD: $!";
        eval {
-               $DBH->do("set character set utf8");
-               $DBH->do("set names utf8");
-               $DBH->do("set time_zone = '+0:00'");
+               # PostgreSQL defaults to utf8 everywhere so we don't need to set it
+               # MySQL defaults to latin1
+               #$DBH->do("set character set utf8");
+               #$DBH->do("set names utf8");
+               #$DBH->do("set time_zone = '+0:00'");
+               # standard SQL
+               $DBH->do("SET TIME ZONE +0");
        } or do {
                undef $__CACHED_DBH__;
                die $@;