Changeset 491 for branches/htmlform/cgi-bin
- Timestamp:
- 09/23/10 20:06:19 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/htmlform/cgi-bin/admin.cgi
r489 r491 42 42 syslog "debug", "$authuser active"; 43 43 44 # Set up the CGI object... 45 my $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) 51 my %webvar = $q->Vars; 52 53 # anyone got a better name? :P 54 my $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 44 60 # Why not a global DB handle? (And a global statement handle, as well...) 45 61 # Use the connectDB function, otherwise we end up confusing ourselves … … 49 65 ($ip_dbh,$errstr) = connectDB_My; 50 66 if (!$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 73 if ($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 } 61 79 62 80 if ($IPDBacl{$authuser} !~ /A/) { … … 69 87 } 70 88 71 # Set up the CGI object...72 my $q = new CGI::Simple;73 # ... and get query-string params as well as POST params if necessary74 $q->parse_query_string;75 76 # Convenience; saves changing all references to %webvar77 ##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)78 my %webvar = $q->Vars;79 80 89 my $header = HTML::Template->new(filename => "admin/header.tmpl"); 81 90 … … 91 100 } 92 101 102 # handle index page 93 103 if ($webvar{action} eq 'main') { 94 104 $header->param(mainpage => 1); … … 128 138 129 139 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; 131 142 } 132 143 … … 163 174 @data = $sth->fetchrow_array; 164 175 # 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 } 167 180 } elsif ($webvar{alloctype} =~ /^(.)i$/) { 168 181 $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')"); … … 170 183 @data = $sth->fetchrow_array; 171 184 # 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 } 174 189 } else { 175 190 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')"); … … 177 192 @data = $sth->fetchrow_array; 178 193 # 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 } 181 198 } 182 199
Note:
See TracChangeset
for help on using the changeset viewer.