Changeset 531 for trunk/cgi-bin/main.cgi


Ignore:
Timestamp:
10/29/12 18:09:30 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move most SQL for allocation update into IPDB.pm. See #34.

File:
1 edited

Legend:

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

    r530 r531  
    797797  }
    798798
    799   # Check to see if we can update restricted data
    800   my $privdata = '';
    801   if ($IPDBacl{$authuser} =~ /s/) {
    802     $privdata = ",privdata='$webvar{privdata}'";
    803   }
    804 
    805799  # Make sure incoming data is in correct format - custID among other things.
    806800  return if !validateInput;
    807801
    808   # SQL transaction wrapper
    809   eval {
    810     # Relatively simple SQL transaction here.
    811     my $sql;
    812     if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
    813       $sql = "UPDATE poolips SET custid='$webvar{custid}',".
    814         "city=?,description=?,notes=?,".
    815         "circuitid='$webvar{circid}',".
    816         "$privdata where ip='$webvar{block}'";
    817     } else {
    818       $sql = "UPDATE allocations SET custid='$webvar{custid}',".
    819         "city=?,description=?,notes=?,".
    820         "circuitid='$webvar{circid}'$privdata,".
    821         "type='$webvar{alloctype}',".
    822         "swip='".($webvar{swip} eq 'on' ? 'y' : 'n')."' ".
    823         "where cidr='$webvar{block}'";
    824     }
    825     # Log the details of the change.
    826     syslog "debug", $sql;
    827     $sth = $ip_dbh->prepare($sql);
    828     $sth->execute($webvar{city}, $webvar{desc}, $webvar{notes});
    829 ## node hack
    830     if ($webvar{node}) {
    831       # done with delete/insert so we don't have to worry about funkyness updating a node ref that isn't there
    832       $ip_dbh->do("DELETE FROM noderef WHERE block='$webvar{block}'");
    833       $sth = $ip_dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
    834       $sth->execute($webvar{block},$webvar{node});
    835     }
    836 ## end node hack
    837     $ip_dbh->commit;
    838   };
    839   if ($@) {
    840     my $msg = $@;
    841     eval { $ip_dbh->rollback; };
     802  my %updargs = (
     803        custid          => $webvar{custid},
     804        city            => $webvar{city},
     805        description     => $webvar{desc},
     806        notes           => $webvar{notes},
     807        circuitid       => $webvar{circid},
     808        block           => $webvar{block},
     809        type            => $webvar{alloctype},
     810        );
     811
     812  # Semioptional values
     813  $updargs{privdata} = $webvar{privdata} if $IPDBacl{$authuser} =~ /s/;
     814  $updargs{node} = $webvar{node} if $webvar{node};
     815
     816  my ($code,$msg) = updateBlock($ip_dbh, %updargs);
     817
     818  if ($code eq 'FAIL') {
    842819    syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
    843820    $page->param(err => "Could not update block/IP $webvar{block}: $msg");
     
    847824  # If we get here, the operation succeeded.
    848825  syslog "notice", "$authuser updated $webvar{block}";
     826##fixme:  log details of the change?  old way is in the .debug stream anyway.
    849827##fixme:  need to wedge something in to allow "update:field" notifications
    850828## hmm.  how to tell what changed?  O_o
Note: See TracChangeset for help on using the changeset viewer.