Changeset 62


Ignore:
Timestamp:
01/19/10 16:50:05 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint
dns.cgi:

Fix lurking rebuglet on removing search filter
Add logging on domain active/inactive
Make sure to propagate error messages on domain add/delete as required
Logging of domain add/delete should now be complete
Record add/delete/update logging should be complete (not completely tested)
Explicitly set $startwith, $filter, and $searchsubs in listdomains()

DNSDB.pm:

Remove debugging cruft in DNSDB
Return the parent ID for a record in getRecLine
Normalize some SQL formatting

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r61 r62  
    243243  my $domid = shift;
    244244
    245 return "FAIL", "whee!";
    246245  # Allow transactions, and raise an exception on errors so we can catch it later.
    247246  # Use local to make sure these get "reset" properly on exiting this block
     
    684683  my $id = shift;
    685684
    686   my $sql = "select record_id,host,type,val,distance,weight,port,ttl from ".
    687         (($def eq 'def' or $def eq 'y') ? 'default_' : '').
    688         "records where record_id=$id";
    689 print "MDEBUG: $sql<br>\n";
     685  my $sql = "SELECT record_id,host,type,val,distance,weight,port,ttl".
     686        (($def eq 'def' or $def eq 'y') ? ',group_id FROM default_' : ',domain_id FROM ').
     687        "records WHERE record_id=?";
    690688  my $sth = $dbh->prepare($sql);
    691   $sth->execute;
    692 
    693   my ($recid,$host,$rtype,$val,$distance,$weight,$port,$ttl) = $sth->fetchrow_array();
     689  $sth->execute($id);
     690
     691  my ($recid,$host,$rtype,$val,$distance,$weight,$port,$ttl,$parid) = $sth->fetchrow_array();
    694692
    695693  if ($sth->err) {
     
    706704  $ret{port}    = $port;
    707705  $ret{ttl}     = $ttl;
     706  $ret{parid}   = $parid;
    708707
    709708  return %ret;
     
    728727  my $order = shift || 'host';
    729728
    730   my $sql = "select record_id,host,type,val,distance,weight,port,ttl from";
     729  my $sql = "SELECT record_id,host,type,val,distance,weight,port,ttl FROM ";
    731730  if ($type eq 'def' or $type eq 'y') {
    732731    $sql .= " default_records where group_id=$id";
     
    861860  my $id = shift;
    862861
    863   my $sth = $dbh->prepare("delete from ".($defrec eq 'y' ? 'default_' : '')."records where record_id=?");
     862return "FAIL", "wakka wakka";
     863  my $sth = $dbh->prepare("DELETE FROM ".($defrec eq 'y' ? 'default_' : '')."records WHERE record_id=?");
    864864  $sth->execute($id);
    865865
  • trunk/dns.cgi

    r61 r62  
    6969# per-page startwith, filter, searchsubs
    7070$session->param($webvar{page}.'startwith', $webvar{startwith}) if $webvar{startwith};
    71 $session->param($webvar{page}.'filter', $webvar{filter}) if $webvar{filter};
     71$session->param($webvar{page}.'filter', $webvar{filter}) if defined($webvar{filter});
    7272$webvar{searchsubs} =~ s/^n ?// if $webvar{searchsubs};
    7373$session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if defined($webvar{searchsubs});
     
    166166# this currently only handles "domain on", "domain off"
    167167  if (defined($webvar{action})) {
    168     domStatus($dbh,$webvar{id},$webvar{action});
     168    my $stat = domStatus($dbh,$webvar{id},$webvar{action});
     169    logaction($webvar{id}, $session->param("username"), parentID($webvar{id}, 'dom', 'group'),
     170        "Changed ".domainName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive'));
    169171  }
    170172
    171173  $page->param(curpage => $webvar{page});
     174  if ($webvar{del_failed}) {
     175    $page->param(del_failed => 1);
     176    $page->param(errmsg => $webvar{errmsg});
     177  }
    172178
    173179  listdomains();
     
    177183  # hmm.  nothing to do here?
    178184  # - group list is filled by the same bit that fills the group list in the menu
     185  if ($webvar{add_failed}) {
     186    $page->param(add_failed => 1);
     187    $page->param(errmsg => $webvar{errmsg});
     188    $page->param(domain => $webvar{domain});
     189  }
    179190
    180191} elsif ($webvar{page} eq 'adddomain') {
     
    186197    changepage(page => "reclist", id => $msg);
    187198  } else {
     199    logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)");
    188200    changepage(page => "newdomain", add_failed => 1, domain => $webvar{domain}, errmsg => $msg);
    189201  }
     
    207219    if ($code ne 'OK') {
    208220# need to find failure mode
    209       $page->param(del_failed => 1);
    210       $page->param(errmsg => $msg);
    211       logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom");
    212       listdomains($curgroup);
    213 ##work
     221      logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)");
     222      changepage(page => "domlist", del_failed => 1, errmsg => $msg);
    214223    } else {
    215224      logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom");
     
    295304      if ($webvar{defrec} eq 'y') {
    296305        logaction(0, $session->param("username"), $webvar{parentid},
    297                 "Failed adding default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     306                "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
    298307      } else {
    299308        logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
    300                 "Failed adding record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl}");
     309                "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
    301310      }
    302311    }
     
    384393    $page->param(recval => $rec{val});
    385394  } elsif ($webvar{del} eq 'ok') {
    386 # get groupid of deleted record before we try to delete it
    387     my $pargrp = parentID($webvar{id}, 'rec', 'group', $webvar{defrec});
     395# get rec data before we try to delete it
     396    my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
    388397    my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
    389398    if ($code ne 'OK') {
    390399## need to find failure mode
    391       #logaction(
     400      if ($webvar{defrec} eq 'y') {
     401        logaction(0, $session->param("username"), $rec{parid},
     402                "Failed deleting default record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
     403      } else {
     404        logaction($rec{parid}, $session->param("username"), parentID($rec{parid}, 'dom', 'group'),
     405                "Failed deleting record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
     406      }
    392407      $page->param(del_failed => 1);
    393408      $page->param(errmsg => $msg);
    394409      showdomain($webvar{defrec}, $webvar{parentid});
    395410    } else {
    396 ##log
     411      if ($webvar{defrec} eq 'y') {
     412        logaction(0, $session->param("username"), $rec{parid},
     413                "Deleted default record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
     414      } else {
     415        logaction($rec{parid}, $session->param("username"), parentID($rec{parid}, 'dom', 'group'),
     416                "Deleted record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
     417      }
    397418      changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
    398419    }
     
    907928    $rec->{type} = $typemap{$rec->{type}};
    908929    $rec->{row} = $row % 2;
    909     $rec->{defrec} = $webvar{defrec};
     930    $rec->{defrec} = $def;
    910931    $rec->{sid} = $webvar{sid};
    911932    $rec->{id} = $id;
     
    10081029
    10091030sub listdomains {
     1031
     1032  $startwith = $session->param($webvar{page}.'startwith');
     1033  $filter = $session->param($webvar{page}.'filter');
     1034  $searchsubs = $session->param($webvar{page}.'searchsubs');
    10101035
    10111036##fixme:  $logingroup or $curgroup?
Note: See TracChangeset for help on using the changeset viewer.