1893 |
1893 |
function update_alias_url_data() {
|
1894 |
1894 |
global $config, $g;
|
1895 |
1895 |
|
|
1896 |
$updated = false;
|
|
1897 |
|
1896 |
1898 |
/* item is a url type */
|
1897 |
|
$lockkey = lock('config');
|
|
1899 |
$lockkey = lock('aliasurl');
|
1898 |
1900 |
if (is_array($config['aliases']['alias'])) {
|
1899 |
1901 |
foreach ($config['aliases']['alias'] as $x => $alias) {
|
1900 |
1902 |
if (empty($alias['aliasurl']))
|
... | ... | |
1916 |
1918 |
else if (stristr($alias_url, ".zip"))
|
1917 |
1919 |
process_alias_unzip($temp_filename);
|
1918 |
1920 |
if (file_exists("{$temp_filename}/aliases")) {
|
1919 |
|
$file_contents = file_get_contents("{$temp_filename}/aliases");
|
1920 |
|
$file_contents = str_replace("#", "\n#", $file_contents);
|
1921 |
|
$file_contents_split = explode("\n", $file_contents);
|
1922 |
|
foreach ($file_contents_split as $fc) {
|
1923 |
|
$tmp = trim($fc);
|
1924 |
|
if (stristr($fc, "#")) {
|
1925 |
|
$tmp_split = explode("#", $tmp);
|
1926 |
|
$tmp = trim($tmp_split[0]);
|
1927 |
|
}
|
1928 |
|
if (trim($tmp) <> "") {
|
1929 |
|
if ($isfirst == 1)
|
1930 |
|
$address .= " ";
|
1931 |
|
$address .= $tmp;
|
1932 |
|
$isfirst = 1;
|
1933 |
|
}
|
|
1921 |
$fd = @fopen("{$temp_filename}/aliases");
|
|
1922 |
if (!$fd) {
|
|
1923 |
log_error(gettext("Could not process aliases from alias: {$alias_url}"));
|
|
1924 |
continue;
|
1934 |
1925 |
}
|
|
1926 |
/* NOTE: fgetss() is not a typo RTFM before being smart */
|
|
1927 |
while (($fc = fgetss($fd)) !== FALSE) {
|
|
1928 |
$tmp = trim($fc, " \t\n\r");
|
|
1929 |
if (empty($tmp))
|
|
1930 |
continue;
|
|
1931 |
$tmp_str = strstr($tmp, '#', true);
|
|
1932 |
if (!empty($tmp_str))
|
|
1933 |
$tmp = $tmp_str;
|
|
1934 |
if ($isfirst == 1)
|
|
1935 |
$address .= ' ';
|
|
1936 |
$address .= $tmp;
|
|
1937 |
$isfirst = 1;
|
|
1938 |
}
|
|
1939 |
fclose($fd);
|
1935 |
1940 |
mwexec("/bin/rm -rf {$temp_filename}");
|
1936 |
1941 |
}
|
1937 |
1942 |
}
|
1938 |
|
if($isfirst > 0) {
|
|
1943 |
if (!empty($address)) {
|
1939 |
1944 |
$config['aliases']['alias'][$x]['address'] = $address;
|
1940 |
1945 |
$updated = true;
|
1941 |
1946 |
}
|
1942 |
1947 |
}
|
1943 |
1948 |
}
|
1944 |
1949 |
unlock($lockkey);
|
1945 |
|
if ($updated) {
|
1946 |
|
write_config();
|
1947 |
|
send_event("filter reload");
|
1948 |
|
}
|
|
1950 |
|
|
1951 |
/* Report status to callers as well */
|
|
1952 |
return $updated;
|
1949 |
1953 |
}
|
1950 |
1954 |
|
1951 |
1955 |
function process_alias_unzip($temp_filename) {
|
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.