static function assign($id, $source_type, $source_field, $source_value) { global $DB; $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP(); if ($source_field == "model") { // Get auth $snmp_auth = new PluginFusioninventorySnmpauth(); switch ($source_type) { case NETWORKING_TYPE: $FK_snmp_auth_DB = $snmp_auth->GetSNMPAuth($id, NETWORKING_TYPE); $plugin_fusioninventory_snmp->update_network_infos($id, $source_value, $FK_snmp_auth_DB); break; case PRINTER_TYPE: $FK_snmp_auth_DB = $snmp_auth->GetSNMPAuth($id, PRINTER_TYPE); $plugin_fusioninventory_snmp->update_printer_infos($id, $source_value, $FK_snmp_auth_DB); break; } } else { if ($source_field == "auth") { switch ($source_type) { case NETWORKING_TYPE: // Get model $FK_model_DB = $plugin_fusioninventory_snmp->GetSNMPModel($id, NETWORKING_TYPE); $plugin_fusioninventory_snmp->update_network_infos($id, $FK_model_DB, $source_value); break; case PRINTER_TYPE: // Get model $FK_model_DB = $plugin_fusioninventory_snmp->GetSNMPModel($id, PRINTER_TYPE); $plugin_fusioninventory_snmp->update_printer_infos($id, $FK_model_DB, $source_value); break; } } } }
/** * Determine CDP ports (trunk) * * @param $ID_Device : ID of device * @param $type type of device (NETWORKING_TYPE, PRINTER_TYPE ...) * @param $oidsModel : oid list from model SNMP * @param $oidvalues : list of values from agent query * @param $ArrayPort_LogicalNum_SNMPNum : array logical port number => SNMP port number (ifindex) * @param $ArrayPortsID : array with port name and port ID (from DB) * * @return array of trunk ports * **/ static function cdp_trunk($ID_Device, $type, $oidsModel, $oidvalues, $ArrayPort_LogicalNum_SNMPNum, $ArrayPortsID) { global $DB; $netwire = new Netwire(); $nn = new NetworkPort_NetworkPort(); $snmp_queries = new PluginFusioninventorySNMP(); if ($_SESSION['fusioninventory_logs'] == "1") { $logs = new PluginFusioninventoryLogs(); } $walks = new PluginFusioninventoryWalk(); $Threads = new PluginFusioninventoryProcesses(); $tmpc = new PluginFusioninventoryTmpConnections(); $manuf3com = new PluginFusioninventoryManufacturer3com(); $manufCisco = new PluginFusioninventoryManufacturerCisco(); $manufHP = new PluginFusioninventoryManufacturerHP(); $Array_cdp_ifIndex = array(); $Array_trunk_ifIndex = array(); $Array_multiplemac_ifIndex = array(); //$trunk_no_cdp = array(); if ($_SESSION['fusioninventory_logs'] == "1") { $logs->write("fusioninventory_fullsync", ">>>>>>>>>> Networking : Get cdp trunk ports <<<<<<<<<<", $type, $ID_Device, 1); } switch (!false) { case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "Cisco IOS Software, C1"): $sysDescr = "Cisco IOS Software, C1"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "Cisco"): $sysDescr = "Cisco"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "ProCurve J"): case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "HP J4"): case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "PROCURVE J"): $sysDescr = "ProCurve J"; break; case strstr($oidvalues[".1.3.6.1.2.1.1.1.0"][""], "3Com IntelliJack NJ225"): $sysDescr = "3Com IntelliJack NJ225"; break; } // Detect if ports are non trunk and have multiple mac addresses // (with list of dot1dTpFdbPort & dot1dBasePortIfIndex) // Get all port_number $pass = 0; //$manufCisco->NbMacEachPort if ($sysDescr == "Cisco") { $Array_vlan = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['vtpVlanName'], 1); if (array_count_values($Array_vlan) != 0 and array_count_values($Array_vlan) != 0) { $pass = 1; // Creation of var for each port foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) { $Arraydot1dTpFdbPort[$ifIndex] = 0; } foreach ($Array_vlan as $num => $vlan) { $ArrayPortNumber = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dTpFdbPort'], 1, $vlan); foreach ($ArrayPortNumber as $num => $dynamicdata) { $BridgePortNumber = $oidvalues[$oidsModel[0][1]['dot1dTpFdbPort'] . "." . $dynamicdata][$vlan]; $Arraydot1dTpFdbPort[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . "." . $BridgePortNumber][$vlan]]++; } } } } if ($pass == "1") { foreach ($Arraydot1dTpFdbPort as $ifIndex => $num) { if ($num > 1) { $Array_multiplemac_ifIndex[$ifIndex] = 1; } } } else { if ($pass == "0") { $Arraydot1dTpFdbPort = array(); $ArrayConnectionsPort = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dTpFdbPort'], 1); foreach ($ArrayConnectionsPort as $num => $Connectionkey) { $Arraydot1dTpFdbPort[] = $oidvalues[$oidsModel[0][1]['dot1dTpFdbPort'] . "." . $Connectionkey][""]; } $ArrayCount = array_count_values($Arraydot1dTpFdbPort); $ArrayPortNumber = $walks->GetoidValuesFromWalk($oidvalues, $oidsModel[0][1]['dot1dBasePortIfIndex'], 1); foreach ($ArrayPortNumber as $num => $PortNumber) { if (isset($ArrayCount[$PortNumber]) and $ArrayCount[$PortNumber] > 1) { $Array_multiplemac_ifIndex[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . "." . $PortNumber][""]] = 1; } } } } if ($sysDescr == "Cisco IOS Software, C1") { $Array_multiplemac_ifIndex[$oidvalues[$oidsModel[0][1]['dot1dBasePortIfIndex'] . ".3"][$vlan]] = 1; } // End detection of ports non trunk and have multiple mac addresses // Initialization of Trunk ports (Trunk in Cisco AND Tagged in other switchs) $Array_trunk_ifIndex = array(); // ***** Get Trunk / taged ports switch ($sysDescr) { case "Cisco": $Array_trunk_ifIndex = $manufCisco->TrunkPorts($oidvalues, $oidsModel, $ID_Device, $type); break; case "ProCurve J": $Array_trunk_ifIndex = $manufHP->TrunkPorts($oidvalues, $oidsModel, $ID_Device, $type); break; } // ***** Get CDP ports switch ($sysDescr) { case "Cisco": list($Array_cdp_ifIndex, $Array_multiplemac_ifIndex) = $manufCisco->CDPPorts($oidvalues, $oidsModel, $ID_Device, $type, $Array_multiplemac_ifIndex); break; case "ProCurve J": list($Array_cdp_ifIndex, $Array_multiplemac_ifIndex) = $manufHP->CDPPorts($oidvalues, $oidsModel, $ID_Device, $type, $Array_multiplemac_ifIndex); break; case "3Com IntelliJack NJ225": $Array_multiplemac_ifIndex = $manuf3com->MultiplePorts(); break; } // ** Update for all ports on this network device the field 'trunk' in // glpi_plugin_fusioninventory_networking_ports foreach ($ArrayPort_LogicalNum_SNMPNum as $num => $ifIndex) { $query = "SELECT *, `glpi_plugin_fusioninventory_networking_ports`.`ID` AS `sid`\n FROM `glpi_networking_ports`\n LEFT JOIN `glpi_plugin_fusioninventory_networking_ports`\n ON `glpi_plugin_fusioninventory_networking_ports`.`FK_networking_ports` =\n `glpi_networking_ports`.`ID`\n WHERE `device_type`='2'\n AND `on_device`='" . $ID_Device . "'\n AND `logical_number`='" . $ifIndex . "';"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { // If trunk => 1 if (isset($Array_trunk_ifIndex[$ifIndex]) and $Array_trunk_ifIndex[$ifIndex] == "1") { if ($data['trunk'] != "1") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='1'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "0", "1", "", $_SESSION['FK_process']); // Remove vlan $snmp_queries->CleanVlan($data['FK_networking_ports']); $snmp_queries->CleanVlan($netwire->getOppositeContact($data['FK_networking_ports'])); } // If multiple => -1 } else { if (isset($Array_multiplemac_ifIndex[$ifIndex]) and $Array_multiplemac_ifIndex[$ifIndex] == "1") { if ($data['trunk'] != "-1") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='-1'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "0", "-1", "", $_SESSION['FK_process']); // Remove vlan PluginFusioninventoryDb::lock_wire_check(); PluginFusioninventorySnmphistory::addLogConnection("remove", $netwire->getOppositeContact($data['FK_networking_ports']), $FK_process); PluginFusioninventorySnmphistory::addLogConnection("remove", $data['FK_networking_ports'], $FK_process); $snmp_queries->CleanVlan($data['FK_networking_ports']); $snmp_queries->CleanVlan($netwire->getOppositeContact($data['FK_networking_ports'])); // Remove connection if ($nn->getFromDBForNetworkPort($data['FK_networking_ports'])) { $nn->delete(array('id' => $data['FK_networking_ports'])); } PluginFusioninventoryDb::lock_wire_unlock(); } } else { if ($data['trunk'] != "0") { $query_update = "UPDATE `glpi_plugin_fusioninventory_networking_ports`\n SET `trunk`='0'\n WHERE `ID`='" . $data['sid'] . "';"; $DB->query($query_update); PluginFusioninventorySnmphistory::addLog($data["FK_networking_ports"], "trunk", "1", "0", "", $_SESSION['FK_process']); } } } } } // ***** Add ports and connections in glpi_plugin_fusioninventory_tmp_* tables for connections between // switchs foreach ($Array_multiplemac_ifIndex as $ifIndex => $val) { $ifName = $oidvalues[$oidsModel[0][1]['ifName'] . "." . $ifIndex][""]; $TMP_ID = $tmpc->UpdatePort($ID_Device, $ArrayPortsID[$ifName]); switch ($sysDescr) { case "Cisco": $manufCisco->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; case "ProCurve J": $manufHP->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; case "3Com IntelliJack NJ225": $manuf3com->tmpConnections($oidvalues, $oidsModel, $ifIndex, $TMP_ID, $ID_Device, $type); break; } } foreach ($Array_cdp_ifIndex as $ifIndex => $val) { $ifName = $oidvalues[$oidsModel[0][1]['ifName'] . "." . $ifIndex][""]; $TMP_ID = $tmpc->UpdatePort($ID_Device, $ArrayPortsID[$ifName], 1); $Array_multiplemac_ifIndex[$ifIndex] = 1; } return $Array_multiplemac_ifIndex; }
GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------ */ // ---------------------------------------------------------------------- // Original Author of file: David DURIEUX // Purpose of file: // ---------------------------------------------------------------------- $NEEDED_ITEMS = array("networking"); define('GLPI_ROOT', '../../..'); include GLPI_ROOT . "/inc/includes.php"; checkRight("networking", "r"); PluginFusioninventoryAuth::checkRight("snmp_networking", "r"); $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP(); if (isset($_POST['update']) && isset($_POST['ID'])) { PluginFusioninventoryAuth::checkRight("snmp_networking", "w"); $plugin_fusioninventory_snmp->update_network_infos($_POST['ID'], $_POST['model_infos'], $_POST['FK_snmp_connection']); } else { if (isset($_POST["GetRightModel"]) && isset($_POST['ID'])) { $plugin_fusioninventory_model_infos = new PluginFusioninventoryModelInfos(); $plugin_fusioninventory_model_infos->getrightmodel($_POST['ID'], NETWORKING_TYPE); } } glpi_header($_SERVER['HTTP_REFERER']);
function showForm($target, $ID) { global $DB, $CFG_GLPI, $LANG; $history = new PluginFusioninventorySnmphistory(); if (!PluginFusioninventory::haveRight("snmp_networking", "r")) { return false; } if (PluginFusioninventory::haveRight("snmp_networking", "w")) { $canedit = true; } else { $canedit = false; } include GLPI_ROOT . "/plugins/fusioninventory/inc_constants/snmp.mapping.constant.php"; $this->ID = $ID; $nw = new Netwire(); $CommonItem = new CommonItem(); $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP(); echo "<script type='text/javascript' src='" . GLPI_ROOT . "/lib/extjs/adapter/prototype/prototype.js'></script>"; echo "<script type='text/javascript' src='" . GLPI_ROOT . "/lib/extjs/adapter/prototype/effects.js'></script>"; if (!($data = $this->find("`FK_networking`='" . $ID . "'", '', 1))) { // Add in database if not exist $input['FK_networking'] = $ID; $ID_tn = $this->add($input); $this->getFromDB($ID_tn); } else { foreach ($data as $ID_tn => $datas) { $this->fields = $data[$ID_tn]; } } $PID = $this->fields['last_PID_update']; // Form networking informations echo "<div align='center'>\n <form method='post' name='snmp_form' id='snmp_form' action=\"" . $target . "\">"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["snmp"][11]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . $LANG['plugin_fusioninventory']["profile"][24] . "</td>"; echo "<td align='center'>"; $query_models = "SELECT * \n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `device_type`!='2'\n AND `device_type`!='0';"; $result_models = $DB->query($query_models); $exclude_models = array(); while ($data_models = $DB->fetch_array($result_models)) { $exclude_models[] = $data_models['ID']; } Dropdown::show("PluginFusioninventoryModelInfos", array('name' => "model_infos", 'value' => $this->fields['FK_model_infos'], 'comments' => 0, 'used' => $exclude_models)); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td align='center'>" . $LANG['plugin_fusioninventory']["functionalities"][43] . "</td>"; echo "<td align='center'>"; PluginFusioninventorySNMP::auth_dropdown($this->fields['FK_snmp_connection']); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1 center'>"; echo "<td>"; echo " <input type='submit' name='GetRightModel'\n value='" . $LANG['plugin_fusioninventory']["model_info"][13] . "' class='submit'/></td>"; echo "<td>"; echo "<input type='hidden' name='ID' value='" . $ID . "'>"; echo "<input type='submit' name='update' value=\"" . $LANG["buttons"][7] . "\" class='submit' >"; echo "</td>"; echo "</tr>"; echo "</table></form>"; // Remote action of agent $pfit = new PluginFusioninventoryTask(); $pfit->RemoteStateAgent($target, $ID, NETWORKING_TYPE, array('INVENTORY' => 1)); // SNMP Informations // echo "<div align='center'> echo "<form method='post' name='snmp_form' id='snmp_form' action=\"" . $target . "\">"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["title"][1]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1 center'>"; echo "<td colspan='2' height='30'>"; echo $LANG['plugin_fusioninventory']["snmp"][52] . ": " . convDateTime($this->fields['last_fusioninventory_update']); echo "</td>"; echo "</tr>"; // Get link field to detect if cpu, memory and uptime are get onthis network device $Array_Object_TypeNameConstant = $plugin_fusioninventory_snmp->GetLinkOidToFields($ID, NETWORKING_TYPE); $mapping_name = array(); foreach ($Array_Object_TypeNameConstant as $object => $mapping_type_name) { $mapping_name[$mapping_type_name] = "1"; } if (isset($mapping_name['uptime']) and $mapping_name['uptime'] == "1") { echo "<tr class='tab_bg_1 center'>"; echo "<td>" . $LANG['plugin_fusioninventory']["snmp"][12] . "</td>"; echo "<td>"; $sysUpTime = $this->fields['uptime']; if (strstr($sysUpTime, "days")) { list($day, $hour, $minute, $sec, $ticks) = sscanf($sysUpTime, "%d days, %d:%d:%d.%d"); } else { if (strstr($sysUpTime, "hours")) { $day = 0; list($hour, $minute, $sec, $ticks) = sscanf($sysUpTime, "%d hours, %d:%d.%d"); } else { if (strstr($sysUpTime, "minutes")) { $day = 0; $hour = 0; list($minute, $sec, $ticks) = sscanf($sysUpTime, "%d minutes, %d.%d"); } else { if ($sysUpTime == "0") { $day = 0; $hour = 0; $minute = 0; $sec = 0; } else { list($hour, $minute, $sec, $ticks) = sscanf($sysUpTime, "%d:%d:%d.%d"); $day = 0; } } } } echo "<b>{$day}</b> " . $LANG["stats"][31] . " "; echo "<b>{$hour}</b> " . $LANG["job"][21] . " "; echo "<b>{$minute}</b> " . $LANG["job"][22] . " "; echo " " . strtolower($LANG["rulesengine"][42]) . " <b>{$sec}</b> " . $LANG["stats"][34] . " "; echo "</td>"; echo "</tr>"; } if (isset($mapping_name['cpu']) and $mapping_name['cpu'] == "1" or isset($mapping_name['cpuuser']) and $mapping_name['cpuuser'] == "1" and (isset($mapping_name['cpusystem']) and $mapping_name['cpusystem'] == "1")) { echo "<tr class='tab_bg_1 center'>"; echo "<td>" . $LANG['plugin_fusioninventory']["snmp"][13] . "</td>"; echo "<td>"; PluginFusioninventoryDisplay::bar($this->fields['cpu'], '', 'inverse'); echo "</td>"; echo "</tr>"; } if (isset($mapping_name['memory']) and $mapping_name['memory'] == "1") { echo "<tr class='tab_bg_1 center'>"; echo "<td>" . $LANG['plugin_fusioninventory']["snmp"][14] . "</td>"; echo "<td>"; $query2 = "SELECT *\n FROM `glpi_networking`\n WHERE `ID`='" . $ID . "';"; $result2 = $DB->query($query2); $data2 = $DB->fetch_assoc($result2); if (empty($data2["ram"])) { $ram_pourcentage = 0; } else { $ram_pourcentage = ceil(100 * ($data2["ram"] - $this->fields['memory']) / $data2["ram"]); } PluginFusioninventoryDisplay::bar($ram_pourcentage, " (" . ($data2["ram"] - $this->fields['memory']) . " Mo / " . $data2["ram"] . " Mo)", 'inverse'); echo "</td>"; echo "</tr>"; } echo "</table></form>"; // ********************************************************************************************** // // *********************************** METTRE TABLEAU DES PORTS ********************************* // // ********************************************************************************************** // function ByteSize($bytes, $sizeoct = 1024) { $size = $bytes / $sizeoct; if ($size < $sizeoct) { $size = number_format($size, 0); $size .= ' K'; } else { if ($size / $sizeoct < $sizeoct) { $size = number_format($size / $sizeoct, 0); $size .= ' M'; } else { if ($size / $sizeoct / $sizeoct < $sizeoct) { $size = number_format($size / $sizeoct / $sizeoct, 0); $size .= ' G'; } else { if ($size / $sizeoct / $sizeoct / $sizeoct < $sizeoct) { $size = number_format($size / $sizeoct / $sizeoct / $sizeoct, 0); $size .= ' T'; } } } } return $size; } $query = "\n\t\tSELECT *,glpi_plugin_fusioninventory_networking_ports.ifmac as ifmacinternal\n\t\t\n\t\tFROM glpi_plugin_fusioninventory_networking_ports\n\n\t\tLEFT JOIN glpi_networking_ports\n\t\tON glpi_plugin_fusioninventory_networking_ports.FK_networking_ports = glpi_networking_ports.ID \n\t\tWHERE glpi_networking_ports.on_device='" . $ID . "'\n\t\tORDER BY logical_number "; echo "<script type='text/javascript'>\nfunction close_array(id){\n\tdocument.getElementById('plusmoins'+id).innerHTML = '<img src=\\'" . GLPI_ROOT . "/pics/collapse.gif\\''+\n 'onClick=\\'Effect.Fade(\"viewfollowup'+id+'\");appear_array('+id+');\\' />';\n} \nfunction appear_array(id){\n\tdocument.getElementById('plusmoins'+id).innerHTML = '<img src=\\'" . GLPI_ROOT . "/pics/expand.gif\\''+\n 'onClick=\\'Effect.Appear(\"viewfollowup'+id+'\");close_array('+id+');\\' />';\n}\t\t\n\t\t\n\t\t</script>"; echo "<table class='tab_cadre' cellpadding='5' width='1100'>"; echo "<tr class='tab_bg_1'>"; $query_array = "SELECT *\n FROM `glpi_display`\n WHERE `type`='" . PLUGIN_FUSIONINVENTORY_SNMP_NETWORKING_PORTS . "'\n AND `FK_users`='0'\n ORDER BY `rank`;"; $result_array = $DB->query($query_array); echo "<th colspan='" . (mysql_num_rows($result_array) + 2) . "'>"; echo $LANG['plugin_fusioninventory']["snmp"][40]; $result = $DB->query($query); echo ' (' . $DB->numrows($result) . ')'; if ($_SESSION["glpilanguage"] == "fr_FR") { $url_legend = "https://forge.indepnet.net/wiki/fusioninventory/Fr_VI_visualisationsdonnees_2_reseau"; } else { $url_legend = "https://forge.indepnet.net/wiki/fusioninventory/En_VI_visualisationsdonnees_2_reseau"; } echo " <a href='" . $url_legend . "'>[ " . $LANG['plugin_fusioninventory']["functionalities"][6] . " ]</a>"; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo '<th><img alt="Sélectionnez les éléments à afficher par défaut" title="Sélectionnez les éléments à afficher par défaut" src="' . GLPI_ROOT . '/pics/options_search.png" class="pointer" onclick="var w = window.open(\'' . GLPI_ROOT . '/front/popup.php?popup=search_config&type=5157\' ,\'glpipopup\', \'height=400, width=1000, top=100, left=100, scrollbars=yes\' ); w.focus();"></th>'; echo "<th>" . $LANG["common"][16] . "</th>"; $query_array = "SELECT * \n FROM `glpi_display`\n WHERE `type`='5157'\n AND `FK_users`='0'\n ORDER BY `rank`;"; $result_array = $DB->query($query_array); while ($data_array = $DB->fetch_array($result_array)) { echo "<th>"; switch ($data_array['num']) { case 2: echo $LANG['plugin_fusioninventory']["snmp"][42]; break; case 3: echo $LANG['plugin_fusioninventory']["snmp"][43]; break; case 4: echo $LANG['plugin_fusioninventory']["snmp"][44]; break; case 5: echo $LANG['plugin_fusioninventory']["snmp"][45]; break; case 6: echo $LANG['plugin_fusioninventory']["snmp"][46]; break; case 7: echo $LANG['plugin_fusioninventory']["snmp"][47]; break; case 8: echo $LANG['plugin_fusioninventory']["snmp"][48]; break; case 9: echo $LANG['plugin_fusioninventory']["snmp"][49]; break; case 10: echo $LANG['plugin_fusioninventory']["snmp"][51]; break; case 11: echo $LANG['plugin_fusioninventory']["mapping"][115]; break; case 12: echo $LANG["networking"][17]; break; case 13: echo $LANG['plugin_fusioninventory']["snmp"][50]; break; case 14: echo $LANG["networking"][56]; break; case 15: echo $LANG['plugin_fusioninventory']["snmp"][41]; break; } echo "</th>"; } echo "</tr>"; // Fin de l'entête du tableau if ($result) { while ($data = $DB->fetch_array($result)) { $background_img = ""; if ($data["trunk"] == "1" and (strstr($data["ifstatus"], "up") or strstr($data["ifstatus"], "1"))) { $background_img = " style='background-image: url(\"" . GLPI_ROOT . "/plugins/fusioninventory/pics/port_trunk.png\"); '"; } else { if ($data["trunk"] == "-1" and (strstr($data["ifstatus"], "up") or strstr($data["ifstatus"], "1"))) { $background_img = " style='background-image: url(\"" . GLPI_ROOT . "/plugins/fusioninventory/pics/multiple_mac_addresses.png\"); '"; } else { if (strstr($data["ifstatus"], "up") or strstr($data["ifstatus"], "1")) { $background_img = " style='background-image: url(\"" . GLPI_ROOT . "/plugins/fusioninventory/pics/connected_trunk.png\"); '"; } } } echo "<tr class='tab_bg_1 center' height='40'" . $background_img . ">"; echo "<td id='plusmoins" . $data["ID"] . "'><img src='" . GLPI_ROOT . "/pics/expand.gif' onClick='Effect.Appear(\"viewfollowup" . $data["ID"] . "\");close_array(" . $data["ID"] . ");' /></td>"; echo "<td><a href='networking.port.php?ID=" . $data["ID"] . "'>" . $data["name"] . "</a></td>"; $query_array = "SELECT *\n FROM `glpi_display`\n WHERE `type`='5157'\n AND `FK_users`='0'\n ORDER BY `rank`;"; $result_array = $DB->query($query_array); while ($data_array = $DB->fetch_array($result_array)) { switch ($data_array['num']) { case 2: echo "<td>" . $data["ifmtu"] . "</td>"; break; case 3: echo "<td>" . ByteSize($data["ifspeed"], 1000) . "bps</td>"; break; case 4: echo "<td>"; if (strstr($data["ifstatus"], "up") or strstr($data["ifinternalstatus"], "1")) { echo "<img src='" . GLPI_ROOT . "/pics/greenbutton.png'/>"; } else { if (strstr($data["ifstatus"], "down") or strstr($data["ifinternalstatus"], "2")) { echo "<img src='" . GLPI_ROOT . "/pics/redbutton.png'/>"; } else { if (strstr($data["ifstatus"], "testing") or strstr($data["ifinternalstatus"], "3")) { echo "<img src='" . GLPI_ROOT . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } } } echo "</td>"; break; case 5: echo "<td>" . $data["iflastchange"] . "</td>"; break; case 6: echo "<td>"; if ($data["ifinoctets"] == "0") { echo "-"; } else { echo ByteSize($data["ifinoctets"], 1000) . "o"; } echo "</td>"; break; case 7: if ($data["ifinerrors"] == "0") { echo "<td>-"; } else { echo "<td background='#cf9b9b' class='tab_bg_1_2'>"; echo $data["ifinerrors"]; } echo "</td>"; break; case 8: echo "<td>"; if ($data["ifinoctets"] == "0") { echo "-"; } else { echo ByteSize($data["ifoutoctets"], 1000) . "o"; } echo "</td>"; break; case 9: if ($data["ifouterrors"] == "0") { echo "<td>-"; } else { echo "<td background='#cf9b9b' class='tab_bg_1_2'>"; echo $data["ifouterrors"]; } echo "</td>"; break; case 10: echo "<td>" . $data["portduplex"] . "</td>"; break; case 11: // ** internal mac echo "<td>" . $data["ifmac"] . "</td>"; break; case 12: // ** Mac address and link to device which are connected to this port $opposite_port = $nw->getOppositeContact($data["FK_networking_ports"]); if ($opposite_port != "") { $query_device = "SELECT * \n FROM `glpi_networking_ports`\n WHERE `ID`='" . $opposite_port . "';"; $result_device = $DB->query($query_device); $data_device = $DB->fetch_assoc($result_device); $CommonItem->getFromDB($data_device["device_type"], $data_device["on_device"]); $link1 = $CommonItem->getLink(1); $link = str_replace($CommonItem->getName(0), $data_device["ifmac"], $CommonItem->getLink()); $link2 = str_replace($CommonItem->getName(0), $data_device["ifaddr"], $CommonItem->getLink()); if ($data_device["device_type"] == PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN) { if ($CommonItem->getField("accepted") == "1") { echo "<td style='background:#bfec75'\n class='tab_bg_1_2'>" . $link1; } else { echo "<td background='#cf9b9b'\n class='tab_bg_1_2'>" . $link1; } if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } echo "</td>"; } else { echo "<td>" . $link1; if (!empty($link)) { echo "<br/>" . $link; } if (!empty($link2)) { echo "<br/>" . $link2; } echo "</td>"; } } else { echo "<td></td>"; } break; case 13: // ** Connection status echo "<td>"; if (strstr($data["ifstatus"], "up") or strstr($data["ifstatus"], "1")) { echo "<img src='" . GLPI_ROOT . "/pics/greenbutton.png'/>"; } else { if (strstr($data["ifstatus"], "down") or strstr($data["ifstatus"], "2")) { echo "<img src='" . GLPI_ROOT . "/pics/redbutton.png'/>"; } else { if (strstr($data["ifstatus"], "testing") or strstr($data["ifstatus"], "3")) { echo "<img src='" . GLPI_ROOT . "/plugins/fusioninventory/pics/yellowbutton.png'/>"; } else { if (strstr($data["ifstatus"], "dormant") or strstr($data["ifstatus"], "5")) { echo "<img src='" . GLPI_ROOT . "/plugins/fusioninventory/pics/orangebutton.png'/>"; } } } } echo "</td>"; break; case 14: echo "<td>"; $canedit = haveRight("networking", "w"); $used = array(); $query_vlan = "SELECT * FROM glpi_networking_vlan WHERE FK_port='" . $data["ID"] . "'"; $result_vlan = $DB->query($query_vlan); if ($DB->numrows($result_vlan) > 0) { echo "<table cellpadding='0' cellspacing='0'>"; while ($line = $DB->fetch_array($result_vlan)) { $used[] = $line["FK_vlan"]; $a_vlan = Dropdown::getDropdownName("glpi_dropdown_vlan", $line["FK_vlan"], 1); echo "<tr><td>" . $a_vlan['name'] . " [" . $a_vlan['comments'] . "]"; echo "</td><td>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/networking.port.php?unassign_vlan=unassigned&ID=" . $line["ID"] . "'>"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/delete2.png\" alt='" . $LANG['buttons'][6] . "' title='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; } echo "</table>"; } else { echo " "; } echo "</td>"; break; case 15: //Port description echo "<td>" . $data["ifdescr"] . "</td>"; break; } } echo "</tr>"; // Historique echo "\n\t\t\t\t<tr style='display: none;' id='viewfollowup" . $data["ID"] . "'>\n\t\t\t\t\t<td colspan='" . (mysql_num_rows($result_array) + 2) . "'>" . PluginFusioninventorySnmphistory::showHistory($data["ID"]) . "</td>\n\t\t\t\t</tr>\n\t\t\t\t"; } } echo "</table>"; }
function showFormPrinter_pagescounter($target, $ID) { global $DB, $CFG_GLPI, $LANG, $FUSIONINVENTORY_MAPPING; $plugin_fusioninventory_printers = new PluginFusioninventoryPrinters(); $plugin_fusioninventory_snmp = new PluginFusioninventorySNMP(); $this->ID = $ID; $query = "SELECT * \n FROM `glpi_plugin_fusioninventory_printers`\n WHERE `FK_printers`=" . $ID . " "; $result = $DB->query($query); $data = $DB->fetch_assoc($result); switch ($data['frequence_days']) { case 1: $frequence = "day"; break; case 7: $frequence = "week"; break; case 30: $frequence = "month"; break; case 365: $frequence = "year"; break; } // get infos to get visible or not the counters $snmp_model_ID = $plugin_fusioninventory_snmp->GetSNMPModel($ID, PRINTER_TYPE); // ** Get link OID fields $Array_Object_TypeNameConstant = $plugin_fusioninventory_snmp->GetLinkOidToFields($ID, PRINTER_TYPE); $mapping_name = array(); foreach ($Array_Object_TypeNameConstant as $object => $mapping_type_name) { //$explode = explode("||", $mapping_type_name); $mapping_name[$mapping_type_name] = "1"; } // Form pages counter // echo "<br>"; echo "<div align='center'><form method='post' name='snmp_form' id='snmp_form'\n action=\"" . $target . "\">"; echo "<table class='tab_cadre' cellpadding='5' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG["cartridges"][39]; echo "</th>"; echo "</tr>"; if (isset($mapping_name['pagecountertotalpages']) and $mapping_name['pagecountertotalpages'] == "1") { // Total page counter echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["mapping"][128]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; // calendrier if (!isset($_SESSION["datetotalpages"])) { $_SESSION["datetotalpages"] = ""; } PluginFusioninventory::printer_calendar($_SESSION["datetotalpages"], "datetotalpages", $target); // fin calendrier echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; $Array = $plugin_fusioninventory_printers->getPagesCount($ID, $frequence, $_SESSION["datetotalpages"], 'pages_total'); echo "<table class='tab_cadre' cellpadding='5' width='900'>"; $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["common"][27], $Array['dates'], 1); $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["printers"][31], $Array['count']); $ecart = $plugin_fusioninventory_printers->counter_page_arrayLine_display_difference("ecart", $Array['count'], $Array['dates']); echo "</table>"; $plugin_fusioninventory_printers->graphBy($ecart, $LANG['plugin_fusioninventory']["mapping"][128], $LANG['plugin_fusioninventory']["printer"][0], 1, $frequence); echo "</td>"; echo "</tr>"; } if (isset($mapping_name['pagecounterblackpages']) and $mapping_name['pagecounterblackpages'] == "1") { // ** Black & white page counter echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["mapping"][129]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; if (!isset($_SESSION["dateblackpages"])) { $_SESSION["dateblackpages"] = ""; } PluginFusioninventory::printer_calendar($_SESSION["dateblackpages"], "dateblackpages", $target); // fin calendrier echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; $Array = $plugin_fusioninventory_printers->getPagesCount($ID, $frequence, $_SESSION["dateblackpages"], 'pages_n_b'); echo "<table class='tab_cadre' cellpadding='5' width='900'>"; $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["common"][27], $Array['dates'], 1); $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["printers"][31], $Array['count']); $ecart = $plugin_fusioninventory_printers->counter_page_arrayLine_display_difference("ecart", $Array['count'], $Array['dates']); echo "</table>"; $plugin_fusioninventory_printers->graphBy($ecart, $LANG['plugin_fusioninventory']["mapping"][129], $LANG['plugin_fusioninventory']["printer"][0], 1, $frequence); echo "</td>"; echo "</tr>"; } if (isset($mapping_name['pagecountercolorpages']) and $mapping_name['pagecountercolorpages'] == "1") { // ** Color page counter echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["mapping"][130]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; if (!isset($_SESSION["datecolorpages"])) { $_SESSION["datecolorpages"] = ""; } PluginFusioninventory::printer_calendar($_SESSION["datecolorpages"], "datecolorpages", $target); // fin calendrier echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; $Array = $plugin_fusioninventory_printers->getPagesCount($ID, $frequence, $_SESSION["datecolorpages"], 'pages_color'); echo "<table class='tab_cadre' cellpadding='5' width='900'>"; $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["common"][27], $Array['dates'], 1); $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["printers"][31], $Array['count']); $ecart = $plugin_fusioninventory_printers->counter_page_arrayLine_display_difference("ecart", $Array['count'], $Array['dates']); echo "</table>"; $plugin_fusioninventory_printers->graphBy($ecart, $LANG['plugin_fusioninventory']["mapping"][130], $LANG['plugin_fusioninventory']["printer"][0], 1, $frequence); echo "</td>"; echo "</tr>"; } if (isset($mapping_name['pagecounterrectoversopages']) and $mapping_name['pagecounterrectoversopages'] == "1") { // ** Recto/Verso page counter echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["mapping"][154]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; if (!isset($_SESSION["daterectoversopages"])) { $_SESSION["daterectoversopages"] = ""; } PluginFusioninventory::printer_calendar($_SESSION["daterectoversopages"], "daterectoversopages", $target); // fin calendrier echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; $Array = $plugin_fusioninventory_printers->getPagesCount($ID, $frequence, $_SESSION["daterectoversopages"], 'pages_recto_verso'); echo "<table class='tab_cadre' cellpadding='5' width='900'>"; $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["common"][27], $Array['dates'], 1); $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["printers"][31], $Array['count']); $ecart = $plugin_fusioninventory_printers->counter_page_arrayLine_display_difference("ecart", $Array['count'], $Array['dates']); echo "</table>"; $plugin_fusioninventory_printers->graphBy($ecart, $LANG['plugin_fusioninventory']["mapping"][154], $LANG['plugin_fusioninventory']["printer"][0], 1, $frequence); echo "</td>"; echo "</tr>"; } if (isset($mapping_name['pagecounterscannedpages']) and $mapping_name['pagecounterscannedpages'] == "1") { // ** Scanned page counter echo "<tr class='tab_bg_1'>"; echo "<th colspan='3'>"; echo $LANG['plugin_fusioninventory']["mapping"][155]; echo "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; if (!isset($_SESSION["datescannedpages"])) { $_SESSION["datescannedpages"] = ""; } PluginFusioninventory::printer_calendar($_SESSION["datescannedpages"], "datescannedpages", $target); // fin calendrier echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; $Array = $plugin_fusioninventory_printers->getPagesCount($ID, $frequence, $_SESSION["datescannedpages"], 'scanned'); echo "<table class='tab_cadre' cellpadding='5' width='900'>"; $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["common"][27], $Array['dates'], 1); $plugin_fusioninventory_printers->counter_page_arrayLine_display($LANG["printers"][31], $Array['count']); $ecart = $plugin_fusioninventory_printers->counter_page_arrayLine_display_difference("ecart", $Array['count'], $Array['dates']); echo "</table>"; $plugin_fusioninventory_printers->graphBy($ecart, $LANG['plugin_fusioninventory']["mapping"][155], $LANG['plugin_fusioninventory']["printer"][0], 1, $frequence); echo "</td>"; echo "</tr>"; } echo "</table>"; }
function plugin_fusioninventory_MassiveActionsDisplay($type, $action) { global $LANG, $CFG_GLPI, $DB; switch ($type) { case NETWORKING_TYPE: switch ($action) { case "plugin_fusioninventory_get_model": if (PluginFusioninventory::haveRight("snmp_models", "w")) { echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_assign_model": if (PluginFusioninventory::haveRight("snmp_models", "w")) { $query_models = "SELECT *\n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `device_type`!='2'\n AND `device_type`!='0';"; $result_models = $DB->query($query_models); $exclude_models = array(); while ($data_models = $DB->fetch_array($result_models)) { $exclude_models[] = $data_models['ID']; } Dropdown::show("PluginFusioninventoryModelInfos", array('name' => "snmp_model", 'value' => "name", 'comments' => false, 'used' => $exclude_models)); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_assign_auth": if (PluginFusioninventory::haveRight("snmp_authentification", "w")) { PluginFusioninventorySNMP::auth_dropdown(); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_manage_locks": $pfil = new PluginFusioninventoryLock(); $pfil->showForm($_SERVER["PHP_SELF"], NETWORKING_TYPE, ''); break; } break; case PRINTER_TYPE: switch ($action) { case "plugin_fusioninventory_get_model": if (PluginFusioninventory::haveRight("snmp_models", "w")) { echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_assign_model": if (PluginFusioninventory::haveRight("snmp_models", "w")) { $query_models = "SELECT *\n FROM `glpi_plugin_fusioninventory_model_infos`\n WHERE `device_type`!='3'\n AND `device_type`!='0';"; $result_models = $DB->query($query_models); $exclude_models = array(); while ($data_models = $DB->fetch_array($result_models)) { $exclude_models[] = $data_models['ID']; } Dropdown::show("PluginFusioninventoryModelInfos", array('name' => "snmp_model", 'value' => "name", 'comments' => false, 'used' => $exclude_models)); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_assign_auth": if (PluginFusioninventory::haveRight("snmp_authentification", "w")) { PluginFusioninventorySNMP::auth_dropdown(); echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; case "plugin_fusioninventory_manage_locks": $pfil = new PluginFusioninventoryLock(); $pfil->showForm($_SERVER["PHP_SELF"], NETWORKING_TYPE, ''); break; } break; case PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN: switch ($action) { case "plugin_fusioninventory_discovery_import": if (PluginFusioninventory::haveRight("unknowndevices", "w")) { echo "<input type=\"submit\" name=\"massiveaction\" class=\"submit\" value=\"" . $LANG["buttons"][2] . "\" >"; } break; } break; } return ""; }
/** * Import CONNECTION *@param $p_connection CONNECTION code to import *@param $p_oPort Port object to connect *@param $p_cdp CDP value (1 or <>1) *@return errors string to be alimented if import ko / '' if ok **/ function importConnection($p_connection, $p_oPort, $p_cdp) { global $LANG; $this->addLog('Function importConnection().'); $errors = ''; $portID = ''; $mac = ''; $ip = ''; $ptsnmp = new PluginFusioninventorySNMP(); if ($p_cdp == 1) { $ifdescr = ''; foreach ($p_connection->children() as $name => $child) { switch ($child->getName()) { case 'IP': $ip = $child; $p_oPort->addIp($ip); break; case 'IFDESCR': $ifdescr = $child; break; default: $errors .= $LANG['plugin_fusioninventory']["errors"][22] . ' CONNECTION (CDP=' . $p_cdp . ') : ' . $child->getName() . "\n"; } } $portID = $ptsnmp->getPortIDfromDeviceIP($ip, $ifdescr); } else { foreach ($p_connection->children() as $name => $child) { switch ($child->getName()) { case 'MAC': $mac = $child; $portID = $ptsnmp->getPortIDfromDeviceMAC($child, $p_oPort->getValue('ID')); $p_oPort->addMac($mac); break; case 'IP': //TODO : si ip ajouter une tache de decouverte sur l'ip pour recup autre info // utile seulement si mac inconnu dans glpi $ip = $child; $p_oPort->addIp($ip); break; default: $errors .= $LANG['plugin_fusioninventory']["errors"][22] . ' CONNECTION (CDP=' . $p_cdp . ') : ' . $child->getName() . "\n"; } } } if ($portID != '') { $p_oPort->addConnection($portID); if ($ip != '') { $p_oPort->setValue('ifaddr', $ip); } } else { $p_oPort->addUnknownConnection($mac, $ip); //TODO : si ip ajouter une tache de decouverte sur l'ip pour recup autre info } return $errors; }