Просмотр исходного кода

add port device name for ports
add port snmp ifname

rajven 4 лет назад
Родитель
Сommit
983368ab61

+ 22 - 24
html/admin/devices/editport.php

@@ -4,6 +4,7 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . $language . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 if (isset($_POST["editport"])) {
+    $new['port_name'] = trim($_POST["f_name"]);
     $new['snmp_index'] = $_POST["f_snmp"] * 1;
     $new['uplink'] = $_POST["f_uplink"] * 1;
     $new['nagios'] = $_POST["f_nagios"] * 1;
@@ -31,33 +32,30 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
 
 <form name="def" action="editport.php?id=<? echo $id; ?>" method="post">
 <table class="data">
-<tr>
-<td>id</td>
-<td>Порт</td>
-<td>snmp</td>
-<td>Комментарий</td>
-<td>Device</td>
-<td>Uplink</td>
-<td>Nagios</td>
-<td>Не проверять</td>
+<tr align="center">
+<td width=20>id</td>
+<td width=40>Порт N</td>
+<td width=40>Порт</td>
+<td width=40>snmp</td>
+<td width=100>ifIndex</td>
+<td width=200>Комментарий</td>
+<td width=100>Device</td>
+<td width=40>Uplink</td>
+<td width=40>Nagios</td>
+<td width=40>Не проверять</td>
 </tr>
 <?php
+print "<tr>";
 print "<td class=\"data\"><input type=hidden name=\"id\" value=".$id.">".$id."</td>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_port' value='".$port['port']."'></td>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_snmp' value='".$port['snmp_index']."'></td>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_comment' value='".$port['comment']."'></td>\n";
-print "<td class=\"data\">";
-print_device_port_select($db_link, 'f_target_port', $device_id, $port['target_port_id']);
-print "</td>\n";
-print "<td class=\"data\">";
-print_qa_select('f_uplink', $port['uplink']);
-print "</td>\n";
-print "<td class=\"data\">";
-print_qa_select('f_nagios', $port['nagios']);
-print "</td>\n";
-print "<td class=\"data\">";
-print_qa_select('f_skip', $port['skip']);
-print "</td>\n";
+print "<td class=\"data\" align=center>".$port['port']."</td>\n";
+print "<td class=\"data\"><input type=\"text\" name='f_name' value='".$port['port_name']."' size=10></td>\n";
+print "<td class=\"data\"><input type=\"text\" name='f_snmp' value='".$port['snmp_index']."' size=10></td>\n";
+print "<td class=\"data\" align=center>".$port['ifName']."</td>\n";
+print "<td class=\"data\"><input type=\"text\" name='f_comment' value='".$port['comment']."' size=40></td>\n";
+print "<td class=\"data\">"; print_device_port_select($db_link, 'f_target_port', $device_id, $port['target_port_id']); print "</td>\n";
+print "<td class=\"data\">"; print_qa_select('f_uplink', $port['uplink']); print "</td>\n";
+print "<td class=\"data\">"; print_qa_select('f_nagios', $port['nagios']); print "</td>\n";
+print "<td class=\"data\">"; print_qa_select('f_skip', $port['skip']); print "</td>\n";
 ?>
 </tr>
 <tr><td colspan=2><input type="submit" name="editport" value="Сохранить"></td></tr>

+ 94 - 59
html/admin/devices/switchport.php

@@ -16,6 +16,41 @@ if (isset($_POST["regensnmp"])) {
     header("Location: " . $_SERVER["REQUEST_URI"]);
 }
 
+if (isset($_POST['save'])) {
+    $saved = array();
+    //button save
+    $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
+    for ($i = 0; $i < $len; $i ++) {
+        $save_id = intval($_POST['save'][$i]);
+        if ($save_id == 0) { continue;  }
+        array_push($saved,$save_id);
+        }
+    //select box
+    $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
+    if ($len>0) {
+        for ($i = 0; $i < $len; $i ++) {
+            $save_id = intval($_POST['f_id'][$i]);
+            if ($save_id == 0) { continue; }
+            if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
+            }
+        }
+    //save changes
+    $len = is_array($saved) ? count($saved) : 0;
+    for ($i = 0; $i < $len; $i ++) {
+        $save_id = intval($saved[$i]);
+        if ($save_id == 0) { continue;  }
+        $len_all = is_array($_POST['p_id']) ? count($_POST['p_id']) : 0;
+        for ($j = 0; $j < $len_all; $j ++) {
+            if (intval($_POST['p_id'][$j]) != $save_id) { continue; }
+            $new['port_name'] = $_POST['f_name'][$j];
+            $new['snmp_index'] = $_POST['f_snmp_index'][$j]*1;
+            update_record($db_link, "device_ports", "id='{$save_id}'", $new);
+            }
+        }
+    header("Location: " . $_SERVER["REQUEST_URI"]);
+    }
+
+
 $switch=get_record($db_link,'devices',"id=".$id);
 
 unset($_POST);
@@ -26,77 +61,77 @@ print_editdevice_submenu($page_url,$id);
 ?>
 <div id="cont">
 <form name="def" action="switchport.php?id=<? echo $id; ?>" method="post">
+<br>
 
-<?php
-print "<br>\n";
-print "<b>Список портов ".$switch['device_name']." - ".$switch['ip']."</b><br>\n";
-
-print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
-print "<tr>\n";
-    print "<td>Порт</td>\n";
-    print "<td>Snmp</td>\n";
-    print "<td>Mac count</td>\n";
-    print "<td>Uplink</td>\n";
-    print "<td>Nagios</td>\n";
-    print "<td>Skip</td>\n";
-    print "<td>Юзер|Device</td>\n";
-    print "<td>Комментарий</td>\n";
-    print "<td>Vlan</td>\n";
-    print "<td>График</td>\n";
-print "</tr>\n";
+<?php print "<b>Список портов ".$switch['device_name']." - ".$switch['ip']."</b><br>\n"; ?>
 
-$sSQL = "SELECT id,snmp_index,port,comment,target_port_id,last_mac_count,uplink,nagios,skip,vlan from device_ports WHERE device_ports.device_id=$id Order by port";
-$flist = mysqli_query($db_link, $sSQL);
-while (list ($d_id, $d_snmp, $d_port, $d_comment, $d_target_id, $d_mac_count, $d_uplink, $d_nagios, $d_skip, $d_vlan) = mysqli_fetch_array($flist)) {
-print "<tr align=center>\n";
-$cl="data";
-if ($d_uplink) { $cl="info"; }
-        print "<td class=\"$cl\"><a href=\"editport.php?id=$d_id\">" . $d_port . "</a></td>\n";
-        print "<td class=\"$cl\" >" . $d_snmp . "</td>\n";
-        print "<td class=\"$cl\" ><button name=\"write\" class=\"j-submit-report\" onclick=\"window.open('portmactable.php?id=" . $d_id . "')\">" . $d_mac_count . "</button></td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_uplink) . "</td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_nagios) . "</td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_skip) . "</td>\n";
+<table class="data" cellspacing="1" cellpadding="4">
+<tr>
+<td><input type="checkbox" onClick="checkAll(this.checked);"></td>
+<td>id</td>
+<td>N</td>
+<td>Порт</td>
+<td>Mac count</td>
+<td>snmp</td>
+<td>Юзер|Device</td>
+<td>Комментарий</td>
+<td>Uplink</td>
+<td>Nagios</td>
+<td>Skip</td>
+<td>Vlan</td>
+<td>ifName</td>
+</tr>
+<?php
+$sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
+$ports=get_records_sql($db_link,$sSQL);
+foreach ($ports as $row) {
+        print "<tr align=center>\n";
+        $cl = "data";
+        print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=f_id[] value='{$row['id']}'></td>\n";
+        print "<td class=\"data\"><input type=\"hidden\" name='p_id[]' value='{$row['id']}'><a href=\"editport.php?id=".$row['id']."\">{$row['id']}</a></td>\n";
+        print "<td class=\"$cl\">".$row['port']."</td>\n";
+        print "<td class=\"$cl\" ><input type=\"text\" name='f_name[]' value='{$row['port_name']}' size=5></td>\n";
+        print "<td class=\"$cl\" ><button name=\"write\" class=\"j-submit-report\" onclick=\"window.open('portmactable.php?id=" . $row['id'] . "')\">" . $row['last_mac_count'] . "</button></td>\n";
+        print "<td class=\"$cl\" ><input type=\"text\" name='f_snmp_index[]' value='{$row['snmp_index']}' size=10></td>\n";
         print "<td class=\"$cl\">";
-        if (isset($d_target_id) and $d_target_id > 0) {
-            print_device_port($db_link, $d_target_id);
+        if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
+            print_device_port($db_link, $row['target_port_id']);
         } else {
-            print_auth_port($db_link, $d_id);
+            print_auth_port($db_link, $row['id']);
         }
         print "</td>\n";
-        print "<td class=\"$cl\">" . $d_comment . "</td>\n";
-        print "<td class=\"$cl\">" . $d_vlan . "</td>\n";
-
+        print "<td class=\"$cl\">" . $row['comment'] . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['uplink']) . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['nagios']) . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['skip']) . "</td>\n";
+        $vlan = $row['vlan'];
+        $ifname= $row['ifName'];
         global $torrus_url;
-        $f_cacti_url = get_cacti_graph($switch['ip'], $d_snmp);
-        if (! isset($torrus_url) and (! isset($f_cacti_url))) {
-                print "<td class=\"$cl\"></td>\n";
-        	} else {
-                if (isset($f_cacti_url)) {
-                    $snmp_url = "<a href=\"$f_cacti_url\">Статистика</a>";
-        	    }
-		if (isset($torrus_url)) {
+        $f_cacti_url = get_cacti_graph($switch['ip'], $row['snmp_index']);
+        if (! isset($torrus_url) and (! isset($f_cacti_url))) {  $snmp_url=$ifname; }
+                else {
+                if (isset($f_cacti_url)) { $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>"; }
+                if (isset($torrus_url)) {
                     $normed_ifname = trim(str_replace("/", "_", $ifname));
-	            $normed_ifname = trim(str_replace(".", "_", $normed_ifname));
-	            $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
-        	    $pattern = '/cisco/i';
-        	    preg_match($pattern, $switch['device_model'], $matches);
-        	    if (isset($matches[0])) {
-                	$normed_ifname = trim(str_replace("Gi", "GigabitEthernet", $normed_ifname));
-        		}
+                    $normed_ifname = trim(str_replace(".", "_", $normed_ifname));
+                    $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
+                    $pattern = '/cisco/i';
+                    preg_match($pattern, $switch['device_model'], $matches);
+                    if (isset($matches[0])) { $normed_ifname = trim(str_replace("Gi", "GigabitEthernet", $normed_ifname)); }
                     $t_url = str_replace("HOST_IP", $switch['ip'], $torrus_url);
-	            $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
-	            $snmp_url = "<a href=\"$t_url\">Статистика</a>";
-        	    }
-		print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
-		}
-        print "</td>\n";
+                    $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
+                    $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
+                    }
+                }
+        print "<td class=\"$cl\">" . $vlan . "</td>\n";
+        print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
 print "</tr>";
 }
 print "<tr>\n";
