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