Ejemplo n.º 1
0
    }
    // This should be in the commit data but if we get a smartass saying it's in the URL
    $dt->Model = $model;
    if (!$person->WriteAccess) {
        $response['error'] = true;
        $response['errorcode'] = 403;
        $response['message'] = __("Unauthorized");
    } else {
        if (!$dt->CreateTemplate()) {
            $response['error'] = true;
            $response['errorcode'] = 404;
            $response['message'] = __("Device template creation failed");
        } else {
            // refresh the model in case we extended it elsewhere
            $d = new DeviceTemplate($dt->TemplateID);
            $d->GetTemplateByID();
            $response['error'] = false;
            $response['errorcode'] = 200;
            $response['devicetemplate'] = $d;
        }
    }
    echoResponse(200, $response);
});
//
//	URL:	/api/v1/devicetemplate/:templateid/dataport/:portnum
//	Method:	PUT
//	Params:
//		Required: templateid, portnum, portlabel
//		Optional: everything else
//	Returns: record as created
//
Ejemplo n.º 2
0
<?php

require_once "../db.inc.php";
require_once "../facilities.inc.php";
$tmpl = new DeviceTemplate();
$deviceList = array();
$searchTerm = "";
if (isset($_REQUEST["q"])) {
    $searchTerm = $_REQUEST["q"];
}
//This will ensure that an empty json record set is returned if this is called directly or in some strange manner
if ($searchTerm != "") {
    $tmpl->TemplateID = $searchTerm;
    $tmpl->GetTemplateByID();
}
header('Content-Type: application/json');
echo json_encode($tmpl);
Ejemplo n.º 3
0
// Get list of media types
if (isset($_GET['mt'])) {
    header('Content-Type: application/json');
    echo json_encode(MediaTypes::GetMediaTypeList());
    exit;
}
if (!$person->WriteAccess) {
    // No soup for you.
    header('Location: ' . redirect());
    exit;
}
$template = new DeviceTemplate();
$manufacturer = new Manufacturer();
if (isset($_POST['deleteme'])) {
    $template->TemplateID = $_POST['TemplateID'];
    if ($template->GetTemplateByID()) {
        // First deal with the case that we are transferring
        if ($template->TemplateID != $_POST['transferid'] && $_POST['transferid'] == 0) {
            // We should do this in bulk,  this has potential to be a real time sink
            foreach (Device::GetDevicesByTemplate($template->TemplateID) as $dev) {
                $dev->TemplateID->{$_POST}['transferid'];
                $dev->UpdateDevice();
            }
        }
        // Transfers are done, delete this shit
        $template->DeleteTemplate();
    }
    echo '1';
    exit;
}
$status = '';
Ejemplo n.º 4
0
 function GetDevicePicture($rear = false, $targetWidth = 220, $nolinks = false)
 {
     // Just in case
     $targetWidth = $targetWidth == 0 ? 220 : $targetWidth;
     $rear = $rear == true || $rear == false ? $rear : true;
     $nolinks = $nolinks == true || $nolinks == false ? $nolinks : false;
     $templ = new DeviceTemplate();
     $templ->TemplateID = $this->TemplateID;
     $templ->GetTemplateByID();
     $resp = "";
     if ($templ->FrontPictureFile != "" && !$rear || $templ->RearPictureFile != "" && $rear) {
         $picturefile = "pictures/";
         $path = "";
         if (preg_match('/api\\//', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()))) {
             $path = "../../";
         }
         $picturefile .= $rear ? $templ->RearPictureFile : $templ->FrontPictureFile;
         if (!file_exists($path . $picturefile)) {
             $picturefile = "pictures/P_ERROR.png";
         }
         // Get the true size of the template image
         list($pictW, $pictH) = getimagesize($path . $picturefile);
         // adjusted height = targetWidth * height:width ratio for 1u * height of device in U
         $targetHeight = $targetWidth * 1.75 / 19 * $this->Height;
         // We need integers for the height and width because browsers act funny with decimals
         $targetHeight = intval($targetHeight);
         $targetWidth = intval($targetWidth);
         // URLEncode the image file name just to be compliant.
         $picturefile = str_replace(' ', "%20", $picturefile);
         // If they have rights to the device then make the picture clickable
         $clickable = $this->Rights != "None" ? "\t\t<a href=\"devices.php?DeviceID={$this->DeviceID}\">\n\t" : "";
         $clickableend = $this->Rights != "None" ? "\n\t\t</a>\n" : "";
         // Add in flags for missing ownership
         // Device pictures are set on the template so always assume template has been set
         $flags = $this->Owner == 0 ? '(O)' : '';
         $flags = $flags != '' ? '<span class="hlight">' . $flags . '</span>' : '';
         // This is for times when you want to use the image on a report but don't want links
         $nolinks = $nolinks ? ' disabled' : '';
         $resp .= "\n\t<div class=\"picture{$nolinks}\" style=\"width: " . $targetWidth . "px; height: " . $targetHeight . "px;\">\n";
         $resp .= "{$clickable}\t\t<img data-deviceid={$this->DeviceID} src=\"{$picturefile}\" alt=\"{$this->Label}\">{$clickableend}\n";
         /*
          * Labels on chassis devices were getting silly with smaller devices.  For aesthetic 
          * reasons we are going to hide the label for the chassis devices that are less than 3U
          * in height and have slots defined.  If it is just a chassis with nothing defined then 
          * go ahead and show the chassis label.
          */
         if ($this->Height < 3 && $this->DeviceType == 'Chassis' && ($rear && $this->RearChassisSlots > 0 || !$rear && $this->ChassisSlots > 0) || ($templ->Model == 'HTRAY' || $templ->Model == 'VTRAY')) {
         } else {
             $resp .= "\t\t<div class=\"label\"><div>{$flags}{$this->Label}" . ((!$this->BackSide && $rear || $this->BackSide && !$rear) && !$this->HalfDepth ? " (" . __("Rear") . ")" : "");
             $resp .= "</div></div>\n";
         }
         $parent = new stdClass();
         $parent->zoomX = $targetWidth / $pictW;
         $parent->zoomY = $targetHeight / $pictH;
         $parent->targetWidth = $targetWidth;
         $parent->targetHeight = $targetHeight;
         $parent->Height = $pictH;
         $parent->Width = $pictW;
         $parent->parentDev = $this;
         $parent->parentTempl = $templ;
         //Children
         $childList = $this->GetDeviceChildren();
         // Edge case where someone put more devices in a tray than they specified it slots
         if ($templ->Model == 'HTRAY' || $templ->Model == 'VTRAY' || $this->ChassisSlots < count($childList)) {
             $this->ChassisSlots = count($childList);
         }
         if (count($childList) > 0) {
             if ($this->ChassisSlots > 0 && !$rear || $this->RearChassisSlots > 0 && $rear || ($templ->Model == 'HTRAY' || $templ->Model == 'VTRAY')) {
                 //children in front face
                 foreach ($childList as $tmpDev) {
                     if ($templ->Model == 'HTRAY' || $templ->Model == 'VTRAY' || (!$tmpDev->BackSide && !$rear || $tmpDev->BackSide && $rear)) {
                         $resp .= $tmpDev->GetChildDevicePicture($parent, $rear);
                     }
                 }
             }
         }
         $resp .= "\t</div>\n";
     } else {
         // We don't have an image on file for this device so return a generic lump of crap
         $resp = "\t<div class=\"genericdevice\" data-deviceid={$this->DeviceID} style=\"width: " . ($targetWidth - 4) . "px;\">\n";
         // Add in flags for missing ownership
         $flags = $this->Owner == 0 ? '(O)' : '';
         $flags .= $this->TemplateID == 0 ? '(T)' : '';
         $flags = $flags != '' ? '<span class="hlight">' . $flags . '</span>' : '';
         // If they have rights to the device then make the picture clickable
         $clickable = $this->Rights != "None" ? "\t\t<a href=\"devices.php?DeviceID={$this->DeviceID}\">\n\t" : "";
         $clickableend = $this->Rights != "None" ? "\n\t\t</a>\n" : "";
         $resp .= "\t\t{$clickable}{$flags}{$this->Label}{$clickableend}\n";
         $resp .= "\t</div>\n";
     }
     return $resp;
 }
