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)
110function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
114require
'main.inc.php';
115require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
116require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
127$action =
GETPOST(
'action',
'aZ09');
128$original_file =
GETPOST(
'file',
'alphanohtml');
129$hashp =
GETPOST(
'hashp',
'aZ09');
130$modulepart =
GETPOST(
'modulepart',
'alpha');
131$urlsource =
GETPOST(
'urlsource',
'alpha');
135if (empty($modulepart) && empty($hashp)) {
138if (empty($original_file) && empty($hashp)) {
141if ($modulepart ==
'fckeditor') {
142 $modulepart =
'medias';
146if ($user->socid > 0) {
147 $socid = $user->socid;
151if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
152 if (!$user->hasRight(
'societe',
'client',
'voir')) {
153 $original_file =
'private/'.$user->id.
'/'.$original_file;
173 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
175 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
177 $tmp = explode(
'/', $ecmfile->filepath, 2);
179 if (is_numeric($tmp[0])) {
180 $tmp = explode(
'/', $tmp[1], 2);
182 $moduleparttocheck = $tmp[0];
185 if ($moduleparttocheck == $modulepart) {
187 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
193 $modulepart = $moduleparttocheck;
194 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
196 $entity = $ecmfile->entity;
197 if ($entity !=
$conf->entity) {
198 $conf->entity = $entity;
199 $conf->setValues($db);
202 $langs->load(
"errors");
209if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
212if (isset($_GET[
"attachment"])) {
213 $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
220$type =
'application/octet-stream';
222 $type =
GETPOST(
'type',
'alpha');
230 $type =
'application/octet-stream';
234$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
235$original_file = str_replace(
'../',
'/', $original_file);
236$original_file = str_replace(
'..\\',
'/', $original_file);
240if (empty($modulepart)) {
246$accessallowed = $check_access[
'accessallowed'];
247$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
248$fullpath_original_file = $check_access[
'original_file'];
253 $sqlprotectagainstexternals =
'';
256 if ($user->socid > 0) {
257 if ($sqlprotectagainstexternals) {
258 $resql = $db->query($sqlprotectagainstexternals);
260 $num = $db->num_rows($resql);
263 $obj = $db->fetch_object($resql);
264 if ($user->socid != $obj->fk_soc) {
277if (!$accessallowed) {
283if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
284 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
285 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
292$filename = basename($fullpath_original_file);
293$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
296dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
297$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
300if (!file_exists($fullpath_original_file_osencoded)) {
301 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
302 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
307$hookmanager->initHooks(array(
'document'));
308$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
309 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
310 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
312$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
314 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
315 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
316 print
"ErrorDownloadDocumentHooks: ".$errors;
324header(
'Content-Description: File Transfer');
326 header(
'Content-Encoding: '.$encoding);
331 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
333 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
336header(
'Cache-Control: Public, must-revalidate');
337header(
'Pragma: public');
344 $readfile = !$imgres;
353 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.
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.