dolibarr  17.0.4
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 if (!$user->admin) {
37 }
38 
39 $action = GETPOST('action', 'aZ09');
40 $sortfield = GETPOST('sortfield', 'aZ09');
41 $sortorder = GETPOST('sortorder', 'aZ09');
42 if (empty($sortfield)) {
43  $sortfield = 'date';
44 }
45 if (empty($sortorder)) {
46  $sortorder = 'desc';
47 }
48 
49 $upload_dir = $conf->admin->dir_temp;
50 
51 
52 /*
53  * Actions
54  */
55 
56 if (GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
57  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
58 
59  dol_add_file_process($upload_dir, 1, 0, 'userfile');
60 }
61 
62 if ($action == 'updateform') {
63  $antivircommand = GETPOST('MAIN_ANTIVIRUS_COMMAND', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example c:\Progra~1\ClamWin\bin\clamscan.exe
64  $antivirparam = GETPOST('MAIN_ANTIVIRUS_PARAM', 'restricthtml'); // Use GETPOST restricthtml because we must accept ". Example --database="C:\Program Files (x86)\ClamWin\lib"
65  $antivircommand = dol_string_nospecial($antivircommand, '', array("|", ";", "<", ">", "&", "+")); // Sanitize command
66  $antivirparam = dol_string_nospecial($antivirparam, '', array("|", ";", "<", ">", "&", "+")); // Sanitize params
67 
68  $res3 = dolibarr_set_const($db, 'MAIN_UPLOAD_DOC', GETPOST('MAIN_UPLOAD_DOC', 'alpha'), 'chaine', 0, '', $conf->entity);
69  $res4 = dolibarr_set_const($db, "MAIN_UMASK", GETPOST('MAIN_UMASK', 'alpha'), 'chaine', 0, '', $conf->entity);
70  $res5 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_COMMAND", trim($antivircommand), 'chaine', 0, '', $conf->entity);
71  $res6 = dolibarr_set_const($db, "MAIN_ANTIVIRUS_PARAM", trim($antivirparam), 'chaine', 0, '', $conf->entity);
72  if ($res3 && $res4 && $res5 && $res6) {
73  setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
74  }
75 } elseif ($action == 'deletefile') {
76  // Delete file
77  $langs->load("other");
78  $file = $conf->admin->dir_temp.'/'.GETPOST('urlfile', 'alpha');
79  $ret = dol_delete_file($file);
80  if ($ret) {
81  setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile', 'alpha')), null, 'mesgs');
82  } else {
83  setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile', 'alpha')), null, 'errors');
84  }
85 }
86 
87 
88 /*
89  * View
90  */
91 
92 $form = new Form($db);
93 
94 $wikihelp = 'EN:Setup_Security|FR:Paramétrage_Sécurité|ES:Configuración_Seguridad';
95 llxHeader('', $langs->trans("Files"), $wikihelp);
96 
97 print load_fiche_titre($langs->trans("SecuritySetup"), '', 'title_setup');
98 
99 print '<span class="opacitymedium">'.$langs->trans("SecurityFilesDesc")."</span><br>\n";
100 print "<br>\n";
101 
102 
103 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
104 print '<input type="hidden" name="token" value="'.newToken().'">';
105 print '<input type="hidden" name="action" value="updateform">';
106 
107 $head = security_prepare_head();
108 
109 print dol_get_fiche_head($head, 'file', '', -1);
110 
111 print '<br>';
112 
113 // Upload options
114 
115 print '<div class="div-table-responsive-no-min">';
116 print '<table class="noborder centpercent nomarginbottom">';
117 print '<tr class="liste_titre">';
118 print '<td>'.$langs->trans("Parameters").'</td>';
119 print '<td>'.$langs->trans("Value").'</td>';
120 print '</tr>';
121 
122 print '<tr class="oddeven">';
123 print '<td>'.$langs->trans("MaxSizeForUploadedFiles").'.';
124 $max = @ini_get('upload_max_filesize');
125 if (isset($max)) {
126  print '<br><span class="opacitymedium">'.$langs->trans("MustBeLowerThanPHPLimit", ((int) $max) * 1024, $langs->trans("Kb")).'.</span>';
127 } else {
128  print ' '.$langs->trans("NoMaxSizeByPHPLimit").'.';
129 }
130 print '</td>';
131 print '<td class="nowrap">';
132 print '<input class="flat" name="MAIN_UPLOAD_DOC" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UPLOAD_DOC).'"> '.$langs->trans("Kb");
133 print '</td>';
134 print '</tr>';
135 
136 
137 print '<tr class="oddeven">';
138 print '<td>';
139 print $form->textwithpicto($langs->trans("UMask"), $langs->trans("UMaskExplanation"));
140 print '</td>';
141 print '<td class="nowrap">';
142 print '<input class="flat" name="MAIN_UMASK" type="text" size="6" value="'.dol_escape_htmltag($conf->global->MAIN_UMASK).'">';
143 print '</td>';
144 print '</tr>';
145 
146 // Use anti virus
147 
148 print '<tr class="oddeven">';
149 print '<td>'.$langs->trans("AntiVirusCommand").'<br>';
150 print '<span class="opacitymedium">'.$langs->trans("AntiVirusCommandExample").'</span>';
151 // Check command in inside safe_mode
152 print '</td>';
153 print '<td>';
154 if (ini_get('safe_mode') && !empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
155  $langs->load("errors");
156  $basedir = preg_replace('/"/', '', dirname($conf->global->MAIN_ANTIVIRUS_COMMAND));
157  $listdir = explode(';', ini_get('safe_mode_exec_dir'));
158  if (!in_array($basedir, $listdir)) {
159  print img_warning($langs->trans('WarningSafeModeOnCheckExecDir'));
160  dol_syslog("safe_mode is on, basedir is ".$basedir.", safe_mode_exec_dir is ".ini_get('safe_mode_exec_dir'), LOG_WARNING);
161  }
162 }
163 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) : '').'">';
164 if (defined('MAIN_ANTIVIRUS_COMMAND') && !defined('MAIN_ANTIVIRUS_BYPASS_COMMAND_AND_PARAM')) {
165  print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
166 }
167 print "</td>";
168 print '</tr>';
169 
170 // Use anti virus
171 
172 print '<tr class="oddeven">';
173 print '<td>'.$langs->trans("AntiVirusParam").'<br>';
174 print '<span class="opacitymedium">'.$langs->trans("AntiVirusParamExample").'</span>';
175 print '</td>';
176 print '<td>';
177 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) : '').'">';
178 if (defined('MAIN_ANTIVIRUS_PARAM')) {
179  print '<br><span class="opacitymedium">'.$langs->trans("ValueIsForcedBySystem").'</span>';
180 }
181 print "</td>";
182 print '</tr>';
183 
184 print '</table>';
185 print '</div>';
186 
187 print dol_get_fiche_end();
188 
189 print $form->buttonsSaveCancel("Modify", '');
190 
191 print '</form>';
192 
193 
194 // Form to test upload
195 print '<br>';
196 $formfile = new FormFile($db);
197 $formfile->form_attach_new_file($_SERVER['PHP_SELF'], $langs->trans("FormToTestFileUploadForm"), 0, 0, 1, 50, '', '', 1, '', 0);
198 
199 // List of document
200 $filearray = dol_dir_list($upload_dir, "files", 0, '', '', $sortfield, $sortorder == 'desc' ? SORT_DESC : SORT_ASC, 1);
201 if (count($filearray) > 0) {
202  $formfile->list_of_documents($filearray, null, 'admin_temp', '');
203 }
204 
205 // End of page
206 llxFooter();
207 $db->close();
security_prepare_head()
Prepare array with list of tabs.
Definition: admin.lib.php:788
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:632
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:1251
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:61
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:1653
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.