35define(
'MAIN_SECURITY_FORCECSP',
"default-src: 'none'");
39if (!defined(
'NOTOKENRENEWAL')) {
40 define(
'NOTOKENRENEWAL',
'1');
42if (!defined(
'NOREQUIREMENU')) {
43 define(
'NOREQUIREMENU',
'1');
45if (!defined(
'NOREQUIREHTML')) {
46 define(
'NOREQUIREHTML',
'1');
48if (!defined(
'NOREQUIREAJAX')) {
49 define(
'NOREQUIREAJAX',
'1');
53if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN")) {
54 if (!defined(
"NOLOGIN")) {
57 if (!defined(
"NOCSRFCHECK")) {
58 define(
"NOCSRFCHECK", 1);
60 if (!defined(
"NOIPCHECK")) {
61 define(
"NOIPCHECK", 1);
66if ((isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias')) {
67 if (!defined(
"NOLOGIN")) {
70 if (!defined(
"NOCSRFCHECK")) {
71 define(
"NOCSRFCHECK", 1);
73 if (!defined(
"NOIPCHECK")) {
74 define(
"NOIPCHECK", 1);
98function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
111require
'main.inc.php';
112require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
113require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
124$action =
GETPOST(
'action',
'aZ09');
125$original_file =
GETPOST(
'file',
'alphanohtml');
126$hashp =
GETPOST(
'hashp',
'aZ09');
127$modulepart =
GETPOST(
'modulepart',
'alpha');
128$urlsource =
GETPOST(
'urlsource',
'alpha');
132if (empty($modulepart) && empty($hashp)) {
135if (empty($original_file) && empty($hashp)) {
138if ($modulepart ==
'fckeditor') {
139 $modulepart =
'medias';
143if ($user->socid > 0) {
144 $socid = $user->socid;
148if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
149 if (!$user->hasRight(
'societe',
'client',
'voir')) {
150 $original_file =
'private/'.$user->id.
'/'.$original_file;
170 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
172 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
174 $tmp = explode(
'/', $ecmfile->filepath, 2);
176 if (is_numeric($tmp[0])) {
177 $tmp = explode(
'/', $tmp[1], 2);
179 $moduleparttocheck = $tmp[0];
182 if ($moduleparttocheck == $modulepart) {
184 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
190 $modulepart = $moduleparttocheck;
191 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
193 $entity = $ecmfile->entity;
194 if ($entity !=
$conf->entity) {
195 $conf->entity = $entity;
196 $conf->setValues($db);
199 $langs->load(
"errors");
206if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
209if (isset($_GET[
"attachment"])) {
210 $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
217$type =
'application/octet-stream';
219 $type =
GETPOST(
'type',
'alpha');
227 $type =
'application/octet-stream';
231$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
232$original_file = str_replace(
'../',
'/', $original_file);
233$original_file = str_replace(
'..\\',
'/', $original_file);
237if (empty($modulepart)) {
243$accessallowed = $check_access[
'accessallowed'];
244$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
245$fullpath_original_file = $check_access[
'original_file'];
250 $sqlprotectagainstexternals =
'';
253 if ($user->socid > 0) {
254 if ($sqlprotectagainstexternals) {
255 $resql = $db->query($sqlprotectagainstexternals);
257 $num = $db->num_rows($resql);
260 $obj = $db->fetch_object($resql);
261 if ($user->socid != $obj->fk_soc) {
274if (!$accessallowed) {
280if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
281 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
282 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
289$filename = basename($fullpath_original_file);
290$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
293dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
294$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
297if (!file_exists($fullpath_original_file_osencoded)) {
298 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
299 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
304$hookmanager->initHooks(array(
'document'));
305$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
306 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
307 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
309$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
311 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
312 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
313 print
"ErrorDownloadDocumentHooks: ".$errors;
321header(
'Content-Description: File Transfer');
323 header(
'Content-Encoding: '.$encoding);
328 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
330 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
333header(
'Cache-Control: Public, must-revalidate');
334header(
'Pragma: public');
341 $readfile = !$imgres;
350 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage ECM files.
dol_filesize($pathoffile)
Return size of a file.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
correctExifImageOrientation($fileSource, $fileDest, $quality=95)
Add exif orientation correction for image.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.