Changeset 29


Ignore:
Timestamp:
12/20/10 16:14:17 (14 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Add islisted()
Add waslisted table in SQL def
Indicate block status on adding an IP to an existing block
Fix for scripts-not-at-webroot
Tweak for scrolling "blocks in this registrar block" list
Load more config from DB on export

Location:
trunk/dnsbl
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r25 r29  
    260260
    261261
     262# Get info about whether a block, IP or org is listed
     263# Returns ?
     264sub islisted {
     265  my $self = shift;
     266  my $entity = shift;
     267
     268  my $sth;
     269
     270  if ($entity =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
     271    # looking for IP
     272
     273    $sth = $dbh->prepare("SELECT ip,s4list FROM iplist WHERE ip=?");
     274    $sth->execute($entity);
     275    my @ret = $sth->fetchrow_array;
     276    return @ret if @ret;
     277
     278  } elsif ($entity =~ m|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/(\d+)$|) {
     279    # block
     280
     281    my $masklen = $1;
     282
     283    $sth = $dbh->prepare("SELECT block,listme FROM blocks WHERE block=?");
     284    $sth->execute($entity);
     285    my ($block,$listme) = $sth->fetchrow_array;
     286
     287    return if !$block;
     288
     289    $sth = $dbh->prepare("SELECT count(*) FROM iplist WHERE ip << ?");
     290    $sth->execute($entity);
     291    my ($bcount) = $sth->fetchrow_array;
     292    my @ret = ( ($bcount >= $autolist{$masklen}), $listme);
     293    return @ret;
     294
     295  } else {
     296    # org
     297
     298    $sth = $dbh->prepare("SELECT orgid,listme FROM orgs WHERE orgname=?");
     299    $sth->execute($entity);
     300    my ($orgid,$listme) = $sth->fetchrow_array;
     301    return $listme if $orgid;
     302
     303  }
     304
     305  return undef;
     306
     307} # end islisted()
     308
     309
    262310# whee! Recursion is Fun!
    263311# Call ourself to dig down through the layers of blocks from registar-allocation
  • trunk/dnsbl/dnsbl.cgi

    r26 r29  
    8181    my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i);
    8282    if ($block) {
     83      my ($bcl,$bal) = $dnsbl->islisted($block);
     84      $page->param("autob$i" => $bcl);
     85      $page->param("listb$i" => $bal);
     86      my ($ol) = $dnsbl->islisted($org);
     87      $page->param("listorg$i" => $ol);
    8388      $page->param("block$i" => $block);
    8489      $page->param("org$i" => $org);
  • trunk/dnsbl/dnsbl.sql

    r25 r29  
    6767);
    6868
     69
     70-- for tracking IPs that get removed from listing
     71-- note we don't want a PK on IP as with iplist, since we may end up removing an IP more than once.  :/
     72
     73CREATE TABLE waslisted (
     74    ip inet NOT NULL,
     75    count integer DEFAULT 1,
     76    s4list boolean DEFAULT false,
     77    origadded timestamp with time zone DEFAULT now(),
     78    delisted timestamp with time zone DEFAULT now()
     79);
    6980
    7081--
  • trunk/dnsbl/export-dnsbl

    r25 r29  
    3535my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    3636
     37my %config;
     38my $sth = $dbh->prepare("SELECT key,value FROM misc");
     39$sth->execute;
     40while (my ($key,$value) = $sth->fetchrow_array) {
     41  $config{$key} = $value;
     42}
     43
    3744my %iplist;
    3845my $ipref = \%iplist;
     
    5158if ($mode eq 'cidr') {
    5259  # SOA, NS records.  Maybe dnscache needs them?
    53   print "\$SOA 900 company.dnsbl systems.company.com 0 1200 600 600 900\n".
     60  print "\$SOA 900 ".($config{blzone} ? $config{blzone} : 'company').".dnsbl systems.company.com 0 1200 600 600 900\n".
    5461        "\$NS 3600 127.0.0.1\n".
    5562        "\$TTL 900\n";
     
    5865  foreach (sort ipcmp keys %iplist) {
    5966    print "$_:127.0.0.$iplist{$_}:".
    60         ($iplist{$_} & 2 ? '$ relayed a reported spam' : 'Netblock listed on one or more criteria')."\n";
     67        ($iplist{$_} & 2 ?
     68                ($config{iplisted} ? $config{iplisted} : '$ relayed a reported spam') :
     69                ($config{blocklisted} ? $config{blocklisted} : 'Netblock listed on one or more criteria')
     70        )."\n";
    6171  }
    6272} else {
  • trunk/dnsbl/index.shtml

    r2 r29  
    1 <!--#include virtual="/dnsbl.cgi" -->
     1<!--#include virtual="dnsbl.cgi" -->
     2
  • trunk/dnsbl/templates/dbreport.tmpl

    r26 r29  
    1818<TMPL_IF NAME=browsebits>
    1919<td valign=top>
     20<div class="scroll780">
    2021<TMPL_VAR NAME=browsebits>
     22</div>
    2123</td>
    2224</TMPL_IF>
  • trunk/dnsbl/templates/dnsbl.css

    r22 r29  
    8585  font-weight: bold;
    8686}
     87.scroll780 {
     88  border: 2px solid #0000ff;
     89  height: 780px;
     90  width: 800px;
     91  overflow: auto;
     92}
  • trunk/dnsbl/templates/report.tmpl

    r26 r29  
    1515
    1616<tr><td nowrap>Registrar delegation</td></tr>
    17 <tr>
    18 <td>Netblock:</td>
     17<tr<TMPL_IF autob0> class="auto0"</TMPL_IF>>
     18<td><span class="<TMPL_IF listb0>b0list</TMPL_IF>">Netblock:</span></td>
    1919<td colspan=2><input name=block0 value="<TMPL_VAR block0>" size=40></td>
    2020</tr>
    21 <tr>
    22 <td>Org/Person:</td>
     21<tr<TMPL_IF autob0> class="auto0"</TMPL_IF>>
     22<td><span class="<TMPL_IF listorg0>b0org</TMPL_IF>">Org/Person:</span></td>
    2323<td colspan=2><input name=org0 value="<TMPL_VAR org0>" size=40></td>
    2424</tr>
    2525
    2626<tr><td>1st subdelegation</td></tr>
    27 <tr>
    28 <td>Netblock:</td>
     27<tr<TMPL_IF autob1> class="auto1"</TMPL_IF>>
     28<td><span class="<TMPL_IF listb1>b1list</TMPL_IF>">Netblock:</span></td>
    2929<td colspan=2><input name=block1 value="<TMPL_VAR block1>" size=40></td>
    3030</tr>
    31 <tr>
    32 <td>Org/Person:</td>
     31<tr<TMPL_IF autob1> class="auto1"</TMPL_IF>>
     32<td><span class="<TMPL_IF listorg1>b1org</TMPL_IF>">Org/Person:</span></td>
    3333<td colspan=2><input name=org1 value="<TMPL_VAR org1>" size=40></td>
    3434</tr>
    3535
    3636<tr><td>2nd subdelegation</td></tr>
    37 <tr>
    38 <td>Netblock:</td>
     37<tr<TMPL_IF autob2> class="auto2"</TMPL_IF>>
     38<td><span class="<TMPL_IF listb2>b2list</TMPL_IF>">Netblock:</span></td>
    3939<td colspan=2><input name=block2 value="<TMPL_VAR block2>" size=40></td>
    4040</tr>
    41 <tr>
    42 <td>Org/Person:</td>
     41<tr<TMPL_IF autob2> class="auto2"</TMPL_IF>>
     42<td><span class="<TMPL_IF listorg2>b2org</TMPL_IF>">Org/Person:</span></td>
    4343<td colspan=2><input name=org2 value="<TMPL_VAR org2>" size=40></td>
    4444</tr>
     
    5151<TMPL_IF NAME=browsebits>
    5252<td valign=top>
     53<div class="scroll780">
    5354<TMPL_VAR NAME=browsebits>
     55</div>
    5456</td>
    5557</TMPL_IF>
Note: See TracChangeset for help on using the changeset viewer.