Révision e45bae34
Ajouté par Ermal il y a environ 10 ans
etc/inc/pfsense-utils.inc | ||
---|---|---|
1913 | 1913 |
download_file($alias_url, $temp_filename . "/aliases", $verify_ssl); |
1914 | 1914 |
|
1915 | 1915 |
/* if the item is tar gzipped then extract */ |
1916 |
if (stristr($alias_url, ".tgz")) |
|
1917 |
process_alias_tgz($temp_filename); |
|
1918 |
else if (stristr($alias_url, ".zip")) |
|
1919 |
process_alias_unzip($temp_filename); |
|
1916 |
if (stripos($alias_url, '.tgz')) { |
|
1917 |
if (!process_alias_tgz($temp_filename)) |
|
1918 |
continue; |
|
1919 |
} else if (stripos($alias_url, '.zip')) { |
|
1920 |
if (!process_alias_unzip($temp_filename)) |
|
1921 |
continue; |
|
1922 |
} |
|
1920 | 1923 |
if (file_exists("{$temp_filename}/aliases")) { |
1921 | 1924 |
$fd = @fopen("{$temp_filename}/aliases"); |
1922 | 1925 |
if (!$fd) { |
... | ... | |
1953 | 1956 |
} |
1954 | 1957 |
|
1955 | 1958 |
function process_alias_unzip($temp_filename) { |
1956 |
if(!file_exists("/usr/local/bin/unzip")) |
|
1957 |
return; |
|
1959 |
if(!file_exists("/usr/local/bin/unzip")) { |
|
1960 |
log_error(gettext("Alias archive is a .zip file which cannot be decompressed because utility is missing!")); |
|
1961 |
return false; |
|
1962 |
} |
|
1958 | 1963 |
rename("{$temp_filename}/aliases", "{$temp_filename}/aliases.zip"); |
1959 | 1964 |
mwexec("/usr/local/bin/unzip {$temp_filename}/aliases.tgz -d {$temp_filename}/aliases/"); |
1960 | 1965 |
unlink("{$temp_filename}/aliases.zip"); |
1961 | 1966 |
$files_to_process = return_dir_as_array("{$temp_filename}/"); |
1962 | 1967 |
/* foreach through all extracted files and build up aliases file */ |
1963 |
$fd = fopen("{$temp_filename}/aliases", "w"); |
|
1968 |
$fd = @fopen("{$temp_filename}/aliases", "w"); |
|
1969 |
if (!$fd) { |
|
1970 |
log_error(gettext("Could not open {$temp_filename}/aliases for writing!")); |
|
1971 |
return false; |
|
1972 |
} |
|
1964 | 1973 |
foreach($files_to_process as $f2p) { |
1965 |
$file_contents = file_get_contents($f2p); |
|
1966 |
fwrite($fd, $file_contents); |
|
1974 |
$tmpfd = @fopen($f2p, 'r'); |
|
1975 |
if (!$tmpfd) { |
|
1976 |
log_error(gettext("The following file could not be read {$f2p} from {$temp_filename}")); |
|
1977 |
continue; |
|
1978 |
} |
|
1979 |
while (($tmpbuf = fread($tmpfd, 65536)) !== FALSE) |
|
1980 |
fwrite($fd, $tmpbuf); |
|
1981 |
fclose($tmpfd); |
|
1967 | 1982 |
unlink($f2p); |
1968 | 1983 |
} |
1969 | 1984 |
fclose($fd); |
1985 |
unset($tmpbuf); |
|
1986 |
|
|
1987 |
return true; |
|
1970 | 1988 |
} |
1971 | 1989 |
|
1972 | 1990 |
function process_alias_tgz($temp_filename) { |
1973 |
if(!file_exists("/usr/bin/tar")) |
|
1974 |
return; |
|
1991 |
if(!file_exists('/usr/bin/tar')) { |
|
1992 |
log_error(gettext("Alias archive is a .tar/tgz file which cannot be decompressed because utility is missing!")); |
|
1993 |
return false; |
|
1994 |
} |
|
1975 | 1995 |
rename("{$temp_filename}/aliases", "{$temp_filename}/aliases.tgz"); |
1976 | 1996 |
mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/"); |
1977 | 1997 |
unlink("{$temp_filename}/aliases.tgz"); |
1978 | 1998 |
$files_to_process = return_dir_as_array("{$temp_filename}/"); |
1979 | 1999 |
/* foreach through all extracted files and build up aliases file */ |
1980 |
$fd = fopen("{$temp_filename}/aliases", "w"); |
|
2000 |
$fd = @fopen("{$temp_filename}/aliases", "w"); |
|
2001 |
if (!$fd) { |
|
2002 |
log_error(gettext("Could not open {$temp_filename}/aliases for writing!")); |
|
2003 |
return false; |
|
2004 |
} |
|
1981 | 2005 |
foreach($files_to_process as $f2p) { |
1982 |
$file_contents = file_get_contents($f2p); |
|
1983 |
fwrite($fd, $file_contents); |
|
2006 |
$tmpfd = @fopen($f2p, 'r'); |
|
2007 |
if (!$tmpfd) { |
|
2008 |
log_error(gettext("The following file could not be read {$f2p} from {$temp_filename}")); |
|
2009 |
continue; |
|
2010 |
} |
|
2011 |
while (($tmpbuf = fread($tmpfd, 65536)) !== FALSE) |
|
2012 |
fwrite($fd, $tmpbuf); |
|
2013 |
fclose($tmpfd); |
|
1984 | 2014 |
unlink($f2p); |
1985 | 2015 |
} |
1986 | 2016 |
fclose($fd); |
2017 |
unset($tmpbuf); |
|
2018 |
|
|
2019 |
return true; |
|
1987 | 2020 |
} |
1988 | 2021 |
|
1989 | 2022 |
function version_compare_dates($a, $b) { |
Formats disponibles : Unified diff
Make the alias url processing functions not memory hungry!