Changeset 541 for trunk/cgi-bin


Ignore:
Timestamp:
11/02/12 15:54:31 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Start on SQL in admin.cgi. See #34.

  • Convert Q-n-D allocation list on main page to use existing getTypeList()
  • Convert timestamp-update master block list to use new getMasterList(), with a flag set to return the last-modified time. Also convert main.cgi new assignment page to use this, with the flag set to not return the lastmod.
  • Tweak admin main template to match

While following the code for the master block list, I also removed
several useless globals (@masterblocks, %allocated, %free, and
%routed) since they were only used originally in one place (index
page from main.cgi), obsoleted by changes in r523, and in fact got
overridden locally before that anyway.

Location:
trunk/cgi-bin
Files:
3 edited

Legend:

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

    r536 r541  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK    = qw(
    25         %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist @masterblocks
    26         %allocated %free %routed %bigfree %IPDBacl %aclmsg
     25        %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
     26        %IPDBacl %aclmsg
    2727        &initIPDBGlobals &connectDB &finish &checkDBSanity
    2828        &addMaster
    2929        &listSummary &listMaster &listRBlock &listFree &listPool
    30         &getTypeList &getPoolSelect &findAllocateFrom
     30        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    3131        &ipParent &subParent &blockParent &getRoutedCity
    3232        &allocateBlock &updateBlock &deleteBlock &getBlockData
     
    3838%EXPORT_TAGS    = ( ALL => [qw(
    3939                %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    40                 @masterblocks %allocated %free %routed %bigfree %IPDBacl %aclmsg
     40                %IPDBacl %aclmsg
    4141                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4242                &addMaster
    4343                &listSummary &listMaster &listRBlock &listFree &listPool
    44                 &getTypeList &getPoolSelect &findAllocateFrom
     44                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    4545                &ipParent &subParent &blockParent &getRoutedCity
    4646                &allocateBlock &updateBlock &deleteBlock &getBlockData
     
    5858our @citylist;
    5959our @poplist;
    60 our @masterblocks;
    61 our %allocated;
    62 our %free;
    63 our %routed;
    64 our %bigfree;
    6560our %IPDBacl;
    6661
     
    121116  }
    122117
    123   # Master block list
    124   $sth = $dbh->prepare("select cidr from masterblocks order by cidr");
    125   $sth->execute;
    126   return (undef,$sth->errstr) if $sth->err;
    127   for (my $i=0; my @data = $sth->fetchrow_array(); $i++) {
    128     $masterblocks[$i] = new NetAddr::IP $data[0];
    129     $allocated{"$masterblocks[$i]"} = 0;
    130     $free{"$masterblocks[$i]"} = 0;
    131     $bigfree{"$masterblocks[$i]"} = 128; # Larger number means smaller block.
    132                                         # Set to 128 to prepare for IPv6
    133     $routed{"$masterblocks[$i]"} = 0;
    134   }
    135 
    136118  # Load ACL data.  Specific username checks are done at a different level.
    137119  $sth = $dbh->prepare("select username,acl from users");
     
    469451  return \@poolips;
    470452} # end listPool()
     453
     454
     455## IPDB::getMasterList()
     456# Get a list of master blocks, optionally including last-modified timestamps
     457# Takes an optional flag to indicate whether to include timestamps;
     458#  'm' includes ctime, all others (suggest 'c') do not.
     459# Returns an arrayref to a list of hashrefs
     460sub getMasterList {
     461  my $dbh = shift;
     462  my $stampme = shift || 'm';   # optional but should be set by caller for clarity
     463
     464  my $mlist = $dbh->selectall_arrayref("SELECT cidr AS master".($stampme eq 'm' ? ',mtime' : '').
     465        " FROM masterblocks ORDER BY cidr", { Slice => {} });
     466  return $mlist;
     467} # end getMasterList()
    471468
    472469
  • trunk/cgi-bin/admin.cgi

    r517 r541  
    106106  $sth->execute;
    107107
    108   my @typelist;
    109   my $count = 0;
    110   while (my ($type,$listname) = $sth->fetchrow_array) {
    111     my %row = (
    112         selected => $count++,
    113         type => $type,
    114         dispname => $listname
    115         );
    116     push @typelist, \%row;
    117   }
    118   $page->param(typelist => \@typelist);
    119 
    120   my @masterlist;
    121   $sth = $ip_dbh->prepare("select cidr,mtime from masterblocks order by cidr");
    122   $sth->execute;
    123   while (my ($cidr,$mtime) = $sth->fetchrow_array) {
    124     my %row = (
    125         master => $cidr,
    126         masterdate => $mtime
    127         );
    128     push @masterlist, \%row;
    129   }
    130   $page->param(masterlist => \@masterlist);
     108  my $tlist = getTypeList($ip_dbh, 'a');
     109  $tlist->[0]->{sel} = 1;
     110  $page->param(typelist => $tlist);
     111
     112  my $mlist = getMasterList($ip_dbh, 'm');
     113  $page->param(masterlist => $mlist);
    131114
    132115}
  • trunk/cgi-bin/main.cgi

    r540 r541  
    338338    }
    339339  } else {
    340     my @masterlist;
    341     foreach my $master (@masterblocks) {
    342       my %row = (master => "$master");
    343       push (@masterlist, \%row);
    344     }
    345     $page->param(masterlist => \@masterlist);
     340    my $mlist = getMasterList($ip_dbh, 'c');
     341    $page->param(masterlist => $mlist);
    346342
    347343    my @pops;
Note: See TracChangeset for help on using the changeset viewer.