Project

General

Profile

Bug #9074

Alias URL lists only storing last-most list in config.

Added by Paul Bramhall 3 months ago. Updated 3 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Rules/NAT
Target version:
-
Start date:
10/28/2018
Due date:
% Done:

0%

Estimated time:
Affected Version:
2.4.x
Affected Architecture:

Description

When creating an Alias URL list under Firewall->Aliases->URLs, only the IP's from the last-most URL in the list is what is stored in the /cf/conf/config.xml file. The other previous URLs in the list, even though correctly validated & checked, are not kept.

It looks as though the issue lies within the /usr/local/www/firewall_aliases_edit.php file. The issue appears to be that during the loop where each url is downloaded & parsed, the $addresses array is replaced & not appended to when each URL is pulled in & validated. (lines 292 to 299)

 if (file_exists("{$temp_filename}/aliases")) {
         $address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 5000);
         if ($address == null) {
                 /* nothing was found */
                 $input_errors[] = sprintf(gettext("A valid URL must be provided. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
         }
         mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
 } else {

The following patch solves the issue for me, where the array is appended during each iteration.

@@ -253,6 +253,7 @@
         for ($x = 0; $x < $max_alias_addresses - 1; $x++) {
             $_POST['address' . $x] = trim($_POST['address' . $x]);
             if ($_POST['address' . $x]) {
+                $t_address = array();
                 /* fetch down and add in */
                 $temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
                 unlink_if_exists($temp_filename);
@@ -290,10 +291,13 @@
                 }

                 if (file_exists("{$temp_filename}/aliases")) {
-                    $address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 5000);
-                    if ($address == null) {
+                    $t_address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 5000);
+                    if ($t_address == null) {
                         /* nothing was found */
                         $input_errors[] = sprintf(gettext("A valid URL must be provided. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
+                    } else {
+                        $address += $t_address;
                     }
+                    unset($t_address);
                      mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
                 } else {
```                     mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
                 } else {

History

#1 Updated by Paul Bramhall 3 months ago

There still appeared to be some odd behaviour with the change I did above where it was not always appending the array, the following fixes it, as instead of just appending (+=) I am now using the array_push functionality:

@@ -253,6 +253,7 @@
         for ($x = 0; $x < $max_alias_addresses - 1; $x++) {
             $_POST['address' . $x] = trim($_POST['address' . $x]);
             if ($_POST['address' . $x]) {
+                $t_address = array();
                 /* fetch down and add in */
                 $temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
                 unlink_if_exists($temp_filename);
@@ -290,10 +291,13 @@
                 }

                 if (file_exists("{$temp_filename}/aliases")) {
-                    $address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 5000);
-                    if ($address == null) {
+                    $t_address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 5000);
+                    if ($t_address == null) {
                         /* nothing was found */
                         $input_errors[] = sprintf(gettext("A valid URL must be provided. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
+                    } else {
+                        array_push($address, ...$t_address);
                     }
+                    unset($t_address);
                      mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
                 } else {

Also available in: Atom PDF