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 ($hashp ==
'shared') {
151if ($modulepart ==
'fckeditor') {
152 $modulepart =
'medias';
156if ($user->socid > 0) {
157 $socid = $user->socid;
161if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
162 if (!$user->hasRight(
'societe',
'client',
'voir')) {
163 $original_file =
'private/'.$user->id.
'/'.$original_file;
183 if (
GETPOST(
'type',
'alpha')==
'link') {
184 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
185 $link =
new Link($db);
186 $result = $link->fetch(0, $hashp);
187 if ($result > 0 && !empty($link->url)) {
188 header(
'Location: '.$link->url);
191 $langs->load(
"errors");
195 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
197 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
199 $tmp = explode(
'/', $ecmfile->filepath, 2);
201 if (is_numeric($tmp[0])) {
202 $tmp = explode(
'/', $tmp[1], 2);
204 $moduleparttocheck = $tmp[0];
207 if ($moduleparttocheck == $modulepart) {
209 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
215 $modulepart = $moduleparttocheck;
216 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
219 $entity = $ecmfile->entity;
220 if (isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
222 if (is_object($object) &&
$object->id > 0) {
227 if ($entity !=
$conf->entity) {
228 $conf->entity = $entity;
229 $conf->setValues($db);
232 $langs->load(
"errors");
240if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
243if (isset($_GET[
"attachment"])) {
244 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
251$type =
'application/octet-stream';
253 $type =
GETPOST(
'type',
'alpha');
261 $type =
'application/octet-stream';
265$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
266$original_file = str_replace(
'../',
'/', $original_file);
267$original_file = str_replace(
'..\\',
'/', $original_file);
270if (empty($modulepart)) {
276$accessallowed = $check_access[
'accessallowed'];
277$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
278$fullpath_original_file = $check_access[
'original_file'];
283 $sqlprotectagainstexternals =
'';
286 if ($user->socid > 0) {
287 if ($sqlprotectagainstexternals) {
288 $resql = $db->query($sqlprotectagainstexternals);
290 $num = $db->num_rows($resql);
293 $obj = $db->fetch_object($resql);
294 if ($user->socid != $obj->fk_soc) {
307if (!$accessallowed) {
313if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
314 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
315 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
322$filename = basename($fullpath_original_file);
323$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
326dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
327$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
330if (!file_exists($fullpath_original_file_osencoded)) {
331 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
332 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
337$hookmanager->initHooks(array(
'document'));
338$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
339 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
340 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
342$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
344 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
345 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
346 print
"ErrorDownloadDocumentHooks: ".$errors;
354header(
'Content-Description: File Transfer');
356 header(
'Content-Encoding: '.$encoding);
361 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
363 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
366header(
'Cache-Control: Public, must-revalidate');
367header(
'Pragma: public');
374 $readfile = !$imgres;
383 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.