mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
96 lines
3.8 KiB
PHP
Executable File
96 lines
3.8 KiB
PHP
Executable File
#!/usr/local/bin/php
|
|
<?php
|
|
/*
|
|
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:
|
|
|
|
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.
|
|
|
|
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");
|
|
require_once("util.inc");
|
|
require_once("pfsense-utils.inc");
|
|
|
|
|
|
function update_alias_url_data()
|
|
{
|
|
global $config;
|
|
|
|
$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;
|
|
}
|
|
|
|
$address_list = array();
|
|
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 (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;
|
|
}
|
|
// validate address, it should either be an address or a subnet and must be unique
|
|
if ((is_ipaddr($tmp) || is_subnet($tmp)) && !in_array($tmp, $address_list)) {
|
|
$address_list[] = $tmp;
|
|
}
|
|
}
|
|
fclose($fd);
|
|
mwexec("/bin/rm -rf {$temp_filename}");
|
|
}
|
|
}
|
|
if (count($address_list) > 0) {
|
|
$config['aliases']['alias'][$x]['address'] = implode(" ", $address_list);
|
|
$updated = true;
|
|
}
|
|
}
|
|
}
|
|
unlock($lockkey);
|
|
|
|
/* Report status to callers as well */
|
|
return $updated;
|
|
}
|
|
|
|
if (update_alias_url_data()) {
|
|
write_config();
|
|
configd_run("filter reload");
|
|
}
|