- Timestamp:
- 08/16/17 15:23:11 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/search-rpc.cgi
r907 r908 151 151 my @matchtypes; 152 152 153 my %mt = (EXACT => '=', 153 my %mt = ( 154 EXACT => '=', 154 155 EQUAL => '=', 155 NOT => '!~', 156 NOT => '!~', # text only? 156 157 # CIDR options 157 158 MASK => 'MASK', … … 161 162 162 163 if ($args{type}) { 164 my $notflag = ''; 165 if ($args{type} =~ /^NOT:/) { 166 $args{type} =~ s/^NOT://; 167 $notflag = 'NOT '; 168 } 169 if ($args{type} =~ /\./) { 170 $args{type} =~ s/\./_/; 171 push @matchtypes, $notflag.'LIKE'; 172 } else { 173 push @matchtypes, ($notflag ? '<>' : '='); 174 } 163 175 push @fields, 's.type'; 164 176 push @vals, $args{type}; 165 push @matchtypes, '=';166 177 } 167 178 … … 224 235 } 225 236 226 my $sql = q(SELECT s.cidr,s.custid,s.type,s.description,s.city,a.dispname FROM searchme s JOIN alloctypes a ON s.type = a.type); 237 my $cols = "s.cidr, s.custid, s.type, s.city, s.description, s.id, s.parent_id, s.available, s.vrf, a.dispname"; 238 my $sql = qq(SELECT $cols FROM searchme s JOIN alloctypes a ON s.type = a.type); 227 239 my @sqlcriteria; 228 240 for (my $i = 0; $i <= $#fields; $i++) { … … 231 243 $sql .= " WHERE ".join(' AND ', @sqlcriteria) if @sqlcriteria; 232 244 245 # multifield sorting! 246 if ($args{order}) { 247 my @ordfields = split /,/, $args{order}; 248 # there are probably better ways to do this 249 my %omap = (cidr => 's.cidr', net => 's.cidr', network => 's.cidr', ip => 's.cidr', 250 custid => 's.custid', type => 's.type', city => 's.city', 251 desc => 's.description', description => 's.description'); 252 my @ordlist; 253 # only pass sort field values from the list of acceptable field names or aliases as per %omap 254 foreach my $ord (@ordfields) { 255 push @ordlist, $omap{$ord} 256 if grep /^$ord$/, (keys %omap); 257 } 258 if (@ordlist) { 259 $sql .= " ORDER BY ". join(',', @ordlist); 260 } 261 } 262 233 263 my $result = $ip_dbh->selectall_arrayref($sql, {Slice=>{}}, @vals); 234 264 die $ip_dbh->errstr if !$result;
Note:
See TracChangeset
for help on using the changeset viewer.