Changeset 191 for trunk/DNSDB.pm


Ignore:
Timestamp:
12/09/11 16:10:56 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Minor fix in dns-rpc.cgi to load DB user/pass/etc with loadConfig

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r190 r191  
    487487# Log an action
    488488# Internal sub
    489 # Takes a database handle, domain_id, user_id, group_id, email, name and log entry
     489# Takes a database handle, domain_id, group_id, log entry, and user info hash
     490# User info must contain a user ID OR username+fullname
    490491sub _log {
    491492  my $dbh = shift;
    492493  my ($domain_id,$user_id,$group_id,$username,$name,$entry) = @_;
     494
     495##fixme:  need better way(s?) to snag userinfo for log entries
     496  if (!$user_id) {
     497    $user_id, $fullname) = $dbh->fetchrow_array("SELECT user_id, firstname || ' ' || lastname FROM users".
     498        " WHERE username=?", undef, ($username));
     499  } elsif (!$username) {
     500    $username, $fullname) = $dbh->fetchrow_array("SELECT username, firstname || ' ' || lastname FROM users".
     501        " WHERE user_id=?", undef, ($user_id));
     502  }
     503
     504  $name = $fullname if !$name;
    493505
    494506##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
     
    546558  local $dbh->{RaiseError} = 1;
    547559
    548 my $stage = 'insert';
    549560  # Wrap all the SQL in a transaction
    550561  eval {
    551562    # insert the domain...
    552563    $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($domain, $group, $state));
    553 $stage = 'domid';
    554564
    555565    # get the ID...
    556566    ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain));
    557567
    558 $stage = 'loginsert';
    559568    _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname},
    560569        "Added ".($state ? 'active' : 'inactive')." domain $domain");
    561570
    562 $stage = 'getdefrec';
    563571    # ... and now we construct the standard records from the default set.  NB:  group should be variable.
    564572    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?");
     
    592600    my $msg = $@;
    593601    eval { $dbh->rollback; };
    594     return ('FAIL',"$msg : $stage");
     602    return ('FAIL',$msg);
    595603  } else {
    596604    return ('OK',$dom_id);
Note: See TracChangeset for help on using the changeset viewer.