summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/diag_confbak.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr/local/www/diag_confbak.php')
-rw-r--r--src/usr/local/www/diag_confbak.php361
1 files changed, 172 insertions, 189 deletions
diff --git a/src/usr/local/www/diag_confbak.php b/src/usr/local/www/diag_confbak.php
index cc1da99..b048f5e 100644
--- a/src/usr/local/www/diag_confbak.php
+++ b/src/usr/local/www/diag_confbak.php
@@ -51,24 +51,25 @@ if (isset($_POST['backupcount'])) {
$changedescr = "(platform default)";
}
write_config("Changed backup revision count to {$changedescr}");
-} elseif ($_POST) {
- if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm")) || (!isset($_POST['newver']) && !isset($_POST['rmver']))) {
+} elseif ($_GET) {
+ if (!isset($_GET['newver']) && !isset($_GET['rmver']) && !isset($_GET['getcfg']) && !isset($_GET['diff'])) {
header("Location: diag_confbak.php");
return;
}
conf_mount_rw();
$confvers = unserialize(file_get_contents($g['cf_conf_path'] . '/backup/backup.cache'));
- if ($_POST['newver'] != "") {
- if (config_restore($g['conf_path'] . '/backup/config-' . $_POST['newver'] . '.xml') == 0) {
- $savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['newver']), htmlspecialchars($confvers[$_POST['newver']]['description']));
+
+ if ($_GET['newver'] != "") {
+ if (config_restore($g['conf_path'] . '/backup/config-' . $_GET['newver'] . '.xml') == 0) {
+ $savemsg = sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['newver']), htmlspecialchars($confvers[$_GET['newver']]['description']));
} else {
$savemsg = gettext("Unable to revert to the selected configuration.");
}
}
- if ($_POST['rmver'] != "") {
- unlink_if_exists($g['conf_path'] . '/backup/config-' . $_POST['rmver'] . '.xml');
- $savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']), htmlspecialchars($confvers[$_POST['rmver']]['description']));
+ if ($_GET['rmver'] != "") {
+ unlink_if_exists($g['conf_path'] . '/backup/config-' . $_GET['rmver'] . '.xml');
+ $savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_GET['rmver']), htmlspecialchars($confvers[$_GET['rmver']]['description']));
}
conf_mount_ro();
}
@@ -89,7 +90,7 @@ if ($_GET['getcfg'] != "") {
if (($_GET['diff'] == 'Diff') && isset($_GET['oldtime']) && isset($_GET['newtime']) &&
(is_numeric($_GET['oldtime'])) &&
- (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
+ (is_numeric($_GET['newtime']) || ($_GET['newtime'] == 'current'))) {
$diff = "";
$oldfile = $g['conf_path'] . '/backup/config-' . $_GET['oldtime'] . '.xml';
$oldtime = $_GET['oldtime'];
@@ -112,190 +113,172 @@ unset($confvers['versions']);
$pgtitle = array(gettext("Diagnostics"), gettext("Configuration History"));
include("head.inc");
+if ($savemsg) {
+ print_info_box($savemsg, 'success');
+}
+
+if ($diff) {
?>
+<div class="panel panel-default">
+ <div class="panel-heading"><?=gettext("Configuration diff from ")?><?=date(gettext("n/j/y H:i:s"), $oldtime); ?><?=gettext(" to ")?><?=date(gettext("n/j/y H:i:s"), $newtime); ?></div>
+ <div class="panel-body table-responsive">
+ <!-- This table is left un-bootstrapped to maintain the original diff format output -->
+ <table style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;">
-<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
- <?php
- include("fbegin.inc");
- if ($savemsg) {
- print_info_box($savemsg);
+<?php
+ foreach ($diff as $line) {
+ switch (substr($line, 0, 1)) {
+ case "+":
+ $color = "#caffd3";
+ break;
+ case "-":
+ $color = "#ffe8e8";
+ break;
+ case "@":
+ $color = "#a0a0a0";
+ break;
+ default:
+ $color = "#ffffff";
}
- ?>
- <?php if ($diff) { ?>
- <table align="center" width="100%" border="0" cellspacing="0" style="padding-top: 4px; padding-bottom: 4px; vertical-align:middle;" summary="diag confbak">
- <tr>
- <td><?=gettext("Configuration diff from");?> <?php echo date(gettext("n/j/y H:i:s"), $oldtime); ?> <?=gettext("to");?> <?php echo date(gettext("n/j/y H:i:s"), $newtime); ?></td>
- </tr>
- <?php foreach ($diff as $line) {
- switch (substr($line, 0, 1)) {
- case "+":
- $color = "#caffd3";
- break;
- case "-":
- $color = "#ffe8e8";
- break;
- case "@":
- $color = "#a0a0a0";
- break;
- default:
- $color = "#ffffff";
- }
- ?>
- <tr>
- <td valign="middle" bgcolor="<?php echo $color; ?>" style="white-space: pre-wrap;"><?php echo htmlentities($line);?></td>
- </tr>
- <?php } ?>
- </table>
- <br />
- <?php } ?>
- <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="stats">
- <tr>
- <td>
- <?php
- $tab_array = array();
- $tab_array[0] = array(gettext("Config History"), true, "diag_confbak.php");
- $tab_array[1] = array(gettext("Backup/Restore"), false, "diag_backup.php");
- display_top_tabs($tab_array);
- ?>
- </td>
- </tr>
- <tr>
- <td>
- <div id="mainarea">
- <form action="diag_confbak.php" method="post">
- <table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
+?>
+ <tr>
+ <td valign="middle" bgcolor="<?=$color; ?>" style="white-space: pre-wrap;"><?=htmlentities($line)?></td>
+ </tr>
+<?php
+ }
+?>
+ </table>
+ </div>
+</div>
+<?php
+}
+
+$tab_array = array();
+$tab_array[] = array(gettext("Config History"), true, "diag_confbak.php");
+$tab_array[] = array(gettext("Backup/Restore"), false, "diag_backup.php");
+display_top_tabs($tab_array);
+
+require('classes/Form.class.php');
+
+$form = new Form(new Form_Button(
+ 'Submit',
+ gettext("Save")
+));
+
+$section = new Form_Section('Saved Configurations');
+
+$section->addInput(new Form_Input(
+ 'backupcount',
+ 'Backup Count',
+ 'number',
+ $config['system']['backupcount']
+))->setHelp('Maximum number of old configurations to keep. By default this is 30 for a full install or 5 on NanoBSD. ');
+
+$space = exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
-<?php if ($_GET["newver"] || $_GET["rmver"]): ?>
- <tr>
- <td colspan="2" valign="top" class="listtopic"><?php echo gettext("Confirm Action"); ?></td>
- </tr>
- <tr>
- <td width="22%" valign="top" class="vncell">&nbsp;</td>
- <td width="78%" class="vtable">
+$section->addInput(new Form_StaticText(
+ 'Current space used by backups',
+ $space
+));
- <strong><?php echo gettext("Please confirm the selected action"); ?></strong>:
- <br />
- <br /><strong><?php echo gettext("Action"); ?>:</strong>
- <?php if (!empty($_GET["newver"])) {
- echo gettext("Restore from Configuration Backup");
- $target_config = $_GET["newver"]; ?>
- <input type="hidden" name="newver" value="<?php echo htmlspecialchars($_GET["newver"]); ?>" />
- <?php } elseif (!empty($_GET["rmver"])) {
- echo gettext("Remove Configuration Backup");
- $target_config = $_GET["rmver"]; ?>
- <input type="hidden" name="rmver" value="<?php echo htmlspecialchars($_GET["rmver"]); ?>" />
- <?php } ?>
- <br /><strong><?php echo gettext("Target Configuration"); ?>:</strong>
- <?php echo sprintf(gettext('Timestamp %1$s'), date(gettext("n/j/y H:i:s"), $target_config)); ?>
- <br /><input type="submit" name="confirm" value="<?php echo gettext("Confirm"); ?>" />
- </td>
- </tr>
-<?php else: ?>
+$form->add($section);
- <tr>
- <td width="10%">&nbsp;</td>
- <td width="15%" valign="top"><?=gettext("Backup Count");?></td>
- <td width="10%">
- <input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/>
- </td>
- <td width="60%">
- <?= gettext("Enter the number of older configurations to keep in the local backup cache. By default this is 30 for a full install or 5 on NanoBSD."); ?>
- </td>
- <td width= "5%"><input name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /></td>
- </tr>
- <tr>
- <td class="vncell">&nbsp;</td>
- <td colspan="4" class="vncell">
- <?= gettext("NOTE: Be aware of how much space is consumed by backups before adjusting this value. Current space used by backups: "); ?> <?= exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
- </td>
- </tr>
- </table>
- </form>
- <form action="diag_confbak.php" method="get">
- <table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="difference">
- <?php if (is_array($confvers)): ?>
- <tr>
- <td colspan="7" class="list">
- <?= gettext("To view the differences between an older configuration and a newer configuration, select the older configuration using the left column of radio options and select the newer configuration in the right column, then press the Diff button."); ?>
- <br /><br />
- </td>
- </tr>
- <tr>
- <td width="5%" colspan="2" valign="middle" align="center" class="list nowrap"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
- <td width="20%" class="listhdrr"><?=gettext("Date");?></td>
- <td width="5%" class="listhdrr"><?=gettext("Version");?></td>
- <td width="5%" class="listhdrr"><?=gettext("Size");?></td>
- <td width="60%" class="listhdrr"><?=gettext("Configuration Change");?></td>
- <td width="5%" class="list">&nbsp;</td>
- </tr>
- <tr valign="top">
- <td valign="middle" class="list nowrap"></td>
- <td class="list">
- <input type="radio" name="newtime" value="current" />
- </td>
- <td class="listlr"> <?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
- <td class="listr"> <?= $config['version'] ?></td>
- <td class="listr"> <?= format_bytes(filesize("/conf/config.xml")) ?></td>
- <td class="listr"> <?= htmlspecialchars($config['revision']['description']) ?></td>
- <td valign="middle" class="list nowrap"><b><?=gettext("Current");?></b></td>
- </tr>
- <?php
- $c = 0;
- foreach ($confvers as $version):
- if ($version['time'] != 0) {
- $date = date(gettext("n/j/y H:i:s"), $version['time']);
- } else {
- $date = gettext("Unknown");
- }
- ?>
- <tr valign="top">
- <td class="list">
- <input type="radio" name="oldtime" value="<?php echo $version['time'];?>" />
- </td>
- <td class="list">
- <?php if ($c < (count($confvers) - 1)) { ?>
- <input type="radio" name="newtime" value="<?php echo $version['time'];?>" />
- <?php } else { ?>
- &nbsp;
- <?php }
- $c++; ?>
- </td>
- <td class="listlr"> <?= $date ?></td>
- <td class="listr"> <?= $version['version'] ?></td>
- <td class="listr"> <?= format_bytes($version['filesize']) ?></td>
- <td class="listr"> <?= htmlspecialchars($version['description']) ?></td>
- <td valign="middle" class="list nowrap">
- <a href="diag_confbak.php?newver=<?=$version['time'];?>">
- <img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="<?=gettext("Revert to this configuration");?>" title="<?=gettext("Revert to this configuration");?>" />
- </a>
- <a href="diag_confbak.php?rmver=<?=$version['time'];?>">
- <img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="<?=gettext("Remove this backup");?>" title="<?=gettext("Remove this backup");?>" />
- </a>
- <a href="diag_confbak.php?getcfg=<?=$version['time'];?>">
- <img src="/themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" width="17" height="17" border="0" alt="<?=gettext("Download this backup");?>" title="<?=gettext("Download this backup");?>" />
- </a>
- </td>
- </tr>
- <?php endforeach; ?>
- <tr>
- <td colspan="2"><input type="submit" name="diff" value="<?=gettext("Diff"); ?>" /></td>
- <td colspan="5"></td>
- </tr>
- <?php else: ?>
- <tr>
- <td>
- <?php print_info_box(gettext("No backups found.")); ?>
- </td>
- </tr>
- <?php endif; ?>
-<?php endif; ?>
- </table>
- </form>
- </div>
- </td>
- </tr>
- </table>
+print($form);
+
+if (is_array($confvers)) {
+ print_info_box(gettext('To view the differences between an older configuration and a newer configuration, ' .
+ 'select the older configuration using the left column of radio options and select the newer configuration in the right column, ' .
+ 'then press the "Diff" button.'));
+}
+?>
+
+<form action="diag_confbak.php" method="get">
+ <div class="table-resposive">
+ <table class="table table-striped table-hover table-condensed">
+<?php
+if (is_array($confvers)):
+?>
+ <thead>
+ <tr>
+ <th colspan="2">
+ <input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" />
+ </th>
+ <th><?=gettext("Date")?></th>
+ <th><?=gettext("Version")?></th>
+ <th><?=gettext("Size")?></th>
+ <th><?=gettext("Configuration Change")?></th>
+ <th><?=gettext("Actions")?></th>
+ </tr>
+ </thead>
+ <tbody>
+ <!-- First row is the current configuration -->
+ <tr valign="top">
+ <td></td>
+ <td>
+ <input type="radio" name="newtime" value="current" />
+ </td>
+ <td><?= date(gettext("n/j/y H:i:s"), $config['revision']['time']) ?></td>
+ <td><?= $config['version'] ?></td>
+ <td><?= format_bytes(filesize("/conf/config.xml")) ?></td>
+ <td><?= htmlspecialchars($config['revision']['description']) ?></td>
+ <td><?=gettext("Current configuration")?></td>
+ </tr>
+<?php
+ // And now for hte table of prior backups
+ $c = 0;
+ foreach ($confvers as $version):
+ if ($version['time'] != 0) {
+ $date = date(gettext("n/j/y H:i:s"), $version['time']);
+ } else {
+ $date = gettext("Unknown");
+ }
+?>
+ <tr>
+ <td>
+ <input type="radio" name="oldtime" value="<?=$version['time']?>" />
+ </td>
+ <td>
+<?php
+ if ($c < (count($confvers) - 1)) {
+?>
+ <input type="radio" name="newtime" value="<?=$version['time']?>" />
+<?php
+ }
+ $c++;
+?>
+ </td>
+ <td><?= $date ?></td>
+ <td><?= $version['version'] ?></td>
+ <td><?= format_bytes($version['filesize']) ?></td>
+ <td><?= htmlspecialchars($version['description']) ?></td>
+ <td>
+ <a href="diag_confbak.php?newver=<?=$version['time']?>" class="btn btn-xs btn-success"
+ onclick="return confirm('<?=gettext("Are you sure you want to replace the current configuration with this backup?")?>')">
+ <?=gettext("Revert")?>
+ </a>
+ <a href="diag_confbak.php?rmver=<?=$version['time']?>" class="btn btn-xs btn-danger">
+ <?=gettext("Delete")?>
+ </a>
+ <a href="diag_confbak.php?getcfg=<?=$version['time']?>" class="btn btn-xs btn-default">
+ <?=gettext("Download")?>
+ </a>
+ </td>
+ </tr>
+<?php
+ endforeach;
+?>
+ <tr>
+ <td colspan="2"><input type="submit" name="diff" class="btn btn-info btn-xs" value="<?=gettext("Diff"); ?>" /></td>
+ <td colspan="5"></td>
+ </tr>
+<?php
+else:
+ print_info_box(gettext("No backups found."), 'danger');
+endif;
+?>
+ </tbody>
+ </table>
+ </form>
+</div>
-<?php include("fend.inc"); ?>
-</body>
-</html>
+<?php include("foot.inc");
OpenPOWER on IntegriCloud