26require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
62 public $fullpath_original_file;
67 public $fullpath_original_file_osencoded;
77 public $original_file;
92 global
$conf, $hookmanager;
94 define(
'MAIN_SECURITY_FORCECSP',
"default-src: 'none'");
96 if (!defined(
'NOTOKENRENEWAL')) {
97 define(
'NOTOKENRENEWAL',
'1');
99 if (!defined(
'NOREQUIREMENU')) {
100 define(
'NOREQUIREMENU',
'1');
102 if (!defined(
'NOREQUIREHTML')) {
103 define(
'NOREQUIREHTML',
'1');
105 if (!defined(
'NOREQUIREAJAX')) {
106 define(
'NOREQUIREAJAX',
'1');
112 $action =
GETPOST(
'action',
'aZ09');
113 $original_file =
GETPOST(
'file',
'alphanohtml');
114 $modulepart =
GETPOST(
'modulepart',
'alpha');
119 if (empty($modulepart)) {
122 if (empty($original_file)) {
131 if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
134 if (GETPOSTISSET(
"attachment")) {
135 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
142 if (
GETPOST(
'type',
'alpha')) {
143 $type =
GETPOST(
'type',
'alpha');
151 $type =
'application/octet-stream';
155 $original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
156 $original_file = str_replace(
'../',
'/', $original_file);
157 $original_file = str_replace(
'..\\',
'/', $original_file);
161 $moduleName = $modulepart;
162 $moduleNameEn = $moduleName;
163 if ($moduleName ==
'commande') {
164 $moduleNameEn =
'order';
165 } elseif ($moduleName ==
'facture') {
166 $moduleNameEn =
'invoice';
168 $moduleNameUpperEn = strtoupper($moduleNameEn);
172 if (
getDolGlobalInt(
'WEBPORTAL_' . $moduleNameUpperEn .
'_LIST_ACCESS')
173 && in_array($type, array(
'application/pdf'))
175 &&
$context->logged_thirdparty->id == $socId
177 if (isModEnabled($moduleName) && isset(
$conf->{$moduleName}->multidir_output[$entity])) {
178 $original_file =
$conf->{$moduleName}->multidir_output[$entity] .
'/' . $original_file;
182 $fullpath_original_file = $original_file;
186 if (!$accessallowed) {
192 if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
193 dol_syslog(
"Refused to deliver file " . $fullpath_original_file);
199 $refname = basename(dirname($original_file) .
"/");
201 $filename = basename($fullpath_original_file);
202 $filename = preg_replace(
'/\.noexe$/i',
'', $filename);
205 dol_syslog(
"document controller download $fullpath_original_file filename=$filename content-type=$type");
206 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
209 if (!file_exists($fullpath_original_file_osencoded)) {
210 dol_syslog(
"ErrorFileDoesNotExists: " . $fullpath_original_file);
211 print
"ErrorFileDoesNotExists: " . $original_file;
216 $fileSizeMaxDefault = 20 * 1024;
217 $fileSizeMax =
getDolGlobalInt(
'MAIN_SECURITY_MAXFILESIZE_DOWNLOADED', $fileSizeMaxDefault);
218 if ($fileSize > $fileSizeMax) {
219 dol_syslog(
'ErrorFileSizeTooLarge: ' . $fileSize);
220 print
'ErrorFileSizeTooLarge: ' . $fileSize .
' (max ' . $fileSizeMax .
')';
225 $hookmanager->initHooks(array(
'document'));
226 $parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
227 'entity' => $entity,
'refname' => $refname,
'fullpath_original_file' => $fullpath_original_file,
228 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
230 $reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters,
$object, $action);
232 $errors = $hookmanager->error . (is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'') . implode(
', ', $hookmanager->errors) :
'');
233 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : " . $errors);
234 print
"ErrorDownloadDocumentHooks: " . $errors;
238 $this->action = $action;
239 $this->attachment = $attachment;
240 $this->encoding = $encoding;
241 $this->entity = $entity;
242 $this->filename = $filename;
243 $this->fullpath_original_file = $fullpath_original_file;
244 $this->fullpath_original_file_osencoded = $fullpath_original_file_osencoded;
245 $this->modulepart = $modulepart;
246 $this->original_file = $original_file;
257 $this->accessRight =
true;
259 return parent::checkAccess();
271 if (!
$context->controllerInstance->checkAccess()) {
293 if (!
$context->controllerInstance->checkAccess()) {
299 $attachment = $this->attachment;
300 $encoding = $this->encoding;
301 $filename = $this->filename;
302 $fullpath_original_file = $this->fullpath_original_file;
303 $fullpath_original_file_osencoded = $this->fullpath_original_file_osencoded;
310 header(
'Content-Description: File Transfer');
312 header(
'Content-Encoding: ' . $encoding);
316 header(
'Content-Disposition: attachment; filename="' . $filename .
'"');
318 header(
'Content-Disposition: inline; filename="' . $filename .
'"');
320 header(
'Cache-Control: Public, must-revalidate');
321 header(
'Pragma: public');
324 header(
'Content-Length: ' .
dol_filesize($fullpath_original_file));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
static getInstance()
Singleton method to create one instance of this object.
Class for DocumentController.
action()
Action method is called before html output can be used to manage security and change context.
checkAccess()
Check current access to controller.
dol_filesize($pathoffile)
Return size of a file.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
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...
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...
$context
@method int call_trigger(string $triggerName, User $user)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.