Commit 3161dece authored by Franco Fichtner's avatar Franco Fichtner

configuration: pin down backup count+allow none+simplify GUI

parent f42e229b
...@@ -227,6 +227,7 @@ ...@@ -227,6 +227,7 @@
<interval>monthly</interval> <interval>monthly</interval>
</bogons> </bogons>
<kill_states/> <kill_states/>
<backupcount>60</backupcount>
</system> </system>
<interfaces> <interfaces>
<wan> <wan>
......
...@@ -288,7 +288,8 @@ function cleanup_backups() ...@@ -288,7 +288,8 @@ function cleanup_backups()
if (isset($config['system']['backupcount']) && is_numeric($config['system']['backupcount']) && ($config['system']['backupcount'] >= 0)) { if (isset($config['system']['backupcount']) && is_numeric($config['system']['backupcount']) && ($config['system']['backupcount'] >= 0)) {
$revisions = intval($config['system']['backupcount']); $revisions = intval($config['system']['backupcount']);
} else { } else {
$revisions = 30; /* XXX this value used to be left out of the config */
$revisions = 60;
} }
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
......
...@@ -3432,4 +3432,8 @@ function upgrade_111_to_112() ...@@ -3432,4 +3432,8 @@ function upgrade_111_to_112()
} }
} }
} }
if (!isset($config['system']['backupcount'])) {
$config['system']['backupcount'] = 60;
}
} }
...@@ -33,6 +33,12 @@ require_once("guiconfig.inc"); ...@@ -33,6 +33,12 @@ require_once("guiconfig.inc");
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$cnf = OPNsense\Core\Config::getInstance(); $cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true); $confvers = $cnf->getBackups(true);
if (isset($config['system']['backupcount'])) {
$pconfig['backupcount'] = $config['system']['backupcount'];
} else {
# XXX fallback value for older configs
$pconfig['backupcount'] = 60;
}
if (!empty($_GET['getcfg'])) { if (!empty($_GET['getcfg'])) {
foreach ($confvers as $filename => $revision) { foreach ($confvers as $filename => $revision) {
if ($revision['time'] == $_GET['getcfg']) { if ($revision['time'] == $_GET['getcfg']) {
...@@ -79,16 +85,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -79,16 +85,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
} }
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cnf = OPNsense\Core\Config::getInstance(); $input_errors = array();
$confvers = $cnf->getBackups(true); $pconfig = $_POST;
if (!empty($_POST['save'])) {
if (is_numeric($_POST['backupcount']) && ($_POST['backupcount'] >= 0)) { if (!empty($pconfig['save'])) {
$config['system']['backupcount'] = $_POST['backupcount']; if (!isset($pconfig['backupcount']) || !is_numeric($pconfig['backupcount']) || $pconfig['backupcount'] < 0) {
} elseif (isset($config['system']['backupcount'])) { $input_errors[] = gettext('Backup count must be greater or equal to zero.');
unset($config['system']['backupcount']);
} }
if (count($input_errors) == 0) {
$config['system']['backupcount'] = $pconfig['backupcount'];
write_config(gettext('Changed backup revision count.')); write_config(gettext('Changed backup revision count.'));
} elseif (!empty($_POST['act']) && $_POST['act'] == "revert") { $savemsg = get_std_save_message();
}
}
$cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true);
if (!empty($_POST['act']) && $_POST['act'] == "revert") {
foreach ($confvers as $filename => $revision) { foreach ($confvers as $filename => $revision) {
if (isset($revision['time']) && $revision['time'] == $_POST['time']) { if (isset($revision['time']) && $revision['time'] == $_POST['time']) {
if (config_restore($filename) == 0) { if (config_restore($filename) == 0) {
...@@ -113,14 +127,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -113,14 +127,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} }
} }
} }
} }
include("head.inc"); include("head.inc");
?> ?>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
$( document ).ready(function() { $( document ).ready(function() {
...@@ -176,10 +187,13 @@ $( document ).ready(function() { ...@@ -176,10 +187,13 @@ $( document ).ready(function() {
<body> <body>
<?php <?php
include("fbegin.inc"); include("fbegin.inc");
if($savemsg) if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors);
}
if ($savemsg) {
print_info_box($savemsg); print_info_box($savemsg);
}
?> ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
...@@ -193,15 +207,18 @@ $( document ).ready(function() { ...@@ -193,15 +207,18 @@ $( document ).ready(function() {
<th colspan="2" valign="top" class="listtopic"><?=gettext("Backup Count"); ?></th> <th colspan="2" valign="top" class="listtopic"><?=gettext("Backup Count"); ?></th>
</tr> </tr>
<tr> <tr>
<td><input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($config['system']['backupcount']);?>"/></td> <td><input name="backupcount" type="text" class="formfld unknown" size="5" value="<?=htmlspecialchars($pconfig['backupcount']);?>"/></td>
<td><?= gettext("Enter the number of older configurations to keep in the local backup cache. By default this is 30."); ?></td> <td><?= gettext("Enter the number of older configurations to keep in the local backup cache."); ?></td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
</td> </td>
<td> <td>
<?= gettext("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;}'") ?> <?= gettext('Be aware of how much space is consumed by backups before adjusting this value.'); ?>
<?php if (count($confvers)) {
print gettext('Current space used:') . ' ' . exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'");
} ?>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -245,6 +262,7 @@ $( document ).ready(function() { ...@@ -245,6 +262,7 @@ $( document ).ready(function() {
</div> </div>
</section> </section>
<?php endif; ?> <?php endif; ?>
<?php if (count($confvers)): ?>
<form method="get"> <form method="get">
<section> <section>
<div class="content-box"> <div class="content-box">
...@@ -290,14 +308,17 @@ $( document ).ready(function() { ...@@ -290,14 +308,17 @@ $( document ).ready(function() {
<td><b><?=gettext("Current");?></b></td> <td><b><?=gettext("Current");?></b></td>
</tr> </tr>
<?php <?php
$i = 0; $last = count($confvers);
$curr = 1;
foreach($confvers as $version):?> foreach($confvers as $version):?>
<tr> <tr>
<td> <td>
<input type="radio" name="oldtime" value="<?=$version['time'];?>" <?= (!isset($oldcheck) && $i == 0) || (isset($oldcheck) && $oldcheck == $version['time']) ? 'checked="checked"' : '' ?>/> <input type="radio" name="oldtime" value="<?=$version['time'];?>" <?= (!isset($oldcheck) && $curr == 1) || (isset($oldcheck) && $oldcheck == $version['time']) ? 'checked="checked"' : '' ?>/>
</td> </td>
<td> <td>
<?php if ($curr != $last): ?>
<input type="radio" name="newtime" value="<?=$version['time'];?>" <?= isset($newcheck) && $newcheck == $version['time'] ? 'checked="checked"' : ''?>/> <input type="radio" name="newtime" value="<?=$version['time'];?>" <?= isset($newcheck) && $newcheck == $version['time'] ? 'checked="checked"' : ''?>/>
<?php endif ?>
</td> </td>
<td> <?= date(gettext("n/j/y H:i:s"), $version['time']) ?></td> <td> <?= date(gettext("n/j/y H:i:s"), $version['time']) ?></td>
<td> <?= $version['version'] ?></td> <td> <?= $version['version'] ?></td>
...@@ -316,7 +337,7 @@ $( document ).ready(function() { ...@@ -316,7 +337,7 @@ $( document ).ready(function() {
</td> </td>
</tr> </tr>
<?php <?php
$i++; $curr++;
endforeach;?> endforeach;?>
</tbody> </tbody>
</table> </table>
...@@ -324,6 +345,7 @@ $( document ).ready(function() { ...@@ -324,6 +345,7 @@ $( document ).ready(function() {
</div> </div>
</section> </section>
</form> </form>
<?php endif ?>
</section> </section>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment