2015-01-12 13:20:27 +01:00
< ? php
2017-10-03 17:08:16 +02:00
/* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2017-10-03 17:08:16 +02:00
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
2024-03-30 22:09:24 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2024-11-04 23:53:20 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2015-01-12 13:20:27 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2015-01-12 13:20:27 +01:00
*/
/**
* \file htdocs / admin / security_file . php
* \ingroup core
* \brief Security options setup
*/
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
2015-01-12 13:20:27 +01:00
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2018-05-26 18:52:14 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'users' , 'admin' , 'other' ));
2015-01-12 13:20:27 +01:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2022-03-15 12:14:46 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09' );
if ( empty ( $sortfield )) {
$sortfield = 'date' ;
}
if ( empty ( $sortorder )) {
$sortorder = 'desc' ;
}
2015-01-12 13:20:27 +01:00
2019-11-13 19:35:02 +01:00
$upload_dir = $conf -> admin -> dir_temp ;
2015-01-12 13:20:27 +01:00
2023-02-11 16:02:51 +01:00
if ( ! $user -> admin ) {
accessforbidden ();
}
$error = 0 ;
2015-01-12 13:20:27 +01:00
/*
* Actions
*/
2023-10-24 17:00:13 +02:00
if ( GETPOST ( 'sendit' ) && getDolGlobalString ( 'MAIN_UPLOAD_DOC' )) {
2020-10-07 15:01:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2015-01-12 13:20:27 +01:00
2020-10-07 15:01:28 +02:00
dol_add_file_process ( $upload_dir , 1 , 0 , 'userfile' );
2015-01-12 13:20:27 +01:00
}
2021-02-26 22:04:03 +01:00
if ( $action == 'updateform' ) {
2020-09-18 01:29:17 +02:00
$antivircommand = GETPOST ( 'MAIN_ANTIVIRUS_COMMAND' , 'restricthtml' ); // Use GETPOST restricthtml because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
$antivirparam = GETPOST ( 'MAIN_ANTIVIRUS_PARAM' , 'restricthtml' ); // Use GETPOST restricthtml because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
2023-06-03 10:32:41 +02:00
$antivircommand = dol_string_nospecial ( $antivircommand , '' , array ( " | " , " ; " , " < " , " > " , " & " , " + " )); // Sanitize command
$antivirparam = dol_string_nospecial ( $antivirparam , '' , array ( " | " , " ; " , " < " , " > " , " & " , " + " )); // Sanitize params
2019-11-13 19:35:02 +01:00
2023-02-11 16:07:39 +01:00
if ( $antivircommand && ! empty ( $dolibarr_main_restrict_os_commands )) {
2023-02-11 16:02:51 +01:00
$arrayofallowedcommand = explode ( ',' , $dolibarr_main_restrict_os_commands );
$arrayofallowedcommand = array_map ( 'trim' , $arrayofallowedcommand );
dol_syslog ( " Command are restricted to " . $dolibarr_main_restrict_os_commands . " . We check that one of this command is inside " . $antivircommand );
$basenamecmddump = basename ( str_replace ( '\\' , '/' , $antivircommand ));
if ( ! in_array ( $basenamecmddump , $arrayofallowedcommand )) { // the provided command $cmddump must be an allowed command
$errormsg = $langs -> trans ( 'CommandIsNotInsideAllowedCommands' );
setEventMessages ( $errormsg , null , 'errors' );
$error ++ ;
}
}
if ( ! $error ) {
2023-02-17 19:30:50 +01:00
$tmpumask = GETPOST ( 'MAIN_UMASK' , 'alpha' );
$tmpumask = ( octdec ( $tmpumask ) & 0666 );
$tmpumask = decoct ( $tmpumask );
if ( ! preg_match ( '/^0/' , $tmpumask )) {
$tmpumask = '0' . $tmpumask ;
}
2024-03-30 22:09:24 +01:00
if ( empty ( $tmpumask )) { // Also matches '0'
2023-02-17 19:30:50 +01:00
$tmpumask = '0664' ;
}
2023-02-11 16:02:51 +01:00
$res3 = dolibarr_set_const ( $db , 'MAIN_UPLOAD_DOC' , GETPOST ( 'MAIN_UPLOAD_DOC' , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
2023-02-17 19:30:50 +01:00
$res4 = dolibarr_set_const ( $db , " MAIN_UMASK " , $tmpumask , 'chaine' , 0 , '' , $conf -> entity );
2023-02-11 16:02:51 +01:00
$res5 = dolibarr_set_const ( $db , " MAIN_ANTIVIRUS_COMMAND " , trim ( $antivircommand ), 'chaine' , 0 , '' , $conf -> entity );
$res6 = dolibarr_set_const ( $db , " MAIN_ANTIVIRUS_PARAM " , trim ( $antivirparam ), 'chaine' , 0 , '' , $conf -> entity );
2024-12-12 14:40:03 +01:00
$res7 = dolibarr_set_const ( $db , " MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION " , GETPOST ( 'MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION' , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
if ( $res3 && $res4 && $res5 && $res6 && $res7 ) {
2023-02-11 16:02:51 +01:00
setEventMessages ( $langs -> trans ( " RecordModifiedSuccessfully " ), null , 'mesgs' );
}
2021-02-26 22:04:03 +01:00
}
2021-10-10 21:11:48 +02:00
} elseif ( $action == 'deletefile' ) {
2021-02-26 22:04:03 +01:00
// Delete file
2015-01-12 13:20:27 +01:00
$langs -> load ( " other " );
2021-05-17 07:27:02 +02:00
$file = $conf -> admin -> dir_temp . '/' . GETPOST ( 'urlfile' , 'alpha' );
2019-11-13 19:35:02 +01:00
$ret = dol_delete_file ( $file );
2021-02-26 22:04:03 +01:00
if ( $ret ) {
setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' , 'alpha' )), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' , 'alpha' )), null , 'errors' );
}
2015-01-12 13:20:27 +01:00
}
2017-08-18 16:10:21 +02:00
2015-01-12 13:20:27 +01:00
/*
* View
*/
$form = new Form ( $db );
2019-11-13 19:35:02 +01:00
$wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad' ;
2024-06-08 17:03:08 +02:00
llxHeader ( '' , $langs -> trans ( " Files " ), $wikihelp , '' , 0 , 0 , '' , '' , '' , 'mod-admin page-security_file' );
2015-01-12 13:20:27 +01:00
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $langs -> trans ( " SecuritySetup " ), '' , 'title_setup' );
2015-01-12 13:20:27 +01:00
2019-12-09 09:43:38 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " SecurityFilesDesc " ) . " </span><br> \n " ;
2016-04-08 14:28:49 +02:00
print " <br> \n " ;
2015-01-12 13:20:27 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2015-01-12 13:20:27 +01:00
print '<input type="hidden" name="action" value="updateform">' ;
2019-11-13 19:35:02 +01:00
$head = security_prepare_head ();
2015-01-12 13:20:27 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'file' , '' , - 1 );
2015-01-12 13:20:27 +01:00
2021-10-19 16:26:43 +02:00
print '<br>' ;
2015-01-12 13:20:27 +01:00
// Upload options
2017-09-08 10:09:22 +02:00
print '<div class="div-table-responsive-no-min">' ;
2022-09-11 12:18:43 +02:00
print '<table class="noborder centpercent nomarginbottom">' ;
2015-01-12 13:20:27 +01:00
print '<tr class="liste_titre">' ;
2022-12-12 10:25:03 +01:00
print '<td>' . $langs -> trans ( " Parameters " ) . '</td>' ;
2024-09-27 18:55:19 +02:00
print '<td></td>' ;
2015-01-12 13:20:27 +01:00
print '</tr>' ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2022-12-12 10:25:03 +01:00
print '<td>' . $langs -> trans ( " MaxSizeForUploadedFiles " ) . '.' ;
2019-11-13 19:35:02 +01:00
$max = @ ini_get ( 'upload_max_filesize' );
2021-02-26 22:04:03 +01:00
if ( isset ( $max )) {
2022-12-12 10:25:03 +01:00
print '<br><span class="opacitymedium">' . $langs -> trans ( " MustBeLowerThanPHPLimit " , (( int ) $max ) * 1024 , $langs -> trans ( " Kb " )) . '.</span>' ;
2021-02-26 22:04:03 +01:00
} else {
print ' ' . $langs -> trans ( " NoMaxSizeByPHPLimit " ) . '.' ;
}
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '<td class="nowrap">' ;
2023-12-13 15:20:53 +01:00
print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="' . dol_escape_htmltag ( getDolGlobalString ( 'MAIN_UPLOAD_DOC' )) . '"> ' . $langs -> trans ( " Kb " );
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '</tr>' ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2022-12-12 10:25:03 +01:00
print '<td>' ;
print $form -> textwithpicto ( $langs -> trans ( " UMask " ), $langs -> trans ( " UMaskExplanation " ));
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '<td class="nowrap">' ;
2023-12-13 15:20:53 +01:00
print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="' . dol_escape_htmltag ( getDolGlobalString ( 'MAIN_UMASK' )) . '">' ;
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '</tr>' ;
// Use anti virus
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2022-12-12 10:25:03 +01:00
print '<td>' . $langs -> trans ( " AntiVirusCommand " ) . '<br>' ;
2020-05-19 04:21:38 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " AntiVirusCommandExample " ) . '</span>' ;
2015-01-12 13:20:27 +01:00
// Check command in inside safe_mode
print '</td>' ;
print '<td>' ;
2023-10-24 17:00:13 +02:00
if ( ini_get ( 'safe_mode' ) && getDolGlobalString ( 'MAIN_ANTIVIRUS_COMMAND' )) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " errors " );
$basedir = preg_replace ( '/"/' , '' , dirname ( $conf -> global -> MAIN_ANTIVIRUS_COMMAND ));
$listdir = explode ( ';' , ini_get ( 'safe_mode_exec_dir' ));
2021-02-26 22:04:03 +01:00
if ( ! in_array ( $basedir , $listdir )) {
2020-10-07 15:01:28 +02:00
print img_warning ( $langs -> trans ( 'WarningSafeModeOnCheckExecDir' ));
dol_syslog ( " safe_mode is on, basedir is " . $basedir . " , safe_mode_exec_dir is " . ini_get ( 'safe_mode_exec_dir' ), LOG_WARNING );
}
2015-01-12 13:20:27 +01:00
}
2023-02-11 16:02:51 +01:00
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' )) . '">' ;
2021-10-19 12:36:33 +02:00
if ( defined ( 'MAIN_ANTIVIRUS_COMMAND' ) && ! defined ( 'MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM' )) {
2020-10-05 05:00:59 +02:00
print '<br><span class="opacitymedium">' . $langs -> trans ( " ValueIsForcedBySystem " ) . '</span>' ;
}
2015-01-12 13:20:27 +01:00
print " </td> " ;
print '</tr>' ;
// Use anti virus
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2022-12-12 10:25:03 +01:00
print '<td>' . $langs -> trans ( " AntiVirusParam " ) . '<br>' ;
2020-05-19 04:21:38 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " AntiVirusParamExample " ) . '</span>' ;
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '<td>' ;
2023-12-13 15:20:53 +01:00
print '<input type="text" ' . ( defined ( 'MAIN_ANTIVIRUS_PARAM' ) ? 'disabled ' : '' ) . 'name="MAIN_ANTIVIRUS_PARAM" class="minwidth500imp" value="' . ( getDolGlobalString ( 'MAIN_ANTIVIRUS_PARAM' ) ? dol_escape_htmltag ( getDolGlobalString ( 'MAIN_ANTIVIRUS_PARAM' )) : '' ) . '">' ;
2020-10-05 05:00:59 +02:00
if ( defined ( 'MAIN_ANTIVIRUS_PARAM' )) {
print '<br><span class="opacitymedium">' . $langs -> trans ( " ValueIsForcedBySystem " ) . '</span>' ;
}
2015-01-12 13:20:27 +01:00
print " </td> " ;
print '</tr>' ;
2024-12-12 14:40:03 +01:00
print '<tr class="oddeven">' ;
print '<td>' . $langs -> trans ( " UploadExtensionRestriction " ) . '<br>' ;
print '<span class="opacitymedium">' . $langs -> trans ( " UploadExtensionRestrictionExemple " ) . '</span>' ;
print '</td>' ;
print '<td>' ;
2024-12-13 14:52:58 +01:00
print '<input type="text" name="MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION" class="minwidth500imp" value="' . getDolGlobalString ( 'MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION' , 'htm,html,shtml,js,php' ) . '">' ;
2024-12-12 14:40:03 +01:00
print " </td> " ;
print '</tr>' ;
2015-01-12 13:20:27 +01:00
print '</table>' ;
2017-09-08 10:09:22 +02:00
print '</div>' ;
2015-01-12 13:20:27 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-01-12 13:20:27 +01:00
2021-08-24 17:04:17 +02:00
print $form -> buttonsSaveCancel ( " Modify " , '' );
2015-01-12 13:20:27 +01:00
print '</form>' ;
// Form to test upload
print '<br>' ;
2019-11-13 19:35:02 +01:00
$formfile = new FormFile ( $db );
2024-09-20 02:14:31 +02:00
$formfile -> form_attach_new_file ( $_SERVER [ 'PHP_SELF' ], $langs -> trans ( " FormToTestFileUploadForm " ), 0 , 0 , 1 , 50 , null , '' , 1 , '' , 0 );
2015-01-12 13:20:27 +01:00
// List of document
2022-03-15 12:14:46 +01:00
$filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , '' , $sortfield , $sortorder == 'desc' ? SORT_DESC : SORT_ASC , 1 );
2022-12-12 10:25:03 +01:00
if ( count ( $filearray ) > 0 ) {
$formfile -> list_of_documents ( $filearray , null , 'admin_temp' , '' );
}
2015-01-12 13:20:27 +01:00
2018-07-28 18:03:14 +02:00
// End of page
2015-01-12 13:20:27 +01:00
llxFooter ();
$db -> close ();