2005-06-11 12:48:02 +02:00
< ? php
2012-05-13 17:11:31 +02:00
/* Copyright ( C ) 2005 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2007-01-07 19:19:59 +01:00
* Copyright ( C ) 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-08-20 16:50:33 +02:00
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
2005-06-11 12:48:02 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-06-11 12:48:02 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-06-11 12:48:02 +02:00
*/
/**
2008-06-16 14:45:41 +02:00
* \file htdocs / admin / syslog . php
* \ingroup syslog
2011-10-03 17:19:39 +02:00
* \brief Setup page for logs module
2008-06-16 14:45:41 +02:00
*/
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2005-06-11 12:48:02 +02:00
2016-08-16 02:55:18 +02:00
global $conf ;
2011-09-21 15:16:13 +02:00
if ( ! $user -> admin ) accessforbidden ();
2005-06-11 12:48:02 +02:00
2018-05-26 18:52:14 +02:00
// Load translation files required by the page
2020-04-10 10:59:32 +02:00
$langs -> loadLangs ( array ( " admin " , " other " ));
2007-02-27 22:14:15 +01:00
2020-04-10 10:59:32 +02:00
$error = 0 ;
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2012-10-16 02:01:37 +02:00
$syslogModules = array ();
$activeModules = array ();
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> global -> SYSLOG_HANDLERS )) $activeModules = json_decode ( $conf -> global -> SYSLOG_HANDLERS );
2012-10-16 02:01:37 +02:00
2016-08-16 02:55:18 +02:00
$dirsyslogs = array_merge ( array ( '/core/modules/syslog/' ), $conf -> modules_parts [ 'syslog' ]);
foreach ( $dirsyslogs as $reldir ) {
$dir = dol_buildpath ( $reldir , 0 );
$newdir = dol_osencode ( $dir );
if ( is_dir ( $newdir )) {
$handle = opendir ( $newdir );
2012-10-16 02:01:37 +02:00
2016-08-16 02:55:18 +02:00
if ( is_resource ( $handle )) {
while (( $file = readdir ( $handle )) !== false ) {
if ( substr ( $file , 0 , 11 ) == 'mod_syslog_' && substr ( $file , dol_strlen ( $file ) - 3 , 3 ) == 'php' ) {
$file = substr ( $file , 0 , dol_strlen ( $file ) - 4 );
2012-10-16 02:01:37 +02:00
2020-04-10 10:59:32 +02:00
require_once $newdir . $file . '.php' ;
2012-10-16 02:01:37 +02:00
2016-08-16 02:55:18 +02:00
$module = new $file ;
2012-10-16 02:01:37 +02:00
2016-08-16 02:55:18 +02:00
// Show modules according to features level
if ( $module -> getVersion () == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) {
continue ;
}
if ( $module -> getVersion () == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 ) {
continue ;
}
2012-10-16 02:01:37 +02:00
2016-08-16 02:55:18 +02:00
$syslogModules [] = $file ;
}
2012-10-16 02:01:37 +02:00
}
2016-08-16 02:55:18 +02:00
closedir ( $handle );
2012-10-16 02:01:37 +02:00
}
}
}
2011-10-03 17:19:39 +02:00
2007-02-27 22:14:15 +01:00
2005-06-11 12:48:02 +02:00
/*
2008-06-16 14:45:41 +02:00
* Actions
2005-06-11 12:48:02 +02:00
*/
2011-09-21 15:16:13 +02:00
2011-10-03 17:19:39 +02:00
// Set modes
if ( $action == 'set' )
2007-01-05 10:08:03 +01:00
{
2011-10-03 17:19:39 +02:00
$db -> begin ();
2011-09-21 15:16:13 +02:00
2015-02-07 19:12:22 +01:00
$newActiveModules = array ();
2012-10-16 02:01:37 +02:00
$selectedModules = ( isset ( $_POST [ 'SYSLOG_HANDLERS' ]) ? $_POST [ 'SYSLOG_HANDLERS' ] : array ());
2017-06-20 16:54:37 +02:00
2017-04-29 18:30:36 +02:00
// Save options of handler
2015-02-07 19:12:22 +01:00
foreach ( $syslogModules as $syslogHandler )
2007-02-27 22:14:15 +01:00
{
2012-10-16 02:01:37 +02:00
if ( in_array ( $syslogHandler , $syslogModules ))
2008-06-16 14:45:41 +02:00
{
2012-10-16 02:01:37 +02:00
$module = new $syslogHandler ;
2015-02-07 19:12:22 +01:00
if ( in_array ( $syslogHandler , $selectedModules )) $newActiveModules [] = $syslogHandler ;
foreach ( $module -> configure () as $option )
2012-10-16 02:01:37 +02:00
{
2015-02-07 19:12:22 +01:00
if ( isset ( $_POST [ $option [ 'constant' ]]))
2012-10-16 02:01:37 +02:00
{
2015-02-07 19:12:22 +01:00
$_POST [ $option [ 'constant' ]] = trim ( $_POST [ $option [ 'constant' ]]);
2017-04-29 18:30:36 +02:00
dolibarr_del_const ( $db , $option [ 'constant' ], - 1 );
2019-01-27 11:55:16 +01:00
dolibarr_set_const ( $db , $option [ 'constant' ], $_POST [ $option [ 'constant' ]], 'chaine' , 0 , '' , 0 );
2012-10-16 02:01:37 +02:00
}
}
2008-06-16 14:45:41 +02:00
}
2007-02-27 22:14:15 +01:00
}
2011-10-03 17:19:39 +02:00
2015-02-07 19:12:22 +01:00
$activeModules = $newActiveModules ;
2017-04-29 18:30:36 +02:00
2020-04-10 10:59:32 +02:00
dolibarr_del_const ( $db , 'SYSLOG_HANDLERS' , - 1 ); // To be sure ther is not a setup into another entity
2019-01-27 11:55:16 +01:00
dolibarr_set_const ( $db , 'SYSLOG_HANDLERS' , json_encode ( $activeModules ), 'chaine' , 0 , '' , 0 );
2012-08-29 17:43:20 +02:00
2015-08-06 19:19:06 +02:00
// Check configuration
foreach ( $activeModules as $modulename ) {
/**
* @ var LogHandler
*/
$module = new $modulename ;
$error = $module -> checkConfiguration ();
}
2015-02-07 19:12:22 +01:00
2020-04-10 10:59:32 +02:00
if ( ! $error )
2011-10-03 17:19:39 +02:00
{
$db -> commit ();
2015-10-29 13:58:16 +01:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
2011-10-03 17:19:39 +02:00
}
else
{
$db -> rollback ();
2015-10-29 13:58:16 +01:00
setEventMessages ( $error , $errors , 'errors' );
2011-10-03 17:19:39 +02:00
}
2005-06-11 12:48:02 +02:00
}
2011-10-03 17:19:39 +02:00
// Set level
if ( $action == 'setlevel' )
{
$level = GETPOST ( " level " );
2019-01-27 11:55:16 +01:00
$res = dolibarr_set_const ( $db , " SYSLOG_LEVEL " , $level , 'chaine' , 0 , '' , 0 );
2011-10-03 17:19:39 +02:00
dol_syslog ( " admin/syslog: level " . $level );
2020-04-10 10:59:32 +02:00
if ( ! $res > 0 ) $error ++ ;
2018-03-09 16:52:06 +01:00
2020-04-10 10:59:32 +02:00
if ( ! $error )
2018-03-09 16:52:06 +01:00
{
$file_saves = GETPOST ( " file_saves " );
2019-01-27 11:55:16 +01:00
$res = dolibarr_set_const ( $db , " SYSLOG_FILE_SAVES " , $file_saves , 'chaine' , 0 , '' , 0 );
2018-03-09 16:52:06 +01:00
dol_syslog ( " admin/syslog: file saves " . $file_saves );
2020-04-10 10:59:32 +02:00
if ( ! $res > 0 ) $error ++ ;
2018-03-09 16:52:06 +01:00
}
2020-04-10 10:59:32 +02:00
if ( ! $error )
2013-08-20 16:50:33 +02:00
{
2015-10-29 13:58:16 +01:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
2013-08-20 16:50:33 +02:00
}
else
{
2015-10-29 13:58:16 +01:00
setEventMessages ( $langs -> trans ( " Error " ), null , 'errors' );
2011-10-03 17:19:39 +02:00
}
}
2007-01-05 10:08:03 +01:00
2008-06-16 14:45:41 +02:00
/*
* View
*/
2007-01-07 19:19:59 +01:00
2007-01-05 10:08:03 +01:00
llxHeader ();
2020-04-10 10:59:32 +02:00
$form = new Form ( $db );
2009-04-29 17:02:40 +02:00
2020-04-10 10:59:32 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $langs -> trans ( " SyslogSetup " ), $linkback , 'title_setup' );
2007-01-05 10:08:03 +01:00
print '<br>' ;
$def = array ();
2005-06-11 12:48:02 +02:00
2020-04-10 10:59:32 +02:00
$syslogfacility = $defaultsyslogfacility = dolibarr_get_const ( $db , " SYSLOG_FACILITY " , 0 );
$syslogfile = $defaultsyslogfile = dolibarr_get_const ( $db , " SYSLOG_FILE " , 0 );
2008-04-19 22:57:29 +02:00
2020-04-10 10:59:32 +02:00
if ( ! $defaultsyslogfacility ) $defaultsyslogfacility = 'LOG_USER' ;
if ( ! $defaultsyslogfile ) $defaultsyslogfile = 'dolibarr.log' ;
2005-06-11 12:48:02 +02:00
2009-05-07 11:06:57 +02:00
if ( $conf -> global -> MAIN_MODULE_MULTICOMPANY && $user -> entity )
{
print '<div class="error">' . $langs -> trans ( " ContactSuperAdminForChange " ) . '</div>' ;
2015-05-07 11:57:23 +02:00
$option = 'disabled' ;
2009-05-07 11:06:57 +02:00
}
2015-02-07 19:12:22 +01:00
//print "conf->global->MAIN_FEATURES_LEVEL = ".$conf->global->MAIN_FEATURES_LEVEL."<br><br>\n";
2008-06-16 14:45:41 +02:00
// Output mode
2015-09-24 18:27:13 +02:00
print load_fiche_titre ( $langs -> trans ( " SyslogOutput " ));
2005-06-11 12:48:02 +02:00
2007-02-27 22:14:15 +01:00
// Mode
2008-10-03 00:29:54 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2005-06-11 12:48:02 +02:00
print '<input type="hidden" name="action" value="set">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2005-06-11 12:48:02 +02:00
print '<tr class="liste_titre">' ;
2010-05-23 12:20:35 +02:00
print '<td>' . $langs -> trans ( " Type " ) . '</td><td>' . $langs -> trans ( " Value " ) . '</td>' ;
2019-01-31 12:42:38 +01:00
print '<td class="right" colspan="2"><input type="submit" class="button" ' . $option . ' value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2005-06-11 12:48:02 +02:00
print " </tr> \n " ;
2011-10-03 17:19:39 +02:00
2012-10-16 02:01:37 +02:00
foreach ( $syslogModules as $moduleName )
2011-10-06 00:49:58 +02:00
{
2012-10-16 02:01:37 +02:00
$module = new $moduleName ;
2011-10-06 00:49:58 +02:00
2020-04-10 10:59:32 +02:00
$moduleactive = ( int ) $module -> isActive ();
2014-11-12 10:05:40 +01:00
//print $moduleName." = ".$moduleactive." - ".$module->getName()." ".($moduleactive == -1)."<br>\n";
2020-04-10 10:59:32 +02:00
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)
2012-10-17 14:46:20 +02:00
2017-06-20 16:54:37 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2012-10-17 14:46:20 +02:00
print '<td width="140">' ;
2017-04-25 11:59:18 +02:00
print '<input class="oddeven" type="checkbox" name="SYSLOG_HANDLERS[]" value="' . $moduleName . '" ' . ( in_array ( $moduleName , $activeModules ) ? 'checked' : '' ) . ( $moduleactive <= 0 ? 'disabled' : '' ) . '> ' ;
2012-10-17 14:46:20 +02:00
print $module -> getName ();
print '</td>' ;
2012-10-16 02:01:37 +02:00
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2020-04-10 10:59:32 +02:00
$setuparray = $module -> configure ();
2012-10-17 14:46:20 +02:00
if ( $setuparray )
2012-10-16 02:01:37 +02:00
{
2012-10-17 14:46:20 +02:00
foreach ( $setuparray as $option )
2012-10-16 02:01:37 +02:00
{
2020-04-10 10:59:32 +02:00
$tmpoption = $option [ 'constant' ];
if ( ! empty ( $tmpoption ))
2017-04-29 18:30:36 +02:00
{
2020-04-10 10:59:32 +02:00
if ( isset ( $_POST [ $tmpoption ])) $value = $_POST [ $tmpoption ];
elseif ( ! empty ( $conf -> global -> $tmpoption )) $value = $conf -> global -> $tmpoption ;
2017-04-29 18:30:36 +02:00
}
2012-10-16 02:01:37 +02:00
else $value = ( isset ( $option [ 'default' ]) ? $option [ 'default' ] : '' );
2012-10-17 14:46:20 +02:00
2012-10-16 02:01:37 +02:00
print $option [ 'name' ] . ': <input type="text" class="flat" name="' . $option [ 'constant' ] . '" value="' . $value . '"' . ( isset ( $option [ 'attr' ]) ? ' ' . $option [ 'attr' ] : '' ) . '>' ;
2020-04-10 10:59:32 +02:00
if ( ! empty ( $option [ 'example' ])) print '<br>' . $langs -> trans ( " Example " ) . ': ' . $option [ 'example' ];
2017-06-20 16:54:37 +02:00
2019-01-27 11:55:16 +01:00
if ( $option [ 'constant' ] == 'SYSLOG_FILE' && preg_match ( '/^DOL_DATA_ROOT\/[^\/]*$/' , $value ))
2017-06-20 16:54:37 +02:00
{
2020-04-10 10:59:32 +02:00
$filelogparam = ' (<a href="' . DOL_URL_ROOT . '/document.php?modulepart=logs&file=' . basename ( $value ) . '">' ;
$filelogparam .= $langs -> trans ( 'Download' );
$filelogparam .= $filelog . '</a>)' ;
2017-06-20 16:54:37 +02:00
print $filelogparam ;
}
2012-10-16 02:01:37 +02:00
}
}
print '</td>' ;
2019-01-17 14:19:15 +01:00
print '<td class="left">' ;
2012-10-16 02:01:37 +02:00
if ( $module -> getInfo ())
2012-09-07 17:23:16 +02:00
{
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( '' , $module -> getInfo (), 1 , 'help' );
2015-09-07 12:21:26 +02:00
}
if ( $module -> getWarning ())
{
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( '' , $module -> getWarning (), 1 , 'warning' );
2012-09-07 17:23:16 +02:00
}
2012-10-16 02:01:37 +02:00
print '</td>' ;
print " </tr> \n " ;
2012-09-07 17:23:16 +02:00
}
2012-10-16 02:01:37 +02:00
2007-02-27 22:14:15 +01:00
print " </table> \n " ;
print " </form> \n " ;
2007-01-05 10:08:03 +01:00
2014-11-12 10:05:40 +01:00
print '<br>' . " \n \n " ;
2011-10-03 17:19:39 +02:00
2015-09-24 18:27:13 +02:00
print load_fiche_titre ( $langs -> trans ( " SyslogLevel " ));
2011-10-03 17:19:39 +02:00
2007-02-27 22:14:15 +01:00
// Level
2019-03-17 00:32:39 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2007-02-27 22:14:15 +01:00
print '<input type="hidden" name="action" value="setlevel">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2007-02-27 22:14:15 +01:00
print '<tr class="liste_titre">' ;
2010-05-23 12:20:35 +02:00
print '<td>' . $langs -> trans ( " Parameter " ) . '</td><td>' . $langs -> trans ( " Value " ) . '</td>' ;
2019-01-22 11:56:09 +01:00
print '<td class="right"><input type="submit" class="button" ' . $option . ' value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2007-02-27 22:14:15 +01:00
print " </tr> \n " ;
2017-04-14 11:22:48 +02:00
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td width="140">' . $langs -> trans ( " SyslogLevel " ) . '</td>' ;
2009-05-07 11:06:57 +02:00
print '<td colspan="2"><select class="flat" name="level" ' . $option . '>' ;
2020-04-10 10:59:32 +02:00
print '<option value="' . LOG_EMERG . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_EMERG ? 'SELECTED' : '' ) . '>LOG_EMERG (' . LOG_EMERG . ')</option>' ;
print '<option value="' . LOG_ALERT . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_ALERT ? 'SELECTED' : '' ) . '>LOG_ALERT (' . LOG_ALERT . ')</option>' ;
print '<option value="' . LOG_CRIT . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_CRIT ? 'SELECTED' : '' ) . '>LOG_CRIT (' . LOG_CRIT . ')</option>' ;
print '<option value="' . LOG_ERR . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_ERR ? 'SELECTED' : '' ) . '>LOG_ERR (' . LOG_ERR . ')</option>' ;
print '<option value="' . LOG_WARNING . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_WARNING ? 'SELECTED' : '' ) . '>LOG_WARNING (' . LOG_WARNING . ')</option>' ;
print '<option value="' . LOG_NOTICE . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_NOTICE ? 'SELECTED' : '' ) . '>LOG_NOTICE (' . LOG_NOTICE . ')</option>' ;
print '<option value="' . LOG_INFO . '" ' . ( $conf -> global -> SYSLOG_LEVEL == LOG_INFO ? 'SELECTED' : '' ) . '>LOG_INFO (' . LOG_INFO . ')</option>' ;
print '<option value="' . LOG_DEBUG . '" ' . ( $conf -> global -> SYSLOG_LEVEL >= LOG_DEBUG ? 'SELECTED' : '' ) . '>LOG_DEBUG (' . LOG_DEBUG . ')</option>' ;
2007-02-27 22:14:15 +01:00
print '</select>' ;
print '</td></tr>' ;
2018-03-09 16:52:06 +01:00
2020-04-10 10:59:32 +02:00
if ( ! empty ( $conf -> loghandlers [ 'mod_syslog_file' ]) && ! empty ( $conf -> cron -> enabled )) {
2018-03-09 16:52:06 +01:00
print '<tr class="oddeven"><td width="140">' . $langs -> trans ( " SyslogFileNumberOfSaves " ) . '</td>' ;
print '<td colspan="2"><input type="number" name="file_saves" placeholder="14" min="0" step="1" value="' . $conf -> global -> SYSLOG_FILE_SAVES . '" />' ;
print ' (<a href="' . dol_buildpath ( '/cron/list.php' , 1 ) . '?search_label=CompressSyslogs&status=-1">' . $langs -> trans ( 'ConfigureCleaningCronjobToSetFrequencyOfSaves' ) . '</a>)</td></tr>' ;
}
2007-02-27 22:14:15 +01:00
print '</table>' ;
2007-01-05 10:08:03 +01:00
print " </form> \n " ;
2005-06-11 12:48:02 +02:00
2018-07-29 10:29:12 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-22 13:23:13 +01:00
$db -> close ();