27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37 $langs->loadLangs(array(
"admin",
"other"));
40 $action =
GETPOST(
'action',
'aZ09');
42 $syslogModules = array();
43 $activeModules = array();
45 if (!empty($conf->global->SYSLOG_HANDLERS)) {
46 $activeModules = json_decode($conf->global->SYSLOG_HANDLERS);
49 $dirsyslogs = array_merge(array(
'/core/modules/syslog/'), $conf->modules_parts[
'syslog']);
50 foreach ($dirsyslogs as $reldir) {
53 if (is_dir($newdir)) {
54 $handle = opendir($newdir);
56 if (is_resource($handle)) {
57 while (($file = readdir($handle)) !==
false) {
58 if (substr($file, 0, 11) ==
'mod_syslog_' && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
59 $file = substr($file, 0,
dol_strlen($file) - 4);
61 require_once $newdir.$file.
'.php';
66 if ($module->getVersion() ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
69 if ($module->getVersion() ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
73 $syslogModules[] = $file;
87 if ($action ==
'set') {
90 $newActiveModules = array();
91 $selectedModules = (
GETPOSTISSET(
'SYSLOG_HANDLERS') ?
GETPOST(
'SYSLOG_HANDLERS') : array());
94 foreach ($syslogModules as $syslogHandler) {
95 if (in_array($syslogHandler, $syslogModules)) {
96 $module =
new $syslogHandler;
98 if (in_array($syslogHandler, $selectedModules)) {
99 $newActiveModules[] = $syslogHandler;
101 foreach ($module->configure() as $option) {
110 $activeModules = $newActiveModules;
113 dolibarr_set_const($db,
'SYSLOG_HANDLERS', json_encode($activeModules),
'chaine', 0,
'', 0);
116 foreach ($activeModules as $modulename) {
120 $module =
new $modulename;
121 $error = $module->checkConfiguration();
135 if ($action ==
'setlevel') {
145 $file_saves =
GETPOST(
"file_saves");
147 dol_syslog(
"admin/syslog: file saves ".$file_saves);
166 llxHeader(
'', $langs->trans(
"SyslogSetup"));
170 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
171 print
load_fiche_titre($langs->trans(
"SyslogSetup"), $linkback,
'title_setup');
174 $syslogfacility = $defaultsyslogfacility =
dolibarr_get_const($db,
"SYSLOG_FACILITY", 0);
177 if (!$defaultsyslogfacility) {
178 $defaultsyslogfacility =
'LOG_USER';
180 if (!$defaultsyslogfile) {
181 $defaultsyslogfile =
'dolibarr.log';
184 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY) && $user->entity) {
185 print
'<div class="error">'.$langs->trans(
"ContactSuperAdminForChange").
'</div>';
186 $optionmc =
'disabled';
194 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
195 print
'<input type="hidden" name="token" value="'.newToken().
'">';
196 print
'<input type="hidden" name="action" value="set">';
197 print
'<table class="noborder centpercent">';
198 print
'<tr class="liste_titre">';
199 print
'<td>'.$langs->trans(
"Type").
'</td><td>'.$langs->trans(
"Value").
'</td>';
200 print
'<td class="right" colspan="2"><input type="submit" class="button" '.$optionmc.
' value="'.$langs->trans(
"Modify").
'"></td>';
203 foreach ($syslogModules as $moduleName) {
204 $module =
new $moduleName;
206 $moduleactive = (int) $module->isActive();
208 if (($moduleactive == -1) &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') == 0) {
213 print
'<tr class="oddeven">';
214 print
'<td width="140">';
215 print
'<input class="oddeven" type="checkbox" name="SYSLOG_HANDLERS[]" value="'.$moduleName.
'" '.(in_array($moduleName, $activeModules) ?
'checked' :
'').($moduleactive <= 0 ?
'disabled' :
'').
'> ';
216 print $module->getName();
217 if ($moduleName ==
'mod_syslog_syslog') {
218 if (!$module->isActive()) {
219 $langs->load(
"errors");
220 print
$form->textwithpicto(
'', $langs->trans(
"ErrorPHPNeedModule",
'SysLog'));
225 print
'<td class="nowrap">';
226 $setuparray = $module->configure();
228 foreach ($setuparray as $option) {
229 $tmpoption = $option[
'constant'];
230 if (!empty($tmpoption)) {
233 } elseif (!empty($conf->global->$tmpoption)) {
234 $value = $conf->global->$tmpoption;
237 $value = (isset($option[
'default']) ? $option[
'default'] :
'');
240 print $option[
'name'].
': <input type="text" class="flat" name="'.$option[
'constant'].
'" value="'.$value.
'"'.(isset($option[
'attr']) ?
' '.$option[
'attr'] :
'').
'>';
241 if (!empty($option[
'example'])) {
242 print
'<br>'.$langs->trans(
"Example").
': '.$option[
'example'];
245 if ($option[
'constant'] ==
'SYSLOG_FILE' && preg_match(
'/^DOL_DATA_ROOT\/[^\/]*$/', $value)) {
246 $filelogparam =
' (<a href="'.DOL_URL_ROOT.
'/document.php?modulepart=logs&file='.basename($value).
'">';
247 $filelogparam .= $langs->trans(
'Download');
248 $filelogparam .=
' '.basename($value).
'</a>)';
255 print
'<td class="left">';
256 if ($module->getInfo()) {
257 print
$form->textwithpicto(
'', $module->getInfo(), 1,
'help');
259 if ($module->getWarning()) {
260 print
$form->textwithpicto(
'', $module->getWarning(), 1,
'warning');
274 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
275 print
'<input type="hidden" name="token" value="'.newToken().
'">';
276 print
'<input type="hidden" name="action" value="setlevel">';
277 print
'<table class="noborder centpercent">';
278 print
'<tr class="liste_titre">';
279 print
'<td>'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td>';
280 print
'<td class="right"><input type="submit" class="button" '.$optionmc.
' value="'.$langs->trans(
"Modify").
'"></td>';
283 print
'<tr class="oddeven"><td width="140">'.$langs->trans(
"SyslogLevel").
'</td>';
284 print
'<td colspan="2"><select class="flat" name="level" '.$optionmc.
'>';
285 print
'<option value="'.LOG_EMERG.
'" '.($conf->global->SYSLOG_LEVEL == LOG_EMERG ?
'SELECTED' :
'').
'>LOG_EMERG ('.LOG_EMERG.
')</option>';
286 print
'<option value="'.LOG_ALERT.
'" '.($conf->global->SYSLOG_LEVEL == LOG_ALERT ?
'SELECTED' :
'').
'>LOG_ALERT ('.LOG_ALERT.
')</option>';
287 print
'<option value="'.LOG_CRIT.
'" '.($conf->global->SYSLOG_LEVEL == LOG_CRIT ?
'SELECTED' :
'').
'>LOG_CRIT ('.LOG_CRIT.
')</option>';
288 print
'<option value="'.LOG_ERR.
'" '.($conf->global->SYSLOG_LEVEL == LOG_ERR ?
'SELECTED' :
'').
'>LOG_ERR ('.LOG_ERR.
')</option>';
289 print
'<option value="'.LOG_WARNING.
'" '.($conf->global->SYSLOG_LEVEL == LOG_WARNING ?
'SELECTED' :
'').
'>LOG_WARNING ('.LOG_WARNING.
')</option>';
290 print
'<option value="'.LOG_NOTICE.
'" '.($conf->global->SYSLOG_LEVEL == LOG_NOTICE ?
'SELECTED' :
'').
'>LOG_NOTICE ('.LOG_NOTICE.
')</option>';
291 print
'<option value="'.LOG_INFO.
'" '.($conf->global->SYSLOG_LEVEL == LOG_INFO ?
'SELECTED' :
'').
'>LOG_INFO ('.LOG_INFO.
')</option>';
292 print
'<option value="'.LOG_DEBUG.
'" '.($conf->global->SYSLOG_LEVEL >= LOG_DEBUG ?
'SELECTED' :
'').
'>LOG_DEBUG ('.LOG_DEBUG.
')</option>';
296 if (!empty($conf->loghandlers[
'mod_syslog_file']) && !empty($conf->cron->enabled)) {
297 print
'<tr class="oddeven"><td width="140">'.$langs->trans(
"SyslogFileNumberOfSaves").
'</td>';
298 print
'<td colspan="2"><input type="number" name="file_saves" placeholder="14" min="0" step="1" value="'.getDolGlobalString(
'SYSLOG_FILE_SAVES').
'" />';
299 print
' (<a href="'.dol_buildpath(
'/cron/list.php', 1).
'?search_label=CompressSyslogs&status=-1">'.$langs->trans(
'ConfigureCleaningCronjobToSetFrequencyOfSaves').
'</a>)</td></tr>';