Changeset 193 for trunk/DNSDB.pm
- Timestamp:
- 12/09/11 17:56:27 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r192 r193 488 488 # Internal sub 489 489 # Takes a database handle, domain_id, user_id, group_id, email, name and log entry 490 ##fixme: convert to trailing hash for user info 491 # User info must contain a (user ID OR username)+fullname 490 492 sub _log { 491 493 my $dbh = shift; 492 494 my ($domain_id,$user_id,$group_id,$username,$name,$entry) = @_; 495 496 ##fixme: need better way(s?) to snag userinfo for log entries. don't want to have 497 # to pass around yet *another* constant (already passing $dbh, shouldn't need to) 498 if (!$user_id) { 499 $user_id, $fullname) = $dbh->fetchrow_array("SELECT user_id, firstname || ' ' || lastname FROM users". 500 " WHERE username=?", undef, ($username)); 501 } elsif (!$username) { 502 $username, $fullname) = $dbh->fetchrow_array("SELECT username, firstname || ' ' || lastname FROM users". 503 " WHERE user_id=?", undef, ($user_id)); 504 } 505 506 $name = $fullname if !$name; 493 507 494 508 ##fixme: farm out the actual logging to different subs for file, syslog, internal, etc based on config … … 546 560 local $dbh->{RaiseError} = 1; 547 561 548 my $stage = 'insert';549 562 # Wrap all the SQL in a transaction 550 563 eval { 551 564 # insert the domain... 552 565 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($domain, $group, $state)); 553 $stage = 'domid';554 566 555 567 # get the ID... 556 568 ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain)); 557 569 558 $stage = 'loginsert';559 570 _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname}, 560 571 "Added ".($state ? 'active' : 'inactive')." domain $domain"); 561 572 562 $stage = 'getdefrec';563 573 # ... and now we construct the standard records from the default set. NB: group should be variable. 564 574 my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?"); … … 592 602 my $msg = $@; 593 603 eval { $dbh->rollback; }; 594 return ('FAIL', "$msg : $stage");604 return ('FAIL',$msg); 595 605 } else { 596 606 return ('OK',$dom_id);
Note:
See TracChangeset
for help on using the changeset viewer.