Skip to content

Commit fd3f1cf

Browse files
committed
ipv6 search fixes
2 parents eb742f4 + 972935a commit fd3f1cf

6 files changed

Lines changed: 227 additions & 93 deletions

File tree

app/tools/search/search-results-export.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@
2323
# fetch search term
2424
$search_term = $_REQUEST['search_term'];
2525

26-
# check if mac address or ip address
27-
if(strlen($search_term)==17 && substr_count($search_term, ":") == 5)
28-
{
29-
$type = "mac"; //count : -> must be 5
26+
//initialize Pear IPv6 object
27+
require_once( dirname(__FILE__) . '/../../../functions/PEAR/Net/IPv6.php' );
28+
$Net_IPv6 = new Net_IPv6();
29+
30+
// ipv6 ?
31+
if ($Net_IPv6->checkIPv6($search_term)!=false) {
32+
$type = "IPv6";
3033
}
31-
else if(strlen($search_term) == 12 && (substr_count($search_term, ":") == 0) && (substr_count($search_term, ".") == 0))
32-
{
33-
$type = "mac"; //no dots or : -> mac without :
34+
// check if mac address or ip address
35+
elseif(strlen($search_term)==17 && substr_count($search_term, ":") == 5) {
36+
$type = "mac"; //count : -> must be 5
3437
}
35-
else
36-
{
37-
$type = $Addresses->identify_address( $search_term ); //identify address type
38+
else if(strlen($search_term) == 12 && (substr_count($search_term, ":") == 0) && (substr_count($search_term, ".") == 0)){
39+
$type = "mac"; //no dots or : -> mac without :
40+
}
41+
else {
42+
$type = $Addresses->identify_address( $search_term ); //identify address type
3843
}
39-
4044

4145
# reformat if IP address for search
4246
if ($type == "IPv4") { $search_term_edited = $Tools->reformat_IPv4_for_search ($search_term); } //reformat the IPv4 address!
@@ -61,7 +65,7 @@
6165
# search addresses
6266
if(@$_REQUEST['addresses']=="on") { $result_addresses = $Tools->search_addresses($search_term, $search_term_edited['high'], $search_term_edited['low']); }
6367
# search subnets
64-
if(@$_REQUEST['subnets']=="on") { $result_subnets = $Tools->search_subnets($search_term, $search_term_edited['high'], $search_term_edited['low']); }
68+
if(@$_REQUEST['subnets']=="on") { $result_subnets = $Tools->search_subnets($search_term, $search_term_edited['high'], $search_term_edited['low'], $_REQUEST['ip']); }
6569
# search vlans
6670
if(@$_REQUEST['vlans']=="on") { $result_vlans = $Tools->search_vlans($search_term); }
6771

app/tools/search/search-results.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
<script type="text/javascript">
2-
/* fix for ajax-loading tooltips */
3-
$('body').tooltip({ selector: '[rel=tooltip]' });
4-
</script>
5-
61
<?php
72

83
/*
94
* Script to display search results
105
**********************************/
116

127
# for ajax-loaded pages
13-
if(!is_object($Subnets)) {
8+
if(!isset($Subnets)) {
149
# include required scripts
1510
require( dirname(__FILE__) . '/../../../functions/functions.php' );
1611

@@ -26,6 +21,8 @@
2621

2722
# set searchterm
2823
if(isset($_REQUEST['ip'])) {
24+
// trim
25+
$_REQUEST['ip'] = trim($_REQUEST['ip']);
2926
// escape
3027
$_REQUEST['ip'] = htmlspecialchars($_REQUEST['ip']);
3128

@@ -38,15 +35,24 @@
3835
# change * to % for database wildchar
3936
$search_term = str_replace("*", "%", $search_term);
4037

41-
# check if mac address or ip address
42-
if(strlen($search_term)==17 && substr_count($search_term, ":") == 5) {
43-
$type = "mac"; //count : -> must be 5
38+
39+
//initialize Pear IPv6 object
40+
require_once( dirname(__FILE__) . '/../../../functions/PEAR/Net/IPv6.php' );
41+
$Net_IPv6 = new Net_IPv6();
42+
43+
// ipv6 ?
44+
if ($Net_IPv6->checkIPv6($search_term)!=false) {
45+
$type = "IPv6";
46+
}
47+
// check if mac address or ip address
48+
elseif(strlen($search_term)==17 && substr_count($search_term, ":") == 5) {
49+
$type = "mac"; //count : -> must be 5
4450
}
4551
else if(strlen($search_term) == 12 && (substr_count($search_term, ":") == 0) && (substr_count($search_term, ".") == 0)){
46-
$type = "mac"; //no dots or : -> mac without :
52+
$type = "mac"; //no dots or : -> mac without :
4753
}
48-
else{
49-
$type = $Addresses->identify_address( $search_term ); //identify address type
54+
else {
55+
$type = $Addresses->identify_address( $search_term ); //identify address type
5056
}
5157

5258
# reformat if IP address for search
@@ -82,7 +88,7 @@
8288
# search addresses
8389
if(@$_REQUEST['addresses']=="on" && strlen($_REQUEST['ip'])>0) { $result_addresses = $Tools->search_addresses($search_term, $search_term_edited['high'], $search_term_edited['low']); }
8490
# search subnets
85-
if(@$_REQUEST['subnets']=="on" && strlen($_REQUEST['ip'])>0) { $result_subnets = $Tools->search_subnets($search_term, $search_term_edited['high'], $search_term_edited['low']); }
91+
if(@$_REQUEST['subnets']=="on" && strlen($_REQUEST['ip'])>0) { $result_subnets = $Tools->search_subnets($search_term, $search_term_edited['high'], $search_term_edited['low'], $_REQUEST['ip']); }
8692
# search vlans
8793
if(@$_REQUEST['vlans']=="on" && strlen($_REQUEST['ip'])>0) { $result_vlans = $Tools->search_vlans($search_term); }
8894

@@ -103,6 +109,12 @@
103109
?>
104110

105111

112+
<script type="text/javascript">
113+
/* fix for ajax-loading tooltips */
114+
$('body').tooltip({ selector: '[rel=tooltip]' });
115+
</script>
116+
117+
106118
<!-- search result subnet -->
107119
<?php if(@$_REQUEST['subnets']=="on") { ?>
108120
<br>

0 commit comments

Comments
 (0)