security_file.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/security_file.php
  21. * \ingroup core
  22. * \brief Security options setup
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('users', 'admin', 'other'));
  31. $action = GETPOST('action', 'aZ09');
  32. $sortfield = GETPOST('sortfield', 'aZ09');
  33. $sortorder = GETPOST('sortorder', 'aZ09');
  34. if (empty($sortfield)) {
  35. $sortfield = 'date';
  36. }
  37. if (empty($sortorder)) {
  38. $sortorder = 'desc';
  39. }
  40. $upload_dir = $conf->admin->dir_temp;
  41. if (!$user->admin) {
  42. accessforbidden();
  43. }
  44. $error = 0;
  45. /*
  46. * Actions
  47. */
  48. if (GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  50. dol_add_file_process($upload_dir, 1, 0, 'userfile');
  51. }
  52. if ($action == 'updateform') {
  53. $antivircommand = GETPOST('MAIN_ANTIVIRUS_COMMAND', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
  54. $antivirparam = GETPOST('MAIN_ANTIVIRUS_PARAM', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
  55. $antivircommand = dol_string_nospecial($antivircommand, '', array("|", ";", "<", ">", "&")); // Sanitize command
  56. $antivirparam = dol_string_nospecial($antivirparam, '', array("|", ";", "<", ">", "&")); // Sanitize params
  57. if ($antivircommand && !empty($dolibarr_main_restrict_os_commands)) {
  58. $arrayofallowedcommand = explode(',', $dolibarr_main_restrict_os_commands);
  59. $arrayofallowedcommand = array_map('trim', $arrayofallowedcommand);
  60. dol_syslog("Command are restricted to ".$dolibarr_main_restrict_os_commands.". We check that one of this command is inside ".$antivircommand);
  61. $basenamecmddump = basename(str_replace('\\', '/', $antivircommand));
  62. if (!in_array($basenamecmddump, $arrayofallowedcommand)) { // the provided command $cmddump must be an allowed command
  63. $errormsg = $langs->trans('CommandIsNotInsideAllowedCommands');
  64. setEventMessages($errormsg, null, 'errors');
  65. $error++;
  66. }
  67. }
  68. if (!$error) {
  69. $res3 = dolibarr_set_const($db, 'MAIN_UPLOAD_DOC', GETPOST('MAIN_UPLOAD_DOC', 'alpha'), 'chaine', 0, '', $conf->entity);
  70. $res4 = dolibarr_set_const($db, "MAIN_UMASK", GETPOST('MAIN_UMASK', 'alpha'), 'chaine', 0, '', $conf->entity);
  71. $res5 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", trim($antivircommand), 'chaine', 0, '', $conf->entity);
  72. $res6 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", trim($antivirparam), 'chaine', 0, '', $conf->entity);
  73. if ($res3 && $res4 && $res5 && $res6) {
  74. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  75. }
  76. }
  77. } elseif ($action == 'deletefile') {
  78. // Delete file
  79. $langs->load("other");
  80. $file = $conf->admin->dir_temp.'/'.GETPOST('urlfile', 'alpha');
  81. $ret = dol_delete_file($file);
  82. if ($ret) {
  83. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile', 'alpha')), null, 'mesgs');
  84. } else {
  85. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile', 'alpha')), null, 'errors');
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. $form = new Form($db);
  92. $wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
  93. llxHeader('', $langs->trans("Files"), $wikihelp);
  94. print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
  95. print '<span class="opacitymedium">'.$langs->trans("SecurityFilesDesc")."</span><br>\n";
  96. print "<br>\n";
  97. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  98. print '<input type="hidden" name="token" value="'.newToken().'">';
  99. print '<input type="hidden" name="action" value="updateform">';
  100. $head = security_prepare_head();
  101. print dol_get_fiche_head($head, 'file', '', -1);
  102. print '<br>';
  103. // Upload options
  104. print '<div class="div-table-responsive-no-min">';
  105. print '<table class="noborder centpercent nomarginbottom">';
  106. print '<tr class="liste_titre">';
  107. print '<td>'.$langs->trans("Parameters").'</td>';
  108. print '<td>'.$langs->trans("Value").'</td>';
  109. print '</tr>';
  110. print '<tr class="oddeven">';
  111. print '<td>'.$langs->trans("MaxSizeForUploadedFiles").'.';
  112. $max = @ini_get('upload_max_filesize');
  113. if (isset($max)) {
  114. print '<br><span class="opacitymedium">'.$langs->trans("MustBeLowerThanPHPLimit", ((int) $max) * 1024, $langs->trans("Kb")).'.</span>';
  115. } else {
  116. print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
  117. }
  118. print '</td>';
  119. print '<td class="nowrap">';
  120. print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
  121. print '</td>';
  122. print '</tr>';
  123. print '<tr class="oddeven">';
  124. print '<td>';
  125. print $form->textwithpicto($langs->trans("UMask"), $langs->trans("UMaskExplanation"));
  126. print '</td>';
  127. print '<td class="nowrap">';
  128. print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UMASK).'">';
  129. print '</td>';
  130. print '</tr>';
  131. // Use anti virus
  132. print '<tr class="oddeven">';
  133. print '<td>'.$langs->trans("AntiVirusCommand").'<br>';
  134. print '<span class="opacitymedium">'.$langs->trans("AntiVirusCommandExample").'</span>';
  135. // Check command in inside safe_mode
  136. print '</td>';
  137. print '<td>';
  138. if (ini_get('safe_mode') && !empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
  139. $langs->load("errors");
  140. $basedir = preg_replace('/"/', '', dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
  141. $listdir = explode(';', ini_get('safe_mode_exec_dir'));
  142. if (!in_array($basedir, $listdir)) {
  143. print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
  144. dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
  145. }
  146. }
  147. print '<input type="text" '.((defined('MAIN_ANTIVIRUS_COMMAND') && !defined('MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM')) ? 'disabled ' : '').'name="MAIN_ANTIVIRUS_COMMAND" class="minwidth500imp" value="'.dol_escape_htmltag(GETPOSTISSET('MAIN_ANTIVIRUS_COMMAND') ? GETPOST('MAIN_ANTIVIRUS_COMMAND') : getDolGlobalString('MAIN_ANTIVIRUS_COMMAND')).'">';
  148. if (defined('MAIN_ANTIVIRUS_COMMAND') && !defined('MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM')) {
  149. print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
  150. }
  151. print "</td>";
  152. print '</tr>';
  153. // Use anti virus
  154. print '<tr class="oddeven">';
  155. print '<td>'.$langs->trans("AntiVirusParam").'<br>';
  156. print '<span class="opacitymedium">'.$langs->trans("AntiVirusParamExample").'</span>';
  157. print '</td>';
  158. print '<td>';
  159. print '<input type="text" '.(defined('MAIN_ANTIVIRUS_PARAM') ? 'disabled ' : '').'name="MAIN_ANTIVIRUS_PARAM" class="minwidth500imp" value="'.(!empty($conf->global->MAIN_ANTIVIRUS_PARAM) ?dol_escape_htmltag($conf->global->MAIN_ANTIVIRUS_PARAM) : '').'">';
  160. if (defined('MAIN_ANTIVIRUS_PARAM')) {
  161. print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
  162. }
  163. print "</td>";
  164. print '</tr>';
  165. print '</table>';
  166. print '</div>';
  167. print dol_get_fiche_end();
  168. print $form->buttonsSaveCancel("Modify", '');
  169. print '</form>';
  170. // Form to test upload
  171. print '<br>';
  172. $formfile = new FormFile($db);
  173. $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
  174. // List of document
  175. $filearray = dol_dir_list($upload_dir, "files", 0, '', '', $sortfield, $sortorder == 'desc' ? SORT_DESC : SORT_ASC, 1);
  176. if (count($filearray) > 0) {
  177. $formfile->list_of_documents($filearray, null, 'admin_temp', '');
  178. }
  179. // End of page
  180. llxFooter();
  181. $db->close();