Changeset 234 for trunk


Ignore:
Timestamp:
04/18/05 16:27:21 (19 years ago)
Author:
Kris Deugau
Message:

/trunk

Merge new search capability from /branches/new-search-20050223

r171-197 to trunk.

Changes to header.inc conflicted (minor, patched, expected)
Removals from main.cgi conflicted (not sure why)
search.cgi updated with ACL bits (for header)
Proper permissions set on search.cgi - really!

Location:
trunk
Files:
4 edited
2 copied

Legend:

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

    r233 r234  
    4646# Headerize!  Make sure we replace the $$EXTRA0$$ bit as needed.
    4747printHeader('', ($IPDBacl{$authuser} =~ /a/ ?
    48         '<a href="/ip/cgi-bin/main.cgi?action=assign">Add new assignment</a>' : ''
     48        '<td align=right><a href="/ip/cgi-bin/main.cgi?action=assign">Add new assignment</a>' : ''
    4949        ));
    5050
    5151
    5252#prototypes
    53 sub viewBy($$);         # feed it the category and query
    54 sub queryResults($$$);  # args is the sql, the page# and the rowCount
    5553# Needs rewrite/rename
    5654sub countRows($);       # returns first element of first row of passed SQL
     
    132130elsif($webvar{action} eq 'listpool') {
    133131  listPool();
    134 }
    135 elsif($webvar{action} eq 'search') {
    136   if (!$webvar{input}) {
    137     # No search term.  Display everything.
    138     viewBy('all', '');
    139   } else {
    140     # Search term entered.  Display matches.
    141     # We should really sanitize $webvar{input}, no?
    142     viewBy($webvar{searchfor}, $webvar{input});
    143   }
    144132}
    145133
     
    198186
    199187
    200 sub viewBy($$) {
    201   my ($category,$query) = @_;
    202 
    203   # Local variables
    204   my $sql;
    205 
    206 #print "<pre>\n";
    207 
    208 #print "start querysub: query '$query'\n";
    209 # this may happen with more than one subcategory.  Unlikely, but possible.
    210 
    211   # Calculate start point for LIMIT clause
    212   my $offset = ($webvar{page}-1)*$RESULTS_PER_PAGE;
    213 
    214 # Possible cases:
    215 # 1) Partial IP/subnet.  Treated as "first-three-octets-match" in old IPDB,
    216 #    I should be able to handle it similarly here.
    217 # 2a) CIDR subnet.  Treated more or less as such in old IPDB.
    218 # 2b) CIDR netmask.  Not sure how it's treated.
    219 # 3) Customer ID.  Not handled in old IPDB
    220 # 4) Description.
    221 # 5) Invalid data which might be interpretable as an IP or something, but
    222 #    which probably shouldn't be for reasons of sanity.
    223 
    224   if ($category eq 'all') {
    225 
    226     print qq(<div class="heading">Showing all netblock and static-IP allocations</div><br>\n);
    227 
    228     # Need to assemble SQL query in this order to avoid breaking things.
    229     $sql = "select cidr,custid,type,city,description from searchme";
    230     my $count = countRows("select count(*) from ($sql) foo");
    231     $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
    232     queryResults($sql, $webvar{page}, $count);
    233 
    234   } elsif ($category eq 'cust') {
    235 
    236     print qq(<div class="heading">Searching for Customer IDs containing '$query'</div><br>\n);
    237 
    238     # Query for a customer ID.  Note that we can't restrict to "numeric-only"
    239     # as we have non-numeric custIDs in the legacy data.  :/
    240     $sql = "select cidr,custid,type,city,description from searchme where custid ilike '%$query%'";
    241     my $count = countRows("select count(*) from ($sql) foo");
    242     $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
    243     queryResults($sql, $webvar{page}, $count);
    244 
    245   } elsif ($category eq 'desc') {
    246 
    247     print qq(<div class="heading">Searching for descriptions containing '$query'</div><br>\n);
    248     # Query based on description (includes "name" from old DB).
    249     $sql = "select cidr,custid,type,city,description from searchme where description ilike '%$query%'";
    250     my $count = countRows("select count(*) from ($sql) foo");
    251     $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
    252     queryResults($sql, $webvar{page}, $count);
    253 
    254   } elsif ($category =~ /ipblock/) {
    255 
    256     # Query is for a partial IP, a CIDR block in some form, or a flat IP.
    257     print qq(<div class="heading">Searching for IP-based matches on '$query'</div><br>\n);
    258 
    259     $query =~ s/\s+//g;
    260     if ($query =~ /\//) {
    261       # 209.91.179/26 should show all /26 subnets in 209.91.179
    262       my ($net,$maskbits) = split /\//, $query;
    263       if ($query =~ /^(\d{1,3}\.){3}\d{1,3}\/\d{2}$/) {
    264         # /0->/9 are silly to worry about right now.  I don't think
    265         # we'll be getting a class A anytime soon.  <g>
    266         $sql = "select cidr,custid,type,city,description from searchme where cidr='$query'";
    267         queryResults($sql, $webvar{page}, 1);
    268       } else {
    269         print "Finding all blocks with netmask /$maskbits, leading octet(s) $net<br>\n";
    270         # Partial match;  beginning of subnet and maskbits are provided
    271         $sql = "select cidr,custid,type,city,description from searchme where ".
    272                 "text(cidr) like '$net%' and text(cidr) like '%$maskbits'";
    273         my $count = countRows("select count(*) from ($sql) foo");
    274         $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
    275         queryResults($sql, $webvar{page}, $count);
    276       }
    277     } elsif ($query =~ /^(\d{1,3}\.){3}\d{1,3}$/) {
    278       # Specific IP address match
    279       my $sfor = new NetAddr::IP $query;
    280 # We do this convoluted roundabout way of finding things in order
    281 # to bring up matches for single IPs that are within a static block;
    282 # we want to show both the "container" block and the static IP itself.
    283       $sth = $ip_dbh->prepare("select cidr from searchme where cidr >>= '$sfor'");
    284       $sth->execute;
    285       while (my @data = $sth->fetchrow_array()) {
    286         my $cidr = new NetAddr::IP $data[0];
    287         queryResults("select cidr,custid,type,city,description from searchme where ".
    288                 "cidr='$cidr'", $webvar{page}, 1);
    289       }
    290     } elsif ($query =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.?$/) {
    291       print "Finding matches where the first three octets are $query<br>\n";
    292       $sql = "select cidr,custid,type,city,description from searchme where ".
    293                 "text(cidr) like '$query%'";
    294       my $count = countRows("select count(*) from ($sql) foo");
    295       $sql .= " order by cidr limit $RESULTS_PER_PAGE offset $offset";
    296       queryResults($sql, $webvar{page}, $count);
    297     } else {
    298       # This shouldn't happen, but if it does, whoever gets it deserves what they get...
    299       printError("Invalid query.");
    300     }
    301   } else {
    302     # This shouldn't happen, but if it does, whoever gets it deserves what they get...
    303     printError("Invalid searchfor.");
    304   }
    305 } # viewBy
    306 
    307 
    308188# args are: a reference to an array with the row to be printed and the
    309189# class(stylesheet) to use for formatting.
     
    328208  print "</tr>";
    329209} # printRow
    330 
    331 
    332 # Display certain types of search query.  Note that this can't be
    333 # cleanly reused much of anywhere else as the data isn't neatly tabulated.
    334 # This is tied to the search sub tightly enough I may just gut it and provide
    335 # more appropriate tables directly as needed.
    336 sub queryResults($$$) {
    337   my ($sql, $pageNo, $rowCount) = @_;
    338   my $offset = 0;
    339   $offset = $1 if($sql =~ m/.*limit\s+(.*),.*/);
    340 
    341   my $sth = $ip_dbh->prepare($sql);
    342   $sth->execute();
    343 
    344   startTable('Allocation','CustID','Type','City','Description/Name');
    345   my $count = 0;
    346 
    347   while (my @data = $sth->fetchrow_array) {
    348     # cidr,custid,type,city,description
    349     # Prefix subblocks with "Sub "
    350     my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
    351         qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    352         $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);
    353     # Allow listing of pool if desired/required.
    354     if ($data[2] =~ /^.[pd]$/) {
    355       $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
    356         "&pool=$data[0]\">List IPs</a>";
    357     }
    358     printRow(\@row, 'color1', 1) if ($count%2==0);
    359     printRow(\@row, 'color2', 1) if ($count%2!=0);
    360     $count++;
    361   }
    362 
    363   # Have to think on this call, it's primarily to clean up unfetched rows from a select.
    364   # In this context it's probably a good idea.
    365   $sth->finish();
    366 
    367   my $upper = $offset+$count;
    368   print "<tr><td colspan=10 bgcolor=white class=regular>Records found: $rowCount<br><i>Displaying: $offset - $upper</i></td></tr>\n";
    369   print "</table></center>\n";
    370 
    371   # print the page thing..
    372   if ($rowCount > $RESULTS_PER_PAGE) {
    373     my $pages = ceil($rowCount/$RESULTS_PER_PAGE);
    374     print qq(<div class="center"> Page: );
    375     for (my $i = 1; $i <= $pages; $i++) {
    376       if ($i == $pageNo) {
    377         print "<b>$i&nbsp;</b>\n";
    378       } else {
    379         print qq(<a href="/ip/cgi-bin/main.cgi?page=$i&input=$webvar{input}&action=search&searchfor=$webvar{searchfor}">$i</a>&nbsp;\n);
    380       }
    381     }
    382     print "</div>";
    383   }
    384 } # queryResults
    385210
    386211
  • trunk/header.inc

    r233 r234  
    4040<tr class="color1">
    4141<td width=10></td>
    42 <form method="POST" action="/ip/cgi-bin/main.cgi">
    43 <td>Search:
     42<form method="POST" action="/ip/cgi-bin/search.cgi">
     43<td width=390>Quick Search:
    4444<input type="text" name="input" size="20" maxlength="50" class="regular">
    45 <input type=radio name="searchfor" value="ipblock">IP/IP block
    46 <input type=radio name="searchfor" value="desc" checked=yes>Description
    47 <input type=radio name="searchfor" value="cust">Customer ID
    4845<input type=hidden name=page value="1">
    49 <input type=hidden name=action value="search">
     46<input type=hidden name=stype value="q">
    5047<input type=submit value="Go!" class="heading">
    5148<input type="button" value=" Help? " onclick="openHelp()" class="regular">
    52 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
     49</td><td width=10></td><td><a href="/ip/cgi-bin/search.cgi">Complex Search</a></td>
     50<td width=60></td>
    5351$$EXTRA0$$
    54 </td>
    5552</form>
    5653</tr>
  • trunk/help.html

    r4 r234  
    1111<table class="regular">
    1212
    13 <tr><td class="heading">Searches:</td><tr>
     13<tr><td class="heading">Quick Searches:</td><tr>
    1414
    1515<tr class="color1">
  • trunk/ipdb.css

    r199 r234  
    5050.regular {
    5151        font-family: Verdana, Arial, Helvetica, sans-serif;
    52         font-size: 100%;
     52        font-size: 90%;
    5353}
    5454
Note: See TracChangeset for help on using the changeset viewer.