82 global
$conf, $hookmanager, $user;
84 define(
'MAIN_SECURITY_FORCECSP',
"default-src 'none'");
86 if (!defined(
'NOREQUIRESOC')) {
87 define(
'NOREQUIRESOC',
'1');
89 if (!defined(
'NOREQUIRETRAN')) {
90 define(
'NOREQUIRETRAN',
'1');
92 if (!defined(
'NOCSRFCHECK')) {
93 define(
'NOCSRFCHECK',
'1');
95 if (!defined(
'NOTOKENRENEWAL')) {
96 define(
'NOTOKENRENEWAL',
'1');
98 if (!defined(
'NOREQUIREMENU')) {
99 define(
'NOREQUIREMENU',
'1');
101 if (!defined(
'NOREQUIREHTML')) {
102 define(
'NOREQUIREHTML',
'1');
104 if (!defined(
'NOREQUIREAJAX')) {
105 define(
'NOREQUIREAJAX',
'1');
111 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
112 define(
"DOLENTITY", $entity);
116 $action =
GETPOST(
'action',
'aZ09');
117 $original_file =
GETPOST(
'file',
'alphanohtml');
118 $hashp =
GETPOST(
'hashp',
'aZ09', 1);
119 $extname =
GETPOST(
'extname',
'alpha', 1);
120 $modulepart =
GETPOST(
'modulepart',
'alpha', 1);
121 $urlsource =
GETPOST(
'urlsource',
'alpha');
125 if (empty($modulepart) && empty($hashp)) {
128 if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
131 if ($modulepart ==
'fckeditor') {
132 $modulepart =
'medias';
135 $cachestring =
GETPOST(
"cache",
'aZ09');
141 $delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (
int) $cachestring < 999999) ? $cachestring :
'3600');
142 header(
'Cache-Control: max-age=' . $delaycache .
', public, must-revalidate');
143 header(
'Pragma: cache');
144 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s', time() + (
int) $delaycache) .
' GMT');
148 $type =
'application/octet-stream';
149 if (
GETPOST(
'type',
'alpha')) {
150 $type =
GETPOST(
'type',
'alpha');
152 $type = dol_mimetype($original_file);
156 if (preg_match(
'/html/i', $type)) {
160 if (preg_match(
'/\.noexe$/i', $original_file)) {
165 $original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
166 $original_file = str_replace(
'../',
'/', $original_file);
167 $original_file = str_replace(
'..\\',
'/', $original_file);
170 $refname = basename(dirname($original_file) .
"/");
171 if ($refname ==
'thumbs') {
173 $refname = basename(dirname(dirname($original_file)) .
"/");
177 if (!empty($original_file) && !dolIsAllowedForPreview($original_file)) {
182 if (empty($modulepart)) {
188 if ($modulepart ===
'medias' && $entity !=
$conf->entity) {
189 $conf->entity = $entity;
190 $conf->setValues($this->db);
193 $sqlprotectagainstexternals =
'';
194 $fullpath_original_file =
'';
198 $hookmanager->initHooks(array(
'viewimage'));
199 $parameters = array(
'modulepart' => $modulepart,
'original_file' => &$original_file,
200 'sqlprotectagainstexternals' => &$sqlprotectagainstexternals,
'fullpath_original_file' => &$fullpath_original_file,
201 'entity' => $entity,
'accessallowed' => &$accessallowed);
203 $reshook = $hookmanager->executeHooks(
'accessViewImage', $parameters,
$object, $action);
205 $errors = $hookmanager->error . (is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'') . implode(
', ', $hookmanager->errors) :
'');
206 dol_syslog(
"document.php - Errors when executing the hook 'accessViewImage' : " . $errors);
207 print
"ErrorViewImageHooks: " . $errors;
209 } elseif (empty($reshook)) {
211 $accessallowed = $check_access[
'accessallowed'];
212 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
213 $fullpath_original_file = $check_access[
'original_file'];
216 if (!empty($hashp)) {
218 $sqlprotectagainstexternals =
'';
221 if ($user->socid > 0) {
222 if ($sqlprotectagainstexternals) {
223 $resql = $this->db->query($sqlprotectagainstexternals);
225 $num = $this->db->num_rows($resql);
228 $obj = $this->db->fetch_object($resql);
229 if ($user->socid != $obj->fk_soc) {
242 if (!$accessallowed) {
248 if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
249 dol_syslog(
"Refused to deliver file " . $fullpath_original_file);
255 $refname = basename(dirname($original_file) .
"/");
257 $filename = basename($fullpath_original_file);
258 $filename = preg_replace(
'/\.noexe$/i',
'', $filename);
261 dol_syslog(
"document controller download $fullpath_original_file filename=$filename content-type=$type");
262 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
265 if (!file_exists($fullpath_original_file_osencoded)) {
266 dol_syslog(
"ErrorFileDoesNotExists: " . $fullpath_original_file);
267 print
"ErrorFileDoesNotExists: " . $original_file;
272 $fileSizeMax =
getDolGlobalInt(
'MAIN_SECURITY_MAXFILESIZE_DOWNLOADED');
273 if ($fileSizeMax && $fileSize > $fileSizeMax) {
274 dol_syslog(
'ErrorFileSizeTooLarge: ' . $fileSize);
275 print
'ErrorFileSizeTooLarge: ' . $fileSize .
' (max ' . $fileSizeMax .
' Kb)';
280 $hookmanager->initHooks(array(
'document'));
281 $parameters = array(
'modulepart' => $modulepart,
'original_file' => $original_file,
282 'entity' => $entity,
'refname' => $refname,
'fullpath_original_file' => $fullpath_original_file,
283 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
285 $reshook = $hookmanager->executeHooks(
'viewImage', $parameters,
$object, $action);
287 $errors = $hookmanager->error . (is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'') . implode(
', ', $hookmanager->errors) :
'');
288 dol_syslog(
"document.php - Errors when executing the hook 'viewImage' : " . $errors);
289 print
"ErrorViewImageHooks: " . $errors;
294 $this->entity = $entity;
295 $this->filename = $filename;
296 $this->fullpath_original_file = $fullpath_original_file;
297 $this->fullpath_original_file_osencoded = $fullpath_original_file_osencoded;
298 $this->modulepart = $modulepart;
299 $this->original_file = $original_file;