security_file.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <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. // Load translation files required by the page
  29. $langs->loadLangs(array('users', 'admin', '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 ($action == 'updateform')
  43. {
  44. $antivircommand = GETPOST('MAIN_ANTIVIRUS_COMMAND','none'); // Use GETPOST none because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
  45. $antivirparam = GETPOST('MAIN_ANTIVIRUS_PARAM','none'); // Use GETPOST none because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
  46. $antivircommand = dol_string_nospecial($antivircommand, '', array("|", ";", "<", ">", "&")); // Sanitize command
  47. $antivirparam = dol_string_nospecial($antivirparam, '', array("|", ";", "<", ">", "&")); // Sanitize params
  48. $res3=dolibarr_set_const($db, 'MAIN_UPLOAD_DOC',GETPOST('MAIN_UPLOAD_DOC','alpha'),'chaine',0,'',$conf->entity);
  49. $res4=dolibarr_set_const($db, "MAIN_UMASK", GETPOST('MAIN_UMASK','alpha'),'chaine',0,'',$conf->entity);
  50. $res5=dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", trim($antivircommand),'chaine',0,'',$conf->entity);
  51. $res6=dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", trim($antivirparam),'chaine',0,'',$conf->entity);
  52. if ($res3 && $res4 && $res5 && $res6) setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  53. }
  54. // Delete file
  55. else if ($action == 'delete')
  56. {
  57. $langs->load("other");
  58. $file = $conf->admin->dir_temp . '/' . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  59. $ret=dol_delete_file($file);
  60. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile','alpha')), null, 'mesgs');
  61. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile','alpha')), null, 'errors');
  62. Header('Location: '.$_SERVER["PHP_SELF"]);
  63. exit;
  64. }
  65. /*
  66. * View
  67. */
  68. $form = new Form($db);
  69. $wikihelp='EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
  70. llxHeader('',$langs->trans("Files"),$wikihelp);
  71. print load_fiche_titre($langs->trans("SecuritySetup"),'','title_setup');
  72. print $langs->trans("SecurityFilesDesc")."<br>\n";
  73. print "<br>\n";
  74. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  75. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  76. print '<input type="hidden" name="action" value="updateform">';
  77. $head=security_prepare_head();
  78. dol_fiche_head($head, 'file', $langs->trans("Security"), -1);
  79. // Upload options
  80. $var=false;
  81. print '<div class="div-table-responsive-no-min">';
  82. print '<table class="noborder" width="100%">';
  83. print '<tr class="liste_titre">';
  84. print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
  85. print '<td>'.$langs->trans("Value").'</td>';
  86. print '</tr>';
  87. print '<tr class="oddeven">';
  88. print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
  89. $max=@ini_get('upload_max_filesize');
  90. if ($max) print ' '.$langs->trans("MustBeLowerThanPHPLimit",$max*1024,$langs->trans("Kb")).'.';
  91. else print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
  92. print '</td>';
  93. print '<td class="nowrap">';
  94. print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
  95. print '</td>';
  96. print '</tr>';
  97. print '<tr class="oddeven">';
  98. print '<td>'.$langs->trans("UMask").'</td><td align="right">';
  99. print $form->textwithpicto('',$langs->trans("UMaskExplanation"));
  100. print '</td>';
  101. print '<td class="nowrap">';
  102. print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.htmlentities($conf->global->MAIN_UMASK).'">';
  103. print '</td>';
  104. print '</tr>';
  105. // Use anti virus
  106. print '<tr class="oddeven">';
  107. print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
  108. print $langs->trans("AntiVirusCommandExample");
  109. // Check command in inside safe_mode
  110. print '</td>';
  111. print '<td>';
  112. if (ini_get('safe_mode') && ! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
  113. {
  114. $langs->load("errors");
  115. $basedir=preg_replace('/"/','',dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
  116. $listdir=explode(';',ini_get('safe_mode_exec_dir'));
  117. if (! in_array($basedir,$listdir))
  118. {
  119. print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
  120. dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
  121. }
  122. }
  123. print '<input type="text" name="MAIN_ANTIVIRUS_COMMAND" class="minwidth500imp" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)?dol_escape_htmltag($conf->global->MAIN_ANTIVIRUS_COMMAND):'').'">';
  124. print "</td>";
  125. print '</tr>';
  126. // Use anti virus
  127. print '<tr class="oddeven">';
  128. print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
  129. print $langs->trans("AntiVirusParamExample");
  130. print '</td>';
  131. print '<td>';
  132. print '<input type="text" name="MAIN_ANTIVIRUS_PARAM" class="minwidth500imp" value="'.(! empty($conf->global->MAIN_ANTIVIRUS_PARAM)?dol_escape_htmltag($conf->global->MAIN_ANTIVIRUS_PARAM):'').'">';
  133. print "</td>";
  134. print '</tr>';
  135. print '</table>';
  136. print '</div>';
  137. dol_fiche_end();
  138. print '<div class="center"><input type="submit" class="button" name="button" value="'.$langs->trans("Modify").'"></div>';
  139. print '</form>';
  140. // Form to test upload
  141. print '<br>';
  142. $formfile=new FormFile($db);
  143. $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
  144. // List of document
  145. $filearray=dol_dir_list($upload_dir, "files", 0, '', '', 'name', SORT_ASC, 1);
  146. $formfile->list_of_documents($filearray, null, 'admin_temp', '');
  147. // End of page
  148. llxFooter();
  149. $db->close();