PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/security_other.php

https://bitbucket.org/speedealing/speedealing
PHP | 338 lines | 254 code | 46 blank | 38 comment | 49 complexity | 3bcb6f1661c778c2e0b8ad9122a2608b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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/lib/files.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. $langs->load("users");
  28. $langs->load("admin");
  29. $langs->load("other");
  30. if (! $user->admin)
  31. accessforbidden();
  32. $action=GETPOST('action','alpha');
  33. $upload_dir=$conf->admin->dir_temp;
  34. /*
  35. * Actions
  36. */
  37. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  38. {
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. dol_add_file_process($upload_dir, 0, 0, 'userfile');
  41. }
  42. if (preg_match('/set_(.*)/',$action,$reg))
  43. {
  44. $code=$reg[1];
  45. $value=(GETPOST($code) ? GETPOST($code) : 1);
  46. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
  47. {
  48. Header("Location: ".$_SERVER["PHP_SELF"]);
  49. exit;
  50. }
  51. else
  52. {
  53. dol_print_error($db);
  54. }
  55. }
  56. else if (preg_match('/del_(.*)/',$action,$reg))
  57. {
  58. $code=$reg[1];
  59. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  60. {
  61. Header("Location: ".$_SERVER["PHP_SELF"]);
  62. exit;
  63. }
  64. else
  65. {
  66. dol_print_error($db);
  67. }
  68. }
  69. else if ($action == 'MAIN_SESSION_TIMEOUT')
  70. {
  71. if (! dolibarr_set_const($db, "MAIN_SESSION_TIMEOUT", $_POST["MAIN_SESSION_TIMEOUT"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  72. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  73. }
  74. else if ($action == 'MAIN_UPLOAD_DOC')
  75. {
  76. if (! dolibarr_set_const($db, 'MAIN_UPLOAD_DOC',$_POST["MAIN_UPLOAD_DOC"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  77. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  78. }
  79. else if ($action == 'MAIN_UMASK')
  80. {
  81. if (! dolibarr_set_const($db, "MAIN_UMASK", $_POST["MAIN_UMASK"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  82. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  83. }
  84. else if ($action == 'MAIN_ANTIVIRUS_COMMAND')
  85. {
  86. if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", $_POST["MAIN_ANTIVIRUS_COMMAND"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  87. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  88. }
  89. else if ($action == 'MAIN_ANTIVIRUS_PARAM')
  90. {
  91. if (! dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", $_POST["MAIN_ANTIVIRUS_PARAM"],'chaine',0,'',$conf->entity)) dol_print_error($db);
  92. else $mesg=$langs->trans("RecordModifiedSuccessfully");
  93. }
  94. // Delete file
  95. else if ($action == 'delete')
  96. {
  97. $langs->load("other");
  98. $file = $conf->admin->dir_temp . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  99. $ret=dol_delete_file($file);
  100. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  101. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  102. Header('Location: '.$_SERVER["PHP_SELF"]);
  103. exit;
  104. }
  105. /*
  106. * View
  107. */
  108. $form = new Form($db);
  109. llxHeader('',$langs->trans("Miscellanous"));
  110. print_fiche_titre($langs->trans("SecuritySetup"),'','setup');
  111. print $langs->trans("MiscellanousDesc")."<br>\n";
  112. print "<br>\n";
  113. $head=security_prepare_head();
  114. dol_fiche_head($head, 'misc', $langs->trans("Security"));
  115. // Timeout
  116. $var=true;
  117. print '<table width="100%" class="noborder">';
  118. print '<tr class="liste_titre">';
  119. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  120. print '<td>'.$langs->trans("Value").'</td>';
  121. print '<td width="100">&nbsp;</td>';
  122. print "</tr>\n";
  123. $var=!$var;
  124. if (empty($conf->global->MAIN_SESSION_TIMEOUT)) $conf->global->MAIN_SESSION_TIMEOUT=ini_get("session.gc_maxlifetime");
  125. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_SESSION_TIMEOUT" method="POST">';
  126. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  127. print '<tr '.$bc[$var].'>';
  128. print '<td>'.$langs->trans("SessionTimeOut").'</td><td align="right">';
  129. print $form->textwithpicto('',$langs->trans("SessionExplanation",ini_get("session.gc_probability"),ini_get("session.gc_divisor")));
  130. print '</td>';
  131. print '<td nowrap="nowrap">';
  132. print '<input class="flat" name="MAIN_SESSION_TIMEOUT" type="text" size="6" value="'.htmlentities($conf->global->MAIN_SESSION_TIMEOUT).'"> '.strtolower($langs->trans("Seconds"));
  133. print '</td>';
  134. print '<td align="right">';
  135. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  136. print '</td>';
  137. print '</tr></form>';
  138. print '</table>';
  139. print '<br>';
  140. // Other Options
  141. $var=true;
  142. print '<table class="noborder" width="100%">';
  143. print '<tr class="liste_titre">';
  144. print '<td colspan="3">'.$langs->trans("Parameters").'</td>';
  145. print '<td align="right" width="100">'.$langs->trans("Status").'</td>';
  146. print '</tr>';
  147. // Enable Captcha code
  148. $var=!$var;
  149. print "<tr ".$bc[$var].">";
  150. print '<td colspan="3">'.$langs->trans("UseCaptchaCode").'</td>';
  151. print '<td align="right">';
  152. if (function_exists("imagecreatefrompng"))
  153. {
  154. if (! empty($conf->use_javascript_ajax))
  155. {
  156. print ajax_constantonoff('MAIN_SECURITY_ENABLECAPTCHA');
  157. }
  158. else
  159. {
  160. if (empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
  161. {
  162. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_SECURITY_ENABLECAPTCHA">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  163. }
  164. else
  165. {
  166. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_SECURITY_ENABLECAPTCHA">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  167. }
  168. }
  169. }
  170. else
  171. {
  172. $form = new Form($db);
  173. $desc = $form->textwithpicto('',$langs->transnoentities("EnableGDLibraryDesc"),1,'warning');
  174. print $desc;
  175. }
  176. print '</td></tr>';
  177. // Enable advanced perms
  178. $var=!$var;
  179. print "<tr ".$bc[$var].">";
  180. print '<td colspan="3">'.$langs->trans("UseAdvancedPerms").'</td>';
  181. print '<td align="right">';
  182. if (! empty($conf->use_javascript_ajax))
  183. {
  184. print ajax_constantonoff('MAIN_USE_ADVANCED_PERMS');
  185. }
  186. else
  187. {
  188. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  189. {
  190. print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_MAIN_USE_ADVANCED_PERMS">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  191. }
  192. else
  193. {
  194. print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_MAIN_USE_ADVANCED_PERMS">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  195. }
  196. }
  197. print "</td></tr>";
  198. print '</table>';
  199. print '<br>';
  200. // Upload options
  201. $var=false;
  202. print '<table class="noborder" width="100%">';
  203. print '<tr class="liste_titre">';
  204. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  205. print '<td>'.$langs->trans("Value").'</td>';
  206. print '<td width="100">&nbsp;</td>';
  207. print '</tr>';
  208. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UPLOAD_DOC" method="POST">';
  209. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  210. print '<tr '.$bc[$var].'>';
  211. print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
  212. $max=@ini_get('upload_max_filesize');
  213. if ($max) print ' '.$langs->trans("MustBeLowerThanPHPLimit",$max*1024,$langs->trans("Kb")).'.';
  214. else print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
  215. print '</td>';
  216. print '<td nowrap="nowrap">';
  217. print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
  218. print '</td>';
  219. print '<td align="right">';
  220. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  221. print '</td>';
  222. print '</tr></form>';
  223. $var=!$var;
  224. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_UMASK" method="POST">';
  225. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  226. print '<tr '.$bc[$var].'>';
  227. print '<td>'.$langs->trans("UMask").'</td><td align="right">';
  228. print $form->textwithpicto('',$langs->trans("UMaskExplanation"));
  229. print '</td>';
  230. print '<td nowrap="nowrap">';
  231. print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UMASK).'">';
  232. print '</td>';
  233. print '<td align="right">';
  234. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  235. print '</td>';
  236. print '</tr></form>';
  237. // Use anti virus
  238. $var=!$var;
  239. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_COMMAND" method="POST">';
  240. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  241. print "<tr ".$bc[$var].">";
  242. print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
  243. print $langs->trans("AntiVirusCommandExample");
  244. // Check command in inside safe_mode
  245. print '</td>';
  246. print '<td>';
  247. if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
  248. {
  249. $langs->load("errors");
  250. $basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
  251. $listdir=explode(';',ini_get('safe_mode_exec_dir'));
  252. if (! in_array($basedir,$listdir))
  253. {
  254. print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
  255. dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
  256. }
  257. }
  258. print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" size="72" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND):'').'">';
  259. print "</td>";
  260. print '<td align="right">';
  261. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  262. print '</td>';
  263. print '</tr>';
  264. print '</form>';
  265. // Use anti virus
  266. $var=!$var;
  267. print '<form action="'.$_SERVER["PHP_SELF"].'?action=MAIN_ANTIVIRUS_PARAM" method="POST">';
  268. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  269. print "<tr ".$bc[$var].">";
  270. print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
  271. print $langs->trans("AntiVirusParamExample");
  272. print '</td>';
  273. print '<td>';
  274. print '<input type="text" name="MAIN_ANTIVIRUS_PARAM" size="72" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_PARAM)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_PARAM):'').'">';
  275. print "</td>";
  276. print '<td align="right">';
  277. print '<input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'">';
  278. print '</td>';
  279. print '</tr>';
  280. print '</form>';
  281. print '</table>';
  282. dol_fiche_end();
  283. // Form to test upload
  284. print '<br>';
  285. $formfile=new FormFile($db);
  286. $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1);
  287. // List of document
  288. $filearray=dol_dir_list($upload_dir, "files", 0, '', '', 'name', SORT_ASC, 1);
  289. $formfile->list_of_documents($filearray, '', 'admin_temp', '');
  290. llxFooter();
  291. $db->close();
  292. ?>