From 2548b42b24132df0558eb7af208b0e550eed1ef0 Mon Sep 17 00:00:00 2001
From: Christopher Cope <ccope@netgate.com>
Date: Fri, 22 Jul 2022 13:40:26 -0400
Subject: [PATCH] Add option to list ACB restores in reverse order. Feature
 #11266

---
 src/etc/inc/acb.inc                         | 3 ++-
 src/usr/local/www/services_acb.php          | 4 ++++
 src/usr/local/www/services_acb_settings.php | 8 ++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/etc/inc/acb.inc b/src/etc/inc/acb.inc
index 152801b106..5ee9e75923 100644
--- a/src/etc/inc/acb.inc
+++ b/src/etc/inc/acb.inc
@@ -338,7 +338,7 @@ function upload_config($manual = false) {
 // Create a crontab entry for scheduled backups
 // if frequency == "cron", a new crontab entry is created, otherwise any existing
 // ACB entry is removed
-function setup_ACB($enable, $hint, $frequency, $minute, $hours, $month, $day, $dow, $numman, $pwd) {
+function setup_ACB($enable, $hint, $frequency, $minute, $hours, $month, $day, $dow, $numman, $reverse, $pwd) {
 	global $config;
 
 	init_config_arr(array('system', 'acb'));
@@ -357,6 +357,7 @@ function setup_ACB($enable, $hint, $frequency, $minute, $hours, $month, $day, $d
 	$config['system']['acb']['day'] = $day;
 	$config['system']['acb']['dow'] = $dow;
 	$config['system']['acb']['numman'] = $numman;
+	$config['system']['acb']['reverse'] = $reverse;
 	if (strlen($pwd) >= 8) {
 		$config['system']['acb']['encryption_password'] = $pwd;
 	}
diff --git a/src/usr/local/www/services_acb.php b/src/usr/local/www/services_acb.php
index 4fb00dc1d2..6cf46ab353 100644
--- a/src/usr/local/www/services_acb.php
+++ b/src/usr/local/www/services_acb.php
@@ -412,6 +412,10 @@ print('</div>');
 
 			<?php
 				$counter = 0;
+				if ($config['system']['acb']['reverse'] == "yes"){
+					$confvers = array_reverse($confvers);
+				}
+
 				foreach ($confvers as $cv):
 			?>
 					<tr>
diff --git a/src/usr/local/www/services_acb_settings.php b/src/usr/local/www/services_acb_settings.php
index 3e49b2055b..9a2d760d85 100644
--- a/src/usr/local/www/services_acb_settings.php
+++ b/src/usr/local/www/services_acb_settings.php
@@ -92,6 +92,7 @@ if (isset($_POST['save'])) {
 			$pconfig['day'],
 			$pconfig['dow'],
 			$pconfig['numman'],
+			$pconfig['reverse'],
 			$pwd
 		);
 	}
@@ -207,6 +208,13 @@ $section->addInput(new Form_Input(
 ))->setHelp("It may be useful to specify how many manual backups are retained on the server so that automatic backups do not overwrite them." .
 			"A maximum of 50 retained manual backups (of the 100 total backups) is permitted.");
 
+$section->addInput(new Form_Checkbox(
+	'reverse',
+	'Reverse List',
+	'List backups in reverse order',
+	($pconfig['reverse'] == "yes")
+))->setHelp("List backups in reverse order (newest first) when viewing the restore section.");
+
 $form->add($section);
 
 print $form;
-- 
2.25.1

