add multiple ports support

This commit is contained in:
leiweibau
2022-07-28 20:22:36 +02:00
parent e3564ac067
commit eaf84be825

View File

@@ -68,10 +68,10 @@ echo $_REQUEST['device_id'];
<!-- Main content ---------------------------------------------------------- --> <!-- Main content ---------------------------------------------------------- -->
<section class="content"> <section class="content">
<div class="box box-default collapsed-box"> <div class="box box-default collapsed-box">
<div class="box-header with-border"> <div class="box-header with-border" data-widget="collapse">
<h3 class="box-title">Verwalte Netzwerk-Geräte</h3> <h3 class="box-title">Verwalte Netzwerk-Geräte</h3>
<div class="box-tools pull-right"> <div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button> <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div> </div>
</div> </div>
<!-- /.box-header --> <!-- /.box-header -->
@@ -91,10 +91,11 @@ echo $_REQUEST['device_id'];
<option value="Router">Router</option> <option value="Router">Router</option>
<option value="Switch">Switch</option> <option value="Switch">Switch</option>
<option value="WLAN">WLAN</option> <option value="WLAN">WLAN</option>
<option value="Powerline">Powerline</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="exampleInputEmail1">Portanzahl des Gerätes:</label> <label for="exampleInputEmail1">Portanzahl des Gerätes (bei WLAN leer lassen):</label>
<input type="text" class="form-control" id="NetworkDevicePort" name="NetworkDevicePort" placeholder="Portanzahl"> <input type="text" class="form-control" id="NetworkDevicePort" name="NetworkDevicePort" placeholder="Portanzahl">
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -135,6 +136,9 @@ echo $_REQUEST['device_id'];
</div> </div>
<?php <?php
// #####################################
// ## Start Function Setup
// #####################################
function createnetworktab($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) { function createnetworktab($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) {
echo '<li class="'.$activetab.'"><a href="#'.$pia_func_netdevid.'" data-toggle="tab">'.$pia_func_netdevname.' / '.$pia_func_netdevtyp; echo '<li class="'.$activetab.'"><a href="#'.$pia_func_netdevid.'" data-toggle="tab">'.$pia_func_netdevname.' / '.$pia_func_netdevtyp;
if ($pia_func_netdevport != "") {echo ' ('.$pia_func_netdevport.')';} if ($pia_func_netdevport != "") {echo ' ('.$pia_func_netdevport.')';}
@@ -143,7 +147,6 @@ function createnetworktab($pia_func_netdevid, $pia_func_netdevname, $pia_func_ne
function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) { function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_func_netdevtyp, $pia_func_netdevport, $activetab) {
echo '<div class="tab-pane '.$activetab.'" id="'.$pia_func_netdevid.'"> echo '<div class="tab-pane '.$activetab.'" id="'.$pia_func_netdevid.'">
<h4>'.$pia_func_netdevname.' (ID: '.$pia_func_netdevid.')</h4><br>'; <h4>'.$pia_func_netdevname.' (ID: '.$pia_func_netdevid.')</h4><br>';
echo '<div class="box-body no-padding"> echo '<div class="box-body no-padding">
<table class="table table-striped"> <table class="table table-striped">
<tbody><tr> <tbody><tr>
@@ -152,9 +155,10 @@ function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_
<th>Hostname</th> <th>Hostname</th>
<th>Last known IP</th> <th>Last known IP</th>
</tr>'; </tr>';
// Prepare Array // Prepare Array for Devices with Port value
// If no Port is set, the Port number is set to 1
if ($pia_func_netdevport == "") {$pia_func_netdevport = 1;} if ($pia_func_netdevport == "") {$pia_func_netdevport = 1;}
//echo $pia_func_netdevport; // Create Array with specific length
$network_device_portname = array(); $network_device_portname = array();
$network_device_portmac = array(); $network_device_portmac = array();
$network_device_portip = array(); $network_device_portip = array();
@@ -163,39 +167,47 @@ function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_
{ {
for ($x=1; $x<=$pia_func_netdevport; $x++) { $network_device_portname[$x] = ''; $network_device_portmac[$x] = ''; $network_device_portip[$x] = ''; $network_device_portstate[$x] = ''; } for ($x=1; $x<=$pia_func_netdevport; $x++) { $network_device_portname[$x] = ''; $network_device_portmac[$x] = ''; $network_device_portip[$x] = ''; $network_device_portstate[$x] = ''; }
} }
// Debug // make sql query for Network Hardware ID
// print_r($network_device_port);
// SQL for Devices with Network Device Number
global $db; global $db;
$func_sql = 'SELECT * FROM "Devices" WHERE "dev_Infrastructure" = "'.$pia_func_netdevid.'"'; $func_sql = 'SELECT * FROM "Devices" WHERE "dev_Infrastructure" = "'.$pia_func_netdevid.'"';
$func_result = $db->query($func_sql);//->fetchArray(SQLITE3_ASSOC); $func_result = $db->query($func_sql);//->fetchArray(SQLITE3_ASSOC);
while($func_res = $func_result->fetchArray(SQLITE3_ASSOC)) { while($func_res = $func_result->fetchArray(SQLITE3_ASSOC)) {
// Debug
//if(!isset($func_res['dev_Name'])) continue; //if(!isset($func_res['dev_Name'])) continue;
if ($func_res['dev_PresentLastScan'] == 1) {$port_state = '<div class="badge bg-green text-white" style="width: 60px;">Up</div>';} else {$port_state = '<div class="badge bg-red text-white" style="width: 60px;">Down</div>';} if ($func_res['dev_PresentLastScan'] == 1) {$port_state = '<div class="badge bg-green text-white" style="width: 60px;">Online</div>';} else {$port_state = '<div class="badge bg-red text-white" style="width: 60px;">Offline</div>';}
//echo 'Port: '.$func_res['dev_Infrastructure_port'].' - '.$port_state.' - <a href="./deviceDetails.php?mac='.$func_res['dev_MAC'].'">'.$func_res['dev_Name'].' - '.$func_res['dev_LastIP'].'</a><br>'; // Prepare Table with Port > push values in array
if ($pia_func_netdevport > 1) if ($pia_func_netdevport > 1)
{ {
if (stristr($func_res['dev_Infrastructure_port'], ',') == '') {
$network_device_portname[$func_res['dev_Infrastructure_port']] = $func_res['dev_Name']; $network_device_portname[$func_res['dev_Infrastructure_port']] = $func_res['dev_Name'];
$network_device_portmac[$func_res['dev_Infrastructure_port']] = $func_res['dev_MAC']; $network_device_portmac[$func_res['dev_Infrastructure_port']] = $func_res['dev_MAC'];
$network_device_portip[$func_res['dev_Infrastructure_port']] = $func_res['dev_LastIP']; $network_device_portip[$func_res['dev_Infrastructure_port']] = $func_res['dev_LastIP'];
$network_device_portstate[$func_res['dev_Infrastructure_port']] = $func_res['dev_PresentLastScan']; $network_device_portstate[$func_res['dev_Infrastructure_port']] = $func_res['dev_PresentLastScan'];
} else { } else {
// Table without Port $multiport = array();
$multiport = explode(',',$func_res['dev_Infrastructure_port']);
foreach($multiport as $row) {
$network_device_portname[trim($row)] = $func_res['dev_Name'];
$network_device_portmac[trim($row)] = $func_res['dev_MAC'];
$network_device_portip[trim($row)] = $func_res['dev_LastIP'];
$network_device_portstate[trim($row)] = $func_res['dev_PresentLastScan'];
}
unset($multiport);
}
// $network_device_portname[$func_res['dev_Infrastructure_port']] = $func_res['dev_Name'];
// $network_device_portmac[$func_res['dev_Infrastructure_port']] = $func_res['dev_MAC'];
// $network_device_portip[$func_res['dev_Infrastructure_port']] = $func_res['dev_LastIP'];
// $network_device_portstate[$func_res['dev_Infrastructure_port']] = $func_res['dev_PresentLastScan'];
} else {
// Table without Port > echo values
echo '<tr><td>###</td><td>'.$port_state.'</td><td><a href="./deviceDetails.php?mac='.$func_res['dev_MAC'].'"><b>'.$func_res['dev_Name'].'</b></a></td><td>'.$func_res['dev_LastIP'].'</td></tr>'; echo '<tr><td>###</td><td>'.$port_state.'</td><td><a href="./deviceDetails.php?mac='.$func_res['dev_MAC'].'"><b>'.$func_res['dev_Name'].'</b></a></td><td>'.$func_res['dev_LastIP'].'</td></tr>';
} }
} }
// Debug // Create table with Port
//print_r($network_device_portname);
//print_r($network_device_portmac);
//print_r($network_device_portip);
//print_r($network_device_portstate);
if ($pia_func_netdevport > 1) if ($pia_func_netdevport > 1)
{ {
for ($x=1; $x<=$pia_func_netdevport; $x++) for ($x=1; $x<=$pia_func_netdevport; $x++)
{ {
if ($network_device_portstate[$x] == 1) {$port_state = '<div class="badge bg-green text-white" style="width: 60px;">Up</div>';} else {$port_state = '<div class="badge bg-red text-white" style="width: 60px;">Down</div>';} if ($network_device_portstate[$x] == 1) {$port_state = '<div class="badge bg-green text-white" style="width: 60px;">Online</div>';} else {$port_state = '<div class="badge bg-red text-white" style="width: 60px;">Offline</div>';}
echo '<tr> echo '<tr>
<td>'.$x.'</td> <td>'.$x.'</td>
<td>'.$port_state.'</td> <td>'.$port_state.'</td>
@@ -208,13 +220,18 @@ function createnetworktabcontent($pia_func_netdevid, $pia_func_netdevname, $pia_
</div>'; </div>';
echo '</div> '; echo '</div> ';
} }
// #####################################
// ## End Function Setup
// #####################################
// #####################################
// ## Create Tabs
// #####################################
$sql = 'SELECT "device_id", "net_device_name", "net_device_typ", "net_device_port" FROM "network_infrastructure"'; $sql = 'SELECT "device_id", "net_device_name", "net_device_typ", "net_device_port" FROM "network_infrastructure"';
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC); $result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
?> ?>
<div class="nav-tabs-custom"> <div class="nav-tabs-custom">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<?php <?php
$i = 0; $i = 0;
while($res = $result->fetchArray(SQLITE3_ASSOC)){ while($res = $result->fetchArray(SQLITE3_ASSOC)){
@@ -226,10 +243,10 @@ while($res = $result->fetchArray(SQLITE3_ASSOC)){
?> ?>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<?php <?php
// #####################################
// ## Ctreate Tab Content
// #####################################
$i = 0; $i = 0;
while($res = $result->fetchArray(SQLITE3_ASSOC)){ while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['device_id'])) continue; if(!isset($res['device_id'])) continue;