Changeset 270


Ignore:
Timestamp:
03/07/12 17:53:31 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Override any bare ZONE defrecs with the provided pattern while
adding a reverse zone.
Also patch up some UI glitches in error handling for revzone add
(match new domain handling more closely)
See #26

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r269 r270  
    13191319  my $zone = NetAddr::IP->new(shift);
    13201320  return ('FAIL',"Zone name must be a valid CIDR netblock") unless ($zone && $zone->addr !~ /^0/);
    1321   my $revpatt = shift;
     1321  my $revpatt = shift;  # construct a custom (A/AAAA+)? PTR template record
    13221322  my $group = shift;
    13231323  my $state = shift;
     
    13441344
    13451345  my $warnstr = '';
     1346  my $defttl = 3600;    # 1 hour should be reasonable.  And unless things have gone horribly
     1347                        # wrong, we should have a value to override this anyway.
    13461348
    13471349  # Wrap all the SQL in a transaction
     
    13751377      # While we're at it, we substitute $zone for ZONE in the value.
    13761378      if ($val eq 'ZONE') {
     1379        next if $revpatt;       # If we've got a pattern, we skip the default record version.
    13771380##fixme?  do we care if we have multiple whole-zone templates?
    13781381        $val = $zone->network;
     
    14191422                "[new $zone] Added SOA record [contact $tmp1[0]] [master $tmp1[1]] ".
    14201423                "[refresh $tmp2[0]] [retry $tmp2[1]] [expire $tmp2[2]] [minttl $tmp2[3]], TTL $ttl"));
     1424        $defttl = $tmp2[3];
    14211425      } else {
    14221426        my $logentry = "[new $zone] Added record '$host $typemap{$type}";
     
    14271431    }
    14281432
    1429 # Generate record based on provided pattern. 
    1430         my $addr;
    1431         if (_ipparent($dbh, 'n', 'y', \$tmpval, $rdns_id, \$addr)) {
    1432           $val = $addr->addr;
    1433         } else {
    1434           $warnstr .= "\nDefault record '$val $typemap{$type} $host' doesn't fit in $zone, skipping";
    1435           next;
    1436         }
     1433    # Generate record based on provided pattern. 
     1434    if ($revpatt) {
     1435      my $host;
     1436      my $type = ($zone->{isv6} ? 65284 : 65283);
     1437      my $val = $zone->network;
     1438
     1439      # Substitute $zone for ZONE in the hostname.
     1440      $host = _ZONE($zone, $revpatt);
     1441
     1442      my $domid = 0;
     1443      if (!($domid = _hostparent($dbh, $host))) {
     1444        $warnstr .= "\nDefault pattern added as PTR template instead of $typemap{$type};  domain not found for $host";
     1445        $type = 65282;
     1446        $domid = 0;     # just to be explicit.
     1447      }
     1448
     1449      $sth_in->execute($domid,$host,$type,$val,$defttl);
     1450    }
    14371451
    14381452    # If there are warnings (presumably about default records skipped for cause) log them
  • trunk/dns.cgi

    r269 r270  
    448448# getRecByName($dbh, (revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string'));
    449449
    450   if ($webvar{add_failed}) {
    451     $page->param(add_failed => 1);
    452     $page->param(errmsg => $webvar{errmsg});
     450  if ($session->param('add_failed')) {
     451    $session->clear('add_failed');
     452    $page->param(errmsg => $session->param('errmsg'));
     453    $session->clear('errmsg');
    453454    $page->param(revzone => $webvar{revzone});
    454455    $page->param(revpatt => $webvar{revpatt});
     
    475476  } else {
    476477    logaction(0, $session->param("username"), $webvar{group}, "Failed adding reverse zone $webvar{revzone} ($msg)");
    477     changepage(page => "newrevzone", revrec => 'y', add_failed => 1, revzone => $webvar{revzone},
    478         revpatt => $webvar{revpatt}, errmsg => $msg);
     478    $session->param('add_failed', 1);
     479    changepage(page => "newrevzone", revzone => $webvar{revzone}, revpatt => $webvar{revpatt}, errmsg => $msg);
    479480  }
    480481
  • trunk/templates/newrevzone.tmpl

    r260 r270  
    1515<tr><td>
    1616    <table border="0" cellspacing="2" cellpadding="2" width="100%">
    17 <TMPL_IF add_failed>    <tr><td class="errhead" colspan="2">Error adding reverse zone <TMPL_VAR NAME=revzone>:
     17<TMPL_IF errmsg>        <tr><td class="errhead" colspan="2">Error adding reverse zone <TMPL_VAR NAME=revzone>:
    1818<TMPL_VAR NAME=errmsg></td></tr></TMPL_IF>
    1919        <tr class="darkrowheader"><td colspan="2" align="center">Add Reverse Zone</td></tr>
Note: See TracChangeset for help on using the changeset viewer.