From 6c5e7e6ecac0bd43a288b2d0cd3cbc5fdc3eaa44 Mon Sep 17 00:00:00 2001 From: Fernando Ontiveros Date: Wed, 23 Apr 2025 14:49:32 +0000 Subject: [PATCH] fixing error importing es language --- gulliver/system/class.g.php | 28 +++++++++++++------ .../engine/methods/setup/language_Ajax.php | 4 +-- .../engine/methods/setup/languages_Import.php | 16 ++++++++--- workflow/engine/xmlform/login/login.xml | 2 +- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index c6a88ba1d..9d561d005 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -3701,23 +3701,35 @@ class G } /** - * Recursive Is writeable function + * Recursively checks if all files in a directory are writable. * - * @author Erik Amaru Ortiz + * This function scans the specified directory and checks the write permissions + * of all files that match the given pattern. If any file is not writable, + * the function returns false; otherwise, it returns true. * - * @param $path path to scan recursively the write permission - * @param $pattern pattern to filter some specified files - * @return if the $path, assuming that is a directory -> all files in it are writeables or not + * @param string $path The path to the directory to scan recursively. + * @param string $pattern The pattern to filter specific files (default is '*'). + * @return bool Returns true if all files are writable, false otherwise. + * @throws InvalidArgumentException If the provided path is not a directory. */ - public static function is_rwritable($path, $pattern = '*') + public static function is_rwritable(string $path, string $pattern = '*'): bool { + // Check if the provided path is a directory + if (!is_dir($path)) { + throw new InvalidArgumentException("The provided path is not a directory: $path"); + } + + // Retrieve all files matching the pattern $files = G::rglob($pattern, 0, $path); + + // Check write permissions for each file foreach ($files as $file) { if (!is_writable($file)) { - return false; + return false; // Return false if any file is not writable } } - return true; + + return true; // All files are writable } /** diff --git a/workflow/engine/methods/setup/language_Ajax.php b/workflow/engine/methods/setup/language_Ajax.php index 7e41260ea..fbda96848 100644 --- a/workflow/engine/methods/setup/language_Ajax.php +++ b/workflow/engine/methods/setup/language_Ajax.php @@ -105,7 +105,7 @@ try { } $translationRow = new Translation(); $response->data = $languagesList; - print (G::json_encode($response)); + print (json_encode($response)); break; case 'delete': include_once 'classes/model/Translation.php'; @@ -122,7 +122,7 @@ try { //Verify if is the current language if ($locale != SYS_LANG) { try { - Content::removeLanguageContent($locale); + (new Content)->removeLanguageContent($locale); $trn->removeTranslationEnvironment($locale); echo G::LoadTranslation('ID_LANGUAGE_DELETED_SUCCESSFULLY'); } catch (Exception $e) { diff --git a/workflow/engine/methods/setup/languages_Import.php b/workflow/engine/methods/setup/languages_Import.php index 757a692f3..db3ad33cb 100644 --- a/workflow/engine/methods/setup/languages_Import.php +++ b/workflow/engine/methods/setup/languages_Import.php @@ -26,28 +26,36 @@ if ($access != 1) { $result = new stdClass(); try { + // Validate uploaded files ValidationUploadedFiles::getValidationUploadedFiles()->dispatch(function($validator) { throw new Exception($validator->getMessage()); }); - //if the xmlform path is writeable + + // Check if the XML form path is writable if (!is_writable(PATH_XMLFORM)) { throw new Exception(G::LoadTranslation('IMPORT_LANGUAGE_ERR_NO_WRITABLE')); } - //if all xml files within the xmlform directory are writeable + // Check if all XML files within the XML form directory are writable if (!G::is_rwritable(PATH_XMLFORM)) { throw new Exception(G::LoadTranslation('IMPORT_LANGUAGE_ERR_NO_WRITABLE2')); } - $sMaxExecutionTime = ini_get('max_execution_time'); + // Set maximum execution time to unlimited + $originalMaxExecutionTime = ini_get('max_execution_time'); ini_set('max_execution_time', '0'); + // Create an input filter instance $filter = new InputFilter(); + // Retrieve and filter the uploaded language file $languageFile = $_FILES['form']['tmp_name']['LANGUAGE_FILENAME']; $languageFilename = $_FILES['form']['name']['LANGUAGE_FILENAME']; + + // Apply XSS filtering $languageFile = $filter->xssFilterHard($languageFile, 'path'); $languageFilename = $filter->xssFilterHard($languageFilename, 'path'); + if (substr_compare($languageFilename, ".gz", - 3, 3, true) == 0) { $zp = gzopen($languageFile, "r"); $languageFile = tempnam(__FILE__, ''); @@ -94,5 +102,5 @@ try { } ob_clean(); -echo G::json_encode($result); +echo json_encode($result); diff --git a/workflow/engine/xmlform/login/login.xml b/workflow/engine/xmlform/login/login.xml index dd4da8891..3fe339dc9 100644 --- a/workflow/engine/xmlform/login/login.xml +++ b/workflow/engine/xmlform/login/login.xml @@ -1,4 +1,4 @@ - +