mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update fetch function with more error checking
This commit is contained in:
@@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
if (!$resource_is_secure) {
|
if (!$resource_is_secure) {
|
||||||
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
|
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!@is_readable($file)) {
|
|
||||||
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// fetch the file
|
// fetch the file
|
||||||
$fp = fopen($file,'r');
|
if($fp = @fopen($file,'r')) {
|
||||||
while(!feof($fp)) {
|
while(!feof($fp)) {
|
||||||
$content .= fgets ($fp,4096);
|
$content .= fgets ($fp,4096);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
|
||||||
} else {
|
} else {
|
||||||
// not a local file
|
// not a local file
|
||||||
if(preg_match('!^http://!i',$file)) {
|
if(preg_match('!^http://!i',$file)) {
|
||||||
@@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "cluster_host":
|
|
||||||
if(!empty($param_value)
|
|
||||||
&& (gethostbyname($param_value) != $param_value)) {
|
|
||||||
$server_name = $param_value;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
|
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
|
||||||
return;
|
return;
|
||||||
@@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ftp fetch
|
// ftp fetch
|
||||||
$fp = fopen($file,'r');
|
if($fp = @fopen($file,'r')) {
|
||||||
while(!feof($fp)) {
|
while(!feof($fp)) {
|
||||||
$content .= fgets ($fp,4096);
|
$content .= fgets ($fp,4096);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
if (!$resource_is_secure) {
|
if (!$resource_is_secure) {
|
||||||
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
|
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!@is_readable($file)) {
|
|
||||||
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// fetch the file
|
// fetch the file
|
||||||
$fp = fopen($file,'r');
|
if($fp = @fopen($file,'r')) {
|
||||||
while(!feof($fp)) {
|
while(!feof($fp)) {
|
||||||
$content .= fgets ($fp,4096);
|
$content .= fgets ($fp,4096);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
|
||||||
} else {
|
} else {
|
||||||
// not a local file
|
// not a local file
|
||||||
if(preg_match('!^http://!i',$file)) {
|
if(preg_match('!^http://!i',$file)) {
|
||||||
@@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "cluster_host":
|
|
||||||
if(!empty($param_value)
|
|
||||||
&& (gethostbyname($param_value) != $param_value)) {
|
|
||||||
$server_name = $param_value;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
|
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
|
||||||
return;
|
return;
|
||||||
@@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ftp fetch
|
// ftp fetch
|
||||||
$fp = fopen($file,'r');
|
if($fp = @fopen($file,'r')) {
|
||||||
while(!feof($fp)) {
|
while(!feof($fp)) {
|
||||||
$content .= fgets ($fp,4096);
|
$content .= fgets ($fp,4096);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
} else {
|
||||||
|
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user