Changeset 666
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r665 r666 4004 4004 my %args = @_; 4005 4005 4006 $args{revrec} = 'n' if !$args{revrec}; 4007 $args{defrec} = 'n' if !$args{defrec}; 4008 4006 4009 # protection against bad or missing arguments 4007 4010 $args{sortorder} = 'ASC' if !$args{sortorder} || !grep /^$args{sortorder}$/, ('ASC','DESC'); … … 4015 4018 my $perpage = ($args{nrecs} ? $args{nrecs} : $self->{perpage}); 4016 4019 4017 # sort reverse zones on IP, correctly4018 # do other fiddling with $args{sortby} while we're at it.4019 # whee! multisort means just passing comma-separated fields in sortby!4020 my $newsort = '';4021 foreach my $sf (split /,/, $args{sortby}) {4022 $sf = "r.$sf";4023 $sf =~ s/r\.val/inetlazy(r.val)/;4024 # hmm. do we really need to limit this?4025 # if $args{revrec} eq 'y' && $args{defrec} eq 'n';4026 $sf =~ s/r\.type/t.alphaorder/;4027 $newsort .= ",$sf";4028 }4029 $newsort =~ s/^,//;4030 4031 my @bindvars = ($args{id});4032 push @bindvars, ($args{filter},$args{filter}) if $args{filter};4033 4020 4034 4021 ##fixme: do we need a knob to twist to switch from unix epoch to postgres time string? 4035 my $sql = "SELECT r.record_id,r.host,r.type,r.val,r.ttl"; 4022 my @bindvars; 4023 my $sql = "SELECT r.record_id,"; 4024 # only include the parent info if we don't already know which parent we're in 4025 $sql .= "r.domain_id,r.rdns_id," unless $args{id}; 4026 $sql .= "r.host,r.type,r.val,r.ttl"; 4036 4027 $sql .= ",l.description AS locname,stamp,r.stamp < now() AS ispast,r.expires,r.stampactive" 4037 4028 if $args{defrec} eq 'n'; … … 4040 4031 $sql .= "INNER JOIN rectypes t ON r.type=t.val "; # for sorting by type alphabetically 4041 4032 $sql .= "LEFT JOIN locations l ON r.location=l.location " if $args{defrec} eq 'n'; 4042 $sql .= "WHERE "._recparent($args{defrec},$args{revrec})." = ?"; 4043 $sql .= " AND NOT r.type=$reverse_typemap{SOA}"; 4033 $sql .= "WHERE NOT r.type=$reverse_typemap{SOA}"; 4034 4035 # "normal" record list 4036 if ($args{id}) { 4037 $sql .= " AND "._recparent($args{defrec},$args{revrec})." = ?"; 4038 push @bindvars, $args{id}; 4039 } 4040 4041 # Filtering on host/val (mainly normal record list) 4044 4042 if ($args{filter}) { 4045 4043 $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)"; 4046 4044 my $tmp = join('.',reverse(split(/\./,$args{filter}))); 4045 push @bindvars, ($args{filter},$args{filter}); 4047 4046 push @bindvars, ($tmp, $tmp); 4048 4047 } 4048 4049 # Filtering on other fields 4050 foreach (qw(type distance weight port ttl description)) { 4051 if ($args{$_}) { 4052 $sql .= " AND $_ ~* ?"; 4053 push @bindvars, $args{$_}; 4054 } 4055 } 4056 4057 # whee! multisort means just passing comma-separated fields in sortby! 4058 my $newsort = ''; 4059 foreach my $sf (split /,/, $args{sortby}) { 4060 $sf = "r.$sf"; 4061 # sort on IP, correctly 4062 $sf =~ s/r\.val/inetlazy(r.val)/; 4063 # hmm. do we really need to limit this? 4064 # if $args{revrec} eq 'y' && $args{defrec} eq 'n'; 4065 $sf =~ s/r\.type/t.alphaorder/; # subtly different from sorting on rectypes.name 4066 $newsort .= ",$sf"; 4067 } 4068 $newsort =~ s/^,//; 4069 ##enhance: pass in ascending/descending sort per-field 4049 4070 $sql .= " ORDER BY $newsort $args{sortorder}"; 4050 4071 # ensure consistent ordering by sorting on record_id too 4051 4072 $sql .= ", record_id $args{sortorder}"; 4073 4074 # Offset/pagination 4052 4075 $sql .= ($args{offset} eq 'all' ? '' : " LIMIT $perpage OFFSET ".$args{offset}*$perpage); 4053 4076 … … 4078 4101 my $self = shift; 4079 4102 my $dbh = $self->{dbh}; 4080 my $defrec = shift; 4081 my $revrec = shift; 4082 my $id = shift; 4083 my $filter = shift || ''; 4084 4085 # keep the nasties down, since we can't ?-sub this bit. :/ 4086 # note this is chars allowed in DNS hostnames 4087 $filter =~ s/[^a-zA-Z0-9_.:-]//g; 4088 4089 my @bindvars = ($id); 4090 push @bindvars, ($filter,$filter) if $filter; 4103 4104 my %args = @_; 4105 4106 $args{defrec} = 'n' if !$args{defrec}; 4107 $args{revrec} = 'n' if !$args{revrec}; 4108 4109 my @bindvars; 4091 4110 my $sql = "SELECT count(*) FROM ". 4092 _rectable($defrec,$revrec). 4093 " WHERE "._recparent($defrec,$revrec)."=? ". 4094 "AND NOT type=$reverse_typemap{SOA}"; 4095 if ($filter) { 4111 _rectable($args{defrec},$args{revrec}). 4112 " WHERE NOT type=$reverse_typemap{SOA}"; 4113 if ($args{id}) { 4114 $sql .= " AND "._recparent($args{defrec},$args{revrec})." = ?"; 4115 push @bindvars, $args{id}; 4116 } 4117 4118 # Filtering on host/val (mainly normal record list) 4119 if ($args{filter}) { 4096 4120 $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)"; 4097 my $tmp = join('.',reverse(split(/\./,$filter))); 4121 my $tmp = join('.',reverse(split(/\./,$args{filter}))); 4122 push @bindvars, ($args{filter},$args{filter}); 4098 4123 push @bindvars, ($tmp, $tmp); 4099 4124 } 4100 $sql .= " AND (host ~* ? OR val ~* ? OR host ~* ? OR val ~* ?)" if $filter; 4101 my $tmp = join('.',reverse(split(/\./,$filter))); 4102 push @bindvars, ($tmp, $tmp) if $filter; 4125 4126 # Filtering on other fields 4127 foreach (qw(type distance weight port ttl description)) { 4128 if ($args{$_}) { 4129 $sql .= " AND $_ ~* ?"; 4130 push @bindvars, $args{$_}; 4131 } 4132 } 4103 4133 4104 4134 my ($count) = $dbh->selectrow_array($sql, undef, (@bindvars) ); -
trunk/dns-rpc.cgi
r659 r666 455 455 $args{direction} = 'ASC' if !$args{direction}; 456 456 457 my $ret = $dnsdb->getRecCount($args{defrec}, $args{revrec}, $args{id}, $args{filter}); 457 my $ret = $dnsdb->getRecCount(defrec => $args{defrec}, revrec => $args{revrec}, 458 id => $args{id}, filter => $args{filter}); 458 459 459 460 die "$dnsdb->errstr\n" if !$ret; -
trunk/dns.cgi
r641 r666 632 632 $page->param(curpage => $webvar{page}); 633 633 634 my $count = $dnsdb->getRecCount($webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter); 634 my $count = $dnsdb->getRecCount(defrec => $webvar{defrec}, revrec => $webvar{revrec}, 635 id => $webvar{id}, filter => $filter); 635 636 636 637 $sortby = 'host';
Note:
See TracChangeset
for help on using the changeset viewer.