Changeset 264 for trunk


Ignore:
Timestamp:
03/05/12 18:05:39 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint; reverse records that don't match the zone (v4/v6) are skipped
Reverse records that can't fit in the zone are also skipped (... sort of,
still needs work)
Replacing ZONE in value/IP mostly done
See #26

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r262 r264  
    12601260  local $dbh->{RaiseError} = 1;
    12611261
    1262 #$dbh->selectrow_array("SELECT currval('users_user_id_seq')");
     1262  my $warnstr = '';
     1263
    12631264  # Wrap all the SQL in a transaction
    12641265  eval {
     
    12681269    # get the ID...
    12691270    ($rdns_id) = $dbh->selectrow_array("SELECT currval('revzones_rdns_id_seq')");
     1271#$dbh->selectrow_array("SELECT currval('users_user_id_seq')");
    12701272
    12711273    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group, username => $userinfo{name},
     
    12781280    $sth->execute($group);
    12791281    while (my ($host,$type,$val,$ttl) = $sth->fetchrow_array()) {
     1282      # Silently skip v4/v6 mismatches.  This is not an error, this is expected.
     1283      if ($zone->{isv6}) {
     1284        next if ($type == 65280 || $type == 65283);
     1285      } else {
     1286        next if ($type == 65281 || $type == 65284);
     1287      }
    12801288      $host =~ s/ADMINDOMAIN/$config{domain}/g;
     1289
     1290## tmp
     1291sub _ZONE {
     1292  my $zone = shift;
     1293  my $string = shift;
     1294  my $t1 = shift;       # flag for IP/network or hostname
     1295  my $t2 = shift || 'f';        # flag for forward/reverse order?  nb: ignored for IP
     1296
     1297  my $prefix = $zone->network->addr;    # Just In Case someone managed to slip in
     1298                                        # a funky subnet that had host bits set.
     1299  $prefix =~ s/(:0)+$/::/;
     1300  $prefix =~ s/0$//;
     1301
     1302  if ($t1 eq 'net') {
     1303    $string =~ s/ZONE[:.]+/$prefix/;
     1304  } else {
     1305    $prefix =~ s/[:.]+$//;
     1306    if ($t2 eq 'f') {
     1307      $prefix =~ s/[:.]+/-/g;
     1308    } else {
     1309      $prefix = join('-', reverse(split(/[:.]/, $prefix)));
     1310    }
     1311    $string =~ s/ZONE/$prefix/;
     1312  }
     1313  return $string;
     1314}
     1315## tmp
     1316
     1317# Check the zone;  if it's v4 and smaller than a /24 (sub-octet), we need
     1318# to check any template IPs to make sure they're in range.
     1319##fixme: need similar check on v6, except we'll just grump at non-nibble boundaries
     1320# first-pass:  masklen must be divisible by 4
     1321if (!$zone->{isv6} && $zone->masklen > 24) {
     1322      my $net = $zone->network->addr;
     1323      my $bc = $zone->broadcast;
     1324      $net =~ s/^\d+\.\d+\.\d+\.//;
     1325      $bc =~ s/^\d+\.\d+\.\d+\.//;
     1326      my $tmp = $host;
     1327      $tmp =~ s/^ZONE\.//;
     1328      if ($net <= $tmp && $tmp <= $bc) {
     1329      # replace ZONE with actual netblock in IP/value
     1330        unless (my $tmpval = _ZONE($zone, $val, 'net')) {
     1331          $warnstr .= "$val does not fit in $zone;  skipping\n";
     1332          next;
     1333        }
     1334      } else {
     1335        $warnstr .= "Default record '$val $typemap{$type} $host' doesn't fit in $zone, skipping\n";
     1336      }
     1337}
     1338
    12811339##work
    12821340# - replace ZONE in $val
    1283 # - skip records not appropriate for the zone (skip A+PTR on v6 zones, and AAAA+PTR on v4 zones)
    12841341#      $val =~ s/DOMAIN/$domain/g;
     1342
    12851343      $sth_in->execute($host,$type,$val,$ttl);
    12861344      if ($typemap{$type} eq 'SOA') {
     
    13001358      }
    13011359    }
     1360
     1361    # If there are warnings (presumably about default records skipped for cause) log them
     1362    _log($dbh, (rdns_id => $rdns_id, user_id => $userinfo{id}, group_id => $group,
     1363        username => $userinfo{name}, entry => $warnstr))
     1364        if $warnstr;
    13021365
    13031366    # once we get here, we should have suceeded.
Note: See TracChangeset for help on using the changeset viewer.