security_file.php 7.6 KB

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