Changeset 111 for trunk


Ignore:
Timestamp:
12/24/04 15:10:56 (20 years ago)
Author:
Kris Deugau
Message:

/trunk

Cleanup of display and fallthrough logic:

  • printFooter is now called once, and once ONLY, at the end of execution of main.cgi.
  • All execution in main.cgi should terminate at a single point; this allows MUCH easier cleanup of global data, filehandles, database handle(s), etc and printing the footer.

validateInput() cleanup:

  • Fixed logic to check POP locations as necessary

General code cleanup

  • Removed useless legacy commented code fragments
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r106 r111  
    127127  }
    128128
    129   printFooter;
    130129} # end add new master
    131130
     
    149148    viewBy($webvar{searchfor}, $webvar{input});
    150149  }
    151   printFooter();
    152150}
    153151
     
    188186  printAndExit("Error $boing:  ".$excuses[$rnd/30.0]);
    189187}
     188## Finally! Done with that NASTY "case" emulation!
    190189
    191190
    192191
    193192# Clean up IPDB globals, DB handle, etc.
    194 finish;
     193finish($ip_dbh);
     194# We print the footer here, so we don't have to do it elsewhere.
     195printFooter;
    195196# Just in case something waaaayyy down isn't in place
    196197# properly... we exit explicitly.
    197198exit;
     199
    198200
    199201
     
    294296    } else {
    295297      # This shouldn't happen, but if it does, whoever gets it deserves what they get...
    296       printAndExit("Invalid query.");
     298      printError("Invalid query.");
    297299    }
    298300  } else {
    299301    # This shouldn't happen, but if it does, whoever gets it deserves what they get...
    300     printAndExit("Invalid searchfor.");
     302    printError("Invalid searchfor.");
    301303  }
    302304} # viewBy
     
    477479  print "Note:  Free blocks noted here include both routed and unrouted blocks.\n";
    478480
    479   # Because of the way this sub gets called, we don't need to print the footer here.
    480   # (index.shtml makes an SSI #include call to cgi-bin/main.cgi?action=index)
    481   # If we do, the footer comes in twice...
    482   #printFooter;
    483481} # showSummary
    484482
     
    608606
    609607  print "</table>\n";
    610   printFooter;
    611608} # showMaster
    612609
     
    696693
    697694  print "</table>\n";
    698   printFooter;
    699695} # showRBlock
    700696
     
    752748  print "</table>\n";
    753749
    754   printFooter;
    755750} # end listPool
    756751
     
    815810  print $html;
    816811
    817   printFooter();
    818812} # assignBlock
    819813
     
    828822  # Going to manually validate some items.
    829823  # custid and city are automagic.
    830   validateInput();
    831 
    832 # This isn't always useful.
    833 #  if (!$webvar{maskbits}) {
    834 #    printAndExit("Please enter a CIDR block length.");
    835 #  }
     824  return if !validateInput();
    836825
    837826# Several different cases here.
     
    882871
    883872      if (!$webvar{maskbits}) {
    884         printAndExit("Please specify a CIDR mask length.");
     873        printError("Please specify a CIDR mask length.");
     874        return;
    885875      }
    886876      my $sql;
     
    901891        if ($webvar{alloctype} =~ /^[cdsmw]p$/) {
    902892          if (($webvar{city} !~ /^(Sudbury|North Bay)$/) && ($webvar{alloctype} eq 'dp')) {
    903             printAndExit("You must chose Sudbury or North Bay for DSL pools."); }
     893            printError("You must chose Sudbury or North Bay for DSL pools.");
     894            return;
     895          }
    904896          $city = $webvar{city};
    905897          $failmsg = "No suitable free block found.<br>\nYou will have to route another".
     
    924916      my @data = $sth->fetchrow_array();
    925917      if ($data[0] eq "") {
    926         printAndExit($failmsg);
     918        printError($failmsg);
     919        return;
    927920      }
    928921      $cidr = new NetAddr::IP $data[0];
     
    973966  print $html;
    974967
    975   printFooter;
    976968} # end confirmAssign
    977969
     
    981973  # Some things are done more than once.
    982974  printHeader('');
    983   validateInput();
     975  return if !validateInput();
    984976
    985977  # $code is "success" vs "failure", $msg contains OK for a
     
    990982        $webvar{circid});
    991983
    992   if ($code) {
    993     syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
    994         "'$webvar{alloctype}' by $authuser failed: '$msg'";
    995     printAndExit("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
    996         " failed: $msg\n");
    997   } else {
     984  if ($code eq 'OK') {
    998985    if ($webvar{alloctype} =~ /^.i$/) {
    999986      print qq(<div class="center"><div class="heading">The IP $msg has been allocated to customer $webvar{custid}</div></div>);
    1000987      # Notify tech@example.com
    1001988      mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation",
    1002         "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}");
     989        "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
     990        "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
    1003991    } else {
    1004992      print qq(<div class="center"><div class="heading">The block $webvar{fullcidr} was ).
     
    1008996    syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
    1009997        "'$webvar{alloctype}'";
    1010   }
    1011 
    1012   printFooter();
     998  } else {
     999    syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
     1000        "'$webvar{alloctype}' by $authuser failed: '$msg'";
     1001    printError("Allocation of $webvar{fullcidr} as $disp_alloctypes{$webvar{alloctype}}".
     1002        " failed: $msg\n");
     1003  }
     1004
    10131005} # end insertAssign()
    10141006
     
    10191011sub validateInput {
    10201012  if ($webvar{city} eq '-') {
    1021     printAndExit("Please choose a city.");
     1013    printError("Please choose a city.");
     1014    return;
    10221015  }
    10231016  chomp $webvar{alloctype};
     
    10251018  if ($webvar{alloctype} =~ /^(ci|di|cn|mi|wi)$/) {
    10261019    if (!$webvar{custid}) {
    1027       printAndExit("Please enter a customer ID.");
     1020      printError("Please enter a customer ID.");
     1021      return;
    10281022    }
    10291023    if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF|TEMP)(?:-\d\d?)?$/) {
    1030       printAndExit("Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for static IPs for staff.");
     1024      printError("Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for static IPs for staff.");
     1025      return;
    10311026    }
    10321027    print "<!-- [ In validateInput().  Insert customer ID cross-check here. ] -->\n";
    1033   } elsif ($webvar{alloctype} =~ /^([cdsmw]p|si|dn|dy|dc|ee|rr|ii)$/){
     1028  } elsif ($webvar{alloctype} =~ /^([cdsmw]p|si|dn|dy|dc|ee|rr|in)$/){
    10341029    # All non-customer allocations MUST be entered with "our" customer ID.
    10351030    # I have Defined this as 6750400 for consistency.
    10361031    $webvar{custid} = "6750400";
    1037     if ($webvar{alloctype} eq 'rr') {
    1038       my $flag;
    1039       foreach (@poplist) {
    1040         if (/^$webvar{city}$/) {
    1041           $flag = 'y'; last;
    1042         }
    1043       }
    1044       if (!$flag) {
    1045         printAndExit("Please choose a valid POP location for a routed netblock.  Valid ".
    1046                 "POP locations are currently:<br>\n".join (" - ", @poplist));
    1047       }
    1048     }
    10491032  } else {
    1050 print "$webvar{alloctype}";
    10511033    # Danger! Danger!  alloctype should ALWAYS be set by a dropdown.  Anyone
    10521034    # managing to call things in such a way as to cause this deserves a cryptic error.
    1053     printAndExit("Invalid alloctype");
    1054   }
    1055   return 0;
     1035    printError("Invalid alloctype");
     1036    return;
     1037  }
     1038
     1039  # Check POP location
     1040  my $flag;
     1041  if ($webvar{alloctype} eq 'rr') {
     1042    $flag = 'for a routed netblock';
     1043    foreach (@poplist) {
     1044      if (/^$webvar{city}$/) {
     1045        $flag = 'n';
     1046        last;
     1047      }
     1048    }
     1049  } else {
     1050    $flag = 'n';
     1051    if ($webvar{pop} =~ /^-$/) {
     1052      $flag = 'to route the block from/through';
     1053    }
     1054  }
     1055  if ($flag ne 'n') {
     1056    printError("Please choose a valid POP location $flag.  Valid ".
     1057        "POP locations are currently:<br>\n".join (" - ", @poplist));
     1058    return;
     1059  }
     1060
     1061  return 'OK';
    10561062} # end validateInput
    10571063
     
    11281134  print $html;
    11291135
    1130   printFooter();
    11311136} # edit()
    11321137
     
    11641169    eval { $ip_dbh->rollback; };
    11651170    syslog "err", "$authuser could not update block/IP '$webvar{block}': '$@'";
    1166     printAndExit("Could not update block/IP $webvar{block}: $@");
     1171    printError("Could not update block/IP $webvar{block}: $@");
     1172    return;
    11671173  }
    11681174
     
    11701176  syslog "notice", "$authuser updated $webvar{block}";
    11711177  open (HTML, "../updated.html")
    1172         or croak "Could not open updated.html :$!";
     1178        or croak "Could not open updated.html :$!";
    11731179  my $html = join('', <HTML>);
    11741180
     
    11881194  print $html;
    11891195
    1190   printFooter;
    11911196} # update()
    11921197
     
    12031208  # Serves'em right for getting here...
    12041209  if (!defined($webvar{block})) {
    1205     printAndExit("Error 332");
     1210    printError("Error 332");
     1211    return;
    12061212  }
    12071213
     
    12771283
    12781284  print $html;
    1279   printFooter;
    12801285} # end edit()
    12811286
     
    12961301    if ($webvar{alloctype} =~ /^.i$/) {
    12971302      syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
    1298       printAndExit("Could not deallocate static IP $webvar{block}: $msg");
     1303      printError("Could not deallocate static IP $webvar{block}: $msg");
    12991304    } else {
    13001305      syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
    1301       printAndExit("Could not deallocate netblock $webvar{block}: $msg");
    1302     }
    1303   }
    1304 
    1305   printFooter;
     1306      printError("Could not deallocate netblock $webvar{block}: $msg");
     1307    }
     1308  }
     1309
    13061310} # finalDelete
    13071311
  • trunk/index.shtml

    r4 r111  
    11<!--#include file="header.inc"-->
    22<!--#include virtual="/ip/cgi-bin/main.cgi?action=index" -->
    3 <!--#include file="footer.inc"-->
Note: See TracChangeset for help on using the changeset viewer.