Changeset 397


Ignore:
Timestamp:
10/02/12 18:15:38 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Caught some inconsistencies getting the RPC CGI updated.

  • Normalize to use of odd in record list, same as other lists. Also normalize which case is which in templates so all lists look consistent.
  • Normalize calling convention and database calls in list-getting subs
    • getZoneList, with light tweak to template for field name
    • getDomRecs, with conversion from fixed arguments to hash
  • Normalize checks on list offsets to the best one, from getZoneList
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r391 r397  
    21742174        ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage}".
    21752175        " OFFSET ".$args{offset}*$config{perpage});
    2176   my $sth = $dbh->prepare($sql);
    2177   $sth->execute(@filterargs);
    2178   my $rownum = 0;
    2179 
    2180   while (my @data = $sth->fetchrow_array) {
    2181     my %row;
    2182     $row{domainid} = $data[0];
    2183     $row{domain} = $data[1];
    2184     $row{status} = $data[2];
    2185     $row{group} = $data[3];
    2186     push @zonelist, \%row;
    2187   }
    2188 
    2189   return \@zonelist;
     2176
     2177  my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) );
     2178  return $ret;
    21902179} # end getZoneList()
    21912180
     
    24672456  # protection against bad or missing arguments
    24682457  $args{sortorder} = 'ASC' if !$args{sortorder};
    2469   $args{offset} = 0 if !$args{offset};
     2458  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/;
    24702459
    24712460  # munge sortby for columns in database
     
    26932682  $args{sortorder} = 'ASC' if !$args{sortorder};
    26942683  $args{sortby} = 'u.username' if !$args{sortby};
    2695   $args{offset} = 0 if !$args{offset};
     2684  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/;
    26962685
    26972686  my $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ".
     
    31233112  $args{sortorder} = 'ASC' if !$args{sortorder};
    31243113  $args{sortby} = 'l.description' if !$args{sortby};
    3125   $args{offset} = 0 if !$args{offset};
     3114  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/;
    31263115
    31273116  my $sql = "SELECT l.location, l.description, l.iplist, g.group_name ".
     
    33073296  $errstr = '';
    33083297  my $dbh = shift;
    3309   my $def = shift;
    3310   my $rev = shift;
    3311   my $id = shift;
    3312   my $nrecs = shift || 'all';
    3313   my $nstart = shift || 0;
    3314 
    3315 ## for order, need to map input to column names
    3316   my $order = shift || 'host';
    3317   my $direction = shift || 'ASC';
    3318 
    3319   my $filter = shift || '';
     3298
     3299  my %args = @_;
     3300
     3301  my @filterargs;
     3302
     3303  push @filterargs, $args{filter} if $args{filter};
     3304
     3305  # protection against bad or missing arguments
     3306  $args{sortorder} = 'ASC' if !$args{sortorder};
     3307  $args{sortby} = 'host' if !$args{sortby} && $args{rev} eq 'n';        # default sort by host on domain record list
     3308  $args{sortby} = 'val' if !$args{sortby} && $args{rev} eq 'y';         # default sort by IP on revzone record list
     3309  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/; 
    33203310
    33213311  # sort reverse zones on IP, correctly
    3322   # do other fiddling with $order while we're at it.
    3323   $order = "r.$order";
    3324   $order = 'CAST (r.val AS inet)' if $rev eq 'y' && $order eq 'r.val';
    3325   $order = 't.alphaorder' if $order eq 'r.type';
     3312  # do other fiddling with $args{sortby} while we're at it.
     3313  $args{sortby} = "r.$args{sortby}";
     3314  $args{sortby} = 'CAST (r.val AS inet)' if $args{revrec} eq 'y' && $args{sortby} eq 'r.val';
     3315  $args{sortby} = 't.alphaorder' if $args{sortby} eq 'r.type';
    33263316
    33273317  my $sql = "SELECT r.record_id,r.host,r.type,r.val,r.ttl";
    3328   $sql .= ",l.description AS locname" if $def eq 'n';
    3329   $sql .= ",r.distance,r.weight,r.port" if $rev eq 'n';
    3330   $sql .= " FROM "._rectable($def,$rev)." r ";
     3318  $sql .= ",l.description AS locname" if $args{defrec} eq 'n';
     3319  $sql .= ",r.distance,r.weight,r.port" if $args{revrec} eq 'n';
     3320  $sql .= " FROM "._rectable($args{defrec},$args{revrec})." r ";
    33313321  $sql .= "INNER JOIN rectypes t ON r.type=t.val ";     # for sorting by type alphabetically
    3332   $sql .= "LEFT JOIN locations l ON r.location=l.location " if $def eq 'n';
    3333   $sql .= "WHERE "._recparent($def,$rev)." = ?";
     3322  $sql .= "LEFT JOIN locations l ON r.location=l.location " if $args{defrec} eq 'n';
     3323  $sql .= "WHERE "._recparent($args{defrec},$args{revrec})." = ?";
    33343324  $sql .= " AND NOT r.type=$reverse_typemap{SOA}";
    3335   $sql .= " AND host ~* ?" if $filter;
    3336   # use alphaorder column for "correct" ordering of sort-by-type instead of DNS RR type number
    3337   $sql .= " ORDER BY $order $direction";
     3325  $sql .= " AND host ~* ?" if $args{filter};
     3326  $sql .= " ORDER BY $args{sortby} $args{sortorder}";
    33383327  # ensure consistent ordering by sorting on record_id too
    3339   $sql .= ", record_id $direction";
    3340 
    3341   my @bindvars = ($id);
    3342   push @bindvars, $filter if $filter;
    3343 
    3344   # just to be ultraparanoid about SQL injection vectors
    3345   if ($nstart ne 'all') {
    3346     $sql .= " LIMIT ? OFFSET ?";
    3347     push @bindvars, $nrecs;
    3348     push @bindvars, ($nstart*$nrecs);
    3349   }
    3350   my $sth = $dbh->prepare($sql) or warn $dbh->errstr;
    3351   $sth->execute(@bindvars) or warn "$sql: ".$sth->errstr;
    3352 
    3353   my @retbase;
    3354   while (my $ref = $sth->fetchrow_hashref()) {
    3355     push @retbase, $ref;
    3356   }
    3357 
    3358   my $ret = \@retbase;
     3328  $sql .= ", record_id $args{sortorder}";
     3329  $sql .= ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     3330
     3331  my @bindvars = ($args{id});
     3332  push @bindvars, $args{filter} if $args{filter};
     3333
     3334  my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, (@bindvars) );
    33593335  return $ret;
    33603336} # end getDomRecs()
     
    37823758  $args{sortby} = 'stamp' if !$args{sortby};
    37833759  $args{sortorder} = 'DESC' if !$args{sortorder};
    3784   $args{offset} = 0 if !$args{offset};
     3760  $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/;
    37853761
    37863762  my %sortmap = (fname => 'name', username => 'email', entry => 'entry', stamp => 'stamp');
  • trunk/dns.cgi

    r392 r397  
    18701870  $page->param(ttl      => $soa->{ttl});
    18711871
    1872   my $foo2 = getDomRecs($dbh,$def,$rev,$id,$perpage,$webvar{offset},$sortby,$sortorder,$filter);
    1873 
    1874   my $row = 0;
     1872  my $foo2 = getDomRecs($dbh,(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset},
     1873        sortby => $sortby, sortorder => $sortorder, filter => $filter));
     1874
    18751875  foreach my $rec (@$foo2) {
    18761876    $rec->{type} = $typemap{$rec->{type}};
    1877     $rec->{row} = $row % 2;
    1878     $rec->{defrec} = $def;
    1879     $rec->{revrec} = $rev;
    18801877    $rec->{sid} = $webvar{sid};
    1881     $rec->{id} = $id;
    18821878    $rec->{fwdzone} = $rev eq 'n';
    18831879    $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
    18841880    $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
    18851881    $rec->{port} = 'n/a' unless ($rec->{type} eq 'SRV');
    1886     $row++;
    18871882# ACLs
    18881883    $rec->{record_edit} = ($permissions{admin} || $permissions{record_edit});
  • trunk/templates/domlist.tmpl

    r379 r397  
    3939<TMPL_IF name=domtable>
    4040<TMPL_LOOP name=domtable>
    41 <tr class="row<TMPL_IF __odd__>1<TMPL_ELSE>0</TMPL_IF>">
    42         <td align="left"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=reclist&amp;id=<TMPL_VAR NAME=domainid>&amp;defrec=n<TMPL_UNLESS domlist>&amp;revrec=y</TMPL_UNLESS>"><TMPL_VAR NAME=domain></a></td>
     41<tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>">
     42        <td align="left"><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=reclist&amp;id=<TMPL_VAR NAME=domain_id>&amp;defrec=n<TMPL_UNLESS domlist>&amp;revrec=y</TMPL_UNLESS>"><TMPL_VAR NAME=domain></a></td>
    4343        <td><TMPL_IF status>Active<TMPL_ELSE>Inactive</TMPL_IF></td>
    4444        <td><TMPL_VAR name=group></td>
  • trunk/templates/reclist.tmpl

    r383 r397  
    6060</tr>
    6161<TMPL_LOOP NAME=reclist>
    62 <tr class="row<TMPL_VAR NAME=row>">
     62<tr class="row<TMPL_IF __odd__>0<TMPL_ELSE>1</TMPL_IF>">
    6363<TMPL_IF fwdzone>
    6464        <td><TMPL_IF record_edit><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&amp;page=record&amp;parentid=<TMPL_VAR NAME=id>&amp;defrec=<TMPL_VAR NAME=defrec>&amp;revrec=<TMPL_VAR NAME=revrec>&amp;recact=edit&amp;id=<TMPL_VAR NAME=record_id>"><TMPL_VAR NAME=host></a><TMPL_IF locname> (<TMPL_VAR NAME=locname>)</TMPL_IF><TMPL_ELSE><TMPL_VAR NAME=host><TMPL_IF locname> (<TMPL_VAR NAME=locname>)</TMPL_IF></TMPL_IF></td>
Note: See TracChangeset for help on using the changeset viewer.