Changeset 173 for trunk


Ignore:
Timestamp:
02/24/05 17:12:09 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

Merged additional SQL cleanup changes from /branches/sql-cleanup r172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r167 r173  
    204204
    205205    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";
    207209    my $count = countRows("select count(*) from ($sql) foo");
    208210    $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
     
    215217    # Query for a customer ID.  Note that we can't restrict to "numeric-only"
    216218    # 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%'";
    218220    my $count = countRows("select count(*) from ($sql) foo");
    219221    $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
     
    224226    print qq(<div class="heading">Searching for descriptions containing '$query'</div><br>\n);
    225227    # 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%'";
    227229    my $count = countRows("select count(*) from ($sql) foo");
    228230    $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
     
    241243        # /0->/9 are silly to worry about right now.  I don't think
    242244        # 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'";
    244246        queryResults($sql, $webvar{page}, 1);
    245247      } else {
    246248        print "Finding all blocks with netmask /$maskbits, leading octet(s) $net<br>\n";
    247249        # 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'";
    250252        my $count = countRows("select count(*) from ($sql) foo");
    251253        $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
     
    254256    } elsif ($query =~ /^(\d{1,3}\.){3}\d{1,3}$/) {
    255257      # 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})/);
    258258      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'");
    260263      $sth->execute;
    261264      while (my @data = $sth->fetchrow_array()) {
    262265        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);
    266268      }
    267269    } elsif ($query =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.?$/) {
    268270      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%'";
    270273      my $count = countRows("select count(*) from ($sql) foo");
    271274      $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
Note: See TracChangeset for help on using the changeset viewer.