Changeset 491 for branches


Ignore:
Timestamp:
09/23/10 20:06:19 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert dangling DB error to template in admin.cgi; remove all refs to printAndExit().
See #3, #15, #26.

Location:
branches/htmlform
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/admin.cgi

    r489 r491  
    4242syslog "debug", "$authuser active";
    4343
     44# Set up the CGI object...
     45my $q = new CGI::Simple;
     46# ... and get query-string params as well as POST params if necessary
     47$q->parse_query_string;
     48
     49# Convenience;  saves changing all references to %webvar
     50##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
     51my %webvar = $q->Vars;
     52
     53# anyone got a better name?  :P
     54my $thingroot = $ENV{SCRIPT_FILENAME};
     55$thingroot =~ s|cgi-bin/admin.cgi||;
     56
     57# Set up some globals
     58$ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
     59
    4460# Why not a global DB handle?  (And a global statement handle, as well...)
    4561# Use the connectDB function, otherwise we end up confusing ourselves
     
    4965($ip_dbh,$errstr) = connectDB_My;
    5066if (!$ip_dbh) {
    51   printAndExit("Database error: $errstr\n");
    52 }
    53 initIPDBGlobals($ip_dbh);
    54 
    55 # anyone got a better name?  :P
    56 my $thingroot = $ENV{SCRIPT_FILENAME};
    57 $thingroot =~ s|cgi-bin/admin.cgi||;
    58 
    59 # Set up some globals
    60 $ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
     67  $webvar{action} = "dberr";
     68} else {
     69  initIPDBGlobals($ip_dbh);
     70}
     71
     72# handle DB error output
     73if ($webvar{action} eq 'dberr') {
     74  my $page = HTML::Template->new(filename => "admin/dberr.tmpl");
     75  $page->param(errmsg => $errstr);
     76  print "Content-Type: text/html\n\n".$page->output;
     77  exit;
     78}
    6179
    6280if ($IPDBacl{$authuser} !~ /A/) {
     
    6987}
    7088
    71 # Set up the CGI object...
    72 my $q = new CGI::Simple;
    73 # ... and get query-string params as well as POST params if necessary
    74 $q->parse_query_string;
    75 
    76 # Convenience;  saves changing all references to %webvar
    77 ##fixme:  tweak for handling <select multiple='y' size=3> (list with multiple selection)
    78 my %webvar = $q->Vars;
    79 
    8089my $header = HTML::Template->new(filename => "admin/header.tmpl");
    8190
     
    91100}
    92101
     102# handle index page
    93103if ($webvar{action} eq 'main') {
    94104  $header->param(mainpage => 1);
     
    128138
    129139  if ($webvar{cidr} !~ /^\s*(\d{1,3}\.){3}\d{1,3}(\/\d{2})?\s*$/) {
    130     printAndExit("Can't allocate something that's not a netblock/ip");
     140    $page->param(errmsg => "Can't allocate something that's not a netblock/ip");
     141    goto ERRJUMP;
    131142  }
    132143
     
    163174    @data = $sth->fetchrow_array;
    164175# User deserves errors if user can't be bothered to find the free block first.
    165     printAndExit("Can't allocate from outside a free block!!\n")
    166         if !$data[0];
     176    if (!$data[0]) {
     177      $page->param(errmsg => "Can't allocate from outside a free block!!");
     178      goto ERRJUMP;
     179    }
    167180  } elsif ($webvar{alloctype} =~ /^(.)i$/) {
    168181    $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')");
     
    170183    @data = $sth->fetchrow_array;
    171184# User deserves errors if user can't be bothered to find the pool and a free IP first.
    172     printAndExit("Can't allocate static IP from outside a pool!!\n")
    173         if !$data[0];
     185    if (!$data[0]) {
     186      $page->param(errmsg => "Can't allocate static IP from outside a pool!!");
     187      goto ERRJUMP;
     188    }
    174189  } else {
    175190    $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')");
     
    177192    @data = $sth->fetchrow_array;
    178193# User deserves errors if user can't be bothered to find the free block first.
    179     printAndExit("Can't allocate from outside a routed block!!\n")
    180         if !$data[0];
     194    if (!$data[0]) {
     195      $page->param(errmsg => "Can't allocate from outside a routed block!!");
     196      goto ERRJUMP;
     197    }
    181198  }
    182199
Note: See TracChangeset for help on using the changeset viewer.