System: Configuration: History - move "backupcount" setting to "System: Configuration: Backups" for https://github.com/opnsense/core/issues/6828

Local backup configuration would be best stored in the backup configuration for consistency. Eventually we should refactor the backup configuration as well, but while refactoring the history page and adding a host selection (when used in conjunction with OPNcentral), this setting is a bit out of place.
This commit is contained in:
Ad Schellevis 2023-09-25 21:38:37 +02:00
parent 56e2940430
commit dd40f71523
2 changed files with 44 additions and 46 deletions

View File

@ -110,7 +110,7 @@ $do_reboot = false;
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
$pconfig['backupcount'] = isset($config['system']['backupcount']) ? $config['system']['backupcount'] : null;
foreach ($backupFactory->listProviders() as $providerId => $provider) {
foreach ($provider['handle']->getConfigurationFields() as $field) {
$fieldId = $providerId . "_" .$field['name'];
@ -324,6 +324,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
system_cron_configure();
}
} elseif (!empty($pconfig['save'])) {
if ($pconfig['backupcount'] != null && (!is_numeric($pconfig['backupcount']) || $pconfig['backupcount'] <= 0)) {
$input_errors[] = gettext('Backup count must be greater than zero.');
}
if (count($input_errors) == 0) {
if ($pconfig['backupcount'] != null) {
$config['system']['backupcount'] = $pconfig['backupcount'];
} elseif (isset($config['system']['backupcount'])) {
unset($config['system']['backupcount']);
}
write_config('Changed backup revision count');
$savemsg = get_std_save_message();
}
}
}
@ -374,6 +387,32 @@ $( document ).ready(function() {
<?php if (isset($input_messages)) print_info_box($input_messages); ?>
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<form method="post" enctype="multipart/form-data">
<section class="col-xs-12">
<div class="content-box tab-content table-responsive __mb">
<table class="table table-striped">
<div class="content-box tab-content table-responsive __mb">
<table class="table table-striped">
<tbody>
<tr>
<td colspan="2"><strong><?= gettext('Backup Count') ?></strong></td>
</tr>
<tr>
<td><input name="backupcount" type="text" size="5" value="<?= html_safe($pconfig['backupcount']) ?>"/></td>
<td><?= gettext("Enter the number of older configurations to keep in the local backup cache."); ?></td>
</tr>
<tr>
<td><input name="save" type="submit" class="btn btn-primary" value="<?= html_safe(gettext('Save')) ?>"/></td>
<td>
<?= gettext('Be aware of how much space is consumed by backups before adjusting this value.'); ?>
<?php if (count(OPNsense\Core\Config::getInstance()->getBackups(true)) > 0): ?>
<?= gettext('Current space used:') . ' ' . exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
<?php endif ?>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="col-xs-12">
<div class="content-box tab-content table-responsive __mb">
<table class="table table-striped">

View File

@ -93,21 +93,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors = array();
$pconfig = $_POST;
if (!empty($pconfig['save'])) {
if ($pconfig['backupcount'] != null && (!is_numeric($pconfig['backupcount']) || $pconfig['backupcount'] <= 0)) {
$input_errors[] = gettext('Backup count must be greater than zero.');
}
if (count($input_errors) == 0) {
if ($pconfig['backupcount'] != null) {
$config['system']['backupcount'] = $pconfig['backupcount'];
} elseif (isset($config['system']['backupcount'])) {
unset($config['system']['backupcount']);
}
write_config('Changed backup revision count');
$savemsg = get_std_save_message();
}
}
$cnf = OPNsense\Core\Config::getInstance();
$confvers = $cnf->getBackups(true);
array_shift($confvers);
@ -206,41 +191,15 @@ include("fbegin.inc");
?>
<section class="page-content-main">
<form method="post" id="iform">
<input type="hidden" id="time" name="time" value="" />
<input type="hidden" id="action" name="act" value="" />
</form>
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<section class="col-xs-12">
<form method="post" id="iform">
<input type="hidden" id="time" name="time" value="" />
<input type="hidden" id="action" name="act" value="" />
<div class="content-box tab-content table-responsive __mb">
<table class="table table-striped">
<tbody>
<tr>
<td colspan="2"><strong><?= gettext('Backup Count') ?></strong></td>
</tr>
<tr>
<td>
<input name="backupcount" type="text" size="5" value="<?= html_safe($pconfig['backupcount']) ?>"/>
</td>
<td><?= gettext("Enter the number of older configurations to keep in the local backup cache."); ?></td>
</tr>
<tr>
<td>
<input name="save" type="submit" class="btn btn-primary" value="<?= html_safe(gettext('Save')) ?>"/>
</td>
<td>
<?= gettext('Be aware of how much space is consumed by backups before adjusting this value.'); ?>
<?php if (isset($confvers) && count($confvers) > 0): ?>
<?= gettext('Current space used:') . ' ' . exec("/usr/bin/du -sh /conf/backup | /usr/bin/awk '{print $1;}'") ?>
<?php endif ?>
</td>
</tr>
</tbody>
</table>
</div>
</form>
<?php if ($diff): ?>
<div class="content-box tab-content table-responsive __mb" style="overflow: scroll;">
<table class="table table-striped">