31define(
'MAIN_SECURITY_FORCECSP',
"default-src: 'none'");
35if (!defined(
'NOREQUIRESOC')) {
36 define(
'NOREQUIRESOC',
'1');
38if (!defined(
'NOREQUIRETRAN')) {
39 define(
'NOREQUIRETRAN',
'1');
41if (!defined(
'NOCSRFCHECK')) {
42 define(
'NOCSRFCHECK',
'1');
44if (!defined(
'NOTOKENRENEWAL')) {
45 define(
'NOTOKENRENEWAL',
'1');
47if (!defined(
'NOREQUIREMENU')) {
48 define(
'NOREQUIREMENU',
'1');
50if (!defined(
'NOREQUIREHTML')) {
51 define(
'NOREQUIREHTML',
'1');
53if (!defined(
'NOREQUIREAJAX')) {
54 define(
'NOREQUIREAJAX',
'1');
61if (isset($_GET[
"modulepart"])) {
65 if ($_GET[
"modulepart"] ==
'mycompany' && preg_match(
'/^\/?logos\//', $_GET[
'file'])) {
69 if ($_GET[
"modulepart"] ==
'barcode') {
73 if ($_GET[
"modulepart"] ==
'medias') {
77 if ($_GET[
"modulepart"] ==
'common') {
81 if ($_GET[
"modulepart"] ==
'userphotopublic') {
85 if ($_GET[
"modulepart"] ==
'product' && isset($_GET[
"publictakepos"])) {
90if (isset($_GET[
"hashp"])) {
95 if (!defined(
"NOLOGIN")) {
98 if (!defined(
"NOCSRFCHECK")) {
99 define(
"NOCSRFCHECK", 1);
101 if (!defined(
"NOIPCHECK")) {
102 define(
"NOIPCHECK", 1);
109$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
110if (is_numeric($entity)) {
111 define(
"DOLENTITY", $entity);
134function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
145function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
149require
'main.inc.php';
150require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
152$action =
GETPOST(
'action',
'aZ09');
153$original_file =
GETPOST(
'file',
'alphanohtml');
154$hashp =
GETPOST(
'hashp',
'aZ09', 1);
155$extname =
GETPOST(
'extname',
'alpha', 1);
156$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
157$urlsource =
GETPOST(
'urlsource',
'alpha');
161if (empty($modulepart) && empty($hashp)) {
164if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
167if ($modulepart ==
'fckeditor') {
168 $modulepart =
'medias';
184if (
GETPOST(
"cache",
'alpha')) {
189 if (empty($dolibarr_nocache)) {
190 if (
GETPOST(
'cache',
'alpha') !=
'1') {
191 $delaycache = 3600 * 24 * 7;
195 header(
'Cache-Control: max-age='.$delaycache.
', public, must-revalidate');
196 header(
'Pragma: cache');
197 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + $delaycache).
' GMT');
200 header(
'Cache-Control: no-cache');
207 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
208 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
210 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
212 $tmp = explode(
'/', $ecmfile->filepath, 2);
214 if (is_numeric($tmp[0])) {
215 $tmp = explode(
'/', $tmp[1], 2);
217 $moduleparttocheck = $tmp[0];
220 if ($moduleparttocheck == $modulepart) {
222 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
228 $modulepart = $moduleparttocheck;
229 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
241$type =
'application/octet-stream';
243 $type =
GETPOST(
'type',
'alpha');
249if (preg_match(
'/html/i', $type)) {
253if (preg_match(
'/\.noexe$/i', $original_file)) {
258$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
259$original_file = str_replace(
'../',
'/', $original_file);
260$original_file = str_replace(
'..\\',
'/', $original_file);
263$refname = basename(dirname($original_file).
"/");
264if ($refname ==
'thumbs') {
266 $refname = basename(dirname(dirname($original_file)).
"/");
275if (empty($modulepart)) {
281if ($modulepart ===
'medias' && $entity != $conf->entity) {
282 $conf->entity = $entity;
283 $conf->setValues($db);
287$accessallowed = $check_access[
'accessallowed'];
288$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
289$fullpath_original_file = $check_access[
'original_file'];
293 $sqlprotectagainstexternals =
'';
295 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
302 if ($user->socid > 0) {
303 if ($sqlprotectagainstexternals) {
304 $resql = $db->query($sqlprotectagainstexternals);
306 $num = $db->num_rows($resql);
309 $obj = $db->fetch_object($resql);
310 if ($user->socid != $obj->fk_soc) {
323if (!$accessallowed) {
329if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
330 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
331 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
337if ($modulepart ==
'barcode') {
338 $generator =
GETPOST(
"generator",
"aZ09");
339 $encoding =
GETPOST(
"encoding",
"aZ09");
340 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
341 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
342 $code =
GETPOST(
"code",
'alphanohtml');
344 $code =
GETPOST(
"code",
'restricthtml');
349 if (preg_match(
'/^virtualcard_([^_]+)_(\d+)\.vcf$/', $code, $reg)) {
351 if ($reg[1] ==
'user') {
352 $vcffile = $conf->user->dir_temp.
'/'.$code;
353 } elseif ($reg[1] ==
'contact') {
354 $vcffile = $conf->contact->dir_temp.
'/'.$code;
358 $code = file_get_contents($vcffile);
363 if (empty($generator) || empty($encoding)) {
364 print
'Error: Parameter "generator" or "encoding" not defined';
368 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
372 foreach ($dirbarcode as $reldir) {
377 if (!is_dir($newdir)) {
381 $result = @include_once $newdir.$generator.
'.modules.php';
388 $classname =
"mod".ucfirst($generator);
390 $module =
new $classname($db);
391 '@phan-var-force ModeleBarCode $module';
392 if ($module->encodingIsSupported($encoding)) {
393 $result = $module->buildBarCode($code, $encoding, $readable);
399 $filename = basename($fullpath_original_file);
402 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
406 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
415 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
418 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
421 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
423 readfile($fullpath_original_file_osencoded);
Class to manage ECM files.
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_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 the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
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 a 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Header empty.