static function createPorts($DeviceID, $update_existing = false) { // If $update_existing is true then we'll try to create all the ports and as a by product // create any new ports. The setting here will ensure we don't log any errors from the // ports that already exist. $dev = new Device(); $dev->DeviceID = $DeviceID; if (!$dev->GetDevice()) { return false; } // Check the user's permissions to modify this device if ($dev->Rights != 'Write') { return false; } $portList = array(); if ($dev->DeviceType == "Switch") { $nameList = SwitchInfo::getPortNames($dev->DeviceID); $aliasList = SwitchInfo::getPortAlias($dev->DeviceID); } // Build the DevicePorts from the existing info in the following priority: // - Template ports table // - SNMP data (if it exists) // - Placeholders //Search template ports $tports = array(); if ($dev->TemplateID > 0) { $tport = new TemplatePorts(); $tport->TemplateID = $dev->TemplateID; $tports = $tport->getPorts(); } if ($dev->DeviceType == "Switch") { for ($n = 0; $n < $dev->Ports; $n++) { $i = $n + 1; $portList[$i] = new DevicePorts(); $portList[$i]->DeviceID = $dev->DeviceID; $portList[$i]->PortNumber = $i; if (isset($tports[$i])) { // Get any attributes from the device template foreach ($tports[$i] as $key => $value) { if (array_key_exists($key, $portList[$i])) { $portList[$i]->{$key} = $value; } } } // pull port name first from snmp then from template then just call it port x $portList[$i]->Label = isset($nameList[$n]) ? $nameList[$n] : isset($tports[$i]) && $tports[$i]->Label ? $tports[$i]->Label : __("Port") . $i; $portList[$i]->Notes = isset($aliasList[$n]) ? $aliasList[$n] : ''; $portList[$i]->createPort($update_existing); } } else { for ($n = 0; $n < $dev->Ports; $n++) { $i = $n + 1; $portList[$i] = new DevicePorts(); $portList[$i]->DeviceID = $dev->DeviceID; $portList[$i]->PortNumber = $i; if (isset($tports[$i])) { // Get any attributes from the device template foreach ($tports[$i] as $key => $value) { if (array_key_exists($key, $portList[$i])) { $portList[$i]->{$key} = $value; } } } $portList[$i]->Label = $portList[$i]->Label == "" ? __("Port") . $i : $portList[$i]->Label; $portList[$i]->createPort($update_existing); if ($dev->DeviceType == "Patch Panel") { $label = $portList[$i]->Label; $i = $i * -1; $portList[$i] = new DevicePorts(); $portList[$i]->DeviceID = $dev->DeviceID; $portList[$i]->PortNumber = $i; $portList[$i]->Label = $label; $portList[$i]->createPort($update_existing); } } } return $portList; }
echo json_encode(SwitchInfo::getPortNames($_POST['refreshswitch'])); } elseif (isset($_POST['Notes'])) { $dev->DeviceID = $_POST['refreshswitch']; $dev->GetDevice(); // This function should be hidden if they don't have rights, but just in case if ($dev->Rights == "Write") { foreach (SwitchInfo::getPortAlias($_POST['refreshswitch']) as $PortNumber => $Notes) { $port = new DevicePorts(); $port->DeviceID = $_POST['refreshswitch']; $port->PortNumber = $PortNumber; $port->getPort(); $port->Notes = $Notes; $port->updatePort(); } } echo json_encode(SwitchInfo::getPortAlias($_POST['refreshswitch'])); } else { echo json_encode(SwitchInfo::getPortStatus($_POST['refreshswitch'])); } exit; } if (isset($_POST["currwatts"]) && isset($_POST['pduid']) && $_POST['pduid'] > 0) { $pdu = new PowerDistribution(); $pdu->PDUID = $_POST['pduid']; $wattage->Wattage = 'Err'; $wattage->LastRead = 'Err'; if ($pdu->GetPDU()) { $cab->CabinetID = $pdu->CabinetID; $cab->GetCabinet(); if ($person->canWrite($cab->AssignedTo)) { $wattage = $pdu->LogManualWattage($_POST["currwatts"]);