29define(
'MAIN_SECURITY_FORCECSP',
"default-src: 'none'");
33if (!defined(
'NOREQUIRESOC')) {
34 define(
'NOREQUIRESOC',
'1');
36if (!defined(
'NOREQUIRETRAN')) {
37 define(
'NOREQUIRETRAN',
'1');
39if (!defined(
'NOCSRFCHECK')) {
40 define(
'NOCSRFCHECK',
'1');
42if (!defined(
'NOTOKENRENEWAL')) {
43 define(
'NOTOKENRENEWAL',
'1');
45if (!defined(
'NOREQUIREMENU')) {
46 define(
'NOREQUIREMENU',
'1');
48if (!defined(
'NOREQUIREHTML')) {
49 define(
'NOREQUIREHTML',
'1');
51if (!defined(
'NOREQUIREAJAX')) {
52 define(
'NOREQUIREAJAX',
'1');
58if (isset($_GET[
"modulepart"])) {
60 if ($_GET[
"modulepart"] ==
'mycompany' && preg_match(
'/^\/?logos\//', $_GET[
'file'])) {
64 if ($_GET[
"modulepart"] ==
'barcode') {
68 if ($_GET[
"modulepart"] ==
'medias') {
71 if ($_GET[
"modulepart"] ==
'userphotopublic') {
75 if ($_GET[
"modulepart"] ==
'product' && isset($_GET[
"publictakepos"])) {
80if (isset($_GET[
"hashp"])) {
85 if (!defined(
"NOLOGIN")) {
88 if (!defined(
"NOCSRFCHECK")) {
89 define(
"NOCSRFCHECK", 1);
91 if (!defined(
"NOIPCHECK")) {
92 define(
"NOIPCHECK", 1);
97$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
98if (is_numeric($entity)) {
99 define(
"DOLENTITY", $entity);
121require
'main.inc.php';
122require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
124$action =
GETPOST(
'action',
'aZ09');
125$original_file =
GETPOST(
'file',
'alphanohtml');
126$hashp =
GETPOST(
'hashp',
'aZ09', 1);
127$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
128$urlsource =
GETPOST(
'urlsource',
'alpha');
129$entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity);
132if (empty($modulepart) && empty($hashp)) {
135if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
138if ($modulepart ==
'fckeditor') {
139 $modulepart =
'medias';
155if (
GETPOST(
"cache",
'alpha')) {
158 if (empty($dolibarr_nocache)) {
159 header(
'Cache-Control: max-age=3600, public, must-revalidate');
160 header(
'Pragma: cache');
161 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + 3600).
' GMT');
164 header(
'Cache-Control: no-cache');
171 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
173 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
175 $tmp = explode(
'/', $ecmfile->filepath, 2);
177 if (is_numeric($tmp[0])) {
178 $tmp = explode(
'/', $tmp[1], 2);
180 $moduleparttocheck = $tmp[0];
183 if ($moduleparttocheck == $modulepart) {
185 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
191 $modulepart = $moduleparttocheck;
192 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
195 $langs->load(
"errors");
201$type =
'application/octet-stream';
203 $type =
GETPOST(
'type',
'alpha');
209if (preg_match(
'/html/i', $type)) {
213if (preg_match(
'/\.noexe$/i', $original_file)) {
218$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
219$original_file = str_replace(
'../',
'/', $original_file);
220$original_file = str_replace(
'..\\',
'/', $original_file);
223$refname = basename(dirname($original_file).
"/");
224if ($refname ==
'thumbs') {
226 $refname = basename(dirname(dirname($original_file)).
"/");
235if (empty($modulepart)) {
241if ($modulepart ===
'medias' && $entity != $conf->entity) {
242 $conf->entity = $entity;
243 $conf->setValues($db);
247$accessallowed = $check_access[
'accessallowed'];
248$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
249$fullpath_original_file = $check_access[
'original_file'];
253 $sqlprotectagainstexternals =
'';
254} elseif (isset($_GET[
"publictakepos"])) {
255 if (!empty($conf->global->TAKEPOS_AUTO_ORDER)) {
260 if ($user->socid > 0) {
261 if ($sqlprotectagainstexternals) {
262 $resql = $db->query($sqlprotectagainstexternals);
264 $num = $db->num_rows($resql);
267 $obj = $db->fetch_object($resql);
268 if ($user->socid != $obj->fk_soc) {
281if (!$accessallowed) {
287if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
288 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
289 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
295if ($modulepart ==
'barcode') {
296 $generator =
GETPOST(
"generator",
"aZ09");
297 $encoding =
GETPOST(
"encoding",
"aZ09");
298 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
299 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
300 $code =
GETPOST(
"code",
'alphanohtml');
302 $code =
GETPOST(
"code",
'restricthtml');
305 if (empty($generator) || empty($encoding)) {
306 print
'Error: Parameter "generator" or "encoding" not defined';
310 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
314 foreach ($dirbarcode as $reldir) {
319 if (!is_dir($newdir)) {
323 $result = @include_once $newdir.$generator.
'.modules.php';
330 $classname =
"mod".ucfirst($generator);
331 $module =
new $classname($db);
332 if ($module->encodingIsSupported($encoding)) {
333 $result = $module->buildBarCode($code, $encoding, $readable);
339 $filename = basename($fullpath_original_file);
342 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
345 if (!
dol_is_file($fullpath_original_file) && empty($_GET[
"noalt"])) {
346 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
355 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
358 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
361 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
363 readfile($fullpath_original_file_osencoded);
Class to manage ECM files.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_is_file($pathoffile)
Return if path is a file.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
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.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
if(is_numeric( $entity)) llxHeader()
Header empty.