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 >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . 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
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// 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
2011-09-21 15:16:13 +02:00
if ( ! $user -> admin ) accessforbidden ();
2005-06-11 12:48:02 +02:00
2007-02-27 22:14:15 +01:00
$langs -> load ( " admin " );
$langs -> load ( " other " );
2013-08-20 16:50:33 +02:00
$error = 0 ;
2011-09-03 15:30:50 +02:00
$action = GETPOST ( " action " );
2012-10-16 02:01:37 +02:00
$syslogModules = array ();
$activeModules = array ();
2013-01-14 17:12:13 +01:00
if ( defined ( 'SYSLOG_HANDLERS' )) $activeModules = json_decode ( constant ( 'SYSLOG_HANDLERS' ));
2012-10-16 02:01:37 +02:00
$dir = dol_buildpath ( '/core/modules/syslog/' );
if ( is_dir ( $dir ))
{
$handle = opendir ( $dir );
if ( is_resource ( $handle ))
{
$var = true ;
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 );
require_once $dir . $file . '.php' ;
$module = new $file ;
// Show modules according to features level
2012-10-22 00:43:59 +02:00
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
$syslogModules [] = $file ;
}
}
closedir ( $handle );
}
}
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
2012-10-16 02:01:37 +02:00
$activeModules = array ();
$selectedModules = ( isset ( $_POST [ 'SYSLOG_HANDLERS' ]) ? $_POST [ 'SYSLOG_HANDLERS' ] : array ());
2010-05-23 12:20:35 +02:00
2012-10-16 02:01:37 +02:00
foreach ( $selectedModules 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 ;
if ( $module -> isActive ())
{
$activeModules [] = $syslogHandler ;
foreach ( $module -> configure () as $option )
{
if ( $_POST [ $option [ 'constant' ]])
{
dolibarr_del_const ( $db , $option [ 'constant' ], 0 );
2013-04-10 15:08:03 +02: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
2013-04-10 15:08:03 +02:00
dolibarr_set_const ( $db , 'SYSLOG_HANDLERS' , json_encode ( $activeModules ), 'chaine' , 0 , '' , 0 );
2012-08-29 17:43:20 +02:00
if ( ! $error )
2011-10-03 17:19:39 +02:00
{
$db -> commit ();
2013-08-20 16:50:33 +02:00
setEventMessage ( $langs -> trans ( " SetupSaved " ));
2011-10-03 17:19:39 +02:00
}
else
{
$db -> rollback ();
2013-08-20 16:50:33 +02:00
setEventMessage ( $langs -> trans ( " Error " ), '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 " );
$res = dolibarr_set_const ( $db , " SYSLOG_LEVEL " , $level , 'chaine' , 0 , '' , 0 );
dol_syslog ( " admin/syslog: level " . $level );
if ( ! $res > 0 ) $error ++ ;
if ( ! $error )
2013-08-20 16:50:33 +02:00
{
setEventMessage ( $langs -> trans ( " SetupSaved " ));
}
else
{
setEventMessage ( $langs -> trans ( " Error " ), '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 ();
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2009-04-29 17:02:40 +02:00
2008-01-26 16:10:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
print_fiche_titre ( $langs -> trans ( " SyslogSetup " ), $linkback , 'setup' );
2007-01-05 10:08:03 +01:00
print '<br>' ;
$def = array ();
2005-06-11 12:48:02 +02:00
2009-05-07 11:06:57 +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
2005-06-11 12:48:02 +02:00
if ( ! $defaultsyslogfacility ) $defaultsyslogfacility = 'LOG_USER' ;
if ( ! $defaultsyslogfile ) $defaultsyslogfile = 'dolibarr.log' ;
2009-05-07 11:06:57 +02:00
if ( $conf -> global -> MAIN_MODULE_MULTICOMPANY && $user -> entity )
{
print '<div class="error">' . $langs -> trans ( " ContactSuperAdminForChange " ) . '</div>' ;
$option = 'disabled="disabled"' ;
}
2008-06-16 14:45:41 +02:00
// Output mode
2005-06-11 12:48:02 +02:00
print_titre ( $langs -> trans ( " SyslogOutput " ));
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">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2005-06-11 12:48:02 +02:00
print '<input type="hidden" name="action" value="set">' ;
2007-01-05 10:08:03 +01:00
print '<table class="noborder" width="100%">' ;
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>' ;
2009-05-07 11:06:57 +02:00
print '<td align="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 " ;
$var = true ;
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
2012-10-17 14:46:20 +02:00
$moduleactive = $module -> isActive ();
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-16 02:01:37 +02:00
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2012-10-17 14:46:20 +02:00
print '<td width="140">' ;
print '<input ' . $bc [ $var ] . ' type="checkbox" name="SYSLOG_HANDLERS[]" value="' . $moduleName . '" ' . ( in_array ( $moduleName , $activeModules ) ? 'checked="checked"' : '' ) . ( ! $moduleactive ? 'disabled="disabled"' : '' ) . '> ' ;
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">' ;
2012-10-17 14:46:20 +02:00
$setuparray = $module -> configure ();
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
{
2012-12-27 14:25:52 +01:00
if ( isset ( $_POST [ $option [ 'constant' ]])) $value = $_POST [ $option [ 'constant' ]];
else if ( defined ( $option [ 'constant' ])) $value = constant ( $option [ 'constant' ]);
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' ] : '' ) . '>' ;
}
}
print '</td>' ;
print '<td align="left">' ;
if ( $module -> getInfo ())
2012-09-07 17:23:16 +02:00
{
2012-10-16 02:01:37 +02:00
print $form -> textwithpicto ( '' , $module -> getInfo ());
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
2011-10-03 17:19:39 +02:00
print '<br>' ;
print_titre ( $langs -> trans ( " SyslogLevel " ));
2007-02-27 22:14:15 +01:00
// Level
print '<form action="syslog.php" method="post">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2007-02-27 22:14:15 +01:00
print '<input type="hidden" name="action" value="setlevel">' ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2010-05-23 12:20:35 +02:00
print '<td>' . $langs -> trans ( " Parameter " ) . '</td><td>' . $langs -> trans ( " Value " ) . '</td>' ;
2009-05-07 11:06:57 +02:00
print '<td align="right"><input type="submit" class="button" ' . $option . ' value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2007-02-27 22:14:15 +01:00
print " </tr> \n " ;
$var = true ;
$var =! $var ;
2012-05-13 17:11:31 +02:00
print '<tr ' . $bc [ $var ] . '><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 . '>' ;
2007-05-10 20:25:19 +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>' ;
2009-11-17 22:03:33 +01:00
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>' ;
print '</table>' ;
2007-01-05 10:08:03 +01:00
print " </form> \n " ;
2005-06-11 12:48:02 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-22 13:23:13 +01:00
$db -> close ();