[123] | 1 | #!/usr/bin/perl
|
---|
| 2 | # Check all customer IDs to see which are invalid
|
---|
| 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2010-07-26 21:00:00 +0000 (Mon, 26 Jul 2010) $
|
---|
| 6 | # SVN revision $Rev: 445 $
|
---|
| 7 | # Last update by $Author: kdeugau $
|
---|
| 8 | ###
|
---|
[445] | 9 | # Copyright (C) 2004-2010 Kris Deugau
|
---|
[123] | 10 |
|
---|
| 11 | use DBI;
|
---|
[128] | 12 | use IPDB 2.0 qw(:ALL);
|
---|
[123] | 13 |
|
---|
| 14 | # We'll be hosing the server with several thousand queries. We
|
---|
| 15 | # REALLY don't want the overhead and load of opening a new connection
|
---|
| 16 | # for each query.
|
---|
| 17 | #use CustIDCK;
|
---|
| 18 |
|
---|
| 19 | use NetAddr::IP;
|
---|
| 20 |
|
---|
| 21 | $priv1 = new NetAddr::IP '10.0.0.0/8';
|
---|
| 22 | $priv2 = new NetAddr::IP '172.16.0.0/12';
|
---|
| 23 | $priv3 = new NetAddr::IP '192.168.0.0/16';
|
---|
| 24 |
|
---|
| 25 | print "Content-type: text/plain\n\n";
|
---|
| 26 |
|
---|
[128] | 27 | ($dbh,$errstr) = connectDB("ipdb", "ipdb", "ipdbpwd");
|
---|
[318] | 28 | $IDH = DBI->connect ("DBI:Pg:host=billing;dbname=custids", "cidcheck", "c1dch4ck");
|
---|
[169] | 29 |
|
---|
| 30 | $sth = $dbh->prepare("select distinct def_custid from alloctypes where listorder >=40");
|
---|
| 31 | $sth->execute;
|
---|
| 32 | while (@data = $sth->fetchrow_array) {
|
---|
| 33 | push @def_custids, $data[0];
|
---|
| 34 | }
|
---|
[445] | 35 | $sth = $dbh->prepare("select cidr,custid from searchme where not (custid='$IPDB::defcustid') ".
|
---|
[123] | 36 | "and not (custid='STAFF') order by cidr");
|
---|
[318] | 37 | #$sth = $dbh->prepare("select cidr,custid from searchme order by cidr");
|
---|
[123] | 38 | $sth->execute;
|
---|
| 39 |
|
---|
| 40 | $IDS = $IDH->prepare("select custid from custid where custid=?");
|
---|
| 41 |
|
---|
| 42 | $count = $bad = 0;
|
---|
| 43 | while (@data = $sth->fetchrow_array) {
|
---|
| 44 | $cidr = new NetAddr::IP $data[0];
|
---|
[169] | 45 | if ($cidr->within($priv1) or $cidr->within($priv2) or $cidr->within($priv3) or
|
---|
| 46 | (grep /$data[1]/, @def_custids)) {
|
---|
[123] | 47 | # no-op. we ignore these.
|
---|
| 48 | } else {
|
---|
[169] | 49 | $count++;
|
---|
[123] | 50 | $IDS->execute($data[1]);
|
---|
| 51 | $hr = $IDS->fetchrow_hashref();
|
---|
| 52 | if (!$hr->{custid}) {
|
---|
| 53 | print " $data[0]\thas invalid CustID '$data[1]'\n";
|
---|
| 54 | $bad++;
|
---|
| 55 | }
|
---|
| 56 | $IDS->finish;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | $IDH->disconnect;
|
---|
| 61 | $dbh->disconnect;
|
---|
| 62 |
|
---|
| 63 | print "$count customer blocks, $bad bad.\n";
|
---|
| 64 | exit 0;
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | ### Ported subs of sorts from CustIDCK.pm
|
---|