Merge pull request #779 from abhishek-webkul/gli-1503

Fixed: Module zip validation on Module upload on Modules and Services page
This commit is contained in:
Rohit Jain
2024-03-15 13:06:49 +05:30
committed by GitHub

View File

@@ -444,8 +444,12 @@ class AdminModulesControllerCore extends AdminController
@unlink($file);
$this->recursiveDeleteOnDisk($tmp_folder);
if ($success && $redirect) {
Tools::redirectAdmin(self::$currentIndex.'&conf=8&anchor='.ucfirst($folder).'&token='.$this->token);
if ($success) {
if ($redirect) {
Tools::redirectAdmin(self::$currentIndex.'&conf=8&anchor='.ucfirst($folder).'&token='.$this->token);
} else {
$success = $folder;
}
}
return $success;
@@ -610,7 +614,7 @@ class AdminModulesControllerCore extends AdminController
} elseif (!move_uploaded_file($_FILES['file']['tmp_name'], _PS_MODULE_DIR_.$_FILES['file']['name'])) {
$this->errors[] = Tools::displayError('An error occurred while copying the archive to the module directory.');
} else {
$this->extractArchive(_PS_MODULE_DIR_.$_FILES['file']['name'], $redirect);
return $this->extractArchive(_PS_MODULE_DIR_.$_FILES['file']['name'], $redirect);
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to add this.');
@@ -1669,11 +1673,9 @@ class AdminModulesControllerCore extends AdminController
public function ajaxProcessUploadModule()
{
$response = array('success' => false);
$this->postProcessDownload(false);
$folder = $this->postProcessDownload(false);
if (!count($this->errors)) {
$filename = $_FILES['file']['name'];
$filename = explode('.', $filename);
if ($module = Module::getInstanceByName($filename[0])) {
if ($folder && $module = Module::getInstanceByName($folder)) {
$response['success'] = true;
if (Module::isInstalled($module->name)) {
$response['msg'] = $this->l('module already installed, update if available');
@@ -1692,6 +1694,9 @@ class AdminModulesControllerCore extends AdminController
'author' => $module->author,
'image' => $module->image ? $module->image : ''
);
} else {
$this->errors[] = $this->l('The uploaded file does not contain a valid module.');
$response['errors'] = $this->errors;
}
} else {
$response['errors'] = $this->errors;