Fix: convert line delimiters

This commit is contained in:
Regis Houssin 2012-09-12 12:41:44 +02:00
parent b75efdcf10
commit 7358223c8f

View File

@ -568,7 +568,7 @@ function dol_unescapefile($filename)
* @param int $nohook Disable all hooks * @param int $nohook Disable all hooks
* @param string $varfiles _FILES var name * @param string $varfiles _FILES var name
* @return int >0 if OK, <0 or string if KO * @return int >0 if OK, <0 or string if KO
* @see dolCheckUploadedFile, dol_move * @see dol_move
*/ */
function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile') function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
{ {
@ -579,121 +579,121 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
$file_name = $dest_file; $file_name = $dest_file;
if (empty($nohook)) if (empty($nohook))
{ {
// If an upload error has been reported // If an upload error has been reported
if ($uploaderrorcode) if ($uploaderrorcode)
{ {
switch($uploaderrorcode) switch($uploaderrorcode)
{ {
case UPLOAD_ERR_INI_SIZE: // 1 case UPLOAD_ERR_INI_SIZE: // 1
return 'ErrorFileSizeTooLarge'; return 'ErrorFileSizeTooLarge';
break; break;
case UPLOAD_ERR_FORM_SIZE: // 2 case UPLOAD_ERR_FORM_SIZE: // 2
return 'ErrorFileSizeTooLarge'; return 'ErrorFileSizeTooLarge';
break; break;
case UPLOAD_ERR_PARTIAL: // 3 case UPLOAD_ERR_PARTIAL: // 3
return 'ErrorPartialFile'; return 'ErrorPartialFile';
break; break;
case UPLOAD_ERR_NO_TMP_DIR: // case UPLOAD_ERR_NO_TMP_DIR: //
return 'ErrorNoTmpDir'; return 'ErrorNoTmpDir';
break; break;
case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_CANT_WRITE:
return 'ErrorFailedToWriteInDir'; return 'ErrorFailedToWriteInDir';
break; break;
case UPLOAD_ERR_EXTENSION: case UPLOAD_ERR_EXTENSION:
return 'ErrorUploadBlockedByAddon'; return 'ErrorUploadBlockedByAddon';
break; break;
default: default:
break; break;
} }
}
// If we need to make a virus scan
if (empty($disablevirusscan) && file_exists($src_file) && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
{
if (! class_exists('AntiVir')) {
require DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php';
}
$antivir=new AntiVir($db);
$result = $antivir->dol_avscan_file($src_file);
if ($result < 0) // If virus or error, we stop here
{
$reterrors=$antivir->errors;
dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$antivir->errors), LOG_WARNING);
return 'ErrorFileIsInfectedWithAVirus: '.join(',',$reterrors);
}
}
// Security:
// Disallow file with some extensions. We renamed them.
// Car si on a mis le rep documents dans un rep de la racine web (pas bien), cela permet d'executer du code a la demande.
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$dest_file))
{
$file_name.= '.noexe';
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipes dans les noms de fichiers.
if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
{
dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
return -1;
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
{
dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
return -2;
} }
if (! is_object($hookmanager)) // If we need to make a virus scan
{ if (empty($disablevirusscan) && file_exists($src_file) && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
if (! class_exists('HookManager')) { {
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array if (! class_exists('AntiVir')) {
require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; require DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php';
$hookmanager=new HookManager($db); }
} $antivir=new AntiVir($db);
} $result = $antivir->dol_avscan_file($src_file);
$hookmanager->initHooks(array('fileslib')); if ($result < 0) // If virus or error, we stop here
{
$parameters=array('filename' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); $reterrors=$antivir->errors;
dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$antivir->errors), LOG_WARNING);
return 'ErrorFileIsInfectedWithAVirus: '.join(',',$reterrors);
}
}
// Security:
// Disallow file with some extensions. We renamed them.
// Car si on a mis le rep documents dans un rep de la racine web (pas bien), cela permet d'executer du code a la demande.
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$dest_file))
{
$file_name.= '.noexe';
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipes dans les noms de fichiers.
if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
{
dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
return -1;
}
// Security:
// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans
// les noms de fichiers.
if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
{
dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
return -2;
}
if (! is_object($hookmanager))
{
if (! class_exists('HookManager')) {
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($db);
}
}
$hookmanager->initHooks(array('fileslib'));
$parameters=array('filename' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
$reshook=$hookmanager->executeHooks('dolMoveUploadedFile', $parameters, $object); $reshook=$hookmanager->executeHooks('dolMoveUploadedFile', $parameters, $object);
} }
if (empty($reshook)) if (empty($reshook))
{ {
// The file functions must be in OS filesystem encoding. // The file functions must be in OS filesystem encoding.
$src_file_osencoded=dol_osencode($src_file); $src_file_osencoded=dol_osencode($src_file);
$file_name_osencoded=dol_osencode($file_name); $file_name_osencoded=dol_osencode($file_name);
// Check if destination dir is writable // Check if destination dir is writable
// TODO // TODO
// Check if destination file already exists // Check if destination file already exists
if (! $allowoverwrite) if (! $allowoverwrite)
{ {
if (file_exists($file_name_osencoded)) if (file_exists($file_name_osencoded))
{ {
dol_syslog("Files.lib::dol_move_uploaded_file File ".$file_name." already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING); dol_syslog("Files.lib::dol_move_uploaded_file File ".$file_name." already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
return 'ErrorFileAlreadyExists'; return 'ErrorFileAlreadyExists';
} }
} }
// Move file // Move file
$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
if ($return) if ($return)
{ {
if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
return 1; // Success return 1; // Success
} }
else else
{ {
dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR); dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
return -3; // Unknown error return -3; // Unknown error
} }
} }
} }
@ -713,26 +713,26 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n
global $db, $conf, $user, $langs; global $db, $conf, $user, $langs;
global $hookmanager; global $hookmanager;
$langs->load("other"); $langs->load("other");
$langs->load("errors"); $langs->load("errors");
if (empty($nohook)) if (empty($nohook))
{ {
if (! is_object($hookmanager)) if (! is_object($hookmanager))
{ {
if (! class_exists('HookManager')) { if (! class_exists('HookManager')) {
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($db); $hookmanager=new HookManager($db);
} }
} }
$hookmanager->initHooks(array('fileslib')); $hookmanager->initHooks(array('fileslib'));
$parameters=array( $parameters=array(
'file' => $file, 'file' => $file,
'disableglob'=> $disableglob, 'disableglob'=> $disableglob,
'nophperrors' => $nophperrors 'nophperrors' => $nophperrors
); );
$reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object); $reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object);
} }
@ -742,33 +742,29 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n
} }
else else
{ {
$error=0; $error=0;
//print "x".$file." ".$disableglob; //print "x".$file." ".$disableglob;
$ok=true; $ok=true;
$file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset
if (empty($disableglob) && ! empty($file_osencoded)) if (empty($disableglob) && ! empty($file_osencoded))
{ {
foreach (glob($file_osencoded) as $filename) foreach (glob($file_osencoded) as $filename)
{ {
if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr
else $ok=unlink($filename); // The unlink encapsulated by dolibarr else $ok=unlink($filename); // The unlink encapsulated by dolibarr
if ($ok) dol_syslog("Removed file ".$filename, LOG_DEBUG); if ($ok) dol_syslog("Removed file ".$filename, LOG_DEBUG);
else dol_syslog("Failed to remove file ".$filename, LOG_WARNING); else dol_syslog("Failed to remove file ".$filename, LOG_WARNING);
} }
} }
else else
{ {
if ($nophperrors) $ok=@unlink($file_osencoded); // The unlink encapsulated by dolibarr if ($nophperrors) $ok=@unlink($file_osencoded); // The unlink encapsulated by dolibarr
else $ok=unlink($file_osencoded); // The unlink encapsulated by dolibarr else $ok=unlink($file_osencoded); // The unlink encapsulated by dolibarr
if ($ok) { if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG);
dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
} }
else {
dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
}
}
return $ok; return $ok;
} }
} }