// // Copy an existing device to the new position, adjusting the name automagically per rules in the CopyDevice method // URL: /api/v1/device/:deviceid/copyto/:newposition // Method: PUT // Params: deviceid (passed in URL) // Required: Label, cabinetid // Optional: everything else // Returns: record as created // $app->put('/device/:deviceid/copyto/:newposition', function ($deviceid, $newposition) use($app) { $dev = new Device(); $dev->DeviceID = $deviceid; $dev->GetDevice(); $cab = new Cabinet(); $cab->CabinetID = $dev->Cabinet; if (!$cab->GetCabinet()) { $response['error'] = true; $response['errorcode'] = 404; $response['message'] = __("Cabinet not found"); } else { if ($cab->Rights != "Write") { $response['error'] = true; $response['errorcode'] = 403; $response['message'] = __("Unauthorized"); } else { if (!$dev->CopyDevice(null, $newposition)) { $response['error'] = true; $response['errorcode'] = 404; $response['message'] = __("Device creation failed"); } else { // refresh the model in case we extended it elsewhere
<?php require_once "db.inc.php"; require_once "facilities.inc.php"; $subheader = __("Map Selector"); if (!$person->SiteAdmin) { // No soup for you. header("Location: " . redirect()); exit; } $dc = new DataCenter(); $cab = new Cabinet(); $cab->CabinetID = $_REQUEST["cabinetid"]; $cab->GetCabinet(); $dc->DataCenterID = $cab->DataCenterID; $dc->GetDataCenter(); if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "Submit") { $cab->MapX1 = intval($_REQUEST["x1"]); $cab->MapX2 = intval($_REQUEST["x2"]); $cab->MapY1 = intval($_REQUEST["y1"]); $cab->MapY2 = intval($_REQUEST["y2"]); $cab->FrontEdge = $_REQUEST["frontedge"]; $cab->UpdateCabinet(); $url = redirect("cabnavigator.php?cabinetid={$cab->CabinetID}"); header("Location: {$url}"); } $height = 0; $width = 0; if (strlen($dc->DrawingFileName) > 0) { $mapfile = "drawings/{$dc->DrawingFileName}"; if (file_exists($mapfile)) {
function MakePath() { $this->MakeSafe(); //reset PathError $this->PathError = 0; //check devices/ports $device = new Device(); $device->DeviceID = $this->devID1; if (!$device->GetDevice()) { $this->PathError = 1; //dev1 does not exist return false; } $devType1 = $device->DeviceType; if ($device->DeviceType == "Patch Panel") { $this->PathError = 2; //dev1 is a Patch Pannel return false; } $port1 = new DevicePorts(); $port1->DeviceID = $this->devID1; $port1->PortNumber = $this->port1; if (!$port1->getPort()) { $this->PathError = 3; //dev1,port1 is missing return False; } if ($port1->ConnectedDeviceID > 0 && $port1->ConnectedPort > 0) { $this->PathError = 4; //dev1,port1 is connected return False; } $device->DeviceID = $this->devID2; if (!$device->GetDevice()) { $this->PathError = 5; //dev2 does not exist return false; } $devType2 = $device->DeviceType; if ($device->DeviceType == "Patch Panel") { $this->PathError = 6; //dev2 is a Patch Pannel return false; } $port2 = new DevicePorts(); $port2->DeviceID = $this->devID2; $port2->PortNumber = $this->port2; if (!$port2->getPort()) { $this->PathError = 7; //dev2,port2 is missing return False; } if ($port2->ConnectedDeviceID > 0 && $port2->ConnectedPort > 0) { $this->PathError = 8; //dev2,port2 is connected return False; } //get dev2 info $this->cab2 = $device->GetDeviceCabinetID(); //cab2 $cabinet = new Cabinet(); $cabinet->CabinetID = $this->cab2; $cabinet->GetCabinet(); $this->row2 = $cabinet->CabRowID; //row2 //if dev2 is panel protected device (connected to rear connection of a panel) $this->espejo2 = $port2->ConnectedDeviceID > 0 && $port2->ConnectedPort < 0; @unlink('ppath.log'); $this->escribe_log("**** NEW PATH ****"); $this->escribe_log("DEV1: ID=" . $this->devID1 . " PORT=" . $this->port1); $this->escribe_log("DEV2: ID=" . $this->devID2 . " PORT=" . $this->port2 . " CAB_ID=" . $this->cab2 . " ROW_ID=" . $this->row2); $this->escribe_log("-------------------"); //reset Path $this->ClearPath(); //initiate list with device1, port1, weitgh=0, prev_dev=0, prev_port=0 $this->AddNodeToList($this->devID1, $this->port1, 0, 0, 0); while ($this->SelectNode()) { if ($this->DeviceID == $this->devID2) { $this->escribe_log("Target found. Making the PATH..."); //make the path $i = 1; while ($this->DeviceID > 0) { $dev = $this->DeviceID; $port = $this->PortNumber; $Path[$i]["DeviceID"] = $dev; $Path[$i]["PortNumber"] = $port; $this->DeviceID = $this->nodes[$dev][$port]["prev_dev"]; $this->PortNumber = $this->nodes[$dev][$port]["prev_port"]; $i++; } for ($j = 1; $j < $i; $j++) { $this->Path[$j]["DeviceID"] = $Path[$i - $j]["DeviceID"]; $this->Path[$j]["PortNumber"] = $Path[$i - $j]["PortNumber"]; } $this->escribe_log("PATH created."); $this->escribe_log(""); return true; } $this->UpdateList(); } $this->PathError = 9; //not found return false; }
function DeletePDU() { global $person; $this->MakeSafe(); // Do not attempt anything else if the lookup fails if (!$this->GetPDU()) { return false; } // Check rights $cab = new Cabinet(); $cab->CabinetID = $this->CabinetID; $cab->GetCabinet(); if (!$person->canWrite($cab->AssignedTo)) { return false; } // First, remove any connections to the PDU $tmpConn = new PowerConnection(); $tmpConn->PDUID = $this->PDUID; $connList = $tmpConn->GetConnectionsByPDU(); foreach ($connList as $delConn) { $delConn->RemoveConnection(); } // Clear out any records from PDUStats, possible S.U.T. involving changing // a devicetype but leaving behind a phantom reading for a non-power device $sql = "DELETE FROM fac_PDUStats WHERE PDUID={$this->PDUID};"; $this->exec($sql); $sql = "DELETE FROM fac_PowerDistribution WHERE PDUID={$this->PDUID};"; if (!$this->exec($sql)) { // Something went south and this didn't delete. return false; } else { class_exists('LogActions') ? LogActions::LogThis($this) : ''; return true; } }
<?php require_once "db.inc.php"; require_once "facilities.inc.php"; $subheader = __("Data Center Statistics"); $cab = new Cabinet(); $dc = new DataCenter(); $dev = new Device(); //setting airflow if (isset($_POST["cabinetid"]) && isset($_POST["airflow"]) && $person->SiteAdmin) { $cab->CabinetID = $_POST["cabinetid"]; if ($cab->GetCabinet()) { if ($cab->CabRowID > 0 && isset($_POST["row"]) && $_POST["row"] == "true") { //update all row $cabinets = $cab->GetCabinetsByRow(); foreach ($cabinets as $index => $cabinet) { $cabinet->FrontEdge = $_POST["airflow"]; $cabinet->UpdateCabinet(); } } else { //update cabinet $cab->FrontEdge = $_POST["airflow"]; $cab->UpdateCabinet(); } } exit; } if (isset($_POST['dc']) && (isset($_POST['getobjects']) || isset($_POST['getoverview']))) { $payload = array(); if (isset($_POST['getobjects'])) { $cab->DataCenterID = $_POST['dc'];
foreach ($cabinetList as $cab) { $device = new Device(); $device->Cabinet = $cab->CabinetID; foreach ($device->ViewDevicesByCabinet(true) as $dev) { if (!isset($devList[$dev->DeviceType])) { $devList[$dev->DeviceType] = array(); } $devList[$dev->DeviceType][$dev->DeviceID] = array(); } } } } elseif (isset($_REQUEST['cabid'])) { $cabid = isset($_POST['cabid']) ? $_POST['cabid'] : $_GET['cabid']; $cabinet = new Cabinet(); $cabinet->CabinetID = $cabid; $cabinet->GetCabinet(); $datacenter = new DataCenter(); $datacenter->DataCenterID = $cabinet->DataCenterID; $datacenter->GetDataCenter(); $graphname .= "Cabinet " . $cabinet->Location . " in Data Center " . $datacenter->Name; $device = new Device(); $device->Cabinet = $cabid; foreach ($device->ViewDevicesByCabinet(true) as $dev) { if (!isset($devList[$dev->DeviceType])) { $devList[$dev->DeviceType] = array(); } $devList[$dev->DeviceType][$dev->DeviceID] = array(); } } elseif (isset($_REQUEST['tagname'])) { $graphname .= "Custom Tag " . $_REQUEST['tagname']; $device = new Device();
function BuildCabinet($cabid, $face = "front") { $cab = new Cabinet($cabid); $cab->GetCabinet(); $order = $cab->U1Position == "Top" ? false : true; $dev = new Device(); $dev->Cabinet = $cab->CabinetID; $dev->ParentDevice = 0; $bounds = array('max' => array('position' => 0, 'height' => 0), 'min' => array('position' => 0, 'height' => 0)); // Read in all the devices and make sure they fit the cabinet. If not expand it foreach ($dev->Search() as $device) { if ($device->Position == 0) { continue; } $pos = $order ? $device->Position : $device->Position - $device->Height; if ($device->Position > $bounds['max']['position']) { $bounds['max']['position'] = $device->Position; $bounds['max']['height'] = $device->Height; } if ($pos < $bounds['min']['position']) { $bounds['min']['position'] = $pos; $bounds['min']['height'] = 1; } } if ($order) { $top = max($cab->CabinetHeight, $bounds['max']['position'] + $bounds['max']['height'] - 1); $bottom = min(0, $bounds['min']['position']); } else { // Reverse order $top = min(1, $bounds['min']['position'] - $bounds['min']['height']); $bottom = max($cab->CabinetHeight, $bounds['max']['position']); } // Build cabinet HTML switch ($face) { case "rear": $cab->Location = "{$cab->Location} (" . __("Rear") . ")"; break; case "side": $cab->Location = "{$cab->Location} (" . __("Side") . ")"; break; default: // Leave the location alone } // helper function to print the rows of the cabinet table if (!function_exists("printrow")) { function printrow($i, $top, $bottom, $order, $face, &$htmlcab, $cabobject) { $error = $i > $cabobject->CabinetHeight || $i <= 0 && $order || $i < 0 && !$order ? ' error' : ''; if ($order) { $x = $i <= 0 ? $i - 1 : $i; } else { $x = $i >= 0 ? $i + 1 : $i; } if ($i == $top) { if ($face == "rear") { $rs = "-rear"; } elseif ($face == "side") { $rs = "-side"; } else { $rs = ""; } $rowspan = abs($top) + abs($bottom); $height = (abs($top) + abs($bottom)) * ceil(220 * (1.75 / 19)) . "px"; $htmlcab .= "\t<tr id=\"pos{$x}\"><td class=\"pos{$error}\">{$x}</td><td rowspan={$rowspan}><div id=\"servercontainer{$rs}\" class=\"freespace\" style=\"width: 220px; height: {$height}\" data-face=\"{$face}\"></div></td></tr>\n"; } else { $htmlcab .= "\t<tr id=\"pos{$x}\"><td class=\"pos{$error}\">{$x}</td></tr>\n"; } } } // If they have rights to the device then make the picture clickable $clickable = $cab->Rights != "None" ? "\t\t<a href=\"cabnavigator.php?cabinetid={$cab->CabinetID}\">\n\t" : ""; $clickableend = $cab->Rights != "None" ? "\n\t\t</a>\n" : ""; $htmlcab = "<table class=\"cabinet\" id=\"cabinet{$cab->CabinetID}\">\n\t<tr><th colspan=2>{$clickable}{$cab->Location}{$clickableend}</th></tr>\n\t<tr><td>Pos</td><td>Device</td></tr>\n"; // loop here for the height // numbered high to low, top to bottom if ($order) { for ($i = $top; $i > $bottom; $i--) { printrow($i, $top, $bottom, $order, $face, $htmlcab, $cab); } } else { // numbered low to high, top to bottom for ($i = $top; $bottom > $i; $i++) { printrow($i, $top, $bottom, $order, $face, $htmlcab, $cab); } } $htmlcab .= "</table>\n"; // Wrap it in a nice div $htmlcab = '<div class="cabinet">' . $htmlcab . '</div>'; // debug information // print "Cabinet: $cab->CabinetID Top: $top Bottom: $bottom<br>\n"; return $htmlcab; }