Debug v21

This commit is contained in:
Laurent Destailleur
2024-10-19 23:42:26 +02:00
parent 560829cacf
commit 37880a7964
4 changed files with 102 additions and 65 deletions

View File

@@ -229,13 +229,68 @@ if ($action == 'install' && $allowonlineinstall) {
}
}
if (!$error) {
// TODO Make more test
}
dol_syslog("Uncompress of module file is a success.");
// We check if this is a metapackage
// Load module into $objMod
/*
$modulesdir = array($modulenamedir.'/core/modules/');
foreach ($modulesdir as $dir) {
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
$handle = @opendir($dir);
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
print $dir." ".$file."\n<br>";
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
$modName = substr($file, 0, dol_strlen($file) - 10);
if ($modName) {
try {
$res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
$modName = substr($file, 0, dol_strlen($file) - 10);
if ($modName) {
if (class_exists($modName)) {
$objMod = new $modName($db);
'@phan-var-force DolibarrModules $objMod';
//var_dump($objMod);
}
}
} catch(Exception $e) {
// Nothing done
}
}
}
}
}
}
*/
// Check if module is in the remote malware list
if (!$error) {
if (GETPOST('checkforcompliance') == 'on') {
try {
$res = include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
$dolibarrmodule = new DolibarrModules($db);
$checkRes = $dolibarrmodule->checkForcompliance($modulename);
if (!is_numeric($checkRes) && $checkRes != '') {
$langs->load("errors");
setEventMessages($modulename.' : '.$langs->trans($checkRes), null, 'errors');
}
$error++;
} catch (Exception $e) {
// Nothing done
}
}
}
if (!$error) {
// TODO Make more test ???
}
// We check if this is a metapackage (and wecomplete with child packages)
$modulenamearrays = array();
if (dol_is_file($modulenamedir.'/metapackage.conf')) {
// This is a meta package
@@ -245,32 +300,34 @@ if ($action == 'install' && $allowonlineinstall) {
$modulenamearrays[$modulename] = $modulename;
//var_dump($modulenamearrays);exit;
// Lop on each package of the metapackage
foreach ($modulenamearrays as $modulenameval) {
if (strpos($modulenameval, '#') === 0) {
continue; // Discard comments
}
if (strpos($modulenameval, '//') === 0) {
continue; // Discard comments
}
if (!trim($modulenameval)) {
continue;
}
// Now we install the module
if (!$error) {
@dol_delete_dir_recursive($dirins.'/'.$modulenameval); // delete the target directory
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulenameval;
if (!dol_is_dir($submodulenamedir)) {
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulenameval;
// Lop on each packages (can have several if package is a metapackage)
if (! $error) {
foreach ($modulenamearrays as $modulenameval) {
if (strpos($modulenameval, '#') === 0) {
continue; // Discard comments
}
dol_syslog("We copy now directory ".$submodulenamedir." into target dir ".$dirins.'/'.$modulenameval);
$result = dolCopyDir($submodulenamedir, $dirins.'/'.$modulenameval, '0444', 1);
if ($result <= 0) {
dol_syslog('Failed to call dolCopyDir result='.$result." with param ".$submodulenamedir." and ".$dirins.'/'.$modulenameval, LOG_WARNING);
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToCopyDir", $submodulenamedir, $dirins.'/'.$modulenameval), null, 'errors');
$error++;
if (strpos($modulenameval, '//') === 0) {
continue; // Discard comments
}
if (!trim($modulenameval)) {
continue;
}
// Now we install the module
if (!$error) {
@dol_delete_dir_recursive($dirins.'/'.$modulenameval); // delete the target directory
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulenameval;
if (!dol_is_dir($submodulenamedir)) {
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulenameval;
}
dol_syslog("We copy now directory ".$submodulenamedir." into target dir ".$dirins.'/'.$modulenameval);
$result = dolCopyDir($submodulenamedir, $dirins.'/'.$modulenameval, '0444', 1);
if ($result <= 0) {
dol_syslog('Failed to call dolCopyDir result='.$result." with param ".$submodulenamedir." and ".$dirins.'/'.$modulenameval, LOG_WARNING);
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToCopyDir", $submodulenamedir, $dirins.'/'.$modulenameval), null, 'errors');
$error++;
}
}
}
}
@@ -281,30 +338,6 @@ if ($action == 'install' && $allowonlineinstall) {
}
}
/*
if (!$error) {
if (GETPOST('checkforcompliance')) {
$dir = $dirins;
$file = $modulenameval;
// $installedmodule
try {
$res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
$modName = substr($file, 0, dol_strlen($file) - 10);
if ($modName) {
if (class_exists($modName)) {
$objMod = new $modName($db);
'@phan-var-force DolibarrModules $objMod';
//var_dump($objMod);
}
}
} catch(Exception $e) {
// Nothing done
}
}
}
*/
if (!$error) {
$searchParams = array(
'search_keyword' => $modulenameval,
@@ -318,8 +351,6 @@ if ($action == 'install' && $allowonlineinstall) {
$message = $langs->trans("SetupIsReadyForUse", $redirectUrl, $langs->transnoentitiesnoconv("Home").' - '.$langs->transnoentitiesnoconv("Setup").' - '.$langs->transnoentitiesnoconv("Modules"));
setEventMessages($message, null, 'warnings');
header('Location: ' . $redirectUrl);
exit;
}
} elseif ($action == 'install' && !$allowonlineinstall) {
httponly_accessforbidden("You try to bypass the protection to disallow deployment of an external module. Hack attempt ?");
@@ -1303,13 +1334,13 @@ if ($mode == 'deploy') {
print '<br>';
}
print '<br>';
// $allowfromweb = -1 if installation or setup not correct, 0 if not allowed, 1 if allowed
if ($allowfromweb >= 0) {
if ($allowfromweb == 1) {
//print $langs->trans("ThisIsProcessToFollow").'<br>';
} else {
print '<br>';
print $langs->trans("ThisIsAlternativeProcessToFollow").'<br>';
print '<b>'.$langs->trans("StepNb", 1).'</b>: ';
print str_replace('{s1}', $fullurl, $langs->trans("FindPackageFromWebSite", '{s1}')).'<br>';
@@ -1324,10 +1355,10 @@ if ($mode == 'deploy') {
print '<input type="hidden" name="action" value="install">';
print '<input type="hidden" name="mode" value="deploy">';
print $langs->trans("YouCanSubmitFile").'<br><br>';
print $langs->trans("YouCanSubmitFile").'<br><br><br>';
print '<span class="opacitymedium"><input class="paddingright" type="checkbox" name="checkforcompliance" id="checkforcompliance"'.(getDolGlobalString('DISABLE_CHECK_ON_MALWARE_MODULES') ? ' disabled="disabled"' : 'checked="checked"').'>';
print '<label for="checkforcompliance">'.$langs->trans("CheckIfModuleIsNotBlackListed").'</label>';
print '<label for="checkforcompliance">'.$form->textwithpicto($langs->trans("CheckIfModuleIsNotBlackListed"), $langs->trans("CheckIfModuleIsNotBlackListedHelp")).'</label>';
print '</span><br><br>';
$max = getDolGlobalString('MAIN_UPLOAD_DOC'); // In Kb