dolibarr  16.0.5
security_file.php
Go to the documentation of this file.
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 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('users', 'admin', 'other'));
33 
34 if (!$user->admin) {
36 }
37 
38 $action = GETPOST('action', 'aZ09');
39 $sortfield = GETPOST('sortfield', 'aZ09');
40 $sortorder = GETPOST('sortorder', 'aZ09');
41 if (empty($sortfield)) {
42  $sortfield = 'date';
43 }
44 if (empty($sortorder)) {
45  $sortorder = 'desc';
46 }
47 
48 $upload_dir = $conf->admin->dir_temp;
49 
50 
51 /*
52  * Actions
53  */
54 
55 if (GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
56  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
57 
58  dol_add_file_process($upload_dir, 1, 0, 'userfile');
59 }
60 
61 if ($action == 'updateform') {
62  $antivircommand = GETPOST('MAIN_ANTIVIRUS_COMMAND', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
63  $antivirparam = GETPOST('MAIN_ANTIVIRUS_PARAM', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
64  $antivircommand = dol_string_nospecial($antivircommand, '', array("|", ";", "<", ">", "&")); // Sanitize command
65  $antivirparam = dol_string_nospecial($antivirparam, '', array("|", ";", "<", ">", "&")); // Sanitize params
66 
67  $res3 = dolibarr_set_const($db, 'MAIN_UPLOAD_DOC', GETPOST('MAIN_UPLOAD_DOC', 'alpha'), 'chaine', 0, '', $conf->entity);
68  $res4 = dolibarr_set_const($db, "MAIN_UMASK", GETPOST('MAIN_UMASK', 'alpha'), 'chaine', 0, '', $conf->entity);
69  $res5 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", trim($antivircommand), 'chaine', 0, '', $conf->entity);
70  $res6 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", trim($antivirparam), 'chaine', 0, '', $conf->entity);
71  if ($res3 && $res4 && $res5 && $res6) {
72  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
73  }
74 } elseif ($action == 'deletefile') {
75  // Delete file
76  $langs->load("other");
77  $file = $conf->admin->dir_temp.'/'.GETPOST('urlfile', 'alpha');
78  $ret = dol_delete_file($file);
79  if ($ret) {
80  setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile', 'alpha')), null, 'mesgs');
81  } else {
82  setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile', 'alpha')), null, 'errors');
83  }
84 }
85 
86 
87 /*
88  * View
89  */
90 
91 $form = new Form($db);
92 
93 $wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
94 llxHeader('', $langs->trans("Files"), $wikihelp);
95 
96 print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
97 
98 print '<span class="opacitymedium">'.$langs->trans("SecurityFilesDesc")."</span><br>\n";
99 print "<br>\n";
100 
101 
102 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
103 print '<input type="hidden" name="token" value="'.newToken().'">';
104 print '<input type="hidden" name="action" value="updateform">';
105 
106 $head = security_prepare_head();
107 
108 print dol_get_fiche_head($head, 'file', '', -1);
109 
110 print '<br>';
111 
112 // Upload options
113 
114 print '<div class="div-table-responsive-no-min">';
115 print '<table class="noborder centpercent">';
116 print '<tr class="liste_titre">';
117 print '<td colspan="2">'.$langs->trans("Parameters").'</td>';
118 print '<td>'.$langs->trans("Value").'</td>';
119 print '</tr>';
120 
121 print '<tr class="oddeven">';
122 print '<td colspan="2">'.$langs->trans("MaxSizeForUploadedFiles").'.';
123 $max = @ini_get('upload_max_filesize');
124 if (isset($max)) {
125  print ' '.$langs->trans("MustBeLowerThanPHPLimit", ((int) $max) * 1024, $langs->trans("Kb")).'.';
126 } else {
127  print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
128 }
129 print '</td>';
130 print '<td class="nowrap">';
131 print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
132 print '</td>';
133 print '</tr>';
134 
135 
136 print '<tr class="oddeven">';
137 print '<td>'.$langs->trans("UMask").'</td><td class="right">';
138 print $form->textwithpicto('', $langs->trans("UMaskExplanation"));
139 print '</td>';
140 print '<td class="nowrap">';
141 print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UMASK).'">';
142 print '</td>';
143 print '</tr>';
144 
145 // Use anti virus
146 
147 print '<tr class="oddeven">';
148 print '<td colspan="2">'.$langs->trans("AntiVirusCommand").'<br>';
149 print '<span class="opacitymedium">'.$langs->trans("AntiVirusCommandExample").'</span>';
150 // Check command in inside safe_mode
151 print '</td>';
152 print '<td>';
153 if (ini_get('safe_mode') && !empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
154  $langs->load("errors");
155  $basedir = preg_replace('/"/', '', dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
156  $listdir = explode(';', ini_get('safe_mode_exec_dir'));
157  if (!in_array($basedir, $listdir)) {
158  print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
159  dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
160  }
161 }
162 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) : '').'">';
163 if (defined('MAIN_ANTIVIRUS_COMMAND') && !defined('MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM')) {
164  print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
165 }
166 print "</td>";
167 print '</tr>';
168 
169 // Use anti virus
170 
171 print '<tr class="oddeven">';
172 print '<td colspan="2">'.$langs->trans("AntiVirusParam").'<br>';
173 print '<span class="opacitymedium">'.$langs->trans("AntiVirusParamExample").'</span>';
174 print '</td>';
175 print '<td>';
176 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) : '').'">';
177 if (defined('MAIN_ANTIVIRUS_PARAM')) {
178  print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
179 }
180 print "</td>";
181 print '</tr>';
182 
183 print '</table>';
184 print '</div>';
185 
186 print dol_get_fiche_end();
187 
188 print $form->buttonsSaveCancel("Modify", '');
189 
190 print '</form>';
191 
192 
193 // Form to test upload
194 print '<br>';
195 $formfile = new FormFile($db);
196 $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
197 
198 // List of document
199 $filearray = dol_dir_list($upload_dir, "files", 0, '', '', $sortfield, $sortorder == 'desc' ? SORT_DESC : SORT_ASC, 1);
200 $formfile->list_of_documents($filearray, null, 'admin_temp', '');
201 
202 // End of page
203 llxFooter();
204 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
security_prepare_head
security_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:772
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_add_file_process
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
Definition: files.lib.php:1634
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_delete_file
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1231
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dol_string_nospecial
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
Definition: functions.lib.php:1376
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59