<?php
require_once('./CS_Includes.inc.php');
$compareForm = null;
try {
CS::Check($_GET['from'], CSA_EMPTY|CSA_THROW, 'DeviceCompare with no from_id');
CS::Check($_GET['to'], CSA_EMPTY|CSA_THROW, 'DeviceCompare with no to_id');
if ($_GET['to'] < 1)
throw new CSCompareNoCurrException();
if ($_GET['from'] < 1)
throw new CSCompareNoPrevException();
if ($_GET['from'] > $_GET['to'])
throw new CSCompareBackwardException();
//
// Initialise our CSDevice and get the configuration data
//
$oldFile = new CSConfig($_GET['from']);
$newFile = new CSConfig($_GET['to']);
//
// Build the differ
//
$differ = new CSFileDiff($oldFile, $newFile);
$diffs =& $differ->getDifferences();
//
// Now build the info form
//
$compareForm = new CSForm('Compare.php');
$compareForm->SetFormControlClass('FormControlAreaNoPad');
// Check if we are in diffWin and load controls accordingly.
//
if (isset($_GET['diffwin']))
{
$compareForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => 'Close',
'onclick' => 'window.close();')));
$compareForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => 'Open NCS',
'onclick' => 'window.location.href=\''.$CS->GetOption('url').'\';')));
}
else
{
$compareForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => 'Back',
'onclick' => 'history.back(1);')));
$compareForm->AddButton(new CSFormControl(CSF_BUTTON, array('value' => 'Open in New',
'onclick' => 'openDiff(\''.$oldFile->revision_id.'\', \''.$newFile->revision_id.'\');')));
}
}
catch (Exception $e) {
CS::Abort($e);
}
CS::PrintHtmlHeader();
?>
<body id="Main">
<a name="top"></a><h1>Compare Configuration on "<?php echo $oldFile->getParent()->hostname; ?>"</h1>
<table id="Compare" width="300">
<tr><td class="Rem">Removed Text</td><td class="RemEmpty"> </td></tr>
<tr><td class="Chg" colspan="2" align="center">Changed Text</td></tr>
<tr><td class="AddEmpty"> </td><td class="Add">Added Text</td></tr>
</table>
<?php $compareForm->InsertHtml(); ?>
<?php if ($differ->FilesEqual()): ?>
<p>Configuration revisions are equal!</p>
<?php else: ?>
<table id="Compare" width="100%">
<tr class="Revision"><td>Revision <?php echo $oldFile->revision; ?> (<?php echo $oldFile->created; ?>)</td>
<td>Revision <?php echo $newFile->revision; ?> (<?php echo $newFile->created; ?>)</td></tr>
<?php
foreach($diffs as $diffHeader)
{
echo '<tr class="Header"><td>Line '.$diffHeader['oldline'].'</td>'.
'<td>Line '.$diffHeader['newline'].'</td></tr>';
$differ->InsertDifference($diffHeader);
}
?>
</table>
<p><a href="#top">Top of Page</a></p>
<?php endif; ?>
</body>
</html>