-    print "<td colspan=6>snmp start</td>\n";
-    print "<td class=\"data\"><input type=\"text\" name='f_snmp_start' value=1></td>\n";
-    print "<td><input type=\"submit\" name=\"regensnmp\" value=\"Обновить snmp\"></td>\n";
+print "<td colspan=6>snmp start</td>\n";
+print "<td class=\"data\"><input type=\"text\" name='f_snmp_start' value=1></td>\n";
+print "<td><input type=\"submit\" name=\"regensnmp\" value=\"Обновить snmp\"></td>\n";
+print "<td colspan=5 align=right><input type=\"submit\" name=\"save\" value=\"Сохранить\"></td>\n";
 print "</tr>\n";
 print "</table>\n";
 ?>

+ 102 - 99
html/admin/devices/switchstatus.php

@@ -5,6 +5,19 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $switch=get_record($db_link,'devices',"id=".$id);
 
+if (isset($_POST["regensnmp"])) {
+    $snmp_index = $_POST["f_snmp_start"] * 1;
+    $sSQL = "SELECT id,port from device_ports WHERE device_ports.device_id=$id order by id";
+    $flist = mysqli_query($db_link, $sSQL);
+    LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
+    while (list ($port_id, $port) = mysqli_fetch_array($flist)) {
+        $snmp = $port + $snmp_index - 1;
+        $new['snmp_index'] = $snmp;
+        update_record($db_link, "device_ports", "id='$port_id'", $new);
+        }
+    header("Location: " . $_SERVER["REQUEST_URI"]);
+    }
+
 if (isset($_POST['poe_on']) and $switch['snmp_version']>0) {
     $len = is_array($_POST['poe_on']) ? count($_POST['poe_on']) : 0;
     for ($i = 0; $i < $len; $i ++) {
@@ -74,31 +87,35 @@ if ($switch['snmp_version']>0) {
     print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
     print "<tr>\n";
     print "<td>id</td>\n";
+    print "<td>N</td>\n";
     print "<td>Порт</td>\n";
-    print "<td>Snmp</td>\n";
     print "<td>Mac count</td>\n";
+    print "<td>snmp</td>\n";
+    print "<td>Юзер|Device</td>\n";
+    print "<td>Комментарий</td>\n";
     print "<td>Uplink</td>\n";
     print "<td>Nagios</td>\n";
     print "<td>Skip</td>\n";
-    print "<td>Юзер|Device</td>\n";
-    print "<td>Комментарий</td>\n";
     print "<td>Vlan</td>\n";
-    if ($snmp_ok) {
-        print "<td>Speed</td>\n";
-        print "<td>Errors</td>\n";
-        print "<td>IfName</td>\n";
-        print "<td>Additional</td>\n";
-        print "<td>POE Control</td>\n";
-        print "<td>Port Control</td>\n";
-    }
+    print "<td>IfName</td>\n";
+    print "<td>Speed</td>\n";
+    print "<td>Errors</td>\n";
+    print "<td>Additional</td>\n";
+    print "<td>POE Control</td>\n";
+    print "<td>Port Control</td>\n";
     print "</tr>\n";
-    $sSQL = "SELECT id,snmp_index,port,comment,target_port_id,last_mac_count,uplink,nagios,skip,vlan from device_ports WHERE device_ports.device_id=$id Order by port";
-    $flist = mysqli_query($db_link, $sSQL);
-    while (list ($d_id, $d_snmp, $d_port, $d_comment, $d_target_id, $d_mac_count, $d_uplink, $d_nagios, $d_skip, $d_vlan) = mysqli_fetch_array($flist)) {
+    $sSQL = "SELECT * FROM device_ports WHERE device_ports.device_id=$id ORDER BY port";
+    $ports=get_records_sql($db_link,$sSQL);
+    foreach ($ports as $row) {
         print "<tr align=center>\n";
         $cl = "up";
+        if (!isset($row['port_name']) or empty($row['port_name'])) { 
+            $new_port_info['port_name']=$row['port'];
+            $row['port_name']=$row['port'];
+            update_record($db_link, "device_ports", "id=".$row['id'], $new_port_info);
+            }
         if (isset($switch['ip']) and ($switch['ip'] != '') and $snmp_ok) {
-            $port_state_detail = get_port_state_detail($d_snmp, $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
+            $port_state_detail = get_port_state_detail($row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
             list ($poper, $padmin, $pspeed, $perrors) = explode(';', $port_state_detail);
             if (preg_match('/up/i', $poper)) {
                 $cl = "up";
@@ -111,105 +128,94 @@ if ($switch['snmp_version']>0) {
                 }
             }
         }
-	print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=d_port_index[] value=".$d_snmp." ></td>\n";
-        print "<td class=\"$cl\"><a href=\"editport.php?id=$d_id\">" . $d_port . "</a></td>\n";
-        print "<td class=\"$cl\" >" . $d_snmp . "</td>\n";
-        print "<td class=\"$cl\" ><button name=\"write\" class=\"j-submit-report\" onclick=\"window.open('portmactable.php?id=" . $d_id . "')\">" . $d_mac_count . "</button></td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_uplink) . "</td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_nagios) . "</td>\n";
-        print "<td class=\"$cl\" >" . get_qa($d_skip) . "</td>\n";
+	print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=d_port_index[] value=".$row['snmp_index']." ></td>\n";
+        print "<td class=\"$cl\"><a href=\"editport.php?id=".$row['id']."\">" . $row['port'] . "</a></td>\n";
+        print "<td class=\"$cl\" >" . $row['port_name'] . "</td>\n";
+        print "<td class=\"$cl\" ><button name=\"write\" class=\"j-submit-report\" onclick=\"window.open('portmactable.php?id=" . $row['id'] . "')\">" . $row['last_mac_count'] . "</button></td>\n";
+        print "<td class=\"$cl\" >" . $row['snmp_index'] . "</td>\n";
         print "<td class=\"$cl\">";
-        if (isset($d_target_id) and $d_target_id > 0) {
-            print_device_port($db_link, $d_target_id);
+        if (isset($row['target_port_id']) and $row['target_port_id'] > 0) {
+            print_device_port($db_link, $row['target_port_id']);
         } else {
-            print_auth_port($db_link, $d_id);
+            print_auth_port($db_link, $row['id']);
         }
         print "</td>\n";
-        print "<td class=\"$cl\">" . $d_comment . "</td>\n";
+        print "<td class=\"$cl\">" . $row['comment'] . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['uplink']) . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['nagios']) . "</td>\n";
+        print "<td class=\"$cl\" >" . get_qa($row['skip']) . "</td>\n";
+        $poe_info="POE:None";
+
+        $vlan = $row['vlan'];
+        $ifname= $row['ifName'];
+
         if ($snmp_ok) {
-            $vlan = get_port_vlan($d_port, $d_snmp, $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
-            $ifname = get_snmp_ifname($switch['ip'], $switch['community'], $switch['snmp_version'], $d_snmp);
-            $sfp_status = get_sfp_status($switch['vendor_id'], $d_snmp, $switch['ip'], $switch['community'], $switch['snmp_version'], $modules_oids);
-            $poe_status = get_port_poe_state($switch['vendor_id'], $d_snmp, $switch['ip'], $switch['community'], $switch['snmp_version']);
-            if (!isset($vlan)) { $vlan = $d_vlan; }
-            print "<td class=\"$cl\">" . $vlan . "</td>\n";
-            $speed = "0";
-            $cl_speed = $cl;
-            if ($pspeed == 0) {
-                $speed = "";
-            }
-            if ($pspeed == 10000000) {
-                $speed = "10M";
-                $cl_speed = "speed10M";
-            }
-            if ($pspeed == 100000000) {
-                $speed = "100M";
-                $cl_speed = "speed100M";
-            }
-            if ($pspeed == 1000000000) {
-                $speed = "1G";
-                $cl_speed = "speed1G";
-            }
-            if ($pspeed == 10000000000) {
-                $speed = "10G";
-                $cl_speed = "speed10G";
-            }
-            if ($pspeed == 4294967295) {
-                $speed = "10G";
-                $cl_speed = "speed10G";
-            }
-            if ($pspeed == 10) {
-                $speed = "10G";
-                $cl_speed = "speed10G";
-            }
-            print "<td class=\"$cl_speed\">" . $speed . "</td>\n";
-            $cl_error = $cl;
-            if ($perrors > 0) {
-                $cl_error = "crc";
-            }
-            print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
-            global $torrus_url;
-            $f_cacti_url = get_cacti_graph($switch['ip'], $d_snmp);
-            if (! isset($torrus_url) and (! isset($f_cacti_url))) {
-                print "<td class=\"$cl\">" . $ifname . "</td>\n";
-            } else {
-                if (isset($f_cacti_url)) {
-                    $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>";
+            $vlan = get_port_vlan($row['port'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $switch['fdb_snmp_index']);
+            $ifname = get_snmp_ifname($switch['ip'], $switch['community'], $switch['snmp_version'], $row['snmp_index']);
+            $sfp_status = get_sfp_status($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version'], $modules_oids);
+            $poe_status = get_port_poe_state($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version']);
+            if (isset($poe_status)) {
+                if ($poe_status == 1) {
+                    $port_poe_detail = get_port_poe_detail($switch['vendor_id'], $row['snmp_index'], $switch['ip'], $switch['community'], $switch['snmp_version']);
+                    $poe_info="POE:On " . $port_poe_detail;
+                    }
+                if ($poe_status == 2) { $poe_info="POE:Off"; }
                 }
+            if (!isset($vlan)) { $vlan = $row['vlan']; } else {
+                if ($row['vlan']!==$vlan) {
+                    $new_port_info['vlan']=$vlan;
+                    update_record($db_link, "device_ports", "id=".$row['id'], $new_port_info);
+                    }
+                }
+            if (empty($row['ifName']) or $row['ifName']!==$ifname) {
+                $new_port_info['ifName']=$ifname; 
+                update_record($db_link, "device_ports", "id=".$row['id'], $new_port_info); 
+                }
+            }
+
+        global $torrus_url;
+        $f_cacti_url = get_cacti_graph($switch['ip'], $row['snmp_index']);
+        if (! isset($torrus_url) and (! isset($f_cacti_url))) {  $snmp_url=$ifname; } 
+                else {
+                if (isset($f_cacti_url)) { $snmp_url = "<a href=\"$f_cacti_url\">" . $ifname . "</a>"; }
                 if (isset($torrus_url)) {
                     $normed_ifname = trim(str_replace("/", "_", $ifname));
                     $normed_ifname = trim(str_replace(".", "_", $normed_ifname));
                     $normed_ifname = trim(str_replace(" ", "_", $normed_ifname));
                     $pattern = '/cisco/i';
                     preg_match($pattern, $switch['device_model'], $matches);
-                    if (isset($matches[0])) {
-                        $normed_ifname = trim(str_replace("Gi", "GigabitEthernet", $normed_ifname));
-                    }
+                    if (isset($matches[0])) { $normed_ifname = trim(str_replace("Gi", "GigabitEthernet", $normed_ifname)); }
                     $t_url = str_replace("HOST_IP", $switch['ip'], $torrus_url);
                     $t_url = str_replace("IF_NAME", $normed_ifname, $t_url);
                     $snmp_url = "<a href=\"$t_url\">" . $ifname . "</a>";
+                    }
                 }
-                print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
-            }
-            print "<td class=\"$cl\">" . $sfp_status;
-            if (isset($poe_status)) {
-                if ($poe_status == 1) {
-                    $port_poe_detail = get_port_poe_detail($switch['vendor_id'], $d_snmp, $switch['ip'], $switch['community'], $switch['snmp_version']);
-                    print "POE:On " . $port_poe_detail;
-                }
-                if ($poe_status == 2) {
-                    print "POE:Off";
-                }
-            }
-            print "</td>\n";
-            if (isset($poe_status) and ! $d_skip and ! $switch['is_router']) {
+
+        print "<td class=\"$cl\">" . $vlan . "</td>\n";
+        print "<td class=\"$cl\">" . $snmp_url . "</td>\n";
+
+        $speed = "0";
+        $cl_speed = $cl;
+        if ($pspeed == 0) { $speed = ""; }
+        if ($pspeed == 10000000) { $speed = "10M"; $cl_speed = "speed10M"; }
+        if ($pspeed == 100000000) { $speed = "100M"; $cl_speed = "speed100M"; }
+        if ($pspeed == 1000000000) { $speed = "1G"; $cl_speed = "speed1G"; }
+        if ($pspeed == 10000000000) { $speed = "10G"; $cl_speed = "speed10G"; }
+        if ($pspeed == 4294967295) { $speed = "10G"; $cl_speed = "speed10G"; }
+        if ($pspeed == 10) { $speed = "10G"; $cl_speed = "speed10G"; }
+        print "<td class=\"$cl_speed\">" . $speed . "</td>\n";
+        $cl_error = $cl;
+        if ($perrors > 0) { $cl_error = "crc"; }
+        print "<td class=\"$cl_error\">" . $perrors . "</td>\n";
+        print "<td class=\"$cl\">" . $sfp_status. " ". $poe_info."</td>\n";
+        if (isset($poe_status) and ! $row['skip'] and ! $switch['is_router']) {
                 print "<td class=\"data\">";
                 if ($switch['vendor_id'] != 9) {
                     if ($poe_status == 2) {
-                        print "<button name='poe_on[]' value='{$d_snmp}'>POE On</button>";
+                        print "<button name='poe_on[]' value='{$row['snmp_index']}'>POE On</button>";
                 	}
                     if ($poe_status == 1) {
-                        print "<button name='poe_off[]' value='{$d_snmp}'>POE Off</button>";
+                        print "<button name='poe_off[]' value='{$row['snmp_index']}'>POE Off</button>";
                 	}
             	    } else {
                     print "Not supported";
@@ -218,23 +224,20 @@ if ($switch['snmp_version']>0) {
         	} else {
         	print "<td>Not supported</td>\n";
         	}
-            if (isset($padmin) and ! $d_uplink and ! $d_skip and ! $switch['is_router']) {
+        if (isset($padmin) and ! $row['uplink'] and ! $row['skip'] and ! $switch['is_router']) {
                 print "<td class=\"data\">";
                 if ($switch['vendor_id'] != 9) {
                     if (preg_match('/down/i', $padmin)) {
-                        print "<button name='port_on[]' value='{$d_snmp}'>Enable port</button>";
+                        print "<button name='port_on[]' value='{$row['snmp_index']}'>Enable port</button>";
                 	}
                     if (preg_match('/up/i', $padmin)) {
-                        print "<button name='port_off[]' value='{$d_snmp}'>Shutdown port</button>";
+                        print "<button name='port_off[]' value='{$row['snmp_index']}'>Shutdown port</button>";
                 	}
             	    } else {
                     print "Not supported";
             	    }
                 print "</td>\n";
         	}
-    	    } else {
-    	    print "<td class=\"$cl\">" . $d_vlan . "</td>\n";
-    	    }
         print "</tr>";
     }
     print "<tr>\n";

+ 4 - 3
html/inc/common.php

@@ -943,11 +943,12 @@ function print_device_port_select($db, $field_name, $device_id, $target_id)
     if (! isset($device_id)) {
         $device_id = 0;
     }
-    $d_sql = "SELECT D.device_name, DP.port, DP.device_id, DP.id FROM devices AS D, device_ports AS DP WHERE D.deleted=0 and D.id = DP.device_id AND (DP.device_id<>$device_id or DP.id=$target_id) and (DP.id not in (select target_port_id FROM device_ports WHERE target_port_id>0 and target_port_id<>$target_id)) order by D.device_name,DP.port";
+    $d_sql = "SELECT D.device_name, DP.port, DP.device_id, DP.id, DP.ifName FROM devices AS D, device_ports AS DP WHERE D.deleted=0 and D.id = DP.device_id AND (DP.device_id<>$device_id or DP.id=$target_id) and (DP.id not in (select target_port_id FROM device_ports WHERE target_port_id>0 and target_port_id<>$target_id)) order by D.device_name,DP.port";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item('Empty',0,$target_id);
-    while (list ($f_name, $f_port, $f_device_id, $f_target_id) = mysqli_fetch_array($t_device)) {
-	print_select_item($f_name."[" . $f_port . "]",$f_target_id,$target_id);
+    while (list ($f_name, $f_port, $f_device_id, $f_target_id, $f_ifname) = mysqli_fetch_array($t_device)) {
+        if (empty($f_ifname)) { $f_ifname=$f_port; }
+	print_select_item($f_name."[" . $f_ifname . "]",$f_target_id,$target_id);
     }
     print "</select>\n";
 }

+ 2 - 0
updates/20210918/mysql-device-ports.sql

@@ -0,0 +1,2 @@
+ALTER TABLE `device_ports` ADD `ifName` VARCHAR(40) NULL AFTER `port`;
+ALTER TABLE `device_ports` ADD `port_name` VARCHAR(40) NULL AFTER `ifName`;