Changeset 172 for branches/sql-cleanup
- Timestamp:
- 02/24/05 17:09:30 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sql-cleanup/cgi-bin/main.cgi
r155 r172 204 204 205 205 print qq(<div class="heading">Showing all netblock and static-IP allocations</div><br>\n); 206 $sql = "select * from searchme"; 206 207 # Need to assemble SQL query in this order to avoid breaking things. 208 $sql = "select cidr,custid,type,city,description from searchme"; 207 209 my $count = countRows("select count(*) from ($sql) foo"); 208 210 $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset"; … … 215 217 # Query for a customer ID. Note that we can't restrict to "numeric-only" 216 218 # as we have non-numeric custIDs in the legacy data. :/ 217 $sql = "select *from searchme where custid ilike '%$query%'";219 $sql = "select cidr,custid,type,city,description from searchme where custid ilike '%$query%'"; 218 220 my $count = countRows("select count(*) from ($sql) foo"); 219 221 $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset"; … … 224 226 print qq(<div class="heading">Searching for descriptions containing '$query'</div><br>\n); 225 227 # Query based on description (includes "name" from old DB). 226 $sql = "select *from searchme where description ilike '%$query%'";228 $sql = "select cidr,custid,type,city,description from searchme where description ilike '%$query%'"; 227 229 my $count = countRows("select count(*) from ($sql) foo"); 228 230 $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset"; … … 241 243 # /0->/9 are silly to worry about right now. I don't think 242 244 # we'll be getting a class A anytime soon. <g> 243 $sql = "select *from searchme where cidr='$query'";245 $sql = "select cidr,custid,type,city,description from searchme where cidr='$query'"; 244 246 queryResults($sql, $webvar{page}, 1); 245 247 } else { 246 248 print "Finding all blocks with netmask /$maskbits, leading octet(s) $net<br>\n"; 247 249 # Partial match; beginning of subnet and maskbits are provided 248 $sql = "select * from searchme where text(cidr) like '$net%' and".249 "text(cidr) like ' %$maskbits'";250 $sql = "select cidr,custid,type,city,description from searchme where ". 251 "text(cidr) like '$net%' and text(cidr) like '%$maskbits'"; 250 252 my $count = countRows("select count(*) from ($sql) foo"); 251 253 $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset"; … … 254 256 } elsif ($query =~ /^(\d{1,3}\.){3}\d{1,3}$/) { 255 257 # Specific IP address match 256 print "4-octet pattern found; finding netblock containing IP $query<br>\n";257 my ($net,$ip) = ($query =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})/);258 258 my $sfor = new NetAddr::IP $query; 259 $sth = $ip_dbh->prepare("select * from searchme where text(cidr) like '$net%'"); 259 # We do this convoluted roundabout way of finding things in order 260 # to bring up matches for single IPs that are within a static block; 261 # we want to show both the "container" block and the static IP itself. 262 $sth = $ip_dbh->prepare("select cidr from searchme where cidr >>= '$sfor'"); 260 263 $sth->execute; 261 264 while (my @data = $sth->fetchrow_array()) { 262 265 my $cidr = new NetAddr::IP $data[0]; 263 if ($cidr->contains($sfor)) { 264 queryResults("select * from searchme where cidr='$cidr'", $webvar{page}, 1); 265 } 266 queryResults("select cidr,custid,type,city,description from searchme where ". 267 "cidr='$cidr'", $webvar{page}, 1); 266 268 } 267 269 } elsif ($query =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.?$/) { 268 270 print "Finding matches where the first three octets are $query<br>\n"; 269 $sql = "select * from searchme where text(cidr) like '$query%'"; 271 $sql = "select cidr,custid,type,city,description from searchme where ". 272 "text(cidr) like '$query%'"; 270 273 my $count = countRows("select count(*) from ($sql) foo"); 271 274 $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
Note:
See TracChangeset
for help on using the changeset viewer.