Commit 156f8d44 authored by Franco Fichtner's avatar Franco Fichtner

system: add captive portal session backup #1437

parent 83b5aae6
......@@ -71,6 +71,7 @@
/usr/local/etc/pkg/fingerprints/OPNsense/trusted/opnsense-update.deciso.com.20160725
/usr/local/etc/pkg/fingerprints/OPNsense/trusted/pkg.opnsense.org.20161210
/usr/local/etc/rc
/usr/local/etc/rc.backup_captiveportal
/usr/local/etc/rc.backup_dhcpleases
/usr/local/etc/rc.backup_netflow
/usr/local/etc/rc.backup_rrd
......
......@@ -1606,6 +1606,10 @@ function system_cron_configure($verbose = false)
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', '0', '*/' . $config['system']['netflowbackup']);
}
if (!empty($config['system']['captiveportalbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_captiveportal', '0', '*/' . $config['system']['captiveportalbackup']);
}
if (!empty($config['system']['remotebackup']['GDriveEnabled'])) {
$autocron[] = generate_cron_job('/usr/local/opnsense/scripts/remote_backup.php', 0, 1);
}
......
......@@ -241,10 +241,10 @@ done
# Startup configd
/usr/local/etc/rc.d/configd start
# Restore backups from previous shutdown (if any)
/usr/local/etc/rc.backup_dhcpleases restore
/usr/local/etc/rc.backup_netflow restore
/usr/local/etc/rc.backup_rrd restore
# Restore backups from previous shutdown
for BACKUP in captiveportal dhcpleases netflow rrd; do
/usr/local/etc/rc.backup_${BACKUP} restore
done
# Execute the early syshook / plugin commands
/usr/local/etc/rc.syshook early
......
#!/bin/sh
BACKUPFILE="/conf/captiveportal.sqlite"
BACKUPDB="/var/captiveportal/captiveportal.sqlite"
if [ "${1}" = "restore" ]; then
if [ -f "${BACKUPFILE}" ]; then
cp "${BACKUPFILE}" "${BACKUPDB}"
fi
else
if [ -f "${BACKUPDB}" ]; then
sqlite3 "${BACKUPDB}" ".backup ${BACKUPFILE}"
fi
fi
......@@ -10,9 +10,9 @@
/usr/local/etc/rc.opnsense stop
# backup volatile internals
/usr/local/etc/rc.backup_dhcpleases stop
/usr/local/etc/rc.backup_netflow stop
/usr/local/etc/rc.backup_rrd stop
for BACKUP in captiveportal dhcpleases netflow rrd; do
/usr/local/etc/rc.backup_${BACKUP} stop
done
# wait for config lock to release
php -a >/dev/null << EOF
......
......@@ -85,6 +85,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['rrdbackup'] = !empty($config['system']['rrdbackup']) ? $config['system']['rrdbackup'] : null;
$pconfig['dhcpbackup'] = !empty($config['system']['dhcpbackup']) ? $config['system']['dhcpbackup'] : null;
$pconfig['netflowbackup'] = !empty($config['system']['netflowbackup']) ? $config['system']['netflowbackup'] : null;
$pconfig['captiveportalbackup'] = !empty($config['system']['captiveportalbackup']) ? $config['system']['captiveportalbackup'] : null;
$pconfig['powerd_ac_mode'] = "hadp";
if (!empty($config['system']['powerd_ac_mode'])) {
$pconfig['powerd_ac_mode'] = $config['system']['powerd_ac_mode'];
......@@ -174,6 +175,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($config['system']['netflowbackup']);
}
if (!empty($pconfig['captiveportalbackup'])) {
$config['system']['captiveportalbackup'] = $pconfig['captiveportalbackup'];
} elseif (isset($config['system']['captiveportalbackup'])) {
unset($config['system']['captiveportalbackup']);
}
write_config();
$savemsg = get_std_save_message();
......@@ -340,6 +347,24 @@ include("head.inc");
</div>
</td>
</tr>
<tr>
<td><a id="help_for_captiveportalbackup" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Periodic Captive Portal Backup");?></td>
<td>
<select name="captiveportalbackup" class="selectpicker" data-style="btn-default" id="captiveportalbackup">
<option value='0' <?= $pconfig['captiveportalbackup'] == 0 ? 'selected="selected"' : ''; ?>><?=gettext('Disabled'); ?></option>
<?php
for ($x = 1; $x <= 24; $x++): ?>
<option value="<?= $x ?>" <?= $pconfig['captiveportalbackup'] == $x ? 'selected="selected"' : '';?>>
<?= $x == 1 ? gettext('1 hour') : sprintf(gettext('%s hours'), $x) ?>
</option>
<?php
endfor; ?>
</select>
<div class="hidden" for="help_for_captiveportalbackup">
<?=gettext("This will periodically backup the captive portal session data so it can be restored automatically on the next boot.");?>
</div>
</td>
</tr>
<tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Power Savings"); ?></th>
</tr>
......
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