$s->connectto = $app->request->get('connectto'); $s->listports = $app->request->get('listports'); $s->patchpanels = $app->request->get('patchpanels'); $s->limiter = $app->request->get('limiter'); $response['error'] = false; $response['errorcode'] = 200; // I like nulls and wrote this function originally around them foreach ($s as $prop => $val) { $s->{$prop} = !$val ? null : $val; } if (is_null($s->listports)) { $response['device'] = DevicePorts::getPatchCandidates($deviceid, $s->portnumber, null, $s->patchpanels, $s->limiter); } else { $dp = new DevicePorts(); $dp->DeviceID = $s->connectto; $list = $dp->getPorts(); foreach ($list as $key => $port) { if (!is_null($port->ConnectedDeviceID)) { if ($port->ConnectedDeviceID == $deviceid && $port->ConnectedPort == $s->portnumber) { // This is what is currently connected so leave it in the list } else { // Remove any other ports that already have connections unset($list[$key]); } } } // S.U.T. #2342 I touch myself if ($dp->DeviceID == $deviceid && isset($list[$s->portnumber])) { unset($list[$s->portnumber]); } // Sort the ports so that all front ports will be first then the rear ports.
function UpdateDevice() { global $dbh; // Stupid User Tricks #417 - A user could change a device that has connections (switch or patch panel) to one that doesn't // Stupid User Tricks #148 - A user could change a device that has children (chassis) to one that doesn't // // As a "safety mechanism" we simply won't allow updates if you try to change a chassis IF it has children // For the switch and panel connections, though, we drop any defined connections $tmpDev = new Device(); $tmpDev->DeviceID = $this->DeviceID; // You can't update what doesn't exist, so check for existing record first and retrieve the current location if (!$tmpDev->GetDevice()) { return false; } // Check the user's permissions to modify this device, but only if it's not a CLI call if (php_sapi_name() != "cli" && $tmpDev->Rights != 'Write') { return false; } $this->MakeSafe(); // A child device's cabinet must always match the parent so force it here if ($this->ParentDevice) { $parent = new Device(); $parent->DeviceID = $this->ParentDevice; $parent->GetDevice(); $this->Cabinet = $parent->Cabinet; } // Force all uppercase for labels $this->Label = transform($this->Label); $this->SerialNo = transform($this->SerialNo); $this->AssetTag = transform($this->AssetTag); $sql = "UPDATE fac_Device SET Label=\"{$this->Label}\", SerialNo=\"{$this->SerialNo}\", AssetTag=\"{$this->AssetTag}\", \r\n\t\t\tPrimaryIP=\"{$this->PrimaryIP}\", SNMPCommunity=\"{$this->SNMPCommunity}\", SNMPVersion=\"{$this->SNMPVersion}\",\r\n\t\t\tv3SecurityLevel=\"{$this->v3SecurityLevel}\", v3AuthProtocol=\"{$this->v3AuthProtocol}\",\r\n\t\t\tv3AuthPassphrase=\"{$this->v3AuthPassphrase}\", v3PrivProtocol=\"{$this->v3PrivProtocol}\", v3PrivPassphrase=\"{$this->v3PrivPassphrase}\",\r\n\t\t\tSNMPFailureCount={$this->SNMPFailureCount}, ESX={$this->ESX}, Owner={$this->Owner}, EscalationTimeID={$this->EscalationTimeID}, \r\n\t\t\tEscalationID={$this->EscalationID}, PrimaryContact={$this->PrimaryContact}, \r\n\t\t\tCabinet={$this->Cabinet}, Position={$this->Position}, Height={$this->Height}, Ports={$this->Ports}, \r\n\t\t\tFirstPortNum={$this->FirstPortNum}, TemplateID={$this->TemplateID}, NominalWatts={$this->NominalWatts}, \r\n\t\t\tPowerSupplyCount={$this->PowerSupplyCount}, DeviceType=\"{$this->DeviceType}\", ChassisSlots={$this->ChassisSlots}, \r\n\t\t\tRearChassisSlots={$this->RearChassisSlots},ParentDevice={$this->ParentDevice}, \r\n\t\t\tMfgDate=\"" . date("Y-m-d", strtotime($this->MfgDate)) . "\", \r\n\t\t\tInstallDate=\"" . date("Y-m-d", strtotime($this->InstallDate)) . "\", WarrantyCo=\"{$this->WarrantyCo}\", \r\n\t\t\tWarrantyExpire=\"" . date("Y-m-d", strtotime($this->WarrantyExpire)) . "\", Notes=\"{$this->Notes}\", \r\n\t\t\tReservation={$this->Reservation}, HalfDepth={$this->HalfDepth}, BackSide={$this->BackSide} WHERE DeviceID={$this->DeviceID};"; // If the device won't update for some reason there is no cause to touch anything else about it if (!$dbh->query($sql)) { $info = $dbh->errorInfo(); error_log("UpdateDevice::PDO Error: {$info[2]} SQL={$sql}"); return false; } // If you changed cabinets then the power connections need to be removed if ($tmpDev->Cabinet != $this->Cabinet) { $cab = new Cabinet(); $cab->CabinetID = $this->Cabinet; $cab->GetCabinet(); // Make sure the user has rights to save a device into the new cabinet if ($cab->Rights != "Write") { return false; } // They have rights to do this so clear the power connections now $powercon = new PowerConnection(); $powercon->DeviceID = $this->DeviceID; $powercon->DeleteConnections(); } if ($tmpDev->DeviceType == "Chassis" && $tmpDev->DeviceType != $this->DeviceType) { // SUT #148 - Previously defined chassis is no longer a chassis // If it has children, return with no update $childList = $this->GetDeviceChildren(); if (sizeof($childList) > 0) { $this->GetDevice(); return; } } // Device has been changed to be a CDU from something else so we need to create the extra records if ($this->DeviceType == "CDU" && $tmpDev->DeviceType != $this->DeviceType) { $pdu = new PowerDistribution(); $pdu->CreatePDU($dev->DeviceID); // Device was changed from CDU to something else, clean up the extra shit } elseif ($tmpDev->DeviceType == "CDU" && $tmpDev->DeviceType != $this->DeviceType) { $pdu = new PowerDistribution(); $pdu->PDUID = $this->DeviceID; $pdu->DeletePDU(); } // If we made it to a device update and the number of ports available don't match the device, just fix it. if ($tmpDev->Ports != $this->Ports) { if ($tmpDev->Ports > $this->Ports) { // old device has more ports for ($n = $this->Ports; $n < $tmpDev->Ports; $n++) { $p = new DevicePorts(); $p->DeviceID = $this->DeviceID; $p->PortNumber = $n + 1; $p->removePort(); if ($this->DeviceType == 'Patch Panel') { $p->PortNumber = $p->PortNumber * -1; $p->removePort(); } } } else { // new device has more ports DevicePorts::createPorts($this->DeviceID, true); } } // If we made it to a device update and the number of power ports available don't match the device, just fix it. if ($tmpDev->PowerSupplyCount != $this->PowerSupplyCount) { if ($tmpDev->PowerSupplyCount > $this->PowerSupplyCount) { // old device has more ports for ($n = $this->PowerSupplyCount; $n < $tmpDev->PowerSupplyCount; $n++) { $p = new PowerPorts(); $p->DeviceID = $this->DeviceID; $p->PortNumber = $n + 1; $p->removePort(); } } else { // new device has more ports PowerPorts::createPorts($this->DeviceID, true); } } if (($tmpDev->DeviceType == "Switch" || $tmpDev->DeviceType == "Patch Panel") && $tmpDev->DeviceType != $this->DeviceType) { // SUT #417 - Changed a Switch or Patch Panel to something else (even if you change a switch to a Patch Panel, the connections are different) if ($tmpDev->DeviceType == "Switch") { DevicePorts::removeConnections($this->DeviceID); } if ($tmpDev->DeviceType == "Patch Panel") { DevicePorts::removeConnections($this->DeviceID); $p = new DevicePorts(); $p->DeviceID = $this->DeviceID; $ports = $p->getPorts(); foreach ($ports as $i => $port) { if ($port->PortNumber < 0) { $port->removePort(); } } } } if ($this->DeviceType == "Patch Panel" && $tmpDev->DeviceType != $this->DeviceType) { // This asshole just changed a switch or something into a patch panel. Make the rear ports. $p = new DevicePorts(); $p->DeviceID = $this->DeviceID; if ($tmpDev->Ports != $this->Ports && $tmpDev->Ports < $this->Ports) { // since we just made the new rear ports up there only make the first few, hopefully. for ($n = 1; $n <= $tmpDev->Ports; $n++) { $i = $n * -1; $p->PortNumber = $i; $p->createPort(); } } else { // make a rear port to match every front port $ports = $p->getPorts(); foreach ($ports as $i => $port) { $port->PortNumber = $port->PortNumber * -1; $port->createPort(); } } } // Check and see if we extended the model to include any of the attributes for a CDU if ($this->DeviceType == "CDU") { $pdu = new PowerDistribution(); $pdu->PDUID = $this->DeviceID; $pdu->GetPDU(); foreach ($pdu as $prop => $val) { // See if the device modal was extended if (isset($this->{$prop})) { $pdu->{$prop} = $this->{$prop}; } } // Either we just updated this with new info or it's the same from the get $pdu->CabinetID = $this->Cabinet; $pdu->IPAddress = $this->PrimaryIP; $pdu->UpdatePDU(); } //Update children, if necesary if ($this->ChassisSlots > 0 || $this->RearChassisSlots > 0) { $this->SetChildDevicesCabinet(); } class_exists('LogActions') ? LogActions::LogThis($this, $tmpDev) : ''; return true; }
// Filter devices by rights $devs = array(); foreach ($dev->ViewDevicesByCabinet(true) as $d) { if ($d->Rights == "Write") { $devs[] = $d; } } displayjson($devs); } if (isset($_POST['dev'])) { $dp = new DevicePorts(); $dp->DeviceID = $_POST['dev']; $dev = new Device(); $dev->DeviceID = $dp->DeviceID; $dev->GetDevice(); $ports = $dev->Rights == "Write" ? $dp->getPorts() : array(); displayjson($ports); } // AJAX - End if (!$person->SiteAdmin) { // No soup for you. header('Location: ' . redirect()); exit; } if (isset($_POST['bot_implementar'])) { for ($i = 1; $i < $_POST['elem_path']; $i++) { if ($_POST["PortNumber"][$i] > 0 && $_POST["PortNumber"][$i + 1] < 0) { $port1 = new DevicePorts(); $port1->DeviceID = $_POST["DeviceID"][$i]; $port1->PortNumber = $_POST["PortNumber"][$i]; $port1->Notes = isset($_POST['notes']) ? $_POST['notes'] : "";
if (file_exists("pictures/" . $devTmpl->FrontPictureFile)) { $img = new PHPExcel_Worksheet_Drawing(); $img->setWorksheet($sheet->setActiveSheetIndex($devNum)); $img->setName($dev->Label); $img->setPath("pictures/" . $devTmpl->FrontPictureFile); $img->setCoordinates('B9'); $img->setOffsetX(1); $img->setOffsetY(5); } foreach (range('A', 'B') as $columnID) { $sheet->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true); } $sheet->setActiveSheetIndex(0); $port = new DevicePorts(); $port->DeviceID = $dev->DeviceID; $portList = $port->getPorts(); /* if ( sizeof( $portList ) < 1 ) { // No ports for this device header('Location: '.redirect()); exit; } */ $pport = new PowerPorts(); $pport->DeviceID = $dev->DeviceID; $pportList = $pport->getPorts(); // Make power cable labels based on the number of power supplies foreach ($pportList as $powerPort) { $sheet->getActiveSheet()->SetCellValue('A' . $row, $dev->Label); $sheet->getActiveSheet()->SetCellValue('B' . $row, $powerPort->Label); if ($powerPort->ConnectedDeviceID > 0) {