diff options
author | NOYB <Al_Stu@Frontier.com> | 2016-05-24 18:57:06 -0700 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-05-25 08:33:29 -0400 |
commit | ed6b9103b0f8f58cded1687b612fc999c6f9ab00 (patch) | |
tree | c19f7148061b0bea15cc4768ff35932f416c6722 /src | |
parent | f0f471f7c278e1795679cef63e1bc1d8581ac1ee (diff) | |
download | pfsense-ed6b9103b0f8f58cded1687b612fc999c6f9ab00.zip pfsense-ed6b9103b0f8f58cded1687b612fc999c6f9ab00.tar.gz |
Firewall / Aliases / Edit - New URL Table Alias Type
Make the code cleaner and easier to follow by using the same alias type designations as config.
(cherry picked from commit ebe833f6a9463b0e4add1d97c360af4a682d1add)
Diffstat (limited to 'src')
-rw-r--r-- | src/etc/inc/filter.inc | 3 | ||||
-rw-r--r-- | src/etc/inc/pfsense-utils.inc | 22 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index 9556e15..8976094 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -850,7 +850,8 @@ function filter_generate_aliases() { // TODO: Change it when pf supports tables with ports $urlfn = alias_expand_urltable($aliased['name']); if ($urlfn) { - $aliases .= "{$aliased['name']} = \"{ " . preg_replace("/\n/", " ", file_get_contents($urlfn)) . " }\"\n"; + $ports_tmp = parse_aliases_file($urlfn, "urltable_ports", "-1", false); + $aliases .= "{$aliased['name']} = \"{ " . preg_replace("/\n/", " ", implode("\n", $ports_tmp)) . " }\"\n"; } break; case "port": diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 86f4a51..4ee6e7e 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -1957,8 +1957,8 @@ function parse_aliases_file($filename, $type = "url", $max_items = -1, $kflc = f if (!empty($tmp_str)) { $tmp = $tmp_str; } - $valid = ($type == "url" && (is_ipaddr($tmp) || is_subnet($tmp))) || - ($type == "url_ports" && (is_port($tmp) || is_portrange($tmp))); + $valid = (($type == "url" || $type == "urltable") && (is_ipaddr($tmp) || is_subnet($tmp))) || + (($type == "url_ports" || $type == "urltable_ports") && (is_port($tmp) || is_portrange($tmp))); if ($valid) { $items[] = $tmp; if (count($items) == $max_items) { @@ -2177,17 +2177,17 @@ function process_alias_urltable($name, $type, $url, $freq, $forceupdate=false, $ 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)); + $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)); - } else { - $urltable = parse_aliases_file($tmp_urltable_filename, "url", "-1", true); - if (is_array($urltable)) { - file_put_contents($urltable_filename, implode("\n", $urltable)); - } + + $parsed_contents = parse_aliases_file($tmp_urltable_filename, $type, "-1", true); + if ($type == "url_ports") { + $parsed_contents = group_ports($parsed_contents, true); + } + if (is_array($parsed_contents)) { + file_put_contents($urltable_filename, implode("\n", $parsed_contents)); } + /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ if (($g['platform'] == $g['product_name']) && !isset($config['system']['use_mfs_tmpvar'])) { unlink_if_exists("{$g['cf_conf_path']}/RAM_Disk_Store{$urltable_filename}.tgz"); |