Changeset 106 for trunk/cgi-bin/IPDB.pm
- Timestamp:
- 12/22/04 16:25:59 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r96 r106 21 21 $VERSION = 2.0; 22 22 @ISA = qw(Exporter); 23 @EXPORT_OK = qw(&initIPDBGlocals &connectDB &finish &checkDBSanity &allocateBlock 24 &deleteBlock &mailNotify); 23 @EXPORT_OK = qw( 24 %disp_alloctypes %list_alloctypes @citylist @poplist @masterblocks 25 &initIPDBGlobals &connectDB &finish &checkDBSanity &allocateBlock &deleteBlock 26 &mailNotify 27 ); 25 28 26 29 @EXPORT = (); # Export nothing by default. 27 %EXPORT_TAGS = ( ALL => [qw( &initIPDBGlocals &connectDB &finish &checkDBSanity 28 &allocateBlock &deleteBlock &mailNotify)] 29 ); 30 %EXPORT_TAGS = ( ALL => [qw( 31 %disp_alloctypes %list_alloctypes @citylist @poplist @masterblocks 32 &initIPDBGlobals &connectDB &finish &checkDBSanity &allocateBlock 33 &deleteBlock &mailNotify 34 )] 35 ); 30 36 31 37 ## … … 36 42 our @citylist; 37 43 our @poplist; 44 our @masterblocks; 38 45 39 46 # Let's initialize the globals. … … 44 51 my $sth; 45 52 46 # Initialize alloctypes list47 $sth = $dbh->prepare("select type,dispname from alloctypes");53 # Initialize alloctypes hashes 54 $sth = $dbh->prepare("select * from alloctypes order by listorder"); 48 55 $sth->execute; 49 return (undef,$sth->errstr) if $sth->err;50 56 while (my @data = $sth->fetchrow_array) { 51 $disp_alloctypes{$data[0]} = $data[1]; 57 $disp_alloctypes{$data[0]} = $data[2]; 58 if ($data[3] < 900) { 59 $list_alloctypes{$data[0]} = $data[1]; 60 } 52 61 } 53 62 … … 56 65 $sth->execute; 57 66 return (undef,$sth->errstr) if $sth->err; 58 my $i = 0;59 my $j = 0;60 67 while (my @data = $sth->fetchrow_array) { 61 $citylist[$i++] =$data[0];68 push @citylist, $data[0]; 62 69 if ($data[1] eq 'y') { 63 $poplist[$j++] =$data[0];70 push @poplist, $data[0]; 64 71 } 65 72 } 73 74 # Master block list 75 $sth = $dbh->prepare("select * from masterblocks order by cidr"); 76 $sth->execute; 77 for (my $i=0; my @data = $sth->fetchrow_array(); $i++) { 78 $masterblocks[$i] = new NetAddr::IP $data[0]; 79 } 80 return (undef,$sth->errstr) if $sth->err; 66 81 67 82 return (1,"OK"); … … 117 132 118 133 134 ## IPDB::checkDBSanity() 119 135 # Quick check to see if the db is responding. A full integrity 120 136 # check will have to be a separate tool to walk the IP allocation trees. 121 137 sub checkDBSanity { 122 my $dbh = connectDB();138 my ($dbh) = $_[0]; 123 139 124 140 if (!$dbh) { 125 print "Cannot connect to the database!"; 141 print "No database handle, or connection has been closed."; 142 return -1; 126 143 } else { 127 144 # it connects, try a stmt. … … 134 151 } else { 135 152 print "Connected to the database, but could not execute test statement. ".$sth->errstr(); 153 return -1; 136 154 } 137 155 } 138 156 # Clean up after ourselves. 139 $dbh->disconnect;157 # $dbh->disconnect; 140 158 } # end checkDBSanity 141 159 … … 187 205 return ('FAIL',$msg); 188 206 } else { 189 return ('OK'," OK");207 return ('OK',"$cidr"); 190 208 } 191 209
Note:
See TracChangeset
for help on using the changeset viewer.