Changeset 546 for trunk


Ignore:
Timestamp:
11/07/12 17:45:28 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Tweak custid check in both main.cgi and admin.cgi; move the
general hardcoded checks into CustIDCK.pm.

Location:
trunk/cgi-bin
Files:
3 edited

Legend:

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

    r517 r546  
    3434  my $custid = shift;
    3535
    36   return 1 if $custid =~ /^STAFF$/;
    37   return 1 if $custid =~ /^5554242$/;  # just in case some later change might block this
    38   return 1 if $custid =~ /^\d{7}$/;
    39   return 1 if $custid =~ /^\d{10}$/;
     36  # hardcoded "OK" custids.
     37  return 1 if $custid =~ /^STAFF(?:-\d\d?)?$/;
     38  return 1 if $custid =~ /^5554242(?:-\d\d?)?$/;  # just in case some later change might block this
     39  return 1 if $custid =~ /^\d{7}(?:-\d\d?)?$/;
     40  return 1 if $custid =~ /^\d{10}(?:-\d\d?)?$/;
     41
     42  # Force uppercase for now...
     43  $custid =~ tr/a-z/A-Z/;
    4044
    4145# some example code for a database check
     
    6670
    6771  # We should have a valid DB connection by now.
    68   my $sth = $dbh->prepare("SELECT custid FROM custid WHERE custid = '$custid'");
    69   $sth->execute;
     72 
     73  my $hr = $dbh->selectrow_hashref("SELECT custid FROM custid WHERE custid = ?", undef, ($custid) );
     74  my $status = 0;
    7075  if ($dbh->err) {
    7176    $CustIDCK::Error = 1;
    7277    $CustIDCK::ErrMsg = $dbh->errstr();
    73     $sth->finish;
    74     $dbh->disconnect;
    75     return 0;
     78  } else {
     79    $status = 1 if ( $hr->{custid} );
    7680  }
    77   my $hr = $sth->fetchrow_hashref();
    78   my $status = 0;
    79   $status = 1 if ( $hr->{custid} );
    80   $sth->finish;
    8181  $dbh->disconnect;
    8282  return $status;
  • trunk/cgi-bin/admin.cgi

    r545 r546  
    123123  my $custid = $def_custids{$webvar{alloctype}};
    124124  if ($custid eq '') {
    125     if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
    126       # Force uppercase for now...
    127       $webvar{custid} =~ tr/a-z/A-Z/;
    128       # Crosscheck with billing.
    129       my $status = CustIDCK->custid_exist($webvar{custid});
    130       if ($CustIDCK::Error) {
    131         $page->param(errmsg => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
    132         goto ERRJUMP;
    133       }
    134       if (!$status) {
    135         $page->param(errmsg => "Customer ID not valid.  Make sure the Customer ID ".
    136           "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
    137           "non-customer assignments.");
    138         goto ERRJUMP;
    139       }
     125    # Crosscheck with billing.
     126    my $status = CustIDCK->custid_exist($webvar{custid});
     127    if ($CustIDCK::Error) {
     128      $page->param(errmsg => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
     129      goto ERRJUMP;
     130    }
     131    if (!$status) {
     132      $page->param(errmsg => "Customer ID not valid.  Make sure the Customer ID ".
     133        "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
     134        "non-customer assignments.");
     135      goto ERRJUMP;
    140136    }
    141137    # Type that doesn't have a default custid
  • trunk/cgi-bin/main.cgi

    r541 r546  
    572572      return;
    573573    }
    574     if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
    575       # Force uppercase for now...
    576       $webvar{custid} =~ tr/a-z/A-Z/;
    577       # Crosscheck with billing.
    578       my $status = CustIDCK->custid_exist($webvar{custid});
    579       if ($CustIDCK::Error) {
    580         $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
    581         return;
    582       }
    583       if (!$status) {
    584         $page->param(err => "Customer ID not valid.  Make sure the Customer ID ".
    585           "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
    586           "non-customer assignments.");
    587         return;
    588       }
     574    # Crosscheck with billing.
     575    my $status = CustIDCK->custid_exist($webvar{custid});
     576    if ($CustIDCK::Error) {
     577      $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
     578      return;
     579    }
     580    if (!$status) {
     581      $page->param(err => "Customer ID not valid.  Make sure the Customer ID ".
     582        "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
     583        "non-customer assignments.");
     584      return;
    589585    }
    590586#    print "<!-- [ In validateInput().  Insert customer ID cross-check here. ] -->\n";
Note: See TracChangeset for help on using the changeset viewer.