Changeset 446


Ignore:
Timestamp:
01/04/13 17:06:46 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Fine-tune new reverse zone process to support setting a default
location.
Also make sure that an initial new location will be created as a
two-character alphabetic ID, since we're being paranoid about what
tinydns will accept for these.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r445 r446  
    19791979  my $dbh = shift;
    19801980  my $zone = NetAddr::IP->new(shift);
     1981
    19811982  return ('FAIL',"Zone name must be a valid CIDR netblock") unless ($zone && $zone->addr !~ /^0/);
    19821983  my $revpatt = shift;  # construct a custom (A/AAAA+)? PTR template record
    19831984  my $group = shift;
    19841985  my $state = shift;
     1986  my $defloc = shift || '';
    19851987
    19861988  $state = 1 if $state =~ /^active$/;
     
    20072009  # Wrap all the SQL in a transaction
    20082010  eval {
    2009     # insert the domain...
    2010     $dbh->do("INSERT INTO revzones (revnet,group_id,status) VALUES (?,?,?)", undef, ($zone, $group, $state));
     2011    # insert the zone...
     2012    $dbh->do("INSERT INTO revzones (revnet,group_id,status,default_location) VALUES (?,?,?,?)", undef,
     2013        ($zone, $group, $state, $defloc) );
    20112014
    20122015    # get the ID...
     
    20182021    # ... and now we construct the standard records from the default set.  NB:  group should be variable.
    20192022    my $sth = $dbh->prepare("SELECT host,type,val,ttl FROM default_rev_records WHERE group_id=?");
    2020     my $sth_in = $dbh->prepare("INSERT INTO records (rdns_id,domain_id,host,type,val,ttl)".
    2021         " VALUES ($rdns_id,?,?,?,?,?)");
     2023    my $sth_in = $dbh->prepare("INSERT INTO records (rdns_id,domain_id,host,type,val,ttl,location)".
     2024        " VALUES ($rdns_id,?,?,?,?,?,?)");
    20222025    $sth->execute($group);
    20232026    while (my ($host,$type,$val,$ttl) = $sth->fetchrow_array()) {
     
    20732076      }
    20742077
    2075       $sth_in->execute($domid,$host,$type,$val,$ttl);
     2078      $sth_in->execute($domid,$host,$type,$val,$ttl,$defloc);
    20762079
    20772080      if ($typemap{$type} eq 'SOA') {
     
    20832086        $defttl = $tmp2[3];
    20842087      } else {
    2085         my $logentry = "[new $zone] Added record '$host $typemap{$type}";
    2086         _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
    2087                 entry => $logentry." $val', TTL $ttl"));
     2088        my $logentry = "[new $zone] Added record '$host $typemap{$type} $val', TTL $ttl";
     2089        $logentry .= ", default location ".getLoc($dbh, $defloc)->{description} if $defloc;
     2090        _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group, entry => $logentry) );
    20882091      }
    20892092    }
     
    21052108      }
    21062109
    2107       $sth_in->execute($domid,$host,$type,$val,$defttl);
     2110      $sth_in->execute($domid,$host,$type,$val,$defttl,$defloc);
    21082111      my $logentry = "[new $zone] Added record '$host $typemap{$type}";
    21092112      _log($dbh, (rdns_id => $rdns_id, domain_id => $domid, group_id => $group,
     
    30413044    ($loc) = ($loc =~ /^(..)/);
    30423045    my $origloc = $loc;
     3046    $loc = 'aa' if !$loc;       
    30433047    # Make a change...
    30443048    $loc++;
     
    32523256
    32533257  my @loclist;
    3254   push @loclist, { locname => "(None/public)", loc => '', selected => ($sel ? 0 : ($sel eq '' ? 1 : 0)) };
     3258  push @loclist, { locname => "(Default/All)", loc => '', selected => ($sel ? 0 : ($sel eq '' ? 1 : 0)) };
    32553259  while (my ($locname, $loc) = $sth->fetchrow_array) {
    32563260    my %row = (
  • trunk/dns.cgi

    r436 r446  
    449449
    450450  fill_grouplist("grouplist");
     451  my $loclist = getLocDropdown($dbh, $curgroup);
     452  $page->param(loclist => $loclist);
    451453
    452454  # prepopulate revpatt with the matching default record
     
    473475
    474476  my ($code,$msg) = addRDNS($dbh, $webvar{revzone}, $webvar{revpatt}, $webvar{group},
    475         ($webvar{makeactive} eq 'on' ? 1 : 0));
     477        ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{location});
    476478
    477479  if ($code eq 'OK') {
  • trunk/templates/newrevzone.tmpl

    r270 r446  
    2828        </tr>
    2929        <tr class="datalinelight">
     30                <td>Default location/view:</td>
     31                <td align="left">
     32                        <select name="location">
     33                        <TMPL_LOOP loclist>
     34                        <option value="<TMPL_VAR NAME=loc>"<TMPL_IF selected> selected</TMPL_IF>><TMPL_VAR NAME=locname></option>
     35                        </TMPL_LOOP>
     36                        </select>
     37                </td>
     38        </tr>
     39        <tr class="datalinelight">
    3040                <td>Add reverse zone to group:</td>
    3141                <td><select name="group">
Note: See TracChangeset for help on using the changeset viewer.