Changeset 77


Ignore:
Timestamp:
09/10/25 12:22:02 (4 days ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Finally unpack the subtle SQL tweaks from production that kept excluded
blocks from setting bitmask values, and properly handle setting and
unsetting the per-IP exclusion flag

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r75 r77  
    242242  my $rep = shift;
    243243  my $exclude = shift || 'n';
     244  $exclude = 'y' if $exclude eq 'on';
    244245  my $sth;
    245246  my $rows = 0;
     
    253254        $sth = $dbh->prepare("INSERT INTO iplist (ip,parent,exclude) VALUES ".
    254255                "(?,(SELECT block FROM blocks WHERE block >> ? ORDER BY level DESC LIMIT 1),?)");
    255         $sth->execute($rep,$rep,($exclude ? 'y' : 'n')) or die "couldn't add entry for $rep: ".$dbh->errstr."\n";
     256        $sth->execute($rep, $rep, $exclude) or die "couldn't add entry for $rep: ".$dbh->errstr."\n";
    256257      } elsif ($rows == 1) {
    257258        $sth = $dbh->prepare("UPDATE iplist SET count=count+1,".
    258                 " exclude=".($exclude ? "'y'" : "'n'"). " WHERE ip=?");
     259                " exclude = ? WHERE ip = ?");
    259260        $sth->execute($exclude, $rep) or die "couldn't update listing for $rep: ".$dbh->errstr."\n";
    260261      } else {
     
    265266      my $updsth = $dbh->prepare("UPDATE blocks SET ipcount=(".
    266267        "SELECT count(*) FROM iplist i JOIN blocks b ON b.block=i.parent WHERE i.ip << ? AND i.exclude='n' AND b.exclude='n'".
    267         ") WHERE block=?");
     268        ") WHERE block = ?");
    268269      while (my ($block) = $sth->fetchrow_array) {
    269270        $updsth->execute($block,$block);
     
    410411    }
    411412    $sth = $dbh->prepare("UPDATE blocks SET exclude = ?, comments = ?, ipcount = ".
    412         "(SELECT count(*) FROM iplist WHERE ip << ? AND exclude='n')".
     413        "(SELECT count(*) FROM iplist i JOIN blocks b ON b.block=i.parent WHERE i.ip << ? AND i.exclude='n' AND b.exclude='n')".
    413414        " WHERE block = ?");
    414415    $sth->execute($exclude, $comment, "$block", "$block");
     
    559560    $sth->execute($container);
    560561    ($bcount,$listme,$bexclude,$listorg) = $sth->fetchrow_array();
     562    $bcount = 0 if !$bcount;
    561563    $bitmask |= $bitfields{$level-1} if $bcount >= $autolist{$masklen};
    562564    $bitmask |= $bitfields{"block".($level-1)} if $listme;
Note: See TracChangeset for help on using the changeset viewer.