diff options
author | Ermal <eri@pfsense.org> | 2014-04-30 07:07:56 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2014-04-30 07:07:56 +0000 |
commit | 8422cdd583ef135172c5a7a259282ea6d091512c (patch) | |
tree | 25a5b9e033211e31bff379c9c672ec99dffa2fbe | |
parent | 0ad946164c2cf6b1fa872f739cf108e73c5a5c78 (diff) | |
download | pfsense-8422cdd583ef135172c5a7a259282ea6d091512c.zip pfsense-8422cdd583ef135172c5a7a259282ea6d091512c.tar.gz |
Rewrite update_alias_url_data to be with small memory footprint. Also return the status if an update is performed to callers and remove the write_config call embedded here since its not good to have this by default.
-rw-r--r-- | etc/inc/pfsense-utils.inc | 46 | ||||
-rwxr-xr-x | etc/rc.update_alias_url_data | 6 |
2 files changed, 29 insertions, 23 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 1ab966a..a08bbc7 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1893,8 +1893,10 @@ function update_alias_names_upon_change($section, $field, $new_alias_name, $orig function update_alias_url_data() { global $config, $g; + $updated = false; + /* item is a url type */ - $lockkey = lock('config'); + $lockkey = lock('aliasurl'); if (is_array($config['aliases']['alias'])) { foreach ($config['aliases']['alias'] as $x => $alias) { if (empty($alias['aliasurl'])) @@ -1916,36 +1918,38 @@ function update_alias_url_data() { else if (stristr($alias_url, ".zip")) process_alias_unzip($temp_filename); if (file_exists("{$temp_filename}/aliases")) { - $file_contents = file_get_contents("{$temp_filename}/aliases"); - $file_contents = str_replace("#", "\n#", $file_contents); - $file_contents_split = explode("\n", $file_contents); - foreach ($file_contents_split as $fc) { - $tmp = trim($fc); - if (stristr($fc, "#")) { - $tmp_split = explode("#", $tmp); - $tmp = trim($tmp_split[0]); - } - if (trim($tmp) <> "") { - if ($isfirst == 1) - $address .= " "; - $address .= $tmp; - $isfirst = 1; - } + $fd = @fopen("{$temp_filename}/aliases"); + if (!$fd) { + log_error(gettext("Could not process aliases from alias: {$alias_url}")); + continue; } + /* NOTE: fgetss() is not a typo RTFM before being smart */ + while (($fc = fgetss($fd)) !== FALSE) { + $tmp = trim($fc, " \t\n\r"); + if (empty($tmp)) + continue; + $tmp_str = strstr($tmp, '#', true); + if (!empty($tmp_str)) + $tmp = $tmp_str; + if ($isfirst == 1) + $address .= ' '; + $address .= $tmp; + $isfirst = 1; + } + fclose($fd); mwexec("/bin/rm -rf {$temp_filename}"); } } - if($isfirst > 0) { + if (!empty($address)) { $config['aliases']['alias'][$x]['address'] = $address; $updated = true; } } } unlock($lockkey); - if ($updated) { - write_config(); - send_event("filter reload"); - } + + /* Report status to callers as well */ + return $updated; } function process_alias_unzip($temp_filename) { diff --git a/etc/rc.update_alias_url_data b/etc/rc.update_alias_url_data index 9b81d84..5cc6088 100755 --- a/etc/rc.update_alias_url_data +++ b/etc/rc.update_alias_url_data @@ -36,6 +36,8 @@ require_once("config.inc"); require_once("functions.inc"); -update_alias_url_data(); - +if (update_alias_url_data()) { + write_config(); + send_event("filter reload"); +} ?> |