Changeset 397
- Timestamp:
- 10/02/12 18:15:38 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r391 r397 2174 2174 ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage}". 2175 2175 " 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; 2190 2179 } # end getZoneList() 2191 2180 … … 2467 2456 # protection against bad or missing arguments 2468 2457 $args{sortorder} = 'ASC' if !$args{sortorder}; 2469 $args{offset} = 0 if !$args{offset} ;2458 $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/; 2470 2459 2471 2460 # munge sortby for columns in database … … 2693 2682 $args{sortorder} = 'ASC' if !$args{sortorder}; 2694 2683 $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+)$/; 2696 2685 2697 2686 my $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ". … … 3123 3112 $args{sortorder} = 'ASC' if !$args{sortorder}; 3124 3113 $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+)$/; 3126 3115 3127 3116 my $sql = "SELECT l.location, l.description, l.iplist, g.group_name ". … … 3307 3296 $errstr = ''; 3308 3297 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+)$/; 3320 3310 3321 3311 # sort reverse zones on IP, correctly 3322 # do other fiddling with $ orderwhile we're at it.3323 $ order = "r.$order";3324 $ order = 'CAST (r.val AS inet)' if $rev eq 'y' && $ordereq 'r.val';3325 $ order = 't.alphaorder' if $ordereq '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'; 3326 3316 3327 3317 my $sql = "SELECT r.record_id,r.host,r.type,r.val,r.ttl"; 3328 $sql .= ",l.description AS locname" if $ defeq 'n';3329 $sql .= ",r.distance,r.weight,r.port" if $ reveq '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 "; 3331 3321 $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 $ defeq '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})." = ?"; 3334 3324 $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}"; 3338 3327 # 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) ); 3359 3335 return $ret; 3360 3336 } # end getDomRecs() … … 3782 3758 $args{sortby} = 'stamp' if !$args{sortby}; 3783 3759 $args{sortorder} = 'DESC' if !$args{sortorder}; 3784 $args{offset} = 0 if !$args{offset} ;3760 $args{offset} = 0 if !$args{offset} || $args{offset} !~ /^(?:all|\d+)$/; 3785 3761 3786 3762 my %sortmap = (fname => 'name', username => 'email', entry => 'entry', stamp => 'stamp'); -
trunk/dns.cgi
r392 r397 1870 1870 $page->param(ttl => $soa->{ttl}); 1871 1871 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 1875 1875 foreach my $rec (@$foo2) { 1876 1876 $rec->{type} = $typemap{$rec->{type}}; 1877 $rec->{row} = $row % 2;1878 $rec->{defrec} = $def;1879 $rec->{revrec} = $rev;1880 1877 $rec->{sid} = $webvar{sid}; 1881 $rec->{id} = $id;1882 1878 $rec->{fwdzone} = $rev eq 'n'; 1883 1879 $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV'); 1884 1880 $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV'); 1885 1881 $rec->{port} = 'n/a' unless ($rec->{type} eq 'SRV'); 1886 $row++;1887 1882 # ACLs 1888 1883 $rec->{record_edit} = ($permissions{admin} || $permissions{record_edit}); -
trunk/templates/domlist.tmpl
r379 r397 39 39 <TMPL_IF name=domtable> 40 40 <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>&page=reclist&id=<TMPL_VAR NAME=domain id>&defrec=n<TMPL_UNLESS domlist>&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>&page=reclist&id=<TMPL_VAR NAME=domain_id>&defrec=n<TMPL_UNLESS domlist>&revrec=y</TMPL_UNLESS>"><TMPL_VAR NAME=domain></a></td> 43 43 <td><TMPL_IF status>Active<TMPL_ELSE>Inactive</TMPL_IF></td> 44 44 <td><TMPL_VAR name=group></td> -
trunk/templates/reclist.tmpl
r383 r397 60 60 </tr> 61 61 <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>"> 63 63 <TMPL_IF fwdzone> 64 64 <td><TMPL_IF record_edit><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=record&parentid=<TMPL_VAR NAME=id>&defrec=<TMPL_VAR NAME=defrec>&revrec=<TMPL_VAR NAME=revrec>&recact=edit&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.