Changeset 744 for trunk


Ignore:
Timestamp:
08/29/16 16:16:13 (8 years ago)
Author:
Kris Deugau
Message:

/trunk

Finally commit extension of log records to tuck "child" entries (ie,
new record in new zone, or mergerec's --detail argument) entries in
as subrecords of a parent, along with a bit of UI chrome to hide them.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r741 r744  
    146146                domain  => 'domain_id',
    147147                revzone => 'rdns_id',
    148                 record  => 'record_id'
     148                record  => 'record_id',
    149149        );
    150150my %par_col = (
     
    456456#  group_id, log entry
    457457# and optionally one or more of:
    458 #  domain_id, rdns_id
     458#  domain_id, rdns_id, logparent
    459459# The %userdata hash provides the user ID, username, and fullname
     460# Returns the log entry ID, mainly for use in bulk operations to allow a "parent" log entry
     461# and a set of child entries (eg, domain add and the individual default-record-copy entries)
    460462sub _log {
    461463  my $self = shift;
     
    466468  $args{rdns_id} = 0 if !$args{rdns_id};
    467469  $args{domain_id} = 0 if !$args{domain_id};
     470  $args{logparent} = 0 if !$args{logparent};
    468471
    469472##fixme:  farm out the actual logging to different subs for file, syslog, internal, etc based on config
    470473#  if ($self->{log_channel} eq 'sql') {
    471   $dbh->do("INSERT INTO log (domain_id,rdns_id,group_id,entry,user_id,email,name) VALUES (?,?,?,?,?,?,?)",
     474  $dbh->do("INSERT INTO log (domain_id,rdns_id,group_id,logparent,entry,user_id,email,name) ".
     475        "VALUES (?,?,?,?,?,?,?,?)",
    472476        undef,
    473         ($args{domain_id}, $args{rdns_id}, $args{group_id}, $args{entry},
     477        ($args{domain_id}, $args{rdns_id}, $args{group_id}, $args{logparent}, $args{entry},
    474478                $self->{loguserid}, $self->{logusername}, $self->{logfullname}) );
     479
     480  my ($log_id) = $dbh->selectrow_array("SELECT currval('log_log_id_seq')");
     481  return $log_id;
     482
    475483#  } elsif ($self->{log_channel} eq 'file') {
    476484#  } elsif ($self->{log_channel} eq 'syslog') {
     
    23742382        undef, ($domain, $defloc));
    23752383
    2376     $self->_log(domain_id => $dom_id, group_id => $group,
     2384    my $logparent = $self->_log(domain_id => $dom_id, group_id => $group,
    23772385        entry => "Added ".($state ? 'active' : 'inactive')." domain $domain");
    23782386
     
    23902398        my @tmp1 = split /:/, $host;
    23912399        my @tmp2 = split /:/, $val;
    2392         $self->_log(domain_id => $dom_id, group_id => $group,
     2400        $self->_log(domain_id => $dom_id, group_id => $group, logparent => $logparent,
    23932401                entry => "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
    23942402                "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl");
     
    23972405        $logentry .= " [distance $dist]" if $typemap{$type} eq 'MX';
    23982406        $logentry .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$type} eq 'SRV';
    2399         $self->_log(domain_id => $dom_id, group_id => $group,
     2407        $self->_log(domain_id => $dom_id, group_id => $group, logparent => $logparent,
    24002408                entry => $logentry." $val', TTL $ttl");
    24012409      }
     
    48674875    $sql = "SELECT count(*) FROM log l ";
    48684876  } else {
    4869     $sql = "SELECT l.user_id AS userid, l.name AS userfname, d.domain, l.domain_id, r.revnet AS revzone, ".
     4877    $sql = "SELECT l.log_id AS logparent, l.user_id AS userid, l.name AS userfname, d.domain, l.domain_id, ".
     4878        "r.revnet AS revzone, ".
    48704879        "l.rdns_id, l.entry AS logentry, date_trunc('second',l.stamp) AS logtime ".
    48714880        "FROM log l ".
     
    48844893  }
    48854894
     4895  # trim log "subentries" - we'll figure out where to stash these later
     4896  $sql .= " AND logparent = 0";
     4897
    48864898  # add the entry filter, if any
    48874899  $sql .= ($args{filter} ? " AND entry ~* ?" : '');
     
    49034915    $sql .= " ORDER BY $args{sortby} $args{sortorder}, log_id $args{sortorder}".
    49044916        ($args{offset} eq 'all' ? '' : " LIMIT $self->{perpage} OFFSET ".$args{offset}*$self->{perpage});
    4905     my $loglist = $dbh->selectall_arrayref($sql, { Slice => {} }, ($idarg, @filterargs) );
    4906     $errstr = $dbh->errstr if !$loglist;
    4907     return $loglist;
     4917    my @loglist;
     4918    my $sth = $dbh->prepare($sql);
     4919    my $logchild = $dbh->prepare("SELECT entry FROM log WHERE logparent = ? ORDER BY log_id");
     4920    $sth->execute($idarg, @filterargs);
     4921    while (my $row = $sth->fetchrow_hashref) {
     4922      $logchild->execute($row->{logparent});
     4923      my $childlist = $logchild->fetchall_arrayref({});
     4924      $row->{childentries} = $childlist;
     4925      push @loglist, $row;
     4926    }
     4927    return \@loglist;
    49084928  }
    49094929
     
    55105530  eval {
    55115531
     5532    my $logparent;
     5533
    55125534    if ($rev eq 'n') {
    55135535##fixme:  serial
     
    55175539      ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')");
    55185540      $domain_id = $zone_id;
    5519       $self->_log(group_id => $group, domain_id => $domain_id,
     5541      $logparent = $self->_log(group_id => $group, domain_id => $domain_id,
    55205542                entry => "[Added ".($args{status} ? 'active' : 'inactive')." domain $zone via AXFR]");
    55215543    } else {
     
    55265548      ($zone_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
    55275549      $rdns_id = $zone_id;
    5528       $self->_log(group_id => $group, rdns_id => $rdns_id,
     5550      $logparent = $self->_log(group_id => $group, rdns_id => $rdns_id,
    55295551                entry => "[Added ".($args{status} ? 'active' : 'inactive')." reverse zone $cidr via AXFR]");
    55305552    }
     
    57785800        $logentry .= " ".($rev eq 'y' ? $host : $val)."', TTL $ttl";
    57795801      }
    5780       $self->_log(group_id => $group, domain_id => $domain_id, rdns_id => $rdns_id, entry => $logentry);
     5802      $self->_log(group_id => $group, domain_id => $domain_id, rdns_id => $rdns_id,
     5803        logparent => $logparent, entry => $logentry);
    57815804
    57825805    } # while axfr_next
  • trunk/mergerecs

    r662 r744  
    3636sub usage {
    3737  die qq(usage:  mergerecs zone [domain] [--detail]
    38     zone  The zone to walk for PTR records to try to merge.
    39   domain  Optionally restrict record merges to a specified domain as well.
     38    zone  The primary zone to walk for records to try to merge.  May be either
     39          a reverse zone or a domain.
     40  domain  Optionally restrict record merges in a reverse zone to a specific
     41          domain.
    4042 --detail Optional argument to add one log entry for each A+PTR pair merged
    4143          instead of a single generic entry.
     
    8284  }
    8385  die "$pzone is not a valid reverse zone specification\n" if !$npzone;
    84   $zid = $dnsdb->revID($npzone);
     86  $zid = $dnsdb->revID($npzone, '');
    8587} else {
    8688  $rev = 'n';
    87   $zid = $dnsdb->domainID($pzone);
    88 }
    89 die "$pzone is not a zone in the database\n" if !$zid;
     89  $zid = $dnsdb->domainID($pzone, '');
     90}
     91die "$pzone is not a zone in the database (".$dnsdb->errstr.")\n" if !$zid;
    9092
    9193# check the second arg.
    92 my $fzid = $dnsdb->domainID($matchdom);
     94my $fzid = $dnsdb->domainID($matchdom, '');
    9395die "$matchdom is not a domain in the database\n" if $matchdom && !$fzid;
    9496
     
    116118    $reclist->execute($zid);
    117119    my $nrecs = 0;
     120    my @cloglist;
    118121    while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) {
    119122      my $etype = 12;
     
    134137        $delsth->execute($erid);
    135138        if ($logdetail) {
    136           $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
     139          my $lid = $dnsdb->_log(group_id => $group, domain_id => $zid, rdns_id => $erdns, entry => $logentry);
     140          push @cloglist, $lid;
    137141          print "$logentry\n";
    138142        }
     
    140144      }
    141145    } # while
    142     if (!$logdetail) {
    143       $dnsdb->_log(group_id => $group, domain_id => $zid,
     146    my $lpid = $dnsdb->_log(group_id => $group, domain_id => $zid,
    144147        entry => "Merged $nrecs A and AAAA records in $pzone with matching PTRs");
     148    # since unlike in most other operations, we only "know" the parent log entry *after*
     149    # we're done entering all the child entries, we have to update the children with the parent ID
     150    my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?");
     151    for my $lcid (@cloglist) {
     152      $assoc->execute($lpid, $lcid);
    145153    }
    146154    print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n";
     
    157165    $reclist->execute($zid);
    158166    my $nrecs = 0;
     167    my @cloglist;
    159168    while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) {
    160169      if ($matchdom) {
     
    178187        $delsth->execute($erid);
    179188        if ($logdetail) {
    180           $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
    181           print "$logentry\n";
     189          my $lid = $dnsdb->_log(group_id => $group, domain_id => $edid, rdns_id => $zid, entry => $logentry);
     190          push @cloglist, $lid;
     191          print "$lid: $logentry\n";
    182192        }
    183193        $nrecs++;
     
    185195    } # while
    186196    my $entry = "Merged $nrecs PTR records in $pzone with matching A or AAAA records".($fzid ? " in $matchdom" : '');
    187     if (!$logdetail) {
    188       if ($fzid) {
    189         $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry);
    190       } else {
    191         $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry);
    192       }
     197    my $lpid;
     198    if ($fzid) {
     199      $lpid = $dnsdb->_log(group_id => $group, domain_id => $fzid, rdns_id => $zid, entry => $entry);
     200    } else {
     201      $lpid = $dnsdb->_log(group_id => $group, rdns_id => $zid, entry => $entry);
     202    }
     203    # since unlike in most other operations, we only "know" the parent log entry *after*
     204    # we're done entering all the child entries, we have to update the children with the parent ID
     205    my $assoc = $dbh->prepare("UPDATE log SET logparent = ? WHERE log_id = ?");
     206    for my $lcid (@cloglist) {
     207      $assoc->execute($lpid, $lcid);
    193208    }
    194209    print "$entry\n";
    195   } # else
     210  }
     211
    196212  $dbh->commit;
    197213};
  • trunk/templates/dns.css

    r731 r744  
    293293        font-size: 1.2em;
    294294}
     295
     296/* Pure CSS "click to show" widget, adapted from the group tree CSS */
     297.collapsible li > input + * {
     298        display: none;
     299}
     300/* when the input is checked, show the content div */
     301.collapsible li > input:checked + * {
     302        display: block;
     303}
     304/* hide the checkbox */
     305.nocheckbox li > input {
     306        display: none;
     307        margin: 0em;
     308        padding: 0px;
     309}
     310/* mostly just making the input label clickable */
     311.collapsible label {
     312        cursor: pointer;
     313        display: inline;
     314        margin: 0em;
     315        padding: 0px;
     316        padding-left: 10px;
     317}
     318/* be nice if we could make this work without the HTML list structure... */
     319.notalist {
     320        list-style: none;
     321        margin: 0;
     322        padding: 1px;
     323}
     324
  • trunk/templates/log.tmpl

    r737 r744  
    5353 NAME=sortby>&amp;order=<TMPL_VAR NAME=order>&amp;id=<TMPL_VAR
    5454 NAME=rdns_id>&amp;ltype=rdns"><TMPL_VAR NAME=revzone></a></td>
    55         <td><TMPL_VAR NAME=logentry></td>
     55<TMPL_IF childentries>
     56        <td>
     57  <ul class="collapsible nocheckbox notalist">
     58    <li class="notalist">
     59      <label for="childlist<TMPL_VAR NAME=logparent>"><TMPL_VAR NAME=logentry>&nbsp;(<img src="<TMPL_VAR
     60 NAME=webpath>/images/tree_open.png" />Click for details)</label>
     61      <input type="checkbox" id="childlist<TMPL_VAR NAME=logparent>" />
     62      <ul class="notalist">
     63        <li class="notalist"><TMPL_LOOP NAME=childentries>
     64          <TMPL_VAR NAME=entry><TMPL_UNLESS __last__><br /></TMPL_UNLESS></TMPL_LOOP>
     65        </li>
     66      </ul>
     67    </li>
     68  </ul>
     69<TMPL_ELSE>
     70        <td><TMPL_VAR NAME=logentry>
     71</TMPL_IF>
     72</td>
    5673        <td><TMPL_VAR NAME=logtime></td>
    5774    </tr>
Note: See TracChangeset for help on using the changeset viewer.