syslog.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  5. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/syslog.php
  22. * \ingroup syslog
  23. * \brief Setup page for logs module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. if (!$user->admin) accessforbidden();
  28. $langs->load("admin");
  29. $langs->load("other");
  30. $error=0;
  31. $action = GETPOST("action");
  32. $syslogModules = array();
  33. $activeModules = array();
  34. if (defined('SYSLOG_HANDLERS')) $activeModules = json_decode(constant('SYSLOG_HANDLERS'));
  35. $dir = dol_buildpath('/core/modules/syslog/');
  36. if (is_dir($dir))
  37. {
  38. $handle = opendir($dir);
  39. if (is_resource($handle))
  40. {
  41. $var=true;
  42. while (($file = readdir($handle))!==false)
  43. {
  44. if (substr($file, 0, 11) == 'mod_syslog_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  45. {
  46. $file = substr($file, 0, dol_strlen($file)-4);
  47. require_once $dir.$file.'.php';
  48. $module = new $file;
  49. // Show modules according to features level
  50. if ($module->getVersion() == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  51. if ($module->getVersion() == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  52. $syslogModules[] = $file;
  53. }
  54. }
  55. closedir($handle);
  56. }
  57. }
  58. /*
  59. * Actions
  60. */
  61. // Set modes
  62. if ($action == 'set')
  63. {
  64. $db->begin();
  65. $activeModules = array();
  66. $selectedModules = (isset($_POST['SYSLOG_HANDLERS']) ? $_POST['SYSLOG_HANDLERS'] : array());
  67. foreach ($selectedModules as $syslogHandler)
  68. {
  69. if (in_array($syslogHandler, $syslogModules))
  70. {
  71. $module = new $syslogHandler;
  72. if ($module->isActive())
  73. {
  74. $activeModules[] = $syslogHandler;
  75. foreach ($module->configure() as $option)
  76. {
  77. if ($_POST[$option['constant']])
  78. {
  79. dolibarr_del_const($db, $option['constant'], 0);
  80. dolibarr_set_const($db, $option['constant'], $_POST[$option['constant']], 'chaine',0, '', 0);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. dolibarr_set_const($db, 'SYSLOG_HANDLERS', json_encode($activeModules), 'chaine',0,'',0);
  87. if (! $error)
  88. {
  89. $db->commit();
  90. setEventMessage($langs->trans("SetupSaved"));
  91. }
  92. else
  93. {
  94. $db->rollback();
  95. setEventMessage($langs->trans("Error"),'errors');
  96. }
  97. }
  98. // Set level
  99. if ($action == 'setlevel')
  100. {
  101. $level = GETPOST("level");
  102. $res = dolibarr_set_const($db,"SYSLOG_LEVEL",$level,'chaine',0,'',0);
  103. dol_syslog("admin/syslog: level ".$level);
  104. if (! $res > 0) $error++;
  105. if (! $error)
  106. {
  107. setEventMessage($langs->trans("SetupSaved"));
  108. }
  109. else
  110. {
  111. setEventMessage($langs->trans("Error"),'errors');
  112. }
  113. }
  114. /*
  115. * View
  116. */
  117. llxHeader();
  118. $form=new Form($db);
  119. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  120. print_fiche_titre($langs->trans("SyslogSetup"),$linkback,'setup');
  121. print '<br>';
  122. $def = array();
  123. $syslogfacility=$defaultsyslogfacility=dolibarr_get_const($db,"SYSLOG_FACILITY",0);
  124. $syslogfile=$defaultsyslogfile=dolibarr_get_const($db,"SYSLOG_FILE",0);
  125. if (! $defaultsyslogfacility) $defaultsyslogfacility='LOG_USER';
  126. if (! $defaultsyslogfile) $defaultsyslogfile='dolibarr.log';
  127. if ($conf->global->MAIN_MODULE_MULTICOMPANY && $user->entity)
  128. {
  129. print '<div class="error">'.$langs->trans("ContactSuperAdminForChange").'</div>';
  130. $option = 'disabled="disabled"';
  131. }
  132. // Output mode
  133. print_titre($langs->trans("SyslogOutput"));
  134. // Mode
  135. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<input type="hidden" name="action" value="set">';
  138. print '<table class="noborder" width="100%">';
  139. print '<tr class="liste_titre">';
  140. print '<td>'.$langs->trans("Type").'</td><td>'.$langs->trans("Value").'</td>';
  141. print '<td align="right" colspan="2"><input type="submit" class="button" '.$option.' value="'.$langs->trans("Modify").'"></td>';
  142. print "</tr>\n";
  143. $var=true;
  144. foreach ($syslogModules as $moduleName)
  145. {
  146. $module = new $moduleName;
  147. $moduleactive=$module->isActive();
  148. 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)
  149. $var=!$var;
  150. print '<tr '.$bc[$var].'>';
  151. print '<td width="140">';
  152. print '<input '.$bc[$var].' type="checkbox" name="SYSLOG_HANDLERS[]" value="'.$moduleName.'" '.(in_array($moduleName, $activeModules) ? 'checked="checked"' : '').(!$moduleactive ? 'disabled="disabled"' : '').'> ';
  153. print $module->getName();
  154. print '</td>';
  155. print '<td class="nowrap">';
  156. $setuparray=$module->configure();
  157. if ($setuparray)
  158. {
  159. foreach ($setuparray as $option)
  160. {
  161. if (isset($_POST[$option['constant']])) $value=$_POST[$option['constant']];
  162. else if (defined($option['constant'])) $value = constant($option['constant']);
  163. else $value = (isset($option['default']) ? $option['default'] : '');
  164. print $option['name'].': <input type="text" class="flat" name="'.$option['constant'].'" value="'.$value.'"'.(isset($option['attr']) ? ' '.$option['attr'] : '').'>';
  165. }
  166. }
  167. print '</td>';
  168. print '<td align="left">';
  169. if ($module->getInfo())
  170. {
  171. print $form->textwithpicto('', $module->getInfo());
  172. }
  173. print '</td>';
  174. print "</tr>\n";
  175. }
  176. print "</table>\n";
  177. print "</form>\n";
  178. print '<br>';
  179. print_titre($langs->trans("SyslogLevel"));
  180. // Level
  181. print '<form action="syslog.php" method="post">';
  182. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  183. print '<input type="hidden" name="action" value="setlevel">';
  184. print '<table class="noborder" width="100%">';
  185. print '<tr class="liste_titre">';
  186. print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
  187. print '<td align="right"><input type="submit" class="button" '.$option.' value="'.$langs->trans("Modify").'"></td>';
  188. print "</tr>\n";
  189. $var=true;
  190. $var=!$var;
  191. print '<tr '.$bc[$var].'><td width="140">'.$langs->trans("SyslogLevel").'</td>';
  192. print '<td colspan="2"><select class="flat" name="level" '.$option.'>';
  193. print '<option value="'.LOG_EMERG.'" '.($conf->global->SYSLOG_LEVEL==LOG_EMERG?'SELECTED':'').'>LOG_EMERG ('.LOG_EMERG.')</option>';
  194. print '<option value="'.LOG_ALERT.'" '.($conf->global->SYSLOG_LEVEL==LOG_ALERT?'SELECTED':'').'>LOG_ALERT ('.LOG_ALERT.')</option>';
  195. print '<option value="'.LOG_CRIT.'" '.($conf->global->SYSLOG_LEVEL==LOG_CRIT?'SELECTED':'').'>LOG_CRIT ('.LOG_CRIT.')</option>';
  196. print '<option value="'.LOG_ERR.'" '.($conf->global->SYSLOG_LEVEL==LOG_ERR?'SELECTED':'').'>LOG_ERR ('.LOG_ERR.')</option>';
  197. print '<option value="'.LOG_WARNING.'" '.($conf->global->SYSLOG_LEVEL==LOG_WARNING?'SELECTED':'').'>LOG_WARNING ('.LOG_WARNING.')</option>';
  198. print '<option value="'.LOG_NOTICE.'" '.($conf->global->SYSLOG_LEVEL==LOG_NOTICE?'SELECTED':'').'>LOG_NOTICE ('.LOG_NOTICE.')</option>';
  199. print '<option value="'.LOG_INFO.'" '.($conf->global->SYSLOG_LEVEL==LOG_INFO?'SELECTED':'').'>LOG_INFO ('.LOG_INFO.')</option>';
  200. print '<option value="'.LOG_DEBUG.'" '.($conf->global->SYSLOG_LEVEL>=LOG_DEBUG?'SELECTED':'').'>LOG_DEBUG ('.LOG_DEBUG.')</option>';
  201. print '</select>';
  202. print '</td></tr>';
  203. print '</table>';
  204. print "</form>\n";
  205. llxFooter();
  206. $db->close();