//added more check on module upload

This commit is contained in:
vAugagneur committed 2012-12-10 14:44:11 +01:00
1 parent 8b817a4a8c
commit 401b3dd41d
1 file changed
+22 -13
+22 -13
View File
@@ -340,27 +340,36 @@ class AdminModulesControllerCore extends AdminController
protected function extractArchive($file, $redirect = true) protected function extractArchive($file, $redirect = true)
{ {
$pathinfo = pathinfo($file); $zip_folders = array();
$tmp_folder = _PS_MODULE_DIR_.md5(time());
$success = false; $success = false;
if (substr($file, -4) == '.zip') if (substr($file, -4) == '.zip')
{ {
if (Tools::ZipExtract($file, _PS_MODULE_DIR_)) if (Tools::ZipExtract($file, $tmp_folder))
$success = true; {
else $zip_folders = scandir($tmp_folder);
$this->errors[] = Tools::displayError('Error while extracting module (file may be corrupted).'); if (Tools::ZipExtract($file, _PS_MODULE_DIR_))
$success = true;
}
} }
else else
{ {
$archive = new Archive_Tar($file); $archive = new Archive_Tar($file);
if ($archive->extract(_PS_MODULE_DIR_)) if ($archive->extract($tmp_folder))
$success = true; {
else $zip_folders = scandir($tmp_folder);
$this->errors[] = Tools::displayError('Error while extracting module (file may be corrupted).'); if ($archive->extract(_PS_MODULE_DIR_))
$success = true;
}
} }
//check if it's a real module if (!$success)
if (!Module::getInstanceByName($pathinfo['filename'])) $this->errors[] = Tools::displayError('Error while extracting module (file may be corrupted).');
$this->errors[] = Tools::displayError('The Zip file you uploaded is not a module');
//check if it's a real module
foreach($zip_folders as $folder)
if (!in_array($folder, array('.', '..', '.svn', '.git', '__MACOSX')) && !Module::getInstanceByName($folder))
$this->errors[] = Tools::displayError('The module '.$folder.' you uploaded is not a module');
@unlink($file); @unlink($file);
if (!count($this->errors) && $success && $redirect) if (!count($this->errors) && $success && $redirect)