From f0f471f7c278e1795679cef63e1bc1d8581ac1ee Mon Sep 17 00:00:00 2001 From: NOYB Date: Tue, 24 May 2016 13:39:09 -0700 Subject: Firewall / Aliases / Edit - New URL Table Alias Type Need to pass alias type to process_alias_urltable() function when creating a new url table alias because it is not yet set/available from config. So the alias_get_type() function can't be successfully used yet. (cherry picked from commit 3b07f4feaf35e70700082240ef03966f74f5df97) --- src/etc/inc/pfsense-utils.inc | 5 +++-- src/etc/rc.update_urltables | 2 +- src/usr/local/www/firewall_aliases_edit.php | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 71219fb..86f4a51 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -2150,7 +2150,7 @@ function pfs_version_compare($cur_time, $cur_text, $remote) { } return $v; } -function process_alias_urltable($name, $url, $freq, $forceupdate=false, $validateonly=false) { +function process_alias_urltable($name, $type, $url, $freq, $forceupdate=false, $validateonly=false) { global $g, $config; $urltable_prefix = "/var/db/aliastables/"; @@ -2177,7 +2177,8 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false, $validat if (download_file($url, $tmp_urltable_filename, $verify_ssl)) { // Convert lines that begin with '$' or ';' to comments '#' instead of deleting them. mwexec("/usr/bin/sed -i \"\" -E 's/^[[:space:]]*($|#|;)/#/g; /^#/!s/\;.*//g;' ". escapeshellarg($tmp_urltable_filename)); - if (alias_get_type($name) == "urltable_ports") { + $type = ($type) ? $type : alias_get_type($name); // If empty type passed, try to get it from config. + if ($type == "urltable_ports") { $ports = parse_aliases_file($tmp_urltable_filename, "url_ports", "-1", true); $ports = group_ports($ports, true); file_put_contents($urltable_filename, implode("\n", $ports)); diff --git a/src/etc/rc.update_urltables b/src/etc/rc.update_urltables index 887dfac..8a2c00b 100755 --- a/src/etc/rc.update_urltables +++ b/src/etc/rc.update_urltables @@ -49,7 +49,7 @@ if (count($todo) > 0) { continue; } - $r = process_alias_urltable($t['name'], $t['url'], $t['freq'], $forceupdate); + $r = process_alias_urltable($t['name'], $t['type'], $t['url'], $t['freq'], $forceupdate); if ($r == 1) { $result = ""; // TODO: Change it when pf supports tables with ports diff --git a/src/usr/local/www/firewall_aliases_edit.php b/src/usr/local/www/firewall_aliases_edit.php index f762fe8..ea60a73 100755 --- a/src/usr/local/www/firewall_aliases_edit.php +++ b/src/usr/local/www/firewall_aliases_edit.php @@ -206,6 +206,7 @@ if ($_POST) { $address = array(); $final_address_details = array(); $alias['name'] = $_POST['name']; + $alias['type'] = $_POST['type']; if (preg_match("/urltable/i", $_POST['type'])) { $address = ""; @@ -219,7 +220,7 @@ if ($_POST) { $alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7; if (!is_URL($alias['url']) || empty($alias['url'])) { $input_errors[] = gettext("A valid URL must be provided."); - } elseif (!process_alias_urltable($alias['name'], $alias['url'], 0, true, true)) { + } elseif (!process_alias_urltable($alias['name'], $alias['type'], $alias['url'], 0, true, true)) { $input_errors[] = gettext("Unable to fetch usable data from URL") . " " . htmlspecialchars($alias['url']); } if ($_POST["detail0"] <> "") { -- cgit v1.1