PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/security_other.php

https://github.com/asterix14/dolibarr
PHP | 350 lines | 256 code | 57 blank | 37 comment | 54 complexity | 4acb2e58f181daca21f2e667747d4bea MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/security_other.php
  20. * \ingroup core
  21. * \brief Security options setup
  22. */
  23. require("../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  26. $langs->load("users");
  27. $langs->load("admin");
  28. $langs->load("other");
  29. if (!$user->admin) accessforbidden();
  30. $upload_dir=$conf->admin->dir_temp;
  31. /*
  32. * Actions
  33. */
  34. if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
  35. {
  36. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  37. $result=create_exdir($upload_dir); // Create dir if not exists
  38. if ($result >= 0)
  39. {
  40. $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],1,0,$_FILES['userfile']['error']);
  41. if (is_numeric($resupload) && $resupload > 0)
  42. {
  43. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  44. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  45. $formmail = new FormMail($db);
  46. $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
  47. }
  48. else
  49. {
  50. $langs->load("errors");
  51. if ($resupload < 0) // Unknown error
  52. {
  53. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  54. }
  55. else if (preg_match('/ErrorFileIsInfectedWithAVirus.(.*)/',$resupload,$reg)) // Files infected by a virus
  56. {
  57. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus");
  58. $mesg.= '<br>'.$langs->trans("Information").': '.$langs->trans($reg[1]);
  59. $mesg.= '</div>';
  60. }
  61. else // Known error
  62. {
  63. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  64. }
  65. }
  66. }
  67. }
  68. if ($_GET["action"] == 'activate_captcha')
  69. {
  70. dolibarr_set_const($db, "MAIN_SECURITY_ENABLECAPTCHA", '1','chaine',0,'',$conf->entity);
  71. Header("Location: security_other.php");
  72. exit;
  73. }
  74. else if ($_GET["action"] == 'disable_captcha')
  75. {
  76. dolibarr_del_const($db, "MAIN_SECURITY_ENABLECAPTCHA",$conf->entity);
  77. Header("Location: security_other.php");
  78. exit;
  79. }
  80. if ($_GET["action"] == 'activate_advancedperms')
  81. {
  82. dolibarr_set_const($db, "MAIN_USE_ADVANCED_PERMS", '1','chaine',0,'',$conf->entity);
  83. Header("Location: security_other.php");
  84. exit;
  85. }
  86. else if ($_GET["action"] == 'disable_advancedperms')
  87. {
  88. dolibarr_del_const($db, "MAIN_USE_ADVANCED_PERMS",$conf->entity);
  89. Header("Location: security_other.php");
  90. exit;
  91. }
  92. if ($_GET["action"] == 'MAIN_SESSION_TIMEOUT')
  93. {
  94. if (! dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", $_POST["MAIN_SESSION_TIMEOUT"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  95. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  96. }
  97. if ($_GET["action"] == 'MAIN_UPLOAD_DOC')
  98. {
  99. if (! dolibarr_set_const($db, 'MAIN_UPLOAD_DOC',$_POST["MAIN_UPLOAD_DOC"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  100. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  101. }
  102. if ($_GET["action"] == 'MAIN_UMASK')
  103. {
  104. if (! dolibarr_set_const($db, "MAIN_UMASK", $_POST["MAIN_UMASK"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  105. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  106. }
  107. if ($_GET["action"] == 'MAIN_ANTIVIRUS_COMMAND')
  108. {
  109. if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", $_POST["MAIN_ANTIVIRUS_COMMAND"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  110. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  111. }
  112. if ($_GET["action"] == 'MAIN_ANTIVIRUS_PARAM')
  113. {
  114. if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", $_POST["MAIN_ANTIVIRUS_PARAM"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  115. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  116. }
  117. /*
  118. * View
  119. */
  120. $form = new Form($db);
  121. llxHeader('',$langs->trans("Miscellanous"));
  122. print_fiche_titre($langs->trans("SecuritySetup"),'','setup');
  123. print $langs->trans("MiscellanousDesc")."<br>\n";
  124. print "<br>\n";
  125. $head=security_prepare_head();
  126. dol_fiche_head($head, 'misc', $langs->trans("Security"));
  127. // Timeout
  128. $var=true;
  129. print '<table width="100%" class="noborder">';
  130. print '<tr class="liste_titre">';
  131. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  132. print '<td>'.$langs->trans("Value").'</td>';
  133. print '<td width="100">&nbsp;</td>';
  134. print "</tr>\n";
  135. $var=!$var;
  136. if (empty($conf->global->MAIN_SESSION_TIMEOUT)) $conf->global->MAIN_SESSION_TIMEOUT=ini_get("session.gc_maxlifetime");
  137. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_SESSION_TIMEOUT" method="POST">';
  138. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  139. print '<tr '.$bc[$var].'>';
  140. print '<td>'.$langs->trans("SessionTimeOut").'</td><td align="right">';
  141. print $form->textwithpicto('',$langs->trans("SessionExplanation",ini_get("session.gc_probability"),ini_get("session.gc_divisor")));
  142. print '</td>';
  143. print '<td nowrap="nowrap">';
  144. print '<input class="flat" name="MAIN_SESSION_TIMEOUT" type="text" size="6" value="'.htmlentities($conf->global->MAIN_SESSION_TIMEOUT).'"> '.$langs->trans("seconds");
  145. print '</td>';
  146. print '<td align="right">';
  147. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  148. print '</td>';
  149. print '</tr></form>';
  150. print '</table>';
  151. print '<br>';
  152. // Other Options
  153. $var=true;
  154. print '<table class="noborder" width="100%">';
  155. print '<tr class="liste_titre">';
  156. print '<td colspan="3">'.$langs->trans("Parameters").'</td>';
  157. print '<td align="right" width="100">'.$langs->trans("Status").'</td>';
  158. print '</tr>';
  159. // Enable Captcha code
  160. $var=!$var;
  161. print "<tr ".$bc[$var].">";
  162. print '<td colspan="3">'.$langs->trans("UseCaptchaCode").'</td>';
  163. print '<td align="right">';
  164. if (function_exists("imagecreatefrompng"))
  165. {
  166. if ($conf->global->MAIN_SECURITY_ENABLECAPTCHA == 0)
  167. {
  168. print '<a href="security_other.php?action=activate_captcha">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  169. }
  170. if($conf->global->MAIN_SECURITY_ENABLECAPTCHA == 1)
  171. {
  172. print '<a href="security_other.php?action=disable_captcha">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  173. }
  174. }
  175. else
  176. {
  177. $form = new Form($db);
  178. $desc = $form->textwithpicto('',$langs->transnoentities("EnableGDLibraryDesc"),1,'warning');
  179. print $desc;
  180. }
  181. print "</td>";
  182. print "</td>";
  183. print '</tr>';
  184. // Enable advanced perms
  185. $var=!$var;
  186. print "<tr ".$bc[$var].">";
  187. print '<td colspan="3">'.$langs->trans("UseAdvancedPerms").'</td>';
  188. print '<td align="right">';
  189. if ($conf->global->MAIN_USE_ADVANCED_PERMS == 0)
  190. {
  191. print '<a href="security_other.php?action=activate_advancedperms">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  192. }
  193. if($conf->global->MAIN_USE_ADVANCED_PERMS == 1)
  194. {
  195. print '<a href="security_other.php?action=disable_advancedperms">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
  196. }
  197. print "</td>";
  198. print "</td>";
  199. print '</tr>';
  200. print '</table>';
  201. print '<br>';
  202. // Upload options
  203. $var=false;
  204. print '<table class="noborder" width="100%">';
  205. print '<tr class="liste_titre">';
  206. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  207. print '<td>'.$langs->trans("Value").'</td>';
  208. print '<td width="100">&nbsp;</td>';
  209. print '</tr>';
  210. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UPLOAD_DOC" method="POST">';
  211. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  212. print '<tr '.$bc[$var].'>';
  213. print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
  214. $max=@ini_get('upload_max_filesize');
  215. if ($max) print ' '.$langs->trans("MustBeLowerThanPHPLimit",$max*1024,$langs->trans("Kb")).'.';
  216. else print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
  217. print '</td>';
  218. print '<td nowrap="nowrap">';
  219. print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
  220. print '</td>';
  221. print '<td align="right">';
  222. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  223. print '</td>';
  224. print '</tr></form>';
  225. $var=!$var;
  226. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UMASK" method="POST">';
  227. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  228. print '<tr '.$bc[$var].'>';
  229. print '<td>'.$langs->trans("UMask").'</td><td align="right">';
  230. print $form->textwithpicto('',$langs->trans("UMaskExplanation"));
  231. print '</td>';
  232. print '<td nowrap="nowrap">';
  233. print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UMASK).'">';
  234. print '</td>';
  235. print '<td align="right">';
  236. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  237. print '</td>';
  238. print '</tr></form>';
  239. // Use anti virus
  240. $var=!$var;
  241. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_COMMAND" method="POST">';
  242. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  243. print "<tr ".$bc[$var].">";
  244. print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
  245. print $langs->trans("AntiVirusCommandExample");
  246. // Check command in inside safe_mode
  247. print '</td>';
  248. print '<td>';
  249. if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
  250. {
  251. $langs->load("errors");
  252. $basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
  253. $listdir=explode(';',ini_get('safe_mode_exec_dir'));
  254. if (! in_array($basedir,$listdir))
  255. {
  256. print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
  257. dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
  258. }
  259. }
  260. print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" size="72" value="'.htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND).'">';
  261. print "</td>";
  262. print '<td align="right">';
  263. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  264. print '</td>';
  265. print '</tr>';
  266. print '</form>';
  267. // Use anti virus
  268. $var=!$var;
  269. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_PARAM" method="POST">';
  270. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  271. print "<tr ".$bc[$var].">";
  272. print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
  273. print $langs->trans("AntiVirusParamExample");
  274. print '</td>';
  275. print '<td>';
  276. print '<input type="text" name="MAIN_ANTIVIRUS_PARAM" size="72" value="'.htmlentities($conf->global->MAIN_ANTIVIRUS_PARAM).'">';
  277. print "</td>";
  278. print '<td align="right">';
  279. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  280. print '</td>';
  281. print '</tr>';
  282. print '</form>';
  283. print '</table>';
  284. print '</div>';
  285. // Form to test upload
  286. dol_htmloutput_mesg($mesg);
  287. // Affiche formulaire upload
  288. print '<br>';
  289. $formfile=new FormFile($db);
  290. $formfile->form_attach_new_file(DOL_URL_ROOT.'/admin/security_other.php',$langs->trans("FormToTestFileUploadForm"),0,0,1);
  291. $db->close();
  292. llxFooter();
  293. ?>