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);
77} elseif (isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'ticket' && strpos($_SERVER[
'HTTP_REFERER'],
'public/ticket') !==
false) {
78 if (!defined(
"NOLOGIN")) {
81 if (!defined(
"NOCSRFCHECK")) {
82 define(
"NOCSRFCHECK", 1);
84 if (!defined(
"NOIPCHECK")) {
85 define(
"NOIPCHECK", 1);
112function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
127function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
131require
'main.inc.php';
139require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
140require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
143$action =
GETPOST(
'action',
'aZ09');
144$original_file =
GETPOST(
'file',
'alphanohtml');
145$hashp =
GETPOST(
'hashp',
'aZ09');
146$modulepart =
GETPOST(
'modulepart',
'alpha');
147$urlsource =
GETPOST(
'urlsource',
'alpha');
148$entity = GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') : $conf->entity;
151if (empty($modulepart) && empty($hashp)) {
154if (empty($original_file) && empty($hashp)) {
157if ($modulepart ==
'fckeditor') {
158 $modulepart =
'medias';
162if ($user->socid > 0) {
163 $socid = $user->socid;
167if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
168 if (!$user->hasRight(
'societe',
'client',
'voir')) {
169 $original_file =
'private/'.$user->id.
'/'.$original_file;
189 if (
GETPOST(
'type',
'alpha')==
'link') {
190 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
191 $link =
new Link($db);
192 $result = $link->fetch(0, $hashp);
193 if ($result > 0 && !empty($link->url)) {
194 header(
'Location: '.$link->url);
197 $langs->load(
"errors");
201 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
203 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
205 $tmp = explode(
'/', $ecmfile->filepath, 2);
207 if (is_numeric($tmp[0])) {
208 $tmp = explode(
'/', $tmp[1], 2);
210 $moduleparttocheck = $tmp[0];
213 if ($moduleparttocheck == $modulepart) {
215 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
221 $modulepart = $moduleparttocheck;
222 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
225 $entity = $ecmfile->entity;
226 if (
isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
227 $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type);
228 if (is_object($object) &&
$object->id > 0) {
233 if ($entity != $conf->entity) {
234 $conf->entity = $entity;
235 $conf->setValues($db);
238 $langs->load(
"errors");
246if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
249if (isset($_GET[
"attachment"])) {
250 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
257$type =
'application/octet-stream';
259 $type =
GETPOST(
'type',
'alpha');
267 $type =
'application/octet-stream';
271$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
272$original_file = str_replace(
'../',
'/', $original_file);
273$original_file = str_replace(
'..\\',
'/', $original_file);
276if (empty($modulepart)) {
282$accessallowed = $check_access[
'accessallowed'];
283$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
284$fullpath_original_file = $check_access[
'original_file'];
289 $sqlprotectagainstexternals =
'';
292 if ($user->socid > 0) {
293 if ($sqlprotectagainstexternals) {
294 $resql = $db->query($sqlprotectagainstexternals);
296 $num = $db->num_rows($resql);
299 $obj = $db->fetch_object($resql);
300 if ($user->socid != $obj->fk_soc) {
308 } elseif ($modulepart ==
'ticket' && !
getDolGlobalString(
'TICKET_EMAIL_MUST_EXISTS')) {
309 if ($sqlprotectagainstexternals) {
310 $resql = $db->query($sqlprotectagainstexternals);
312 $num = $db->num_rows($resql);
323if (!$accessallowed) {
329if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
330 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
331 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
338$filename = basename($fullpath_original_file);
339$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
342dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
343$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
346if (!file_exists($fullpath_original_file_osencoded)) {
347 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
348 print $langs->trans(
"ErrorFileDoesNotExists") .
' : ' .
dol_escape_htmltag($original_file);
353$hookmanager->initHooks(array(
'document'));
354$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
355 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
356 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
358$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
360 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
361 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
362 print
"ErrorDownloadDocumentHooks: ".$errors;
370header(
'Content-Description: File Transfer');
372 header(
'Content-Encoding: '.$encoding);
377 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
379 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
382header(
'Cache-Control: Public, must-revalidate');
383header(
'Pragma: public');
390 $readfile = !$imgres;
399 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
if(! $sortfield) if(! $sortorder) $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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
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.
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.