forked from Wavyzz/dolibarr
Better error management on import web site with PHP
This commit is contained in:
@@ -328,7 +328,7 @@ function run_sql($sqlfile, $silent = 1, $entity = 0, $usesavepoint = 1, $handler
|
||||
$keyforsql = md5($sqlfile);
|
||||
foreach ($arraysql as $i => $sql) {
|
||||
if ($sql) {
|
||||
// Test if th SQL is allowed SQL
|
||||
// Test if the SQL is allowed SQL
|
||||
if ($onlysqltoimportwebsite) {
|
||||
$newsql = str_replace(array("\'"), '__BACKSLASHQUOTE__', $sql); // Replace the \' char
|
||||
|
||||
@@ -388,6 +388,7 @@ function run_sql($sqlfile, $silent = 1, $entity = 0, $usesavepoint = 1, $handler
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!$qualified) {
|
||||
$error++;
|
||||
//print 'Request '.($i + 1)." contains non allowed instructions.<br>\n";
|
||||
|
||||
@@ -681,7 +681,16 @@ function checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// First check forbidden commands
|
||||
// First check permission
|
||||
if ($phpfullcodestringold != $phpfullcodestring) {
|
||||
if (!$error && !$user->hasRight('website', 'writephp')) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("NotAllowedToAddDynamicContent"), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
// Then check forbidden commands
|
||||
if (!$error) {
|
||||
$forbiddenphpcommands = array("override_function", "session_id", "session_create_id", "session_regenerate_id");
|
||||
if (!getDolGlobalString('WEBSITE_PHP_ALLOW_EXEC')) { // If option is not on, we disallow functions to execute commands
|
||||
$forbiddenphpcommands = array_merge($forbiddenphpcommands, array("exec", "passthru", "shell_exec", "system", "proc_open", "popen", "eval", "dol_eval", "executeCLI"));
|
||||
@@ -718,12 +727,9 @@ function checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
|
||||
$error++;
|
||||
setEventMessages($langs->trans("DynamicPHPCodeContainsAForbiddenInstruction", '$...('), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if ($phpfullcodestringold != $phpfullcodestring) {
|
||||
if (!$error && !$user->hasRight('website', 'writephp')) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("NotAllowedToAddDynamicContent"), null, 'errors');
|
||||
}
|
||||
if (!$error) {
|
||||
$dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
|
||||
$allowimportsite = true;
|
||||
|
||||
Reference in New Issue
Block a user