36define(
'MAIN_SECURITY_FORCECSP',
"default-src: 'none'");
40if (!defined(
'NOTOKENRENEWAL')) {
41 define(
'NOTOKENRENEWAL',
'1');
43if (!defined(
'NOREQUIREMENU')) {
44 define(
'NOREQUIREMENU',
'1');
46if (!defined(
'NOREQUIREHTML')) {
47 define(
'NOREQUIREHTML',
'1');
49if (!defined(
'NOREQUIREAJAX')) {
50 define(
'NOREQUIREAJAX',
'1');
54if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN")) {
55 if (!defined(
"NOLOGIN")) {
58 if (!defined(
"NOCSRFCHECK")) {
59 define(
"NOCSRFCHECK", 1);
61 if (!defined(
"NOIPCHECK")) {
62 define(
"NOIPCHECK", 1);
67if ((isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias')) {
68 if (!defined(
"NOLOGIN")) {
71 if (!defined(
"NOCSRFCHECK")) {
72 define(
"NOCSRFCHECK", 1);
74 if (!defined(
"NOIPCHECK")) {
75 define(
"NOIPCHECK", 1);
102function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
117function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
121require
'main.inc.php';
122require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
123require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
134$action =
GETPOST(
'action',
'aZ09');
135$original_file =
GETPOST(
'file',
'alphanohtml');
136$hashp =
GETPOST(
'hashp',
'aZ09');
137$modulepart =
GETPOST(
'modulepart',
'alpha');
138$urlsource =
GETPOST(
'urlsource',
'alpha');
139$entity = GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') :
$conf->entity;
142if (empty($modulepart) && empty($hashp)) {
145if (empty($original_file) && empty($hashp)) {
148if ($modulepart ==
'fckeditor') {
149 $modulepart =
'medias';
153if ($user->socid > 0) {
154 $socid = $user->socid;
158if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
159 if (!$user->hasRight(
'societe',
'client',
'voir')) {
160 $original_file =
'private/'.$user->id.
'/'.$original_file;
180 if (
GETPOST(
'type',
'alpha')==
'link') {
181 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
182 $link =
new Link($db);
183 $result = $link->fetch(0, $hashp);
184 if ($result > 0 && !empty($link->url)) {
185 header(
'Location: '.$link->url);
188 $langs->load(
"errors");
192 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
194 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
196 $tmp = explode(
'/', $ecmfile->filepath, 2);
198 if (is_numeric($tmp[0])) {
199 $tmp = explode(
'/', $tmp[1], 2);
201 $moduleparttocheck = $tmp[0];
204 if ($moduleparttocheck == $modulepart) {
206 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
212 $modulepart = $moduleparttocheck;
213 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
216 $entity = $ecmfile->entity;
217 if (isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
219 if (is_object($object) &&
$object->id > 0) {
224 if ($entity !=
$conf->entity) {
225 $conf->entity = $entity;
226 $conf->setValues($db);
229 $langs->load(
"errors");
237if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
240if (isset($_GET[
"attachment"])) {
241 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
248$type =
'application/octet-stream';
250 $type =
GETPOST(
'type',
'alpha');
258 $type =
'application/octet-stream';
262$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
263$original_file = str_replace(
'../',
'/', $original_file);
264$original_file = str_replace(
'..\\',
'/', $original_file);
267if (empty($modulepart)) {
273$accessallowed = $check_access[
'accessallowed'];
274$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
275$fullpath_original_file = $check_access[
'original_file'];
280 $sqlprotectagainstexternals =
'';
283 if ($user->socid > 0) {
284 if ($sqlprotectagainstexternals) {
285 $resql = $db->query($sqlprotectagainstexternals);
287 $num = $db->num_rows($resql);
290 $obj = $db->fetch_object($resql);
291 if ($user->socid != $obj->fk_soc) {
304if (!$accessallowed) {
310if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
311 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
312 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
319$filename = basename($fullpath_original_file);
320$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
323dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
324$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
327if (!file_exists($fullpath_original_file_osencoded)) {
328 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
329 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
334$hookmanager->initHooks(array(
'document'));
335$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
336 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
337 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
339$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
341 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
342 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
343 print
"ErrorDownloadDocumentHooks: ".$errors;
351header(
'Content-Description: File Transfer');
353 header(
'Content-Encoding: '.$encoding);
358 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
360 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
363header(
'Cache-Control: Public, must-revalidate');
364header(
'Pragma: public');
371 $readfile = !$imgres;
380 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
fetchObjectByElement($element_id, $element_type, $element_ref='', $useCache=0, $maxCacheByType=10)
Fetch an object from its id and element_type Inclusion of classes is automatic.
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.