mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
(legacy) whitespace rc.update_alias_url_data
This commit is contained in:
parent
a00e519483
commit
bfe5a992b2
@ -1,30 +1,29 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
|
||||
All rights reserved.
|
||||
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
require_once("config.inc");
|
||||
@ -33,72 +32,77 @@ require_once("pfsense-utils.inc");
|
||||
|
||||
function update_alias_url_data()
|
||||
{
|
||||
global $config;
|
||||
global $config;
|
||||
|
||||
$updated = false;
|
||||
$updated = false;
|
||||
/* item is a url type */
|
||||
$lockkey = lock('aliasurl');
|
||||
if (isset($config['aliases']['alias']) && is_array($config['aliases']['alias'])) {
|
||||
foreach ($config['aliases']['alias'] as $x => $alias) {
|
||||
if (empty($alias['aliasurl'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* item is a url type */
|
||||
$lockkey = lock('aliasurl');
|
||||
if (isset($config['aliases']['alias']) && is_array($config['aliases']['alias'])) {
|
||||
foreach ($config['aliases']['alias'] as $x => $alias) {
|
||||
if (empty($alias['aliasurl']))
|
||||
continue;
|
||||
$address = "";
|
||||
$isfirst = 0;
|
||||
foreach ($alias['aliasurl'] as $alias_url) {
|
||||
/* fetch down and add in */
|
||||
$temp_filename = tempnam('/tmp/', 'alias_import');
|
||||
unlink($temp_filename);
|
||||
$verify_ssl = isset($config['system']['checkaliasesurlcert']);
|
||||
mkdir($temp_filename);
|
||||
download_file($alias_url, $temp_filename . "/aliases", $verify_ssl);
|
||||
|
||||
$address = "";
|
||||
$isfirst = 0;
|
||||
foreach ($alias['aliasurl'] as $alias_url) {
|
||||
/* fetch down and add in */
|
||||
$temp_filename = tempnam('/tmp/', 'alias_import');
|
||||
unlink($temp_filename);
|
||||
$verify_ssl = isset($config['system']['checkaliasesurlcert']);
|
||||
mkdir($temp_filename);
|
||||
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")) {
|
||||
$fd = @fopen("{$temp_filename}/aliases", 'r');
|
||||
if (!$fd) {
|
||||
log_error(sprintf(gettext('Could not process aliases from alias: %s'), $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 (!empty($address)) {
|
||||
$config['aliases']['alias'][$x]['address'] = $address;
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
unlock($lockkey);
|
||||
|
||||
/* if the item is tar gzipped then extract */
|
||||
if (stripos($alias_url, '.tgz')) {
|
||||
if (!process_alias_tgz($temp_filename))
|
||||
continue;
|
||||
} else if (stripos($alias_url, '.zip')) {
|
||||
if (!process_alias_unzip($temp_filename))
|
||||
continue;
|
||||
}
|
||||
if (file_exists("{$temp_filename}/aliases")) {
|
||||
$fd = @fopen("{$temp_filename}/aliases", 'r');
|
||||
if (!$fd) {
|
||||
log_error(sprintf(gettext('Could not process aliases from alias: %s'), $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 (!empty($address)) {
|
||||
$config['aliases']['alias'][$x]['address'] = $address;
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
unlock($lockkey);
|
||||
|
||||
/* Report status to callers as well */
|
||||
return $updated;
|
||||
/* Report status to callers as well */
|
||||
return $updated;
|
||||
}
|
||||
|
||||
|
||||
if (update_alias_url_data()) {
|
||||
write_config();
|
||||
configd_run("filter reload");
|
||||
write_config();
|
||||
configd_run("filter reload");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user