Changeset 924


Ignore:
Timestamp:
08/14/25 18:06:51 (8 hours ago)
Author:
Kris Deugau
Message:

/branches/secondaryzones

Complete basic secondary zone add
Fix a minor missing piece filling the newsecondary template
Normalize form field names in the newsecondary template

Location:
branches/secondaryzones
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/secondaryzones/DNSDB.pm

    r923 r924  
    29712971
    29722972
     2973## DNSDB::addSecondary()
     2974# Add a secondary zone
     2975# Takes the zone name, uumeric group, comma-separated list of primary nameserver(s),
     2976# initial active/inactive state, and location tag
     2977# Returns a status code and message
     2978sub addSecondary {
     2979  my $self = shift;
     2980  my $dbh = $self->{dbh};
     2981  my $zone = shift;
     2982  return ('FAIL', "Zone must not be blank\n") if !$zone;
     2983  my $group = shift;
     2984  return ('FAIL', "Group must be specified\n") if !defined($group);
     2985  my $primary = shift;
     2986  return ('FAIL', "Primary server(s) must be specified\n") if !$primary;
     2987  my $state = shift;
     2988  return ('FAIL', "Zone status must be specified\n") if !defined($state);
     2989  my $defloc = shift || '';
     2990
     2991  $state = 1 if $state =~ /^active$/;
     2992  $state = 1 if $state =~ /^on$/;
     2993  $state = 0 if $state =~ /^inactive$/;
     2994  $state = 0 if $state =~ /^off$/;
     2995
     2996  return ('FAIL',"Invalid zone status") if $state !~ /^\d+$/;
     2997
     2998##fixme:  need to handle case of being passed a CIDR value for reverse zone secondary
     2999#  # Check formal .arpa zones
     3000#  if ($zone =~ /\.arpa\.?$/) {
     3001#    my ($code,$cidrzone) = _zone2cidr($zone);
     3002#    return ('FAIL', "Poorly formed .arpa zone name) if $code eq 'FAIL';
     3003#  }
     3004
     3005  $zone = lc($zone) if $self->{lowercase};
     3006  return ('FAIL', "Invalid characters in zone name") if $zone !~ /^[a-zA-Z0-9_.-]+$/;
     3007
     3008  $primary = lc($primary) if $self->{lowercase};
     3009  my @pservers = split /\s*,\s*/, $primary;
     3010  foreach (@pservers) {
     3011    return ('FAIL', "Invalid characters in primary server") if ! /^[a-zA-Z0-9_.-]+$/;
     3012  }
     3013  $primary = join(',', @pservers);
     3014  $primary =~ s/^\s+//;
     3015  $primary =~ s/\s+$//;
     3016
     3017  my $sth = $dbh->prepare("SELECT secondary_id FROM secondaryzones WHERE lower(zone) = lower(?) AND default_location = ?");
     3018  my $zone_id;
     3019
     3020# quick check to start to see if we've already got one
     3021  $sth->execute($zone, $defloc);
     3022  ($zone_id) = $sth->fetchrow_array;
     3023
     3024  return ('FAIL', "Zone already exists") if $zone_id;
     3025
     3026  # Allow transactions, and raise an exception on errors so we can catch it later.
     3027  # Use local to make sure these get "reset" properly on exiting this block
     3028  local $dbh->{AutoCommit} = 0;
     3029  local $dbh->{RaiseError} = 1;
     3030
     3031  my $warnstr = '';
     3032  my $defttl = 3600;    # 1 hour should be reasonable.  And unless things have gone horribly
     3033                        # wrong, we should have a value to override this anyway.
     3034
     3035  # Wrap all the SQL in a transaction
     3036  eval {
     3037##fixme:  add Net::DNS lookup to grab SOA serial when importing records for display as well
     3038    ($zone_id) = $dbh->selectrow_array(
     3039        "INSERT INTO secondaryzones (zone, primaryserver, group_id, status, default_location, zserial) ".
     3040        "VALUES (?,?,?,?,?,?) RETURNING secondary_id",
     3041        undef,
     3042        ($zone, $primary, $group, $state, $defloc, 1) );
     3043
     3044    my $logparent = $self->_log(secondary_id => $zone_id, group_id => $group,
     3045       entry => "Added ".($state ? 'active' : 'inactive')." secondary zone $zone with primary server(s) $primary");
     3046
     3047    # once we get here, we should have suceeded.
     3048    $dbh->commit;
     3049  }; # end eval
     3050
     3051  if ($@) {
     3052    my $msg = $@;
     3053    eval { $dbh->rollback; };
     3054    $self->_log(group_id => $group, entry => "Failed adding secondary zone $zone ($msg)")
     3055       if $self->{log_failures};
     3056    $dbh->commit;      # since we enabled transactions earlier
     3057    return ('FAIL',$msg);
     3058  } else {
     3059    my $retcode = 'OK';
     3060    if ($warnstr) {
     3061      $resultstr = $warnstr;
     3062      $retcode = 'WARN';
     3063    }
     3064    return ($retcode, $zone_id);
     3065  }
     3066
     3067} # end addSecondary()
     3068
     3069
    29733070## DNSDB::delZone()
    29743071# Delete a forward or reverse zone.
  • branches/secondaryzones/dns.cgi

    r922 r924  
    649649    $session->clear('errmsg');
    650650    $page->param(zone => $webvar{zone});
     651    $page->param(primary => $webvar{primary});
    651652    $page->param(addinactive => $webvar{makeactive} eq 'n');
     653  }
     654
     655} elsif ($webvar{page} eq 'addsecondary') {
     656
     657  changepage(page => "secondaryzones", errmsg => "You are not permitted to add secondary zones")
     658        unless ($permissions{admin} || $permissions{domain_create});
     659
     660  # security check - does the user have permission to access this entity?
     661  if (!check_scope(id => $webvar{group}, type => 'group')) {
     662    $session->param('add_failed', 1);
     663##fixme:  zone a security risk for XSS?
     664    changepage(page => "newsecondary", zone => $webvar{zone},
     665        errmsg => "You do not have permission to add a secondary zone to the requested group");
     666  }
     667
     668  $webvar{makeactive} = 0 if !defined($webvar{makeactive});
     669
     670  my ($code,$msg) = $dnsdb->addSecondary($webvar{zone}, $webvar{group}, $webvar{primary}, ($webvar{makeactive} eq 'on' ? 1 : 0),
     671        $webvar{defloc});
     672
     673  if ($code eq 'OK') {
     674    $webvar{zone} = lc($webvar{zone}) if $dnsdb->{lowercase};
     675    $dnsdb->mailNotify("New secondary zone created",
     676        ($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive').qq( secondary zone "$webvar{zone}" added by ).
     677        $session->param("username"));
     678    changepage(page => "secondaryzones", id => $msg);
     679  } else {
     680    $session->param('add_failed', 1);
     681##fixme:  zone a security risk for XSS?
     682    changepage(page => "newsecondary", errmsg => $msg, zone => $webvar{zone}, primary => $webvar{primary},
     683        group => $webvar{group}, makeactive => ($webvar{makeactive} ? 'y' : 'n'), defloc => $webvar{defloc});
    652684  }
    653685
  • branches/secondaryzones/templates/newsecondary.tmpl

    r921 r924  
    2222        <tr class="datalinelight">
    2323                <td>Zone Name:</td>
    24                 <td align="left"><input type="text" name="secondary" value="<TMPL_VAR NAME=secondary>" /></td>
     24                <td align="left"><input type="text" name="zone" value="<TMPL_VAR NAME=zone>" /></td>
    2525        </tr>
    2626        <tr class="datalinelight">
    27                 <td>Primary nameserver(s):</td>
    28                 <td align="left"><input type="text" name="secondary" value="<TMPL_VAR NAME=secondary>" /></td>
     27                <td>Primary Nameserver(s):</td>
     28                <td align="left"><input type="text" name="primary" value="<TMPL_VAR NAME=primary>" /></td>
    2929        </tr>
    3030        <tr class="datalinelight">
Note: See TracChangeset for help on using the changeset viewer.