} } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $cnf = OPNsense\Core\Config::getInstance(); $confvers = $cnf->getBackups(true); if (!empty($_POST['save'])) { if (is_numeric($_POST['backupcount']) && $_POST['backupcount'] >= 0) { $config['system']['backupcount'] = $_POST['backupcount']; } elseif (isset($config['system']['backupcount'])) { unset($config['system']['backupcount']); } write_config(gettext('Changed backup revision count.')); } elseif (!empty($_POST['act']) && $_POST['act'] == "revert") { foreach ($confvers as $filename => $revision) { if (isset($revision['time']) && $revision['time'] == $_POST['time']) { if (config_restore($filename) == 0) { $savemsg = sprintf(gettext('Successfully reverted to timestamp %s with description "%s".'), date(gettext("n/j/y H:i:s"), $_POST['id']), $revision['description']); } else { $savemsg = gettext("Unable to revert to the selected configuration."); } break; } } } elseif (!empty($_POST['act']) && $_POST['act'] == "delete") { foreach ($confvers as $filename => $revision) { if (isset($revision['time']) && $revision['time'] == $_POST['time']) { if (file_exists($filename)) { @unlink($filename); $savemsg = sprintf(gettext('Deleted backup with timestamp %s and description "%s".'), date(gettext("n/j/y H:i:s"), $revision['time']), $revision['description']); } else { $savemsg = gettext("Unable to delete the selected configuration.");
$config['system']['backupcount'] = $_POST['backupcount']; $changedescr = $config['system']['backupcount']; } else { unset($config['system']['backupcount']); $changedescr = "(platform default)"; } write_config("Changed backup revision count to {$changedescr}"); } 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 ($_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 ($_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(); } if ($_GET['getcfg'] != "") { $file = $g['conf_path'] . '/backup/config-' . $_GET['getcfg'] . '.xml'; $exp_name = urlencode("config-{$config['system']['hostname']}.{$config['system']['domain']}-{$_GET['getcfg']}.xml"); $exp_data = file_get_contents($file);
$input_errors[] = "SHA256 values do not match, cannot restore. {$ondisksha256} <> {$sha256}"; } } if (curl_errno($curl_session)) { /* If an error occured, log the error in /tmp/ */ $fd = fopen("/tmp/acb_restoredebug.txt", "w"); fwrite($fd, $get_url . "" . "action=restore&hostname={$hostname}&revision=" . urlencode($_REQUEST['newver']) . "\n\n"); fwrite($fd, $data); fwrite($fd, curl_error($curl_session)); fclose($fd); } else { curl_close($curl_session); } if (!$input_errors && $data) { conf_mount_rw(); if (config_restore("/tmp/config_restore.xml") == 0) { $savemsg = "Successfully reverted the pfSense configuration to revision " . urldecode($_REQUEST['newver']) . "."; $savemsg .= <<<EOF \t\t\t\t\t\t\t<br /> \t\t\t\t\t\t<form action="reboot.php" method="post"> \t\t\t\t\t\t\tWould you like to reboot? \t\t\t\t\t\t\t<input name="Submit" type="submit" class="formbtn" value=" Yes " /> \t\t\t\t\t\t\t<input name="Submit" type="submit" class="formbtn" value=" No " /> \t\t\t\t\t\t</form> EOF; } else { $savemsg = "Unable to revert to the selected configuration."; } print_info_box($savemsg); } else { log_error("There was an error when restoring the AutoConfigBackup item");