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 >
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
*/
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' ;
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
2019-11-13 19:35:02 +01:00
if ( ! $user -> admin )
2015-01-12 13:20:27 +01:00
accessforbidden ();
2019-11-13 19:35:02 +01:00
$action = GETPOST ( 'action' , 'alpha' );
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
/*
* Actions
*/
2019-11-13 19:35:02 +01:00
if ( GETPOST ( 'sendit' ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
2015-01-12 13:20:27 +01:00
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_add_file_process ( $upload_dir , 0 , 0 , 'userfile' );
}
2018-04-18 12:19:23 +02:00
if ( $action == 'updateform' )
2015-01-12 13:20:27 +01:00
{
2019-11-13 19:35:02 +01:00
$antivircommand = GETPOST ( 'MAIN_ANTIVIRUS_COMMAND' , 'none' ); // Use GETPOST none because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
$antivirparam = GETPOST ( 'MAIN_ANTIVIRUS_PARAM' , 'none' ); // Use GETPOST none because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
$antivircommand = dol_string_nospecial ( $antivircommand , '' , array ( " | " , " ; " , " < " , " > " , " & " )); // Sanitize command
$antivirparam = dol_string_nospecial ( $antivirparam , '' , array ( " | " , " ; " , " < " , " > " , " & " )); // Sanitize params
$res3 = dolibarr_set_const ( $db , 'MAIN_UPLOAD_DOC' , GETPOST ( 'MAIN_UPLOAD_DOC' , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
$res4 = dolibarr_set_const ( $db , " MAIN_UMASK " , GETPOST ( 'MAIN_UMASK' , 'alpha' ), 'chaine' , 0 , '' , $conf -> entity );
$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 );
2015-10-29 13:58:16 +01:00
if ( $res3 && $res4 && $res5 && $res6 ) setEventMessages ( $langs -> trans ( " RecordModifiedSuccessfully " ), null , 'mesgs' );
2015-01-12 13:20:27 +01:00
}
// Delete file
2019-01-27 10:49:34 +01:00
elseif ( $action == 'delete' )
2015-01-12 13:20:27 +01:00
{
$langs -> load ( " other " );
2019-11-13 19:35:02 +01:00
$file = $conf -> admin -> dir_temp . '/' . GETPOST ( 'urlfile' , 'alpha' ); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret = dol_delete_file ( $file );
2019-01-27 11:55:16 +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
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ]);
exit ;
}
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' ;
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " Files " ), $wikihelp );
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
2017-03-23 10:59:13 +01:00
dol_fiche_head ( $head , 'file' , $langs -> trans ( " Security " ), - 1 );
2015-01-12 13:20:27 +01:00
// Upload options
2019-11-13 19:35:02 +01:00
$var = false ;
2015-01-12 13:20:27 +01:00
2017-09-08 10:09:22 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2015-01-12 13:20:27 +01:00
print '<tr class="liste_titre">' ;
print '<td colspan="2">' . $langs -> trans ( " Parameters " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Value " ) . '</td>' ;
print '</tr>' ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-12 13:20:27 +01:00
print '<td colspan="2">' . $langs -> trans ( " MaxSizeForUploadedFiles " ) . '.' ;
2019-11-13 19:35:02 +01:00
$max = @ ini_get ( 'upload_max_filesize' );
if ( $max ) print ' ' . $langs -> trans ( " MustBeLowerThanPHPLimit " , $max * 1024 , $langs -> trans ( " Kb " )) . '.' ;
2015-01-12 13:20:27 +01:00
else print ' ' . $langs -> trans ( " NoMaxSizeByPHPLimit " ) . '.' ;
print '</td>' ;
print '<td class="nowrap">' ;
print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="' . htmlentities ( $conf -> global -> MAIN_UPLOAD_DOC ) . '"> ' . $langs -> trans ( " Kb " );
print '</td>' ;
print '</tr>' ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2019-01-22 11:56:09 +01:00
print '<td>' . $langs -> trans ( " UMask " ) . '</td><td class="right">' ;
2019-01-27 11:55:16 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " UMaskExplanation " ));
2015-01-12 13:20:27 +01:00
print '</td>' ;
print '<td class="nowrap">' ;
print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="' . htmlentities ( $conf -> global -> MAIN_UMASK ) . '">' ;
print '</td>' ;
print '</tr>' ;
// Use anti virus
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2015-01-12 13:20:27 +01:00
print '<td colspan="2">' . $langs -> trans ( " AntiVirusCommand " ) . '<br>' ;
print $langs -> trans ( " AntiVirusCommandExample " );
// Check command in inside safe_mode
print '</td>' ;
print '<td>' ;
2019-11-13 19:35:02 +01:00
if ( ini_get ( 'safe_mode' ) && ! empty ( $conf -> global -> MAIN_ANTIVIRUS_COMMAND ))
2015-01-12 13:20:27 +01:00
{
$langs -> load ( " errors " );
2019-11-13 19:35:02 +01:00
$basedir = preg_replace ( '/"/' , '' , dirname ( $conf -> global -> MAIN_ANTIVIRUS_COMMAND ));
$listdir = explode ( ';' , ini_get ( 'safe_mode_exec_dir' ));
if ( ! in_array ( $basedir , $listdir ))
2015-01-12 13:20:27 +01: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 );
}
}
2019-11-13 19:35:02 +01:00
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 ) : '' ) . '">' ;
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">' ;
2015-01-12 13:20:27 +01:00
print '<td colspan="2">' . $langs -> trans ( " AntiVirusParam " ) . '<br>' ;
print $langs -> trans ( " AntiVirusParamExample " );
print '</td>' ;
print '<td>' ;
2019-11-13 19:35:02 +01:00
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 ) : '' ) . '">' ;
2015-01-12 13:20:27 +01:00
print " </td> " ;
print '</tr>' ;
print '</table>' ;
2017-09-08 10:09:22 +02:00
print '</div>' ;
2015-01-12 13:20:27 +01:00
dol_fiche_end ();
print '<div class="center"><input type="submit" class="button" name="button" value="' . $langs -> trans ( " Modify " ) . '"></div>' ;
print '</form>' ;
// Form to test upload
print '<br>' ;
2019-11-13 19:35:02 +01:00
$formfile = new FormFile ( $db );
2015-01-12 13:20:27 +01:00
$formfile -> form_attach_new_file ( $_SERVER [ 'PHP_SELF' ], $langs -> trans ( " FormToTestFileUploadForm " ), 0 , 0 , 1 , 50 , '' , '' , 1 , '' , 0 );
// List of document
2019-11-13 19:35:02 +01:00
$filearray = dol_dir_list ( $upload_dir , " files " , 0 , '' , '' , 'name' , SORT_ASC , 1 );
2015-03-06 01:53:02 +01:00
$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 ();