dolibarr 19.0.3
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
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30require_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');
38if (empty($sortfield)) {
39 $sortfield = 'date';
40}
41if (empty($sortorder)) {
42 $sortorder = 'desc';
43}
44
45$upload_dir = $conf->admin->dir_temp;
46
47if (!$user->admin) {
49}
50
51$error = 0;
52
53
54/*
55 * Actions
56 */
57
58if (GETPOST('sendit') && getDolGlobalString('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
64if ($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';
121llxHeader('', $langs->trans("Files"), $wikihelp);
122
123print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
124
125print '<span class="opacitymedium">'.$langs->trans("SecurityFilesDesc")."</span><br>\n";
126print "<br>\n";
127
128
129print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
130print '<input type="hidden" name="token" value="'.newToken().'">';
131print '<input type="hidden" name="action" value="updateform">';
132
133$head = security_prepare_head();
134
135print dol_get_fiche_head($head, 'file', '', -1);
136
137print '<br>';
138
139// Upload options
140
141print '<div class="div-table-responsive-no-min">';
142print '<table class="noborder centpercent nomarginbottom">';
143print '<tr class="liste_titre">';
144print '<td>'.$langs->trans("Parameters").'</td>';
145print '<td>'.$langs->trans("Value").'</td>';
146print '</tr>';
147
148print '<tr class="oddeven">';
149print '<td>'.$langs->trans("MaxSizeForUploadedFiles").'.';
150$max = @ini_get('upload_max_filesize');
151if (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}
156print '</td>';
157print '<td class="nowrap">';
158print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.dol_escape_htmltag(getDolGlobalString('MAIN_UPLOAD_DOC')).'"> '.$langs->trans("Kb");
159print '</td>';
160print '</tr>';
161
162
163print '<tr class="oddeven">';
164print '<td>';
165print $form->textwithpicto($langs->trans("UMask"), $langs->trans("UMaskExplanation"));
166print '</td>';
167print '<td class="nowrap">';
168print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.dol_escape_htmltag(getDolGlobalString('MAIN_UMASK')).'">';
169print '</td>';
170print '</tr>';
171
172// Use anti virus
173
174print '<tr class="oddeven">';
175print '<td>'.$langs->trans("AntiVirusCommand").'<br>';
176print '<span class="opacitymedium">'.$langs->trans("AntiVirusCommandExample").'</span>';
177// Check command in inside safe_mode
178print '</td>';
179print '<td>';
180if (ini_get('safe_mode') && getDolGlobalString('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}
189print '<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')).'">';
190if (defined('MAIN_ANTIVIRUS_COMMAND') && !defined('MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM')) {
191 print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
192}
193print "</td>";
194print '</tr>';
195
196// Use anti virus
197
198print '<tr class="oddeven">';
199print '<td>'.$langs->trans("AntiVirusParam").'<br>';
200print '<span class="opacitymedium">'.$langs->trans("AntiVirusParamExample").'</span>';
201print '</td>';
202print '<td>';
203print '<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')) : '').'">';
204if (defined('MAIN_ANTIVIRUS_PARAM')) {
205 print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
206}
207print "</td>";
208print '</tr>';
209
210print '</table>';
211print '</div>';
212
213print dol_get_fiche_end();
214
215print $form->buttonsSaveCancel("Modify", '');
216
217print '</form>';
218
219
220// Form to test upload
221print '<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);
227if (count($filearray) > 0) {
228 $formfile->list_of_documents($filearray, null, 'admin_temp', '');
229}
230
231// End of page
232llxFooter();
233$db->close();
security_prepare_head()
Prepare array with list of tabs.
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).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
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.
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).
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.
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.