From ec9bbe2b52214008f6d6c55bf3dafbb8b8080778 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Tue, 20 Jun 2017 16:54:37 +0200 Subject: [PATCH] Help/Need debug of some online instances with the log view --- htdocs/admin/syslog.php | 14 +++++++++++--- htdocs/admin/tools/purge.php | 10 +++++++++- htdocs/core/lib/files.lib.php | 21 +++++++++++++-------- htdocs/document.php | 5 +++-- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/htdocs/admin/syslog.php b/htdocs/admin/syslog.php index 65933c25639..75de985728c 100644 --- a/htdocs/admin/syslog.php +++ b/htdocs/admin/syslog.php @@ -88,7 +88,7 @@ if ($action == 'set') $newActiveModules = array(); $selectedModules = (isset($_POST['SYSLOG_HANDLERS']) ? $_POST['SYSLOG_HANDLERS'] : array()); - + // Save options of handler foreach ($syslogModules as $syslogHandler) { @@ -111,7 +111,7 @@ if ($action == 'set') $activeModules = $newActiveModules; - dolibarr_del_const($db, 'SYSLOG_HANDLERS', -1); // To be sure ther is not a setup into another entity + dolibarr_del_const($db, 'SYSLOG_HANDLERS', -1); // To be sure ther is not a setup into another entity dolibarr_set_const($db, 'SYSLOG_HANDLERS', json_encode($activeModules), 'chaine',0,'',0); // Check configuration @@ -206,7 +206,7 @@ foreach ($syslogModules as $moduleName) //print $moduleName." = ".$moduleactive." - ".$module->getName()." ".($moduleactive == -1)."<br>\n"; if (($moduleactive == -1) && empty($conf->global->MAIN_FEATURES_LEVEL)) continue; // Some modules are hidden if not activable and not into debug mode (end user must not see them) - + print '<tr class="oddeven">'; print '<td width="140">'; print '<input class="oddeven" type="checkbox" name="SYSLOG_HANDLERS[]" value="'.$moduleName.'" '.(in_array($moduleName, $activeModules) ? 'checked' : '').($moduleactive <= 0 ? 'disabled' : '').'> '; @@ -229,6 +229,14 @@ foreach ($syslogModules as $moduleName) print $option['name'].': <input type="text" class="flat" name="'.$option['constant'].'" value="'.$value.'"'.(isset($option['attr']) ? ' '.$option['attr'] : '').'>'; if (! empty($option['example'])) print '<br>'.$langs->trans("Example").': '.$option['example']; + + if ($option['constant'] == 'SYSLOG_FILE' && preg_match('/^DOL_DATA_ROOT\/[^\/]*$/',$value)) + { + $filelogparam =' (<a href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file='.basename($value).'">'; + $filelogparam.=$langs->trans('Download'); + $filelogparam.=$filelog.'</a>)'; + print $filelogparam; + } } } print '</td>'; diff --git a/htdocs/admin/tools/purge.php b/htdocs/admin/tools/purge.php index e913d59a4a7..7a5cb30ae75 100644 --- a/htdocs/admin/tools/purge.php +++ b/htdocs/admin/tools/purge.php @@ -83,7 +83,15 @@ if (! empty($conf->syslog->enabled)) { print '<input type="radio" name="choice" value="logfile"'; print ($choice && $choice=='logfile') ? ' checked' : ''; - print '> '.$langs->trans("PurgeDeleteLogFile",$filelog).'<br><br>'; + $filelogparam=$filelog; + if ($user->admin && preg_match('/^dolibarr.*\.log$/', basename($filelog))) + { + $filelogparam ='<a href="'.DOL_URL_ROOT.'/document.php?modulepart=logs&file='; + $filelogparam.=basename($filelog); + $filelogparam.='">'.$filelog.'</a>'; + } + print '> '.$langs->trans("PurgeDeleteLogFile", $filelogparam); + print '<br><br>'; } print '<input type="radio" name="choice" value="tempfiles"'; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 6257bcb08db..dd21a1345e7 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1825,8 +1825,20 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $lire='creer'; $read='write'; $download='upload'; } + // Wrapping for miscellaneous medias files + if ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) + { + $accessallowed=1; + $original_file=$dolibarr_main_data_root.'/medias/'.$original_file; + } + // Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log + elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root)) + { + $accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file))); + $original_file=$dolibarr_main_data_root.'/'.$original_file; + } // Wrapping for some images - if (($modulepart == 'mycompany' || $modulepart == 'companylogo') && !empty($conf->mycompany->dir_output)) + elseif (($modulepart == 'mycompany' || $modulepart == 'companylogo') && !empty($conf->mycompany->dir_output)) { $accessallowed=1; $original_file=$conf->mycompany->dir_output.'/logos/'.$original_file; @@ -2369,13 +2381,6 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $original_file=$conf->fckeditor->dir_output.'/'.$original_file; } - // Wrapping for miscellaneous medias files - elseif ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) - { - $accessallowed=1; - $original_file=$dolibarr_main_data_root.'/medias/'.$original_file; - } - // Wrapping for backups else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) { diff --git a/htdocs/document.php b/htdocs/document.php index 46e27d57a67..206ea69688a 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -26,6 +26,7 @@ * \brief Wrapper to download data files * \remarks Call of this wrapper is made with URL: * document.php?modulepart=repfichierconcerne&file=pathrelatifdufichier + * document.php?modulepart=logs&file=dolibarr.log */ define('NOTOKENRENEWAL',1); // Disables token renewal @@ -106,7 +107,7 @@ $refname=basename(dirname($original_file)."/"); // Security check if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); -$check_access = dol_check_secure_access_document($modulepart,$original_file,$entity,$refname); +$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, $refname); $accessallowed = $check_access['accessallowed']; $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; $original_file = $check_access['original_file']; // original_file is now a full path name @@ -183,7 +184,7 @@ header('Pragma: public'); //ob_clean(); //flush(); - + readfile($original_file_osencoded); if (is_object($db)) $db->close(); -- GitLab