Changeset 225 for trunk


Ignore:
Timestamp:
01/26/12 14:58:49 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Move some SQL into DNSDB.pm (see #1):
fill_rectypes is now getTypelist, and updated for reverse zones
and the custom DNS record types
Also apply a couple of small nitpick fixes in formatting and spelling

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r224 r225  
    3434        &getSOA &getRecLine &getDomRecs &getRecCount
    3535        &addRec &updateRec &delRec
    36         &getParents
     36        &getTypelist
     37        &getParents
    3738        &isParent
    3839        &domStatus &importAXFR
     
    5455                &getSOA &getRecLine &getDomRecs &getRecCount
    5556                &addRec &updateRec &delRec
    56                 &getParents
     57                &getTypelist
     58                &getParents
    5759                &isParent
    5860                &domStatus &importAXFR
     
    132134
    133135##
    134 ## utilty functions
     136## utility functions
    135137# _rectable()
    136138# Takes default+rdns flags, returns appropriate table name
     
    16071609                record  => 'domain'
    16081610        );
     1611
     1612
     1613## DNSDB::getTypelist()
     1614# Get a list of record types for various UI dropdowns
     1615# Takes database handle, forward/reverse/lookup flag, and optional "tag as selected" indicator (defaults to A)
     1616# Returns an arrayref to list of hashrefs perfect for HTML::Template
     1617sub getTypelist {
     1618  my $dbh = shift;
     1619  my $recgroup = shift;
     1620  my $type = shift || $reverse_typemap{A};
     1621
     1622  # also accepting $webvar{revrec}!
     1623  $recgroup = 'f' if $recgroup eq 'n';
     1624  $recgroup = 'r' if $recgroup eq 'y';
     1625
     1626  my $sql = "SELECT val,name FROM rectypes WHERE ";
     1627  if ($recgroup eq 'r') {
     1628    # reverse zone types
     1629    $sql .= "stdflag=2 OR stdflag=3";
     1630  } elsif ($recgroup eq 'l') {
     1631    # DNS lookup types.  Note we avoid our custom types >= 65280, since those are entirely internal.
     1632    $sql .= "(stdflag=1 OR stdflag=2 OR stdflag=3) AND val < 65280";
     1633  } else {
     1634    # default;  forward zone types.  technically $type eq 'f' but not worth the error message.
     1635    $sql .= "stdflag=1 OR stdflag=2";
     1636  }
     1637  $sql .= " ORDER BY listorder";
     1638
     1639  my $sth = $dbh->prepare($sql);
     1640  $sth->execute;
     1641  my @typelist;
     1642  while (my ($rval,$rname) = $sth->fetchrow_array()) {
     1643    my %row = ( recval => $rval, recname => $rname );
     1644    $row{tselect} = 1 if $rval == $type;
     1645    push @typelist, \%row;
     1646  }
     1647
     1648  # Add SOA on lookups since it's not listed in other dropdowns.
     1649  if ($recgroup eq 'l') {
     1650    my %row = ( recval => $reverse_typemap{SOA}, recname => 'SOA' );
     1651    $row{tselect} = 1 if $reverse_typemap{SOA} == $type;
     1652    push @typelist, \%row;
     1653  }
     1654
     1655  return \@typelist;
     1656} # end getTypelist()
     1657
    16091658
    16101659## DNSDB::getParents()
  • trunk/dns.cgi

    r224 r225  
    601601    $page->param(port           => $recdata->{port});
    602602    $page->param(ttl            => $recdata->{ttl});
    603     fill_rectypes($recdata->{type});
     603    $page->param(typelist       => getTypelist($dbh, $webvar{revrec}, $webvar{type}));
    604604
    605605  } elsif ($webvar{recact} eq 'update') {
     
    13841384
    13851385  $page->param(qfor => $webvar{qfor}) if $webvar{qfor};
    1386   fill_rectypes($webvar{type} ? $webvar{type} : '', 1);
     1386  $page->param(typelist => getTypelist($dbh, 'l', ($webvar{type} ? $webvar{type} : undef)));
    13871387  $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse};
    13881388  $page->param(resolver => $webvar{resolver}) if $webvar{resolver};
     
    17781778}
    17791779
    1780 # fill in record type list on add/update/edit record template
    1781 sub fill_rectypes {
    1782   my $type = shift || $reverse_typemap{A};
    1783   my $soaflag = shift || 0;
    1784 
    1785   my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");
    1786   $sth->execute;
    1787   my @typelist;
    1788   while (my ($rval,$rname) = $sth->fetchrow_array()) {
    1789     my %row = ( recval => $rval, recname => $rname );
    1790     $row{tselect} = 1 if $rval == $type;
    1791     push @typelist, \%row;
    1792   }
    1793   if ($soaflag) {
    1794     my %row = ( recval => $reverse_typemap{SOA}, recname => 'SOA' );
    1795     $row{tselect} = 1 if $reverse_typemap{SOA} == $type;
    1796     push @typelist, \%row;
    1797   }
    1798   $page->param(typelist => \@typelist);
    1799 } # fill_rectypes
    1800 
    18011780sub fill_recdata {
    1802   fill_rectypes($webvar{type});
     1781  $page->param(typelist => getTypelist($dbh, $webvar{revrec}, $webvar{type}));
    18031782
    18041783# le sigh.  we may get called with many empty %webvar keys
Note: See TracChangeset for help on using the changeset viewer.