Commit b5e671d0 authored by Ad Schellevis's avatar Ad Schellevis

replace get_backups + small fixes

parent ddc461df
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
<?php <?php
require_once('config.inc'); require_once('config.inc');
require_once("script/load_phalcon.php");
cleanup_backupcache(); $cnf = OPNsense\Core\Config::getInstance();
$confvers = get_backups(); $confvers = $cnf->getBackups(true);
unset($confvers['versions']);
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
...@@ -27,7 +27,7 @@ function print_backup_info($backup_info, $number) { ...@@ -27,7 +27,7 @@ function print_backup_info($backup_info, $number) {
} }
} }
function list_backups($which="all", $return=false) { function list_backups($which="all") {
global $confvers; global $confvers;
if (count($confvers) == 0) { if (count($confvers) == 0) {
...@@ -35,11 +35,12 @@ function list_backups($which="all", $return=false) { ...@@ -35,11 +35,12 @@ function list_backups($which="all", $return=false) {
return; return;
} }
for ($c = count($confvers)-1; $c >= 0; $c--) { $c = 0 ;
foreach ($confvers as $filename => $bckinfo) {
$c++;
if (is_numeric($which) && ($c != $which)) if (is_numeric($which) && ($c != $which))
continue; continue;
print_backup_info($confvers[$c], $c+1); print_backup_info($bckinfo,$c);
echo "\n";
} }
} }
...@@ -63,14 +64,15 @@ function choose_backup() { ...@@ -63,14 +64,15 @@ function choose_backup() {
function restore_history_backup($number) { function restore_history_backup($number) {
global $g, $fp, $confvers; global $g, $fp, $confvers;
if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) { if (is_numeric($number) && ($number > 0) && ($number <= count($confvers))) {
$realnumber = $number - 1;
echo "\n" . gettext("Is this the backup you wish to restore?") . "\n"; echo "\n" . gettext("Is this the backup you wish to restore?") . "\n";
list_backups($realnumber); list_backups($number);
$thisbackup = $confvers[$realnumber]; $filename = array_keys($confvers)[$number-1];
$thisbackup = $confvers[$filename];
echo gettext("Y/N?") . " : "; echo gettext("Y/N?") . " : ";
$confirm = strtoupper(chop(fgets($fp))); $confirm = strtoupper(chop(fgets($fp)));
if ($confirm == gettext("Y")) { if ($confirm == gettext("Y")) {
if(config_restore('/conf/backup/config-' . $thisbackup['time'] . '.xml') == 0) { $cnf = OPNsense\Core\Config::getInstance();
if($cnf->restoreBackup($filename)){
echo "\n"; echo "\n";
echo sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $thisbackup['time']), $thisbackup['description']); echo sprintf(gettext('Successfully reverted to timestamp %1$s with description "%2$s".'), date(gettext("n/j/y H:i:s"), $thisbackup['time']), $thisbackup['description']);
echo "\n" . gettext("You may need to reboot the firewall or restart services before the restored configuration is fully active.") . "\n\n"; echo "\n" . gettext("You may need to reboot the firewall or restart services before the restored configuration is fully active.") . "\n\n";
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("config.lib.inc");
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("script/load_phalcon.php"); require_once("script/load_phalcon.php");
......
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