Пример #1
0
 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;
 }
Пример #2
0
 static function getConnectedPortList($DeviceID)
 {
     global $dbh;
     $dev = new Device();
     $dev->DeviceID = $DeviceID;
     if (!$dev->GetDevice()) {
         return false;
         // This device doesn't exist
     }
     $sql = "SELECT * FROM fac_PowerPorts WHERE DeviceID={$dev->DeviceID} and ConnectedDeviceID>0";
     $portList = array();
     foreach ($dbh->query($sql) as $row) {
         $portList[$row['PortNumber']] = PowerPorts::RowToObject($row);
     }
     if (sizeof($portList) == 0 && $dev->DeviceType != "Physical Infrastructure") {
         // somehow this device doesn't have ports so make them now
         $portList = PowerPorts::createPorts($dev->DeviceID);
     }
     return $portList;
 }