[123] | 1 | #!/usr/bin/perl
|
---|
| 2 | # Check all customer IDs to see which are invalid
|
---|
| 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2005-01-18 19:56:09 +0000 (Tue, 18 Jan 2005) $
|
---|
| 6 | # SVN revision $Rev: 128 $
|
---|
| 7 | # Last update by $Author: kdeugau $
|
---|
| 8 | ###
|
---|
| 9 | # Copyright (C) 2004 Kris Deugau <kdeugau@vianet.ca>
|
---|
| 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");
|
---|
[123] | 28 | $IDH = DBI->connect ("DBI:Pg:host=billing;dbname=custids", "cidcheck", "c1dch4ck");
|
---|
| 29 | $sth = $dbh->prepare("select cidr,custid from searchme where not (custid='6750400') ".
|
---|
| 30 | "and not (custid='STAFF') order by cidr");
|
---|
| 31 | $sth->execute;
|
---|
| 32 |
|
---|
| 33 | $IDS = $IDH->prepare("select custid from custid where custid=?");
|
---|
| 34 |
|
---|
| 35 | $count = $bad = 0;
|
---|
| 36 | while (@data = $sth->fetchrow_array) {
|
---|
| 37 | $count++;
|
---|
| 38 | $cidr = new NetAddr::IP $data[0];
|
---|
| 39 | if ($cidr->within($priv1) or $cidr->within($priv2) or $cidr->within($priv3)) {
|
---|
| 40 | # no-op. we ignore these.
|
---|
| 41 | } else {
|
---|
| 42 | $IDS->execute($data[1]);
|
---|
| 43 | $hr = $IDS->fetchrow_hashref();
|
---|
| 44 | if (!$hr->{custid}) {
|
---|
| 45 | print " $data[0]\thas invalid CustID '$data[1]'\n";
|
---|
| 46 | $bad++;
|
---|
| 47 | }
|
---|
| 48 | $IDS->finish;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | $IDH->disconnect;
|
---|
| 53 | $dbh->disconnect;
|
---|
| 54 |
|
---|
| 55 | print "$count customer blocks, $bad bad.\n";
|
---|
| 56 | exit 0;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | ### Ported subs of sorts from CustIDCK.pm
|
---|