From f67fad110593960ed8a0f1be58e5543e1ffd94a7 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Tue, 31 Dec 2024 14:04:14 +0100 Subject: [PATCH] Debug v21 --- htdocs/core/lib/functions.lib.php | 9 ++++++++- htdocs/website/class/website.class.php | 17 ++++++++++++++++- htdocs/website/index.php | 21 ++++++++++++++++----- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 933a07f6d22..b2fed05b758 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1672,7 +1672,12 @@ function dol_sanitizePathName($str, $newstr = '_', $unaccent = 1) // Char '>' '<' '|' '$' and ';' are special chars for shells. // Chars '--' can be used into filename to inject special parameters like --use-compress-program to make command with file as parameter making remote execution of command $filesystem_forbidden_chars = array('<', '>', '?', '*', '|', '"', '°', '$', ';', '`'); - $tmp = dol_string_nospecial($unaccent ? dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars); + + $tmp = $str; + if ($unaccent) { + $tmp = dol_string_unaccent($tmp); + } + $tmp = dol_string_nospecial($tmp, $newstr, $filesystem_forbidden_chars); $tmp = preg_replace('/\-\-+/', '_', $tmp); $tmp = preg_replace('/\s+\-([^\s])/', ' _$1', $tmp); $tmp = preg_replace('/\s+\-$/', '', $tmp); @@ -7948,6 +7953,8 @@ function dol_mkdir($dir, $dataroot = '', $newmask = '') dol_syslog("functions.lib::dol_mkdir: dir=".$dir, LOG_INFO); + $dir = dol_sanitizePathName($dir, '_', 0); + $dir_osencoded = dol_osencode($dir); if (@is_dir($dir_osencoded)) { return 0; diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 7ebe585c1f9..225a8433829 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -250,10 +250,25 @@ class Website extends CommonObject } } - // Create subdirectory for images and js + // Create subdirectory for images and js into documents/medias directory dol_mkdir($conf->medias->multidir_output[$conf->entity].'/image/'.$this->ref, DOL_DATA_ROOT); dol_mkdir($conf->medias->multidir_output[$conf->entity].'/js/'.$this->ref, DOL_DATA_ROOT); + $pathofwebsite = $conf->website->dir_output.'/'.$this->ref; + + // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko. + // Recreate also dir of website if not found. + $pathtomedias = DOL_DATA_ROOT.'/medias'; + $pathtomediasinwebsite = $pathofwebsite.'/medias'; + if (!is_link(dol_osencode($pathtomediasinwebsite))) { + dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); + dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists + $result = symlink($pathtomedias, $pathtomediasinwebsite); + if (!$result) { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors'); + } + } // Uncomment this and change WEBSITE to your own tag if you // want this action to call a trigger. // if (!$notrigger) { diff --git a/htdocs/website/index.php b/htdocs/website/index.php index ce9fa0070af..3147fc4b6bd 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -1325,13 +1325,18 @@ if ($action == 'addcontainer' && $usercanedit) { // To generate the CSS, robot and htmlheader file. - // Check symlink to medias and restore it if ko + // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko. + // Recreate also dir of website if not found. $pathtomedias = DOL_DATA_ROOT.'/medias'; $pathtomediasinwebsite = $pathofwebsite.'/medias'; if (!is_link(dol_osencode($pathtomediasinwebsite))) { dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); - dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists + dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists $result = symlink($pathtomedias, $pathtomediasinwebsite); + if (!$result) { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors'); + } } // Now generate the master.inc.php page if it does not exists yet @@ -2296,13 +2301,18 @@ if ((($action == 'updatesource' || $action == 'updatecontent' || $action == 'con $res = 0; if (!$error) { - // Check symlink to medias and restore it if ko + // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko. + // Recreate also dir of website if not found. $pathtomedias = DOL_DATA_ROOT.'/medias'; $pathtomediasinwebsite = $pathofwebsite.'/medias'; if (!is_link(dol_osencode($pathtomediasinwebsite))) { dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); - dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists + dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists $result = symlink($pathtomedias, $pathtomediasinwebsite); + if (!$result) { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors'); + } } /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) @@ -2537,7 +2547,8 @@ if ($action == 'importsiteconfirm' && $usercanedit) { $action = 'importsite'; } else { if (!empty($_FILES) || GETPOSTISSET('templateuserfile')) { - // Check symlink to medias and restore it if ko. Recreate also dir of website if not found. + // Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko. + // Recreate also dir of website if not found. $pathtomedias = DOL_DATA_ROOT.'/medias'; $pathtomediasinwebsite = $pathofwebsite.'/medias'; if (!is_link(dol_osencode($pathtomediasinwebsite))) {