- Timestamp:
- 04/18/05 16:27:21 (20 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/main.cgi
r233 r234 46 46 # Headerize! Make sure we replace the $$EXTRA0$$ bit as needed. 47 47 printHeader('', ($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>' : '' 49 49 )); 50 50 51 51 52 52 #prototypes 53 sub viewBy($$); # feed it the category and query54 sub queryResults($$$); # args is the sql, the page# and the rowCount55 53 # Needs rewrite/rename 56 54 sub countRows($); # returns first element of first row of passed SQL … … 132 130 elsif($webvar{action} eq 'listpool') { 133 131 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 }144 132 } 145 133 … … 198 186 199 187 200 sub viewBy($$) {201 my ($category,$query) = @_;202 203 # Local variables204 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 clause212 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 IPDB220 # 4) Description.221 # 5) Invalid data which might be interpretable as an IP or something, but222 # 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.179262 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 think265 # 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 provided271 $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 match279 my $sfor = new NetAddr::IP $query;280 # We do this convoluted roundabout way of finding things in order281 # 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 } # viewBy306 307 308 188 # args are: a reference to an array with the row to be printed and the 309 189 # class(stylesheet) to use for formatting. … … 328 208 print "</tr>"; 329 209 } # printRow 330 331 332 # Display certain types of search query. Note that this can't be333 # 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 provide335 # 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,description349 # 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] .= ' <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 </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> \n);380 }381 }382 print "</div>";383 }384 } # queryResults385 210 386 211 -
trunk/header.inc
r233 r234 40 40 <tr class="color1"> 41 41 <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: 44 44 <input type="text" name="input" size="20" maxlength="50" class="regular"> 45 <input type=radio name="searchfor" value="ipblock">IP/IP block46 <input type=radio name="searchfor" value="desc" checked=yes>Description47 <input type=radio name="searchfor" value="cust">Customer ID48 45 <input type=hidden name=page value="1"> 49 <input type=hidden name= action value="search">46 <input type=hidden name=stype value="q"> 50 47 <input type=submit value="Go!" class="heading"> 51 48 <input type="button" value=" Help? " onclick="openHelp()" class="regular"> 52 49 </td><td width=10></td><td><a href="/ip/cgi-bin/search.cgi">Complex Search</a></td> 50 <td width=60></td> 53 51 $$EXTRA0$$ 54 </td>55 52 </form> 56 53 </tr> -
trunk/help.html
r4 r234 11 11 <table class="regular"> 12 12 13 <tr><td class="heading"> Searches:</td><tr>13 <tr><td class="heading">Quick Searches:</td><tr> 14 14 15 15 <tr class="color1"> -
trunk/ipdb.css
r199 r234 50 50 .regular { 51 51 font-family: Verdana, Arial, Helvetica, sans-serif; 52 font-size: 100%;52 font-size: 90%; 53 53 } 54 54
Note:
See TracChangeset
for help on using the changeset viewer.