Commit 02a1000c authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) cleanup and validate url alias download, closes...

(legacy) cleanup and validate url alias download, closes https://github.com/opnsense/core/issues/877

(cherry picked from commit cdb5304d)
parent 1e7c91c6
...@@ -30,6 +30,7 @@ require_once("config.inc"); ...@@ -30,6 +30,7 @@ require_once("config.inc");
require_once("util.inc"); require_once("util.inc");
require_once("pfsense-utils.inc"); require_once("pfsense-utils.inc");
function update_alias_url_data() function update_alias_url_data()
{ {
global $config; global $config;
...@@ -43,8 +44,7 @@ function update_alias_url_data() ...@@ -43,8 +44,7 @@ function update_alias_url_data()
continue; continue;
} }
$address = ""; $address_list = array();
$isfirst = 0;
foreach ($alias['aliasurl'] as $alias_url) { foreach ($alias['aliasurl'] as $alias_url) {
/* fetch down and add in */ /* fetch down and add in */
$temp_filename = tempnam('/tmp/', 'alias_import'); $temp_filename = tempnam('/tmp/', 'alias_import');
...@@ -52,17 +52,6 @@ function update_alias_url_data() ...@@ -52,17 +52,6 @@ function update_alias_url_data()
$verify_ssl = isset($config['system']['checkaliasesurlcert']); $verify_ssl = isset($config['system']['checkaliasesurlcert']);
mkdir($temp_filename); mkdir($temp_filename);
download_file($alias_url, $temp_filename . "/aliases", $verify_ssl); download_file($alias_url, $temp_filename . "/aliases", $verify_ssl);
/* if the item is tar gzipped then extract */
if (stripos($alias_url, '.tgz')) {
if (!process_alias_tgz($temp_filename)) {
continue;
}
} elseif (stripos($alias_url, '.zip')) {
if (!process_alias_unzip($temp_filename)) {
continue;
}
}
if (file_exists("{$temp_filename}/aliases")) { if (file_exists("{$temp_filename}/aliases")) {
$fd = @fopen("{$temp_filename}/aliases", 'r'); $fd = @fopen("{$temp_filename}/aliases", 'r');
if (!$fd) { if (!$fd) {
...@@ -79,19 +68,18 @@ function update_alias_url_data() ...@@ -79,19 +68,18 @@ function update_alias_url_data()
if (!empty($tmp_str)) { if (!empty($tmp_str)) {
$tmp = $tmp_str; $tmp = $tmp_str;
} }
if ($isfirst == 1) { // validate address, it should either be an address or a subnet and must be unique
$address .= ' '; if ((is_ipaddr($tmp) || is_subnet($tmp)) && !in_array($tmp, $address_list)) {
$address_list[] = $tmp;
} }
$address .= $tmp;
$isfirst = 1;
} }
fclose($fd); fclose($fd);
mwexec("/bin/rm -rf {$temp_filename}"); mwexec("/bin/rm -rf {$temp_filename}");
} }
} }
if (!empty($address)) { if (count($address_list) > 0) {
$config['aliases']['alias'][$x]['address'] = $address; $config['aliases']['alias'][$x]['address'] = implode(" ", $address_list);
$updated = true; $updated = true;
} }
} }
} }
...@@ -101,7 +89,6 @@ function update_alias_url_data() ...@@ -101,7 +89,6 @@ function update_alias_url_data()
return $updated; return $updated;
} }
if (update_alias_url_data()) { if (update_alias_url_data()) {
write_config(); write_config();
configd_run("filter reload"); configd_run("filter reload");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment