mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #729 from laf/bootgrid-ipsearch
Updated search tables for ipv4,ipv6,mac and arp
This commit is contained in:
100
html/includes/table/address-search.inc.php
Normal file
100
html/includes/table/address-search.inc.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
$where = 1;
|
||||
$param = array();
|
||||
|
||||
if ($_POST['search_type'] == 'ipv4') {
|
||||
$sql = " FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D, `ipv4_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id ";
|
||||
} elseif ($_POST['search_type'] == 'ipv6') {
|
||||
$sql = " FROM `ipv6_addresses` AS A, `ports` AS I, `devices` AS D, `ipv6_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id ";
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
$sql = " FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE ? ";
|
||||
$param = array("%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%");
|
||||
}
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= " AND I.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
if ($_POST['interface']) {
|
||||
$sql .= " AND I.ifDescr LIKE '?'";
|
||||
$param[] = $_POST['interface'];
|
||||
}
|
||||
|
||||
if ($_POST['search_type'] == 'ipv4') {
|
||||
$count_sql = "SELECT COUNT(`ipv4_address_id`) $sql";
|
||||
} elseif ($_POST['search_type'] == 'ipv6') {
|
||||
$count_sql = "SELECT COUNT(`ipv6_address_id`) $sql";
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
$count_sql = "SELECT COUNT(`port_id`) $sql";
|
||||
}
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`hostname` ASC';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT *,`I`.`ifDescr` AS `interface` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $interface) {
|
||||
if ($_POST['address']) {
|
||||
list($addy, $mask) = explode("/", $_POST['address']);
|
||||
if ($_POST['search_type']) {
|
||||
$tmp_mask = '128';
|
||||
if (!Net_IPv6::isInNetmask($interface['ipv6_address'], $addy, $mask)) {
|
||||
$ignore = 1;
|
||||
} else {
|
||||
$ignore = 0;
|
||||
}
|
||||
} else {
|
||||
$tmp_mask = '32';
|
||||
if (!match_network($addy . "/" . $mask, $interface['ipv4_address'])) {
|
||||
$ignore = 1;
|
||||
}
|
||||
}
|
||||
if (!$mask) {
|
||||
$mask = $tmp_mask;
|
||||
}
|
||||
}
|
||||
if (!$ignore) {
|
||||
$speed = humanspeed($interface['ifSpeed']);
|
||||
$type = humanmedia($interface['ifType']);
|
||||
|
||||
if ($_POST['search_type'] == 'ipv6') {
|
||||
list($prefix, $length) = explode("/", $interface['ipv6_network']);
|
||||
$address = Net_IPv6::compress($interface['ipv6_address']) . '/'.$length;
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
$address = formatMac($interface['ifPhysAddress']);
|
||||
} else {
|
||||
list($prefix, $length) = explode("/", $interface['ipv4_network']);
|
||||
$address = $interface['ipv4_address'] . '/' .$length;
|
||||
}
|
||||
|
||||
if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
|
||||
$error_img = generate_port_link($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else {
|
||||
$error_img = "";
|
||||
}
|
||||
if (port_permitted($interface['port_id'])) {
|
||||
$interface = ifLabel ($interface, $interface);
|
||||
$response[] = array('hostname'=>generate_device_link($interface),
|
||||
'interface'=>generate_port_link($interface) . ' ' . $error_img,
|
||||
'address'=>$address,
|
||||
'description'=>$interface['ifAlias']);
|
||||
}
|
||||
}
|
||||
unset($ignore);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
echo _json_encode($output);
|
||||
78
html/includes/table/arp-search.inc.php
Normal file
78
html/includes/table/arp-search.inc.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
$param = array();
|
||||
|
||||
$sql = " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id ";
|
||||
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == "ip") {
|
||||
$sql .= " AND `ipv4_address` LIKE ?";
|
||||
$param = array("%".trim($_POST['address'])."%");
|
||||
} elseif (isset($_POST['searchby']) && $_POST['searchby'] == "mac") {
|
||||
$sql .= " AND `mac_address` LIKE ?";
|
||||
$param = array("%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%");
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= " AND P.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`M`.`port_id`) $sql";
|
||||
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`hostname` ASC';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $entry) {
|
||||
if (!$ignore) {
|
||||
|
||||
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
|
||||
$error_img = generate_port_link($entry,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else {
|
||||
$error_img = "";
|
||||
}
|
||||
|
||||
$arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
|
||||
if ($arp_host) {
|
||||
$arp_name = generate_device_link($arp_host);
|
||||
} else {
|
||||
unset($arp_name);
|
||||
}
|
||||
if ($arp_host) {
|
||||
$arp_if = generate_port_link($arp_host);
|
||||
} else {
|
||||
unset($arp_if);
|
||||
}
|
||||
if ($arp_host['device_id'] == $entry['device_id']) {
|
||||
$arp_name = "Localhost";
|
||||
}
|
||||
if ($arp_host['port_id'] == $entry['port_id']) {
|
||||
$arp_if = "Local port";
|
||||
}
|
||||
$response[] = array('mac_address'=>formatMac($entry['mac_address']),
|
||||
'ipv4_address'=>$entry['ipv4_address'],
|
||||
'hostname'=>generate_device_link($entry),
|
||||
'interface'=>generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img,
|
||||
'remote_device'=>$arp_name,
|
||||
'remote_interface'=>$arp_if);
|
||||
}
|
||||
unset($ignore);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
echo _json_encode($output);
|
||||
@@ -1,139 +1,91 @@
|
||||
<?php print_optionbar_start(28); ?>
|
||||
<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>ARP Entries</strong>
|
||||
</div>
|
||||
<table id="arp-search" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="mac_address">MAC Address</th>
|
||||
<th data-column-id="ipv4_address">IP Address</th>
|
||||
<th data-column-id="hostname" data-order="asc">Device</th>
|
||||
<th data-column-id="interface">Interface</th>
|
||||
<th data-column-id="remote_device" data-sortable="false">Remote device</th>
|
||||
<th data-column-id="remote_interface" data-sortable="false">Remote interface</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<select name="device_id" id="device_id" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<script>
|
||||
|
||||
var grid = $("#arp-search").bootgrid({
|
||||
ajax: true,
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\">"+
|
||||
"<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\">"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Devices</option>"+
|
||||
<?php
|
||||
|
||||
// Select the devices only with ARP tables
|
||||
foreach (dbFetchRows("SELECT D.device_id AS device_id, `hostname` FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id GROUP BY `device_id` ORDER BY `hostname`;") as $data)
|
||||
{
|
||||
echo('<option value="'.$data['device_id'].'"');
|
||||
if ($data['device_id'] == $_POST['device_id']) { echo("selected"); }
|
||||
echo(">".$data['hostname']."</option>");
|
||||
foreach (dbFetchRows("SELECT D.device_id AS device_id, `hostname` FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id GROUP BY `device_id` ORDER BY `hostname`") as $data) {
|
||||
echo('"<option value=\"'.$data['device_id'].'\""+');
|
||||
if ($data['device_id'] == $_POST['device_id']) {
|
||||
echo('" selected "+');
|
||||
}
|
||||
echo('">'.$data['hostname'].'</option>"+');
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select name="searchby" id="searchby" class="form-control input-sm">
|
||||
<option value="mac" <?php if ($_POST['searchby'] != "ip") { echo("selected"); } ?> >MAC Address</option>
|
||||
<option value="ip" <?php if ($_POST['searchby'] == "ip") { echo("selected"); } ?> >IP Address</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="address" id="address" size=40 value="<?php echo($_POST['address']); ?>" class="form-control input-sm" placeholder="Address" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
</form>
|
||||
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"searchby\" id=\"searchby\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"mac\" "+
|
||||
<?php
|
||||
|
||||
if(isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
|
||||
$results = $_POST['results'];
|
||||
} else {
|
||||
$results = 50;
|
||||
if ($_POST['searchby'] != "ip") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
echo('<form method="post" action="search/search=arp/" id="result_form">
|
||||
<table class="table table-hover table-condensed table-striped">
|
||||
<tr>
|
||||
<td colspan="5"><strong>ARP Entries</strong></td>
|
||||
<td><select name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">');
|
||||
$result_options = array('10','50','100','250','500','1000','5000');
|
||||
foreach($result_options as $option) {
|
||||
echo "<option value='$option'";
|
||||
if($results == $option) {
|
||||
echo " selected";
|
||||
}
|
||||
echo ">$option</option>";
|
||||
}
|
||||
echo('</select></td>
|
||||
</tr>');
|
||||
|
||||
$count_query = "SELECT COUNT(M.port_id)";
|
||||
$full_query = "SELECT *";
|
||||
$query = " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D WHERE M.port_id = P.port_id AND P.device_id = D.device_id ";
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == "ip")
|
||||
{
|
||||
$query .= " AND `ipv4_address` LIKE ?";
|
||||
$param = array("%".trim($_POST['address'])."%");
|
||||
} else {
|
||||
$query .= " AND `mac_address` LIKE ?";
|
||||
$param = array("%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%");
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['device_id']))
|
||||
{
|
||||
$query .= " AND P.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
$query .= " ORDER BY M.mac_address";
|
||||
$count_query = $count_query . $query;
|
||||
$count = dbFetchCell($count_query,$param);
|
||||
if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) {
|
||||
$page_number = 1;
|
||||
} else {
|
||||
$page_number = $_POST['page_number'];
|
||||
}
|
||||
$start = ($page_number - 1) * $results;
|
||||
$full_query = $full_query . $query . " LIMIT $start,$results";
|
||||
echo('<tr><th>MAC Address</th><th>IP Address</th><th>Device</th><th>Interface</th><th>Remote device</th><th>Remote interface</th></tr>');
|
||||
foreach (dbFetchRows($full_query, $param) as $entry)
|
||||
{
|
||||
if (!$ignore)
|
||||
{
|
||||
//why are they here for?
|
||||
//$speed = humanspeed($entry['ifSpeed']);
|
||||
//$type = humanmedia($entry['ifType']);
|
||||
|
||||
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0)
|
||||
{
|
||||
$error_img = generate_port_link($entry,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else { $error_img = ""; }
|
||||
|
||||
$arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
|
||||
if ($arp_host) { $arp_name = generate_device_link($arp_host); } else { unset($arp_name); }
|
||||
if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); }
|
||||
if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = "Localhost"; }
|
||||
if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = "Local port"; }
|
||||
|
||||
echo('<tr>
|
||||
<td>' . formatMac($entry['mac_address']) . '</td>
|
||||
<td>' . $entry['ipv4_address'] . '</td>
|
||||
<td>' . generate_device_link($entry) . '</td>
|
||||
<td>' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . '</td>
|
||||
<td>'.$arp_name.'</td>
|
||||
<td>'.$arp_if.'</td>
|
||||
</tr>');
|
||||
}
|
||||
|
||||
unset($ignore);
|
||||
}
|
||||
if($count % $results > 0) {
|
||||
echo(' <tr>
|
||||
<td colspan="6" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
|
||||
</tr>');
|
||||
}
|
||||
echo('</table>
|
||||
<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
|
||||
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
|
||||
</form>');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
function updateResults(results) {
|
||||
$('#results_amount').val(results.value);
|
||||
$('#page_number').val(1);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
">MAC Address</option>"+
|
||||
"<option value=\"ip\" "+
|
||||
<?php
|
||||
|
||||
if ($_POST['searchby'] == "ip") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
?>
|
||||
|
||||
">IP Address</option>"+
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"address\" id=\"address\" value=\""+
|
||||
<?php
|
||||
|
||||
echo '"'.$_POST['address'].'"+';
|
||||
|
||||
?>
|
||||
|
||||
"\" class=\"form-control input-sm\" placeholder=\"Address\" />"+
|
||||
"</div>"+
|
||||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Search</button>"+
|
||||
"</form></span></div>"+
|
||||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
},
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "arp-search",
|
||||
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>',
|
||||
searchby: '<?php echo mres($_POST['searchby']); ?>',
|
||||
address: '<?php echo mres($_POST['address']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
});
|
||||
|
||||
function changePage(page,e) {
|
||||
e.preventDefault();
|
||||
$('#page_number').val(page);
|
||||
$('#result_form').submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,96 +1,82 @@
|
||||
<?php print_optionbar_start(28); ?>
|
||||
<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>IPv4 Addresses</strong>
|
||||
</div>
|
||||
<table id="ipv4-search" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="hostname" data-order="asc">Device</th>
|
||||
<th data-column-id="interface">Interface</th>
|
||||
<th data-column-id="address" data-sortable="false">Address</th>
|
||||
<th data-column-id="description" data-sortable="false">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<select name="device_id" id="device_id" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<script>
|
||||
|
||||
var grid = $("#ipv4-search").bootgrid({
|
||||
ajax: true,
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\">"+
|
||||
"<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\">"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Devices</option>"+
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data)
|
||||
{
|
||||
echo('<option value="'.$data['device_id'].'"');
|
||||
if ($data['device_id'] == $_POST['device_id']) { echo("selected"); }
|
||||
echo(">".$data['hostname']."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select name="interface" id="interface" class="form-control input-sm">
|
||||
<option value="">All Interfaces</option>
|
||||
<option value="Loopback%" <?php if ($_POST['interface'] == "Loopback%") { echo("selected"); } ?> >Loopbacks</option>
|
||||
<option value="Vlan%" <?php if ($_POST['interface'] == "Vlan%") { echo("selected"); } ?> >VLANs</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="address" id="address" size=40 value="<?php echo($_POST['address']); ?>" class="form-control input-sm" placeholder="IPv4 Address"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
echo('<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>IPv4 Addresses</strong>
|
||||
</div>
|
||||
<table class="table table-hover table-condensed table-striped">');
|
||||
|
||||
$query = "SELECT * FROM `ipv4_addresses` AS A, `ports` AS I, `devices` AS D, `ipv4_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id ";
|
||||
|
||||
if (is_numeric($_POST['device_id']))
|
||||
{
|
||||
$query .= " AND I.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
if ($_POST['interface'])
|
||||
{
|
||||
$query .= " AND I.ifDescr LIKE ?";
|
||||
$param[] = $_POST['interface'];
|
||||
}
|
||||
$query .= " ORDER BY A.ipv4_address";
|
||||
|
||||
echo('<tr"><th>Device</a></th><th>Interface</th><th>Address</th><th>Description</th></tr>');
|
||||
|
||||
foreach (dbFetchRows($query, $param) as $interface)
|
||||
{
|
||||
if ($_POST['address'])
|
||||
{
|
||||
list($addy, $mask) = explode("/", $_POST['address']);
|
||||
if (!$mask) { $mask = "32"; }
|
||||
if (!match_network($addy . "/" . $mask, $interface['ipv4_address'])) { $ignore = 1; }
|
||||
}
|
||||
|
||||
if (!$ignore)
|
||||
{
|
||||
$speed = humanspeed($interface['ifSpeed']);
|
||||
$type = humanmedia($interface['ifType']);
|
||||
|
||||
list($prefix, $length) = explode("/", $interface['ipv4_network']);
|
||||
|
||||
if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0)
|
||||
{
|
||||
$error_img = generate_port_link($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else { $error_img = ""; }
|
||||
|
||||
if (port_permitted($interface['port_id']))
|
||||
{
|
||||
$interface = ifLabel ($interface, $interface);
|
||||
|
||||
echo('<tr>
|
||||
<td>' . generate_device_link($interface) . '</td>
|
||||
<td>' . generate_port_link($interface) . ' ' . $error_img . '</td>
|
||||
<td>' . $interface['ipv4_address'] . '/'.$length.'</td>
|
||||
<td>' . $interface['ifAlias'] . "</td>
|
||||
</tr>\n");
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data) {
|
||||
echo('"<option value=\"'.$data['device_id'].'\""+');
|
||||
if ($data['device_id'] == $_POST['device_id']) {
|
||||
echo('" selected "+');
|
||||
}
|
||||
}
|
||||
echo('">'.$data['hostname'].'</option>"+');
|
||||
}
|
||||
?>
|
||||
"</select>"+
|
||||
"</div> "+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"interface\" id=\"interface\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Interfaces</option>"+
|
||||
"<option value=\"Loopback%\""+
|
||||
<?php
|
||||
|
||||
unset($ignore);
|
||||
if ($_POST['interface'] == "Loopback%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
|
||||
echo("</table>");
|
||||
echo("</div>");
|
||||
?>
|
||||
">Loopbacks</option>"+
|
||||
"<option value=\"Vlan%\""+
|
||||
<?php
|
||||
|
||||
if ($_POST['interface'] == "Vlan%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
|
||||
?>
|
||||
">VLANs</option>"+
|
||||
"</select>"+
|
||||
"</div> "+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"address\" id=\"address\" size=40 value=\"<?php echo($_POST['address']); ?>\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+
|
||||
"</div> "+
|
||||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Search</button>"+
|
||||
"</form></span></div>"+
|
||||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
},
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "address-search",
|
||||
search_type: "ipv4",
|
||||
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>',
|
||||
interface: '<?php echo mres($_POST['interface']); ?>',
|
||||
address: '<?php echo mres($_POST['address']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,96 +1,83 @@
|
||||
<?php print_optionbar_start(28); ?>
|
||||
<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>IPv6 Addresses</strong>
|
||||
</div>
|
||||
<table id="ipv6-search" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="hostname">Device</th>
|
||||
<th data-column-id="interface">Interface</th>
|
||||
<th data-column-id="address" data-sortable="false">Address</th>
|
||||
<th data-column-id="description" data-sortable="false">Description</th>
|
||||
</tr>
|
||||
<thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<select name="device_id" id="device_id" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<script>
|
||||
var grid = $("#ipv6-search").bootgrid({
|
||||
ajax: true,
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\">"+
|
||||
"<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\">"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Devices</option>"+
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data)
|
||||
{
|
||||
echo('<option value="'.$data['device_id'].'"');
|
||||
if ($data['device_id'] == $_POST['device_id']) { echo("selected"); }
|
||||
echo(">".$data['hostname']."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select name="interface" id="interface" class="form-control input-sm">
|
||||
<option value="">All Interfaces</option>
|
||||
<option value="Loopback%" <?php if ($_POST['interface'] == "Loopback%") { echo("selected"); } ?> >Loopbacks</option>
|
||||
<option value="Vlan%" <?php if ($_POST['interface'] == "Vlan%") { echo("selected"); } ?> >VLANs</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="address" id="address" size=40 value="<?php echo($_POST['address']); ?>" class="form-control input-sm" placeholder="IPv6 Address"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
echo('<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>IPv6 Addresses</strong>
|
||||
</div>
|
||||
<table class="table table-hover table-condensed table-striped">');
|
||||
|
||||
$query = "SELECT * FROM `ipv6_addresses` AS A, `ports` AS I, `devices` AS D, `ipv6_networks` AS N WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id ";
|
||||
|
||||
if (is_numeric($_POST['device_id']))
|
||||
{
|
||||
$query .= " AND I.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
if ($_POST['interface'])
|
||||
{
|
||||
$query .= " AND I.ifDescr LIKE ?";
|
||||
$param[] = $_POST['interface'];
|
||||
}
|
||||
$query .= " ORDER BY A.ipv6_address";
|
||||
|
||||
echo('<tr><th>Device</a></th><th>Interface</th><th>Address</th><th>Description</th></tr>');
|
||||
|
||||
foreach (dbFetchRows($query, $param) as $interface)
|
||||
{
|
||||
if ($_POST['address'])
|
||||
{
|
||||
list($addy, $mask) = explode("/", $_POST['address']);
|
||||
if (!$mask) { $mask = "128"; }
|
||||
if (!Net_IPv6::isInNetmask($interface['ipv6_address'], $addy, $mask)) { $ignore = 1; } else { $ignore = 0; }
|
||||
}
|
||||
|
||||
if (!$ignore)
|
||||
{
|
||||
$speed = humanspeed($interface['ifSpeed']);
|
||||
$type = humanmedia($interface['ifType']);
|
||||
|
||||
list($prefix, $length) = explode("/", $interface['ipv6_network']);
|
||||
|
||||
if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0)
|
||||
{
|
||||
$error_img = generate_port_link($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else { $error_img = ""; }
|
||||
|
||||
if (port_permitted($interface['port_id']))
|
||||
{
|
||||
$interface = ifLabel ($interface, $interface);
|
||||
|
||||
echo('<tr>
|
||||
<td>' . generate_device_link($interface) . '</td>
|
||||
<td>' . generate_port_link($interface, makeshortif(fixifname($interface['ifDescr']))) . ' ' . $error_img . '</td>
|
||||
<td>' . Net_IPv6::compress($interface['ipv6_address']) . '/'.$length.'</td>
|
||||
<td>' . $interface['ifAlias'] . "</td>
|
||||
</tr>\n");
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data) {
|
||||
echo('"<option value=\"'.$data['device_id'].'\""+');
|
||||
if ($data['device_id'] == $_POST['device_id']) {
|
||||
echo('" selected"+');
|
||||
}
|
||||
}
|
||||
echo('">'.$data['hostname'].'</option>"+');
|
||||
}
|
||||
?>
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"interface\" id=\"interface\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Interfaces</option>"+
|
||||
"<option value=\"Loopback%\""+
|
||||
<?php
|
||||
|
||||
unset($ignore);
|
||||
if ($_POST['interface'] == "Loopback%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
|
||||
echo("</table>");
|
||||
echo('</div>');
|
||||
?>
|
||||
|
||||
">Loopbacks</option>"+
|
||||
"<option value=\"Vlan%\""+
|
||||
<?php
|
||||
|
||||
if ($_POST['interface'] == "Vlan%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
">VLANs</option>"+
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"address\" id=\"address\" size=40 value=\"<?php echo($_POST['address']); ?>\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+
|
||||
"</div>"+
|
||||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Search</button>"+
|
||||
"</form></span></div>"+
|
||||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
},
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "address-search",
|
||||
search_type: "ipv6",
|
||||
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>',
|
||||
interface: '<?php echo mres($_POST['interface']); ?>',
|
||||
address: '<?php echo mres($_POST['address']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,88 +1,87 @@
|
||||
<?php print_optionbar_start(28); ?>
|
||||
<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>MAC Addresses</strong>
|
||||
</div>
|
||||
<table id="mac-search" class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="hostname" data-order="asc">Device</th>
|
||||
<th data-column-id="interface">Interface</th>
|
||||
<th data-column-id="address" data-sortable="false">MAC Address</th>
|
||||
<th data-column-id="description" data-sortable="false">Description</th></tr>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<form method="post" action="" class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<select name="device_id" id="device_id" class="form-control input-sm">
|
||||
<option value="">All Devices</option>
|
||||
<script>
|
||||
|
||||
var grid = $("#mac-search").bootgrid({
|
||||
ajax: true,
|
||||
templates: {
|
||||
header: "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+
|
||||
"<div class=\"col-sm-9 actionBar\"><span class=\"pull-left\">"+
|
||||
"<form method=\"post\" action=\"\" class=\"form-inline\" role=\"form\">"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"device_id\" id=\"device_id\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Devices</option>"+
|
||||
<?php
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data)
|
||||
{
|
||||
echo('<option value="'.$data['device_id'].'"');
|
||||
if ($data['device_id'] == $_POST['device_id']) { echo("selected"); }
|
||||
echo(">".$data['hostname']."</option>");
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select name="interface" id="interface" class="form-control input-sm">
|
||||
<option value="">All Interfaces</option>
|
||||
<option value="Loopback%" <?php if ($_POST['interface'] == "Loopback%") { echo("selected"); } ?> >Loopbacks</option>
|
||||
<option value="Vlan%" <?php if ($_POST['interface'] == "Vlan%") { echo("selected"); } ?> >VLANs</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="address" id="address" size=40 value="<?php echo($_POST['address']); ?>" class="form-control input-sm" placeholder="Mac Address"/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default input-sm">Search</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
echo('<div class="panel panel-default panel-condensed">
|
||||
<div class="panel-heading">
|
||||
<strong>MAC Addresses</strong>
|
||||
</div>
|
||||
<table class="table table-hover table-condensed table-striped">');
|
||||
|
||||
$query = "SELECT * FROM `ports` AS P, `devices` AS D WHERE P.device_id = D.device_id ";
|
||||
$query .= "AND `ifPhysAddress` LIKE ?";
|
||||
$param = array("%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%");
|
||||
|
||||
if (is_numeric($_POST['device_id']))
|
||||
{
|
||||
$query .= " AND P.device_id = ?";
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
if ($_POST['interface'])
|
||||
{
|
||||
$query .= " AND P.ifDescr LIKE ?";
|
||||
$param[] = $_POST['interface'];
|
||||
}
|
||||
$query .= " ORDER BY P.ifPhysAddress";
|
||||
|
||||
echo('<tr><th>Device</a></th><th>Interface</th><th>MAC Address</th><th>Description</th></tr>');
|
||||
foreach (dbFetchRows($query, $param) as $entry)
|
||||
{
|
||||
if (!$ignore)
|
||||
{
|
||||
$speed = humanspeed($entry['ifSpeed']);
|
||||
$type = humanmedia($entry['ifType']);
|
||||
|
||||
if ($entry['in_errors'] > 0 || $entry['out_errors'] > 0)
|
||||
{
|
||||
$error_img = generate_port_link($entry,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else { $error_img = ""; }
|
||||
|
||||
if (port_permitted($entry['port_id']))
|
||||
{
|
||||
$interface = ifLabel ($interface, $interface);
|
||||
|
||||
echo('<tr>
|
||||
<td>' . generate_device_link($entry) . '</td>
|
||||
<td>' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . '</td>
|
||||
<td>' . formatMac($entry['ifPhysAddress']) . '</td>
|
||||
<td>' . $entry['ifAlias'] . "</td>
|
||||
</tr>\n");
|
||||
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data) {
|
||||
echo('"<option value=\"'.$data['device_id'].'\""+');
|
||||
if ($data['device_id'] == $_POST['device_id']) {
|
||||
echo('" selected "+');
|
||||
}
|
||||
}
|
||||
|
||||
unset($ignore);
|
||||
echo('">'.$data['hostname'].'</option>"+');
|
||||
}
|
||||
|
||||
echo("</table>");
|
||||
echo('</div>');
|
||||
|
||||
?>
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<select name=\"interface\" id=\"interface\" class=\"form-control input-sm\">"+
|
||||
"<option value=\"\">All Interfaces</option>"+
|
||||
"<option value=\"Loopback%\" "+
|
||||
<?php
|
||||
|
||||
if ($_POST['interface'] == "Loopback%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
?>
|
||||
">Loopbacks</option>"+
|
||||
"<option value=\"Vlan%\""+
|
||||
<?php
|
||||
|
||||
if ($_POST['interface'] == "Vlan%") {
|
||||
echo('" selected "+');
|
||||
}
|
||||
?>
|
||||
|
||||
">VLANs</option>"+
|
||||
"</select>"+
|
||||
"</div>"+
|
||||
"<div class=\"form-group\">"+
|
||||
"<input type=\"text\" name=\"address\" id=\"address\" value=\""+
|
||||
<?php
|
||||
|
||||
echo($_POST['address']);
|
||||
?>
|
||||
|
||||
"\" class=\"form-control input-sm\" placeholder=\"Mac Address\"/>"+
|
||||
"</div>"+
|
||||
"<button type=\"submit\" class=\"btn btn-default input-sm\">Search</button>"+
|
||||
"</form></span></div>"+
|
||||
"<div class=\"col-sm-3 actionBar\"><p class=\"{{css.actions}}\"></p></div></div></div>"
|
||||
},
|
||||
post: function ()
|
||||
{
|
||||
return {
|
||||
id: "address-search",
|
||||
search_type: "mac",
|
||||
device_id: '<?php echo htmlspecialchars($_POST['device_id']); ?>',
|
||||
interface: '<?php echo mres($_POST['interface']); ?>',
|
||||
address: '<?php echo mres($_POST['address']); ?>'
|
||||
};
|
||||
},
|
||||
url: "/ajax_table.php"
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user