Changeset 911


Ignore:
Timestamp:
08/12/25 15:47:28 (17 hours ago)
Author:
Kris Deugau
Message:

/branches/secondaryzones

First chunk of adding secondary zone management

  • Menu link
  • Zone list page
  • Extend getZoneCount() and getZoneList() to read the secondary zone table
Location:
branches/secondaryzones
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/secondaryzones/DNSDB.pm

    r908 r911  
    31703170#  - an array of "acceptable" groups
    31713171#  - a flag for forward/reverse zones
     3172#  - a flag for primary/secondary zones
    31723173#  - Optionally accept a "starts with" and/or "contains" filter argument
    31733174# Returns an integer count of the resulting zone list.
     
    31963197
    31973198  my $sql;
    3198   # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read
    3199   if ($args{revrec} eq 'n') {
    3200     $sql = "SELECT count(*) FROM domains".
     3199
     3200  if ($args{secondary} eq 'y') {
     3201    # Secondary zones have less distinction between forward/reverse.
     3202    # May need to revisit that once viewing records in the zones.
     3203    $sql = "SELECT count(*) FROM secondaryzones".
     3204        " WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     3205        ($args{startwith} ? " AND zone ~* ?" : '').
     3206        ($args{filter} ? " AND zone ~* ?" : '');
     3207  } else {
     3208    if ($args{revrec} eq 'n') {
     3209      $sql = "SELECT count(*) FROM domains".
    32013210        " WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
    32023211        ($args{startwith} ? " AND domain ~* ?" : '').
    32033212        ($args{filter} ? " AND domain ~* ?" : '');
    3204   } else {
    3205     $sql = "SELECT count(*) FROM revzones".
     3213    } else {
     3214      $sql = "SELECT count(*) FROM revzones".
    32063215        " WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
    32073216        ($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
    3208 #    if ($self->{showrev_arpa} eq 'zone' || $self->{showrev_arpa} eq 'all') {
    32093217      # Just In Case the UI is using formal .arpa notation, and someone enters something reversed,
    32103218      # we want to match both the formal and natural zone name
    32113219      $sql .= ($args{filter} ? " AND (CAST(revnet AS VARCHAR) ~* ? OR CAST(revnet AS VARCHAR) ~* ?)" : '');
    32123220      push @filterargs, join('[.]',reverse(split(/\[\.\]/,$args{filter}))) if $args{filter};
    3213 #    } else {
    3214 #      $sql .= ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
    3215 #    }
     3221    }
    32163222  }
    32173223  my ($count) = $dbh->selectrow_array($sql, undef, @filterargs);
     
    32533259
    32543260  my $sql;
    3255   # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read
    3256   if ($args{revrec} eq 'n') {
    3257     $args{sortby} = 'domain' if !$args{sortby} || !grep /^$args{sortby}$/, ('domain','group','status');
     3261
     3262  if ($args{secondary} eq 'y') {
     3263    $args{sortby} = 'zone' if !$args{sortby} || !grep /^$args{sortby}$/, ('zone','primaryserver','group','status');
    32583264    $sql = q(SELECT
     3265                secondary_id AS zoneid,
     3266                zone,
     3267                primaryserver,
     3268                status,
     3269                groups.group_name AS group,
     3270                l.description AS location
     3271        FROM secondaryzones
     3272        LEFT JOIN locations l ON secondaryzones.default_location=l.location
     3273        INNER JOIN groups ON secondaryzones.group_id=groups.group_id ).
     3274        "WHERE secondaryzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
     3275        ($args{startwith} ? " AND zone ~* ?" : '').
     3276        ($args{filter} ? " AND zone ~* ?" : '');
     3277  } else {
     3278    if ($args{revrec} eq 'n') {
     3279      $args{sortby} = 'domain' if !$args{sortby} || !grep /^$args{sortby}$/, ('domain','group','status');
     3280      $sql = q(SELECT
    32593281                domain_id AS zoneid,
    32603282                domain AS zone,
     
    32683290        ($args{startwith} ? " AND domain ~* ?" : '').
    32693291        ($args{filter} ? " AND domain ~* ?" : '');
    3270   } else {
     3292    } else {
    32713293##fixme:  arguably startwith here is irrelevant.  depends on the UI though.
    3272     $args{sortby} = 'revnet' if !$args{sortby} || !grep /^$args{sortby}$/, ('revnet','group','status');
    3273     $sql = q(SELECT
     3294      $args{sortby} = 'revnet' if !$args{sortby} || !grep /^$args{sortby}$/, ('revnet','group','status');
     3295      $sql = q(SELECT
    32743296                rdns_id AS zoneid,
    32753297                revnet AS zone,
     
    32823304        " WHERE revzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
    32833305        ($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
    3284 #    if ($self->{showrev_arpa} eq 'zone' || $self->{showrev_arpa} eq 'all') {
    32853306      # Just In Case the UI is using formal .arpa notation, and someone enters something reversed,
    32863307      # we want to match both the formal and natural zone name
    32873308      $sql .= ($args{filter} ? " AND (CAST(revnet AS VARCHAR) ~* ? OR CAST(revnet AS VARCHAR) ~* ?)" : '');
    32883309      push @filterargs, join('[.]',reverse(split(/\[\.\]/,$args{filter}))) if $args{filter};
    3289 #    } else {
    3290 #      $sql .= ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
    3291 #    }
     3310    }
    32923311  }
    32933312  # A common tail.
  • branches/secondaryzones/dns.cgi

    r909 r911  
    606606    changepage(page => "revzones");
    607607  }
     608
     609} elsif ($webvar{page} eq 'secondaryzones') {
     610
     611#  $page->param(domlist => 1);
     612
     613# hmm.  seeing problems in some possibly-not-so-corner cases.
     614# this currently only handles "domain on", "domain off"
     615  if (defined($webvar{zonestatus})) {
     616    # security check - does the user have permission to access this entity?
     617    my $flag = 0;
     618    foreach (@viewablegroups) {
     619      $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'secondary');
     620    }
     621    if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
     622      my $stat = $dnsdb->secondaryzoneStatus($webvar{id}, 'n', $webvar{zonestatus});
     623      $page->param(resultmsg => $DNSDB::resultstr);
     624    } else {
     625      $page->param(errmsg => "You are not permitted to view or change the requested domain");
     626    }
     627    $uri_self =~ s/\&zonestatus=[^&]*//g;   # clean up URL for stuffing into templates
     628  }
     629
     630  show_msgs();
     631
     632  $page->param(curpage => $webvar{page});
     633
     634  listsecondaryzones();
     635
    608636
    609637} elsif ($webvar{page} eq 'reclist') {
     
    19671995##fixme
    19681996  $page->param(mayrdns => 1);
     1997  $page->param(maysecondary => 1);
    19691998
    19701999  $page->param(mayloc => ($permissions{admin} || $permissions{location_view}));
     
    23592388
    23602389
     2390sub listsecondaryzones {
     2391# ACLs
     2392  $page->param(secondary_create => ($permissions{admin} || $permissions{domain_create}) );
     2393  $page->param(secondary_edit   => ($permissions{admin} || $permissions{domain_edit}) );
     2394  $page->param(secondary_delete => ($permissions{admin} || $permissions{domain_delete}) );
     2395
     2396  my @childgroups;
     2397  $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs;
     2398  my $childlist = join(',',@childgroups);
     2399
     2400#  my $count = $dnsdb->getSecondaryZoneCount(childlist => $childlist, curgroup => $curgroup,
     2401  my $count = $dnsdb->getZoneCount(childlist => $childlist, curgroup => $curgroup, secondary => 'y',
     2402        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
     2403
     2404# fill page count and first-previous-next-last-all bits
     2405  fill_pgcount($count, 'secondary zone(s)', $dnsdb->groupName($curgroup));
     2406  fill_fpnla($count);
     2407
     2408  $sortby = 'zone';
     2409# sort/order
     2410  $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
     2411  $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
     2412
     2413  $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
     2414  $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
     2415
     2416# set up the headers
     2417  my @cols = ('secondary', 'primaryserver', 'status', 'group');
     2418  my %colheads = (secondary => 'Secondary zone', primaryserver => 'Primary server(s)', status => 'Status', group => 'Group');
     2419  fill_colheads($sortby, $sortorder, \@cols, \%colheads);
     2420
     2421  # hack! hack! pthbttt.  have to rethink the status column storage,
     2422  # or inactive comes "before" active.  *sigh*
     2423  $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status';
     2424
     2425# waffle, waffle - keep state on these as well as sortby, sortorder?
     2426##fixme:  put this higher so the count doesn't get munched?
     2427  $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
     2428
     2429  $page->param(filter => $filter) if $filter;
     2430  $page->param(searchsubs => $searchsubs) if $searchsubs;
     2431
     2432  $page->param(group => $curgroup);
     2433
     2434#  my $zonelist = $dnsdb->getSecondaryZoneList(childlist => $childlist, curgroup => $curgroup,
     2435  my $zonelist = $dnsdb->getZoneList(childlist => $childlist, curgroup => $curgroup, secondary => 'y',
     2436        filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
     2437        offset => $offset, sortby => $sortby, sortorder => $sortorder
     2438        );
     2439# probably don't need this, keeping for reference for now
     2440#  foreach my $rec (@$zonelist) {
     2441#  }
     2442  $page->param(zonetable => $zonelist);
     2443} # end listsecondaryzones()
     2444
     2445
    23612446sub listgroups {
    23622447
  • branches/secondaryzones/templates/menu.tmpl

    r762 r911  
    66<a href="<TMPL_VAR NAME=script_self>&amp;page=domlist">Domains</a><br />
    77<TMPL_IF mayrdns><a href="<TMPL_VAR NAME=script_self>&amp;page=revzones">Reverse Zones</a><br /></TMPL_IF>
     8<TMPL_IF maysecondary><a href="<TMPL_VAR NAME=script_self>&amp;page=secondaryzones">Secondary Zones</a><br /></TMPL_IF>
    89<a href="<TMPL_VAR NAME=script_self>&amp;page=useradmin">Users</a><br />
    910<a href="<TMPL_VAR NAME=script_self>&amp;page=log">Log</a><br />
Note: See TracChangeset for help on using the changeset viewer.