security_file.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  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 3 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/security_file.php
  21. * \ingroup core
  22. * \brief Security options setup
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. $langs->load("users");
  29. $langs->load("admin");
  30. $langs->load("other");
  31. if (! $user->admin)
  32. accessforbidden();
  33. $action=GETPOST('action','alpha');
  34. $upload_dir=$conf->admin->dir_temp;
  35. /*
  36. * Actions
  37. */
  38. if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
  39. {
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  41. dol_add_file_process($upload_dir, 0, 0, 'userfile');
  42. }
  43. if (preg_match('/set_(.*)/',$action,$reg))
  44. {
  45. $code=$reg[1];
  46. $value=(GETPOST($code) ? GETPOST($code) : 1);
  47. if (dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity) > 0)
  48. {
  49. Header("Location: ".$_SERVER["PHP_SELF"]);
  50. exit;
  51. }
  52. else
  53. {
  54. dol_print_error($db);
  55. }
  56. }
  57. else if (preg_match('/del_(.*)/',$action,$reg))
  58. {
  59. $code=$reg[1];
  60. if (dolibarr_del_const($db, $code, $conf->entity) > 0)
  61. {
  62. Header("Location: ".$_SERVER["PHP_SELF"]);
  63. exit;
  64. }
  65. else
  66. {
  67. dol_print_error($db);
  68. }
  69. }
  70. else if ($action == 'updateform')
  71. {
  72. $res3=dolibarr_set_const($db, 'MAIN_UPLOAD_DOC',$_POST["MAIN_UPLOAD_DOC"],'chaine',0,'',$conf->entity);
  73. $res4=dolibarr_set_const($db, "MAIN_UMASK", $_POST["MAIN_UMASK"],'chaine',0,'',$conf->entity);
  74. $res5=dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", $_POST["MAIN_ANTIVIRUS_COMMAND"],'chaine',0,'',$conf->entity);
  75. $res6=dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", $_POST["MAIN_ANTIVIRUS_PARAM"],'chaine',0,'',$conf->entity);
  76. if ($res3 && $res4 && $res5 && $res6) setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  77. }
  78. // Delete file
  79. else if ($action == 'delete')
  80. {
  81. $langs->load("other");
  82. $file = $conf->admin->dir_temp . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  83. $ret=dol_delete_file($file);
  84. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  85. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  86. Header('Location: '.$_SERVER["PHP_SELF"]);
  87. exit;
  88. }
  89. /*
  90. * View
  91. */
  92. $form = new Form($db);
  93. $wikihelp='EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
  94. llxHeader('',$langs->trans("Files"),$wikihelp);
  95. print load_fiche_titre($langs->trans("SecuritySetup"),'','title_setup');
  96. print $langs->trans("SecurityFilesDesc")."<br>\n";
  97. print "<br>\n";
  98. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  99. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  100. print '<input type="hidden" name="action" value="updateform">';
  101. $head=security_prepare_head();
  102. dol_fiche_head($head, 'file', $langs->trans("Security"), -1);
  103. // Upload options
  104. $var=false;
  105. print '<table class="noborder" width="100%">';
  106. print '<tr class="liste_titre">';
  107. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  108. print '<td>'.$langs->trans("Value").'</td>';
  109. print '</tr>';
  110. print '<tr class="oddeven">';
  111. print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
  112. $max=@ini_get('upload_max_filesize');
  113. if ($max) print ' '.$langs->trans("MustBeLowerThanPHPLimit",$max*1024,$langs->trans("Kb")).'.';
  114. else print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
  115. print '</td>';
  116. print '<td class="nowrap">';
  117. print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
  118. print '</td>';
  119. print '</tr>';
  120. print '<tr class="oddeven">';
  121. print '<td>'.$langs->trans("UMask").'</td><td align="right">';
  122. print $form->textwithpicto('',$langs->trans("UMaskExplanation"));
  123. print '</td>';
  124. print '<td class="nowrap">';
  125. print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UMASK).'">';
  126. print '</td>';
  127. print '</tr>';
  128. // Use anti virus
  129. print '<tr class="oddeven">';
  130. print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
  131. print $langs->trans("AntiVirusCommandExample");
  132. // Check command in inside safe_mode
  133. print '</td>';
  134. print '<td>';
  135. if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
  136. {
  137. $langs->load("errors");
  138. $basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
  139. $listdir=explode(';',ini_get('safe_mode_exec_dir'));
  140. if (! in_array($basedir,$listdir))
  141. {
  142. print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
  143. dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
  144. }
  145. }
  146. print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" class="minwidth500imp" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_COMMAND):'').'">';
  147. print "</td>";
  148. print '</tr>';
  149. // Use anti virus
  150. print '<tr class="oddeven">';
  151. print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
  152. print $langs->trans("AntiVirusParamExample");
  153. print '</td>';
  154. print '<td>';
  155. print '<input type="text" name="MAIN_ANTIVIRUS_PARAM" class="minwidth500imp" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_PARAM)?dol_htmlentities($conf->global->MAIN_ANTIVIRUS_PARAM):'').'">';
  156. print "</td>";
  157. print '</tr>';
  158. print '</table>';
  159. dol_fiche_end();
  160. print '<div class="center"><input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'"></div>';
  161. print '</form>';
  162. // Form to test upload
  163. print '<br>';
  164. $formfile=new FormFile($db);
  165. $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
  166. // List of document
  167. $filearray=dol_dir_list($upload_dir, "files", 0, '', '', 'name', SORT_ASC, 1);
  168. $formfile->list_of_documents($filearray, null, 'admin_temp', '');
  169. llxFooter();
  170. $db->close();