Changeset 190
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r186 r190 487 487 # Log an action 488 488 # Internal sub 489 # Takes a database handle, <foo>, <bar>489 # Takes a database handle, domain_id, user_id, group_id, email, name and log entry 490 490 sub _log { 491 my $dbh = shift; 492 my ($domain_id,$user_id,$group_id,$username,$name,$entry) = @_; 493 494 ##fixme: farm out the actual logging to different subs for file, syslog, internal, etc based on config 495 $dbh->do("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) VALUES (?,?,?,?,?,?)", undef, 496 ($domain_id,$user_id,$group_id,$username,$name,$entry)); 497 # 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 498 # 1 2 3 4 5 6 7 491 499 } # end _log 492 500 … … 498 506 ## DNSDB::addDomain() 499 507 # Add a domain 500 # Takes a database handle, domain name, numeric group, and boolean(ish) state (active/inactive) 508 # Takes a database handle, domain name, numeric group, boolean(ish) state (active/inactive), 509 # and user info hash (for logging). 501 510 # Returns a status code and message 502 511 sub addDomain { … … 511 520 return ('FAIL',"Need domain status") if !defined($state); 512 521 522 my %userinfo = @_; # remaining bits. 523 # user ID, username, user full name 524 513 525 $state = 1 if $state =~ /^active$/; 514 526 $state = 1 if $state =~ /^on$/; … … 518 530 return ('FAIL',"Invalid domain status") if $state !~ /^\d+$/; 519 531 532 return ('FAIL', "Invalid characters in domain") if $domain !~ /^[a-zA-Z0-9_.-]+$/; 533 520 534 my $sth = $dbh->prepare("SELECT domain_id FROM domains WHERE domain=?"); 521 535 my $dom_id; … … 532 546 local $dbh->{RaiseError} = 1; 533 547 548 my $stage = 'insert'; 534 549 # Wrap all the SQL in a transaction 535 550 eval { 536 551 # insert the domain... 537 my $sth = $dbh->prepare("insert into domains (domain,group_id,status) values (?,?,?)");538 $sth->execute($domain,$group,$state);552 $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($domain, $group, $state)); 553 $stage = 'domid'; 539 554 540 555 # get the ID... 541 $sth = $dbh->prepare("select domain_id from domains where domain='$domain'"); 542 $sth->execute; 543 ($dom_id) = $sth->fetchrow_array(); 544 556 ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain)); 557 558 $stage = 'loginsert'; 559 _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname}, 560 "Added ".($state ? 'active' : 'inactive')." domain $domain"); 561 562 $stage = 'getdefrec'; 545 563 # ... and now we construct the standard records from the default set. NB: group should be variable. 546 $sth = $dbh->prepare("select host,type,val,distance,weight,port,ttl from default_records where group_id=$group");547 my $sth_in = $dbh->prepare(" insert intorecords (domain_id,host,type,val,distance,weight,port,ttl)".548 " values($dom_id,?,?,?,?,?,?,?)");549 $sth->execute ;564 my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?"); 565 my $sth_in = $dbh->prepare("INSERT INTO records (domain_id,host,type,val,distance,weight,port,ttl)". 566 " VALUES ($dom_id,?,?,?,?,?,?,?)"); 567 $sth->execute($group); 550 568 while (my ($host,$type,$val,$dist,$weight,$port,$ttl) = $sth->fetchrow_array()) { 551 569 $host =~ s/DOMAIN/$domain/g; 552 570 $val =~ s/DOMAIN/$domain/g; 553 571 $sth_in->execute($host,$type,$val,$dist,$weight,$port,$ttl); 572 if ($typemap{$type} eq 'SOA') { 573 my @tmp1 = split /:/, $host; 574 my @tmp2 = split /:/, $val; 575 _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname}, 576 "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ". 577 "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"); 578 } else { 579 my $logentry = "[new $domain] Added record '$host $typemap{$type}"; 580 $logentry .= " [distance $dist]" if $typemap{$type} eq 'MX'; 581 $logentry .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$type} eq 'SRV'; 582 _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname}, 583 $logentry." $val', TTL $ttl"); 584 } 554 585 } 555 586 … … 561 592 my $msg = $@; 562 593 eval { $dbh->rollback; }; 563 return ('FAIL', $msg);594 return ('FAIL',"$msg : $stage"); 564 595 } else { 565 596 return ('OK',$dom_id); -
trunk/dns.cgi
r188 r190 343 343 } 344 344 345 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0)); 345 my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0), 346 (name => $session->param("username"), id => $session->param("uid"))); 346 347 347 348 if ($code eq 'OK') { … … 352 353 $session->param('add_failed', 1); 353 354 ##fixme: domain a security risk for XSS? 355 ##fixme: keep active/inactive state, group selection 354 356 changepage(page => "newdomain", domain => $webvar{domain}, errmsg => $msg); 355 357 }
Note:
See TracChangeset
for help on using the changeset viewer.