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"])) {
62 if ($_GET[
"modulepart"] ==
'mycompany' && preg_match(
'/^\/?logos\//', $_GET[
'file'])) {
66 if ($_GET[
"modulepart"] ==
'barcode') {
70 if ($_GET[
"modulepart"] ==
'medias') {
74 if ($_GET[
"modulepart"] ==
'userphotopublic') {
78 if ($_GET[
"modulepart"] ==
'product' && isset($_GET[
"publictakepos"])) {
83if (isset($_GET[
"hashp"])) {
88 if (!defined(
"NOLOGIN")) {
91 if (!defined(
"NOCSRFCHECK")) {
92 define(
"NOCSRFCHECK", 1);
94 if (!defined(
"NOIPCHECK")) {
95 define(
"NOIPCHECK", 1);
100$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
101if (is_numeric($entity)) {
102 define(
"DOLENTITY", $entity);
124require
'main.inc.php';
125require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
127$action =
GETPOST(
'action',
'aZ09');
128$original_file =
GETPOST(
'file',
'alphanohtml');
129$hashp =
GETPOST(
'hashp',
'aZ09', 1);
130$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
131$urlsource =
GETPOST(
'urlsource',
'alpha');
132$entity = (
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity);
135if (empty($modulepart) && empty($hashp)) {
138if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
141if ($modulepart ==
'fckeditor') {
142 $modulepart =
'medias';
158if (
GETPOST(
"cache",
'alpha')) {
161 if (empty($dolibarr_nocache)) {
162 header(
'Cache-Control: max-age=3600, public, must-revalidate');
163 header(
'Pragma: cache');
164 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + 3600).
' GMT');
167 header(
'Cache-Control: no-cache');
174 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
176 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
178 $tmp = explode(
'/', $ecmfile->filepath, 2);
180 if (is_numeric($tmp[0])) {
181 $tmp = explode(
'/', $tmp[1], 2);
183 $moduleparttocheck = $tmp[0];
186 if ($moduleparttocheck == $modulepart) {
188 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
194 $modulepart = $moduleparttocheck;
195 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
198 $langs->load(
"errors");
204$type =
'application/octet-stream';
206 $type =
GETPOST(
'type',
'alpha');
212if (preg_match(
'/html/i', $type)) {
216if (preg_match(
'/\.noexe$/i', $original_file)) {
221$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
222$original_file = str_replace(
'../',
'/', $original_file);
223$original_file = str_replace(
'..\\',
'/', $original_file);
226$refname = basename(dirname($original_file).
"/");
227if ($refname ==
'thumbs') {
229 $refname = basename(dirname(dirname($original_file)).
"/");
238if (empty($modulepart)) {
244if ($modulepart ===
'medias' && $entity != $conf->entity) {
245 $conf->entity = $entity;
246 $conf->setValues($db);
250$accessallowed = $check_access[
'accessallowed'];
251$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
252$fullpath_original_file = $check_access[
'original_file'];
256 $sqlprotectagainstexternals =
'';
258 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
263 if ($user->socid > 0) {
264 if ($sqlprotectagainstexternals) {
265 $resql = $db->query($sqlprotectagainstexternals);
267 $num = $db->num_rows($resql);
270 $obj = $db->fetch_object($resql);
271 if ($user->socid != $obj->fk_soc) {
284if (!$accessallowed) {
290if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
291 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
292 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
298if ($modulepart ==
'barcode') {
299 $generator =
GETPOST(
"generator",
"aZ09");
300 $encoding =
GETPOST(
"encoding",
"aZ09");
301 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
302 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
303 $code =
GETPOST(
"code",
'alphanohtml');
305 $code =
GETPOST(
"code",
'restricthtml');
308 if (empty($generator) || empty($encoding)) {
309 print
'Error: Parameter "generator" or "encoding" not defined';
313 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
317 foreach ($dirbarcode as $reldir) {
322 if (!is_dir($newdir)) {
326 $result = @include_once $newdir.$generator.
'.modules.php';
333 $classname =
"mod".ucfirst($generator);
334 $module =
new $classname($db);
335 if ($module->encodingIsSupported($encoding)) {
336 $result = $module->buildBarCode($code, $encoding, $readable);
342 $filename = basename($fullpath_original_file);
345 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
348 if (!
dol_is_file($fullpath_original_file) && empty($_GET[
"noalt"])) {
349 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
358 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
361 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
364 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
366 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.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.