Ejemplo n.º 5
0
foreach ($devList as $dev) {
    // including the $cab and $devTempl in here so it gets reset each time and there
    // is no chance for phantom data
    $cab = new Cabinet();
    if ($dev->ParentDevice > 0) {
        $pdev = new Device();
        $pdev->DeviceID = $dev->GetRootDeviceID();
        $pdev->GetDevice();
        $cab->CabinetID = $pdev->Cabinet;
    } else {
        $cab->CabinetID = $dev->Cabinet;
    }
    $cab->GetCabinet();
    $devTmpl = new DeviceTemplate();
    $devTmpl->TemplateID = $dev->TemplateID;
    $devTmpl->GetTemplateByID();
    $position = $dev->Height == 1 ? $dev->Position : $dev->Position . "-" . ($dev->Position + $dev->Height - 1);
    print "<div><div>{$cab->Location}</div><div>{$position}</div><div>{$dev->Label}</div><div>" . $dev->GetDevicePicture('', '', 'nolinks') . "</div></div>\n";
}
print '</div>
<a href="export_port_connections.php?deviceid=wo"><button type="button">' . __("Export Connections") . '</button></a>';
?>

<button type="button" id="clear"><?php 
print __("Clear");
?>
</button>
</div></div>
</div><!-- END div.main -->
</div><!-- END div.page -->
</body>
Ejemplo n.º 6
0
function updateCustomValues($device)
{
    $template = new DeviceTemplate();
    $template->TemplateID = $device->TemplateID;
    $template->GetTemplateByID();
    $dcaList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
    $tdcaList = $template->CustomValues;
    $defaultvalues = array();
    if (isset($dcaList)) {
        foreach ($dcaList as $dca) {
            if ($dca->AllDevices == 1) {
                $defaultvalues[$dca->AttributeID]["value"] = $dca->DefaultValue;
                $defaultvalues[$dca->AttributeID]["required"] = $dca->Required;
            }
        }
    }
    if (isset($tdcaList)) {
        foreach ($tdcaList as $AttributeID => $tdca) {
            $defaultvalues[$AttributeID]["value"] = $tdca["value"];
            $defaultvalues[$AttributeID]["required"] = $tdca["required"];
        }
    }
    $device->DeleteCustomValues();
    if (isset($_POST["customvalue"])) {
        foreach ($_POST["customvalue"] as $AttributeID => $value) {
            if (trim($value) != trim($defaultvalues[$AttributeID]["value"])) {
                $device->InsertCustomValue($AttributeID, $value);
            }
        }
    }
}
Ejemplo n.º 7
0
     $sql = "SELECT a.Name AS DataCenter, b.DeviceID, c.Location, b.Position, \n\t\t\t\tb.Height, b.Label, b.DeviceType, b.AssetTag, b.SerialNo, b.InstallDate, \n\t\t\t\tb.TemplateID, b.Owner, c.CabinetID, c.DataCenterID FROM fac_DataCenter a, \n\t\t\t\tfac_Device b, fac_Cabinet c WHERE b.Cabinet=c.CabinetID AND \n\t\t\t\tc.DataCenterID=a.DataCenterID {$dclimit} ORDER BY DataCenter ASC, Location ASC, \n\t\t\t\tPosition ASC;";
     $result = $dbh->query($sql);
 } else {
     $result = array();
 }
 // Left these expanded in case we need to add or remove columns.  Otherwise I would have just collapsed entirely.
 $body = "<table id=\"export\" class=\"display\">\n\t<thead>\n\t\t<tr>\n\n\t\t\t\t<th>" . __("Data Center") . "</th>\n\t\t\t\t<th>" . __("Location") . "</th>\n\t\t\t\t<th>" . __("Position") . "</th>\n\t\t\t\t<th>" . __("Height") . "</th>\n\t\t\t\t<th>" . __("Name") . "</th>\n\t\t\t\t<th>" . __("Serial Number") . "</th>\n\t\t\t\t<th>" . __("Asset Tag") . "</th>\n\t\t\t\t<th>" . __("Device Type") . "</th>\n\t\t\t\t<th>" . __("Template") . "</th>\n\t\t\t\t<th>" . __("Tags") . "</th>\n\t\t\t\t<th>" . __("Owner") . "</th>\n\t\t\t\t<th>" . __("Installation Date") . "</th>\n\t\t\t</tr>\n\t</thead>\n\t<tbody>\n";
 // suppressing errors for when there is a fake data set in place
 foreach ($result as $row) {
     // insert date formating later for regionalization settings
     $date = date("d M Y", strtotime($row["InstallDate"]));
     $Model = "";
     $Department = "";
     if ($row["TemplateID"] > 0) {
         $templ->TemplateID = $row["TemplateID"];
         $templ->GetTemplateByID();
         $Model = "<a href=\"device_templates.php?TemplateID={$templ->TemplateID}\" target=\"template\">{$templ->Model}</a>";
     }
     if ($row["Owner"] > 0) {
         $dept->DeptID = $row["Owner"];
         $dept->GetDeptByID();
         $Department = $dept->Name;
     }
     $dev->DeviceID = $row["DeviceID"];
     $tags = implode(",", $dev->GetTags());
     $body .= "\t\t<tr>\n\t\t\t\t<td><a href=\"dc_stats.php?dc={$row["DataCenterID"]}\" target=\"datacenter\">{$row["DataCenter"]}</a></td>\n\t\t\t\t<td><a href=\"cabnavigator.php?cabinetid={$row["CabinetID"]}\" target=\"cabinet\">{$row["Location"]}</a></td>\n\t\t\t\t<td>{$row["Position"]}</td>\n\t\t\t\t<td>{$row["Height"]}</td>\n\t\t\t\t<td><a href=\"devices.php?DeviceID={$dev->DeviceID}\" target=\"device\">{$row["Label"]}</a></td>\n\t\t\t\t<td>{$row["SerialNo"]}</td>\n\t\t\t\t<td>{$row["AssetTag"]}</td>\n\t\t\t\t<td><a href=\"search.php?key=dev&DeviceType={$row["DeviceType"]}&search\" target=\"search\">{$row["DeviceType"]}</a></td>\n\t\t\t\t<td>{$Model}</td>\n\t\t\t\t<td>{$tags}</td>\n\t\t\t\t<td>{$Department}</td>\n\t\t\t\t<td>{$date}</td>\n\t\t</tr>\n";
     if ($row["DeviceType"] == "Chassis") {
         // Find all of the children!
         $childList = $dev->GetDeviceChildren();
         foreach ($childList as $child) {
             $cdate = date("d M Y", strtotime($child->InstallDate));
Ejemplo n.º 8
0
 function UpdateTemplate()
 {
     $this->MakeSafe();
     $sql = "UPDATE fac_DeviceTemplate SET ManufacturerID={$this->ManufacturerID},\n\t\t\tModel=\"{$this->Model}\", Height={$this->Height}, Weight={$this->Weight}, \n\t\t\tWattage={$this->Wattage}, DeviceType=\"{$this->DeviceType}\", \n\t\t\tPSCount={$this->PSCount}, NumPorts={$this->NumPorts}, Notes=\"{$this->Notes}\", \n\t\t\tFrontPictureFile=\"{$this->FrontPictureFile}\", RearPictureFile=\"{$this->RearPictureFile}\",\n\t\t\tChassisSlots={$this->ChassisSlots}, RearChassisSlots={$this->RearChassisSlots}, SNMPVersion=\"{$this->SNMPVersion}\",\n\t\t\tGlobalID={$this->GlobalID}, ShareToRepo={$this->ShareToRepo}, KeepLocal={$this->KeepLocal}\n\t\t\tWHERE TemplateID={$this->TemplateID};";
     $old = new DeviceTemplate();
     $old->TemplateID = $this->TemplateID;
     $old->GetTemplateByID();
     if ($old->DeviceType == "CDU" && $this->DeviceType != $old->DeviceType) {
         // Template changed from CDU to something else, clean up the mess
         $cdut = new CDUTemplate();
         $cdut->TemplateID = $this->TemplateID;
         $cdut->DeleteTemplate();
     } elseif ($this->DeviceType == "CDU" && $this->DeviceType != $old->DeviceType) {
         // Template changed to CDU from something else, make the extra stuff
         $cdut = new CDUTemplate();
         $cdut->Model = $this->Model;
         $cdut->ManufacturerID = $this->ManufacturerID;
         $cdut->CreateTemplate($this->TemplateID);
     }
     if ($old->DeviceType == "Sensor" && $this->DeviceType != $old->DeviceType) {
         // Template changed from Sensor to something else, clean up the mess
         $st = new SensorTemplate();
         $st->TemplateID = $this->TemplateID;
         $st->DeleteTemplate();
     } elseif ($this->DeviceType == "Sensor" && $this->DeviceType != $old->DeviceType) {
         // Template changed to Sensor from something else, make the extra stuff
         $st = new SensorTemplate();
         $st->Model = $this->Model;
         $st->ManufacturerID = $this->ManufacturerID;
         $st->CreateTemplate($this->TemplateID);
     }
     if (!$this->query($sql)) {
         return false;
     } else {
         class_exists('LogActions') ? LogActions::LogThis($this, $old) : '';
         $this->MakeDisplay();
         return true;
     }
 }