<?php
require_once('./CS_Includes.inc.php');
try {
CS::Check($_GET['device_id'], CSA_EMPTY|CSA_THROW, 'DeviceView with no device_id');
$device = new CSDevice($_GET['device_id']);
//
// Load the revision array from SQL, and then parse this into
// an array of formatted text to display to the user.
//
$device->LoadRevisionArray();
$history = $device->GetRevisionHistory();
$configList = $device->GetRevisionArray();
//
// Build the device view
//
$viewForm = new CSForm('Admin.php?device_id='.$device->device_id);
$viewForm->AddControl('<strong>Description</strong>', new CSFormControl(CSF_TEXT, array(
'text' => $device->descr)));
$viewForm->AddControl('<strong>IP Address</strong>', new CSFormControl(CSF_TEXT, array(
'text' => $device->ipaddress.' (<a href="telnet://'.$device->ipaddress.'">telnet</a> | <a href="ssh://'.$device->ipaddress.'">ssh</a>)')));
$viewForm->AddControl('<strong>Software Version</strong>', new CSFormControl(CSF_TEXT, array(
'text' => $device->GetVersion().' ('.$CSD_TYPES[$device->type_code].')')));
$viewForm->AddControl('<strong>State</strong>', new CSFormControl(CSF_TEXT, array(
'text' => $CSD_STATES[$device->state_code].($device->state_msg ? ' ('.$device->state_msg.')' : ""))));
$viewForm->AddControl('<strong>Last Updated</strong>', new CSFormControl(CSF_TEXT, array(
'text' => $device->updated)));
if ($device->state_code == CSD_STATE_DISABLED || $device->state_code == CSD_STATE_ARCHIVED) {
$enableButtonValue = 'Enable';
$enableButtonHref = '&enable';
} else {
$enableButtonValue = 'Disable';
$enableButtonHref = '&disable';
}
$viewForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => $enableButtonValue,
'onclick' => 'window.location.href=\'Admin.php?device_id='.$device->device_id.$enableButtonHref.'\';')));
$viewForm->AddButton(new CSFormControl(CSF_SUBMIT, array('value' => 'Modify')));
$viewForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => 'Delete',
'onclick' => 'window.location.href=\'Admin.php?device_id='.$device->device_id.'&delete\';')));
//
// Build our compare form...
//
$cmpForm = new CSForm('Compare.php', 'get');
$cmpForm->AddButton(new CSFormControl(CSF_SUBMIT, array('value' => 'Compare')));
// Build to form controls at once as we can populate them from one list...
$fs = $cmpForm->AddControl('<strong>From Revision</strong>', new CSFormControl(CSF_SELECT, array('name' => 'from')));
$ts = $cmpForm->AddControl('<strong>To Revision</strong>', new CSFormControl(CSF_SELECT, array('name' => 'to')));
$reverseConfigList = array_reverse($configList);
$currItem = 0;
$totalItems = count($reverseConfigList);
foreach($reverseConfigList as $configItem)
{
$currItem++;
if ($currItem == $totalItems) // This our last record
{
$ts->AddChild(new CSFormControl(CSF_OPTION, array('value' => $configItem->revision_id,
'text' => 'r'.$configItem->revision.' ('.$configItem->created.', current)',
'selected' => TRUE)));
}
else
{
$fs->AddChild(new CSFormControl(CSF_OPTION, array('value' => $configItem->revision_id,
'text' => 'r'.$configItem->revision.' ('.$configItem->created.')',
'selected' => FALSE)));
$ts->AddChild(new CSFormControl(CSF_OPTION, array('value' => $configItem->revision_id,
'text' => 'r'.$configItem->revision.' ('.$configItem->created.')',
'selected' => FALSE)));
}
}
if ($fs->getChildCount() == 0)
$fs->AddChild(new CSFormControl(CSF_OPTION, array('value' => '-1',
'text' => '[no previous revision]', 'selected' => TRUE)));
if ($ts->getChildCount() == 0)
$ts->AddChild(new CSFormControl(CSF_OPTION, array('value' => '-1',
'text' => '[no current revision]', 'selected' => TRUE)));
}
catch (Exception $e) {
CS::Abort($e);
}
$i = 0; // Row counter, used below
CS::PrintHtmlHeader();
?>
<body id="Main">
<h1>Device Information for "<?php echo $device->hostname; ?>"</h1>
<?php if (isset($_GET['updated'])): ?>
<p class="InfoMsg">Device record successfully updated.</p>
<?php endif; ?>
<?php if ($device->state_code == CSD_STATE_DISABLED || $device->state_code == CSD_STATE_ARCHIVED): ?>
<p class="InfoMsg">This device is currently disabled or archived and will not be checked for configuration changes!</p>
<?php endif; ?>
<?php $viewForm->InsertHtml(); ?>
<h2>Compare Configurations</h2>
<?php $cmpForm->InsertHtml(); ?>
<h2>Configuration History</h2>
<table width="100%">
<tr class="Header"><td>Revision</td><td>Created</td><td>Size</td><td>Action</td></tr>
<?php foreach($history as $row): ?>
<tr class="<?php echo (++$i % 2) ? 'Odd' : 'Even'; ?>">
<?php foreach($row as $field): ?>
<td><?php echo $field; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>