- Timestamp:
- 08/29/16 16:16:13 (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r741 r744 146 146 domain => 'domain_id', 147 147 revzone => 'rdns_id', 148 record => 'record_id' 148 record => 'record_id', 149 149 ); 150 150 my %par_col = ( … … 456 456 # group_id, log entry 457 457 # and optionally one or more of: 458 # domain_id, rdns_id 458 # domain_id, rdns_id, logparent 459 459 # 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) 460 462 sub _log { 461 463 my $self = shift; … … 466 468 $args{rdns_id} = 0 if !$args{rdns_id}; 467 469 $args{domain_id} = 0 if !$args{domain_id}; 470 $args{logparent} = 0 if !$args{logparent}; 468 471 469 472 ##fixme: farm out the actual logging to different subs for file, syslog, internal, etc based on config 470 473 # 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 (?,?,?,?,?,?,?,?)", 472 476 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}, 474 478 $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 475 483 # } elsif ($self->{log_channel} eq 'file') { 476 484 # } elsif ($self->{log_channel} eq 'syslog') { … … 2374 2382 undef, ($domain, $defloc)); 2375 2383 2376 $self->_log(domain_id => $dom_id, group_id => $group,2384 my $logparent = $self->_log(domain_id => $dom_id, group_id => $group, 2377 2385 entry => "Added ".($state ? 'active' : 'inactive')." domain $domain"); 2378 2386 … … 2390 2398 my @tmp1 = split /:/, $host; 2391 2399 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, 2393 2401 entry => "[new $domain] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ". 2394 2402 "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"); … … 2397 2405 $logentry .= " [distance $dist]" if $typemap{$type} eq 'MX'; 2398 2406 $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, 2400 2408 entry => $logentry." $val', TTL $ttl"); 2401 2409 } … … 4867 4875 $sql = "SELECT count(*) FROM log l "; 4868 4876 } 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, ". 4870 4879 "l.rdns_id, l.entry AS logentry, date_trunc('second',l.stamp) AS logtime ". 4871 4880 "FROM log l ". … … 4884 4893 } 4885 4894 4895 # trim log "subentries" - we'll figure out where to stash these later 4896 $sql .= " AND logparent = 0"; 4897 4886 4898 # add the entry filter, if any 4887 4899 $sql .= ($args{filter} ? " AND entry ~* ?" : ''); … … 4903 4915 $sql .= " ORDER BY $args{sortby} $args{sortorder}, log_id $args{sortorder}". 4904 4916 ($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; 4908 4928 } 4909 4929 … … 5510 5530 eval { 5511 5531 5532 my $logparent; 5533 5512 5534 if ($rev eq 'n') { 5513 5535 ##fixme: serial … … 5517 5539 ($zone_id) = $dbh->selectrow_array("SELECT currval('domains_domain_id_seq')"); 5518 5540 $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, 5520 5542 entry => "[Added ".($args{status} ? 'active' : 'inactive')." domain $zone via AXFR]"); 5521 5543 } else { … … 5526 5548 ($zone_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')"); 5527 5549 $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, 5529 5551 entry => "[Added ".($args{status} ? 'active' : 'inactive')." reverse zone $cidr via AXFR]"); 5530 5552 } … … 5778 5800 $logentry .= " ".($rev eq 'y' ? $host : $val)."', TTL $ttl"; 5779 5801 } 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); 5781 5804 5782 5805 } # while axfr_next -
trunk/mergerecs
r662 r744 36 36 sub usage { 37 37 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. 40 42 --detail Optional argument to add one log entry for each A+PTR pair merged 41 43 instead of a single generic entry. … … 82 84 } 83 85 die "$pzone is not a valid reverse zone specification\n" if !$npzone; 84 $zid = $dnsdb->revID($npzone );86 $zid = $dnsdb->revID($npzone, ''); 85 87 } else { 86 88 $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 } 91 die "$pzone is not a zone in the database (".$dnsdb->errstr.")\n" if !$zid; 90 92 91 93 # check the second arg. 92 my $fzid = $dnsdb->domainID($matchdom );94 my $fzid = $dnsdb->domainID($matchdom, ''); 93 95 die "$matchdom is not a domain in the database\n" if $matchdom && !$fzid; 94 96 … … 116 118 $reclist->execute($zid); 117 119 my $nrecs = 0; 120 my @cloglist; 118 121 while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) { 119 122 my $etype = 12; … … 134 137 $delsth->execute($erid); 135 138 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; 137 141 print "$logentry\n"; 138 142 } … … 140 144 } 141 145 } # while 142 if (!$logdetail) { 143 $dnsdb->_log(group_id => $group, domain_id => $zid, 146 my $lpid = $dnsdb->_log(group_id => $group, domain_id => $zid, 144 147 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); 145 153 } 146 154 print "Merged $nrecs A and AAAA records in $pzone with matching PTRs\n"; … … 157 165 $reclist->execute($zid); 158 166 my $nrecs = 0; 167 my @cloglist; 159 168 while (my ($host,$val,$type,$id,$ttl,$loc) = $reclist->fetchrow_array) { 160 169 if ($matchdom) { … … 178 187 $delsth->execute($erid); 179 188 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"; 182 192 } 183 193 $nrecs++; … … 185 195 } # while 186 196 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); 193 208 } 194 209 print "$entry\n"; 195 } # else 210 } 211 196 212 $dbh->commit; 197 213 }; -
trunk/templates/dns.css
r731 r744 293 293 font-size: 1.2em; 294 294 } 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 53 53 NAME=sortby>&order=<TMPL_VAR NAME=order>&id=<TMPL_VAR 54 54 NAME=rdns_id>&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> (<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> 56 73 <td><TMPL_VAR NAME=logtime></td> 57 74 </tr>
Note:
See TracChangeset
for help on using the changeset viewer.