PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/admin/syslog.php

https://github.com/asterix14/dolibarr
PHP | 252 lines | 178 code | 39 blank | 35 comment | 32 complexity | 67081adced51b496f4ee586a98ff4eab MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  4. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/syslog.php
  21. * \ingroup syslog
  22. * \brief Setup page for logs module
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  26. if (!$user->admin) accessforbidden();
  27. $langs->load("admin");
  28. $langs->load("other");
  29. $error=0; $mesg='';
  30. $action = GETPOST("action");
  31. $syslog_file_on=(defined('SYSLOG_FILE_ON') && constant('SYSLOG_FILE_ON'))?1:0;
  32. $syslog_syslog_on=(defined('SYSLOG_SYSLOG_ON') && constant('SYSLOG_SYSLOG_ON'))?1:0;
  33. $syslog_firephp_on=(defined('SYSLOG_FIREPHP_ON') && constant('SYSLOG_FIREPHP_ON'))?1:0;
  34. /*
  35. * Actions
  36. */
  37. // Set modes
  38. if ($action == 'set')
  39. {
  40. $db->begin();
  41. $res = dolibarr_del_const($db,"SYSLOG_FILE_ON",0);
  42. $res = dolibarr_del_const($db,"SYSLOG_SYSLOG_ON",0);
  43. $res = dolibarr_del_const($db,"SYSLOG_FIREPHP_ON",0);
  44. $syslog_file_on=0;
  45. $syslog_syslog_on=0;
  46. $syslog_firephp_on=0;
  47. if (! $error && GETPOST("filename"))
  48. {
  49. $filename=GETPOST("filename");
  50. $filelog=GETPOST("filename");
  51. $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
  52. $file=@fopen($filelog,"a+");
  53. if ($file)
  54. {
  55. fclose($file);
  56. dol_syslog("admin/syslog: file ".$filename);
  57. $res = dolibarr_set_const($db,"SYSLOG_FILE",$filename,'chaine',0,'',0);
  58. if (! $res > 0) $error++;
  59. $syslog_file_on=GETPOST('SYSLOG_FILE_ON');
  60. if (! $error) $res = dolibarr_set_const($db,"SYSLOG_FILE_ON",$syslog_file_on,'chaine',0,'',0);
  61. }
  62. else
  63. {
  64. $error++;
  65. $mesg = "<font class=\"error\">".$langs->trans("ErrorFailedToOpenFile",$filename)."</font>";
  66. }
  67. }
  68. if (! $error && GETPOST("facility"))
  69. {
  70. $facility=GETPOST("facility");
  71. if (defined($_POST["facility"]))
  72. {
  73. // Only LOG_USER supported on Windows
  74. if (! empty($_SERVER["WINDIR"])) $facility='LOG_USER';
  75. dol_syslog("admin/syslog: facility ".$facility);
  76. $res = dolibarr_set_const($db,"SYSLOG_FACILITY",$facility,'chaine',0,'',0);
  77. if (! $res > 0) $error++;
  78. $syslog_syslog_on=GETPOST('SYSLOG_SYSLOG_ON');
  79. if (! $error) $res = dolibarr_set_const($db,"SYSLOG_SYSLOG_ON",$syslog_syslog_on,'chaine',0,'',0);
  80. }
  81. else
  82. {
  83. $error++;
  84. $mesg = "<font class=\"error\">".$langs->trans("ErrorUnknownSyslogConstant",$facility)."</font>";
  85. }
  86. }
  87. if (! $error && isset($_POST['SYSLOG_FIREPHP_ON'])) // If firephp no available, post is not present
  88. {
  89. $syslog_firephp_on=GETPOST('SYSLOG_FIREPHP_ON');
  90. if (! $error) $res = dolibarr_set_const($db,"SYSLOG_FIREPHP_ON",$syslog_firephp_on,'chaine',0,'',0);
  91. }
  92. if (! $error)
  93. {
  94. $db->commit();
  95. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  96. }
  97. else
  98. {
  99. $db->rollback();
  100. if (empty($mesg)) $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  101. }
  102. }
  103. // Set level
  104. if ($action == 'setlevel')
  105. {
  106. $level = GETPOST("level");
  107. $res = dolibarr_set_const($db,"SYSLOG_LEVEL",$level,'chaine',0,'',0);
  108. dol_syslog("admin/syslog: level ".$level);
  109. if (! $res > 0) $error++;
  110. if (! $error)
  111. {
  112. $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  113. }
  114. else
  115. {
  116. $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  117. }
  118. }
  119. /*
  120. * View
  121. */
  122. llxHeader();
  123. $form=new Form($db);
  124. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  125. print_fiche_titre($langs->trans("SyslogSetup"),$linkback,'setup');
  126. print '<br>';
  127. $def = array();
  128. $syslogfacility=$defaultsyslogfacility=dolibarr_get_const($db,"SYSLOG_FACILITY",0);
  129. $syslogfile=$defaultsyslogfile=dolibarr_get_const($db,"SYSLOG_FILE",0);
  130. if (! $defaultsyslogfacility) $defaultsyslogfacility='LOG_USER';
  131. if (! $defaultsyslogfile) $defaultsyslogfile='dolibarr.log';
  132. if ($conf->global->MAIN_MODULE_MULTICOMPANY && $user->entity)
  133. {
  134. print '<div class="error">'.$langs->trans("ContactSuperAdminForChange").'</div>';
  135. $option = 'disabled="disabled"';
  136. }
  137. // Output mode
  138. print_titre($langs->trans("SyslogOutput"));
  139. // Mode
  140. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  141. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  142. print '<input type="hidden" name="action" value="set">';
  143. print '<table class="noborder" width="100%">';
  144. print '<tr class="liste_titre">';
  145. print '<td>'.$langs->trans("Type").'</td><td>'.$langs->trans("Value").'</td>';
  146. print '<td align="right" colspan="2"><input type="submit" class="button" '.$option.' value="'.$langs->trans("Modify").'"></td>';
  147. print "</tr>\n";
  148. $var=true;
  149. $var=!$var;
  150. print '<tr '.$bc[$var].'><td width="140"><input '.$bc[$var].' type="checkbox" name="SYSLOG_FILE_ON" '.$option.' value="1" '.($syslog_file_on?' checked="checked"':'').'> '.$langs->trans("SyslogSimpleFile").'</td>';
  151. print '<td width="250" nowrap="nowrap">'.$langs->trans("SyslogFilename").': <input type="text" class="flat" name="filename" '.$option.' size="60" value="'.$defaultsyslogfile.'">';
  152. print '</td>';
  153. print "<td align=\"left\">".$form->textwithpicto('',$langs->trans("YouCanUseDOL_DATA_ROOT"));
  154. print '</td></tr>';
  155. $var=!$var;
  156. print '<tr '.$bc[$var].'><td width="140"><input '.$bc[$var].' type="checkbox" name="SYSLOG_SYSLOG_ON" '.$option.' value="1" '.($syslog_syslog_on?' checked="checked"':'').'> '.$langs->trans("SyslogSyslog").'</td>';
  157. print '<td width="250" nowrap="nowrap">'.$langs->trans("SyslogFacility").': <input type="text" class="flat" name="facility" '.$option.' value="'.$defaultsyslogfacility.'">';
  158. print '</td>';
  159. print "<td align=\"left\">".$form->textwithpicto('','Only LOG_USER supported on Windows');
  160. print '</td></tr>';
  161. try
  162. {
  163. set_include_path('/usr/share/php/');
  164. @require_once('FirePHPCore/FirePHP.class.php');
  165. restore_include_path();
  166. $var=!$var;
  167. print '<tr '.$bc[$var].'><td width="140"><input '.$bc[$var].' type="checkbox" name="SYSLOG_FIREPHP_ON" '.$option.' value="1" ';
  168. if (! class_exists('FirePHP')) print ' disabled="disabled"';
  169. else print ($syslog_firephp_on?' checked="checked"':"");
  170. print '> '.$langs->trans("FirePHP").'</td>';
  171. print '<td width="250" nowrap="nowrap">';
  172. print '</td>';
  173. print "<td align=\"left\">".$form->textwithpicto('','FirePHP must be installed onto PHP and FirePHP plugin for Firefox must also be installed');
  174. print '</td></tr>';
  175. }
  176. catch(Exception $e)
  177. {
  178. // Do nothing
  179. print '<!-- FirePHP no available into PHP -->'."\n";
  180. }
  181. print "</table>\n";
  182. print "</form>\n";
  183. print '<br>';
  184. print_titre($langs->trans("SyslogLevel"));
  185. // Level
  186. print '<form action="syslog.php" method="post">';
  187. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  188. print '<input type="hidden" name="action" value="setlevel">';
  189. print '<table class="noborder" width="100%">';
  190. print '<tr class="liste_titre">';
  191. print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
  192. print '<td align="right"><input type="submit" class="button" '.$option.' value="'.$langs->trans("Modify").'"></td>';
  193. print "</tr>\n";
  194. $var=true;
  195. $var=!$var;
  196. print '<tr '.$bc[$var].'><td width=\"140\">'.$langs->trans("SyslogLevel").'</td>';
  197. print '<td colspan="2"><select class="flat" name="level" '.$option.'>';
  198. print '<option value="'.LOG_EMERG.'" '.($conf->global->SYSLOG_LEVEL==LOG_EMERG?'SELECTED':'').'>LOG_EMERG ('.LOG_EMERG.')</option>';
  199. print '<option value="'.LOG_ALERT.'" '.($conf->global->SYSLOG_LEVEL==LOG_ALERT?'SELECTED':'').'>LOG_ALERT ('.LOG_ALERT.')</option>';
  200. print '<option value="'.LOG_CRIT.'" '.($conf->global->SYSLOG_LEVEL==LOG_CRIT?'SELECTED':'').'>LOG_CRIT ('.LOG_CRIT.')</option>';
  201. print '<option value="'.LOG_ERR.'" '.($conf->global->SYSLOG_LEVEL==LOG_ERR?'SELECTED':'').'>LOG_ERR ('.LOG_ERR.')</option>';
  202. print '<option value="'.LOG_WARNING.'" '.($conf->global->SYSLOG_LEVEL==LOG_WARNING?'SELECTED':'').'>LOG_WARNING ('.LOG_WARNING.')</option>';
  203. print '<option value="'.LOG_NOTICE.'" '.($conf->global->SYSLOG_LEVEL==LOG_NOTICE?'SELECTED':'').'>LOG_NOTICE ('.LOG_NOTICE.')</option>';
  204. print '<option value="'.LOG_INFO.'" '.($conf->global->SYSLOG_LEVEL==LOG_INFO?'SELECTED':'').'>LOG_INFO ('.LOG_INFO.')</option>';
  205. print '<option value="'.LOG_DEBUG.'" '.($conf->global->SYSLOG_LEVEL>=LOG_DEBUG?'SELECTED':'').'>LOG_DEBUG ('.LOG_DEBUG.')</option>';
  206. print '</select>';
  207. print '</td></tr>';
  208. print '</table>';
  209. print "</form>\n";
  210. dol_htmloutput_mesg($mesg);
  211. $db->close();
  212. llxFooter();
  213. ?>