Changeset 106 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
12/22/04 16:25:59 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

IPDB rewrite, first stable iteration.

-> uses allocateBlock(), deleteBlock() from IPDB module rather

than hardcoding that in the web script

-> uses global variables from IPDB module for "static" data such

as allocation types and ities (which are loaded from the
database in much the same way that master blocks have been loaded)

-> IPDB.pm contains NO locally-exiting code, nor calls to any code

which exits before returning. This allows returning status codes
to the caller, so that things like database handles can be
properly cleaned up.

There are probably also a long list of minor bugfixes that I've forgotten.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r96 r106  
    2121$VERSION        = 2.0;
    2222@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        );
    2528
    2629@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        );
    3036
    3137##
     
    3642our @citylist;
    3743our @poplist;
     44our @masterblocks;
    3845
    3946# Let's initialize the globals.
     
    4451  my $sth;
    4552
    46   # Initialize alloctypes list
    47   $sth = $dbh->prepare("select type,dispname from alloctypes");
     53  # Initialize alloctypes hashes
     54  $sth = $dbh->prepare("select * from alloctypes order by listorder");
    4855  $sth->execute;
    49   return (undef,$sth->errstr) if $sth->err;
    5056  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    }
    5261  }
    5362
     
    5665  $sth->execute;
    5766  return (undef,$sth->errstr) if $sth->err;
    58   my $i = 0;
    59   my $j = 0;
    6067  while (my @data = $sth->fetchrow_array) {
    61     $citylist[$i++] = $data[0];
     68    push @citylist, $data[0];
    6269    if ($data[1] eq 'y') {
    63       $poplist[$j++] = $data[0];
     70      push @poplist, $data[0];
    6471    }
    6572  }
     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;
    6681
    6782  return (1,"OK");
     
    117132
    118133
     134## IPDB::checkDBSanity()
    119135# Quick check to see if the db is responding.  A full integrity
    120136# check will have to be a separate tool to walk the IP allocation trees.
    121137sub checkDBSanity {
    122   my $dbh = connectDB();
     138  my ($dbh) = $_[0];
    123139
    124140  if (!$dbh) {
    125     print "Cannot connect to the database!";
     141    print "No database handle, or connection has been closed.";
     142    return -1;
    126143  } else {
    127144    # it connects, try a stmt.
     
    134151    } else {
    135152      print "Connected to the database, but could not execute test statement.  ".$sth->errstr();
     153      return -1;
    136154    }
    137155  }
    138156  # Clean up after ourselves.
    139   $dbh->disconnect;
     157#  $dbh->disconnect;
    140158} # end checkDBSanity
    141159
     
    187205      return ('FAIL',$msg);
    188206    } else {
    189       return ('OK',"OK");
     207      return ('OK',"$cidr");
    190208    }
    191209
Note: See TracChangeset for help on using the changeset viewer.