Changeset 193


Ignore:
Timestamp:
12/09/11 17:56:27 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Hack _log() to dig up user data when (not if) it's missing. Better solution needed.
Clean up debugging statements in addDomain()
Add some ##fixme's to dns.cgi
Log distance, port, weight as needed for new MX, SRV records

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r192 r193  
    488488# Internal sub
    489489# 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
    490492sub _log {
    491493  my $dbh = shift;
    492494  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;
    493507
    494508##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
     
    546560  local $dbh->{RaiseError} = 1;
    547561
    548 my $stage = 'insert';
    549562  # Wrap all the SQL in a transaction
    550563  eval {
    551564    # insert the domain...
    552565    $dbh->do("INSERT INTO domains (domain,group_id,status) VALUES (?,?,?)", undef, ($domain, $group, $state));
    553 $stage = 'domid';
    554566
    555567    # get the ID...
    556568    ($dom_id) = $dbh->selectrow_array("SELECT domain_id FROM domains WHERE domain=?", undef, ($domain));
    557569
    558 $stage = 'loginsert';
    559570    _log($dbh, $dom_id, $userinfo{id}, $group, $userinfo{name}, $userinfo{fullname},
    560571        "Added ".($state ? 'active' : 'inactive')." domain $domain");
    561572
    562 $stage = 'getdefrec';
    563573    # ... and now we construct the standard records from the default set.  NB:  group should be variable.
    564574    my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?");
     
    592602    my $msg = $@;
    593603    eval { $dbh->rollback; };
    594     return ('FAIL',"$msg : $stage");
     604    return ('FAIL',$msg);
    595605  } else {
    596606    return ('OK',$dom_id);
  • trunk/dns.cgi

    r192 r193  
    347347
    348348  if ($code eq 'OK') {
    349     logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");
     349#    logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");
    350350    changepage(page => "reclist", id => $msg);
    351351  } else {
     
    519519    if ($code eq 'OK') {
    520520      if ($webvar{defrec} eq 'y') {
    521         my $restr = "Added default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}";
     521        my $restr = "Added default record '$webvar{name} $typemap{$webvar{type}}";
     522        $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX';
     523        $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV';
     524        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    522525        logaction(0, $session->param("username"), $webvar{parentid}, $restr);
    523526        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
    524527      } else {
    525         my $restr = "Added record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}";
     528        my $restr = "Added record '$webvar{name} $typemap{$webvar{type}}".
     529        $restr .= " [distance $dist]" if $typemap{$webvar{type}} eq 'MX';
     530        $restr .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$webvar{type}} eq 'SRV';
     531        $restr .= " $webvar{address}', TTL $webvar{ttl}";
    526532        logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'), $restr);
    527533        changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, resultmsg => $restr);
     
    582588
    583589    if ($code eq 'OK') {
     590##fixme: retrieve old record info for full logging of change
    584591      if ($webvar{defrec} eq 'y') {
    585592        my $restr = "Updated default record from '$oldrec->{host} $typemap{$oldrec->{type}} $oldrec->{val}', TTL $oldrec->{ttl}\n".
Note: See TracChangeset for help on using the changeset viewer.