diff options
-rw-r--r-- | src/etc/inc/pfsense-utils.inc | 22 | ||||
-rw-r--r-- | src/usr/local/www/firewall_aliases.php | 4 | ||||
-rwxr-xr-x | src/usr/local/www/firewall_aliases_edit.php | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 87039f6..9788fb4 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -2148,11 +2148,12 @@ function pfs_version_compare($cur_time, $cur_text, $remote) { } return $v; } -function process_alias_urltable($name, $url, $freq, $forceupdate=false) { +function process_alias_urltable($name, $url, $freq, $forceupdate=false, $validateonly=false) { global $config; $urltable_prefix = "/var/db/aliastables/"; $urltable_filename = $urltable_prefix . $name . ".txt"; + $tmp_urltable_filename = $urltable_filename . ".tmp"; // Make the aliases directory if it doesn't exist if (!file_exists($urltable_prefix)) { @@ -2163,24 +2164,29 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) { } // If the file doesn't exist or is older than update_freq days, fetch a new copy. - if (!file_exists($urltable_filename) || + if (!file_exists($urltable_filename) || (filesize($urltable_filename) == "0") || ((time() - filemtime($urltable_filename)) > ($freq * 86400 - 90)) || $forceupdate) { // Try to fetch the URL supplied conf_mount_rw(); - unlink_if_exists($urltable_filename . ".tmp"); + unlink_if_exists($tmp_urltable_filename); $verify_ssl = isset($config['system']['checkaliasesurlcert']); - if (download_file($url, $urltable_filename . ".tmp", $verify_ssl)) { - mwexec("/usr/bin/sed -E 's/\;.*//g; /^[[:space:]]*($|#)/d' ". escapeshellarg($urltable_filename . ".tmp") . " > " . escapeshellarg($urltable_filename)); + if (download_file($url, $tmp_urltable_filename, $verify_ssl)) { + mwexec("/usr/bin/sed -i \"\" -E 's/\;.*//g; /^[[:space:]]*($|#)/d' " . escapeshellarg($tmp_urltable_filename)); if (alias_get_type($name) == "urltable_ports") { - $ports = explode("\n", str_replace("\r", "", file_get_contents($urltable_filename))); + $ports = parse_aliases_file($tmp_urltable_filename, "url_ports", "-1"); $ports = group_ports($ports); file_put_contents($urltable_filename, implode("\n", $ports)); + } else { + $urltable = parse_aliases_file($tmp_urltable_filename, "url", "-1"); + file_put_contents($urltable_filename, implode("\n", $urltable)); } - unlink_if_exists($urltable_filename . ".tmp"); + unlink_if_exists($tmp_urltable_filename); } else { - touch($urltable_filename); + if (!$validateonly) { + touch($urltable_filename); + } conf_mount_ro(); return false; } diff --git a/src/usr/local/www/firewall_aliases.php b/src/usr/local/www/firewall_aliases.php index 4f422dd..a07da68 100644 --- a/src/usr/local/www/firewall_aliases.php +++ b/src/usr/local/www/firewall_aliases.php @@ -132,6 +132,10 @@ if ($_GET['act'] == "del") { if ($is_alias_referenced == true) { $savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), htmlspecialchars($referenced_by)); } else { + if (preg_match("/urltable/i", $a_aliases[$_GET['id']]['type'])) { + // this is a URL table type alias, delete its file as well + unlink_if_exists("/var/db/aliastables/" . $a_aliases[$_GET['id']]['name'] . ".txt"); + } unset($a_aliases[$_GET['id']]); if (write_config()) { filter_configure(); diff --git a/src/usr/local/www/firewall_aliases_edit.php b/src/usr/local/www/firewall_aliases_edit.php index ae6acaf..d859a3f 100755 --- a/src/usr/local/www/firewall_aliases_edit.php +++ b/src/usr/local/www/firewall_aliases_edit.php @@ -225,7 +225,7 @@ if ($_POST) { $alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7; if (!is_URL($alias['url']) || empty($alias['url'])) { $input_errors[] = gettext("You must provide a valid URL."); - } elseif (!process_alias_urltable($alias['name'], $alias['url'], 0, true)) { + } elseif (!process_alias_urltable($alias['name'], $alias['url'], 0, true, true)) { $input_errors[] = gettext("Unable to fetch usable data from URL") . " " . htmlspecialchars($alias['url']); } if ($_POST["detail0"] <> "") { |