Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add MAC address lookup widget
- Loading branch information
Showing
6 changed files
with
95 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
# required functions | ||
if (!isset($User)) { | ||
require_once(dirname(__FILE__) . '/../../../functions/functions.php'); | ||
# classes | ||
$Database = new Database_PDO; | ||
$User = new User ($Database); | ||
} | ||
|
||
# user must be authenticated | ||
$User->check_user_session(); | ||
|
||
# if direct request that redirect to tools page | ||
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != "XMLHttpRequest") { | ||
header("Location: " . create_link("tools", "mac-lookup")); | ||
} | ||
?> | ||
|
||
<script> | ||
$(document).ready(function() { | ||
if ($("[rel=tooltip]").length) { | ||
$("[rel=tooltip]").tooltip(); | ||
} | ||
|
||
//submit form | ||
$('form#mac_lookup').submit(function() { | ||
var macvendorData = $(this).serialize(); | ||
$.post('app/tools/mac-lookup/results.php', macvendorData, function(data) { | ||
$('div.macvendorResult').html(data).fadeIn('fast'); | ||
}).fail(function(jqxhr, textStatus, errorThrown) { | ||
showError(jqxhr.statusText + "<br>Status: " + textStatus + "<br>Error: " + errorThrown); | ||
}); | ||
return false; | ||
}); | ||
}); | ||
</script> | ||
|
||
<div class="container-fluid" style='padding-top:5px'> | ||
|
||
<!-- search form --> | ||
<form id="mac_lookup" name="search" class='form-inline' role="form" style="margin-bottom:20px;" method="post"> | ||
<div class='input-group'> | ||
<div class='form-group'> | ||
<input class="search input-md form-control" name="mac" placeholder="<?php print _('MAC address'); ?>" value='<?php print @escape_input($_POST['mac']); ?>' type="text" autofocus="autofocus" style='width:250px;'> | ||
<span class="input-group-btn"> | ||
<button type="submit" class="btn btn-md btn-default"><?php print _('search'); ?></button> | ||
</span> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<hr> | ||
|
||
|
||
<div class="macvendorResult"> | ||
<span class="text-muted"><?php print _('Please enter valid MAC address'); ?></span> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
<?php | ||
if (!isset($User)) { | ||
require_once(dirname(__FILE__) . '/../../../functions/functions.php'); | ||
# classes | ||
$Database = new Database_PDO; | ||
$User = new User ($Database); | ||
$Result = new Result(); | ||
} | ||
|
||
# verify that user is logged in | ||
$User->check_user_session(); | ||
|
||
// trim and escape | ||
$mac = escape_input(trim($_POST['mac'])); | ||
$mac = isset($_POST['mac']) ? escape_input(trim($_POST['mac'])) : ""; | ||
|
||
// validate | ||
if($User->validate_mac ($mac)===false) { | ||
$Result->show("warning", _("Invalid MAC address provided")." - ".$mac, false); | ||
} | ||
else { | ||
if ($User->validate_mac($mac) === false) { | ||
$Result->show("warning", _("Invalid MAC address provided") . " - " . $mac, false); | ||
} else { | ||
// check | ||
$mac_vendor = $User->get_mac_address_vendor_details ($mac); | ||
$mac_vendor = $User->get_mac_address_vendor_details($mac, $prefix); | ||
|
||
if($mac_vendor=="") { | ||
$Result->show("info", _("No matches found for prefix")." ".$mac, false); | ||
} | ||
else { | ||
$mac = strtoupper($User->reformat_mac_address ($mac, 1)); | ||
$mac_partial = explode(":", $mac); | ||
if ($mac_vendor == "") { | ||
$Result->show("info", _("No matches found for prefix") . " " . $mac, false); | ||
} else { | ||
$mac = strtoupper($User->reformat_mac_address($mac, 1)); | ||
|
||
print "<div style='font-size:16px;'>Vendor: <strong>".$mac_vendor."</strong></div><hr>"; | ||
print "Prefix: ".$mac_partial[0].":".$mac_partial[1].":".$mac_partial[2]."<br>"; | ||
print "MAC: ".$mac; | ||
print "<div style='font-size:16px;'>Vendor: <strong class='clipboard'>" . escape_input($mac_vendor) . "</strong></div><hr>"; | ||
print "Prefix: " . escape_input($prefix) . "<br>"; | ||
print "MAC: " . $mac; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters