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') {
86 if ($_GET[
"modulepart"] ==
'product' && isset($_GET[
"publictakepos"])) {
91if (isset($_GET[
"hashp"])) {
96 if (!defined(
"NOLOGIN")) {
99 if (!defined(
"NOCSRFCHECK")) {
100 define(
"NOCSRFCHECK", 1);
102 if (!defined(
"NOIPCHECK")) {
103 define(
"NOIPCHECK", 1);
110$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
111if (is_numeric($entity)) {
112 define(
"DOLENTITY", $entity);
137function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
150function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
154require
'main.inc.php';
155require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
165$action =
GETPOST(
'action',
'aZ09');
166$original_file =
GETPOST(
'file',
'alphanohtml');
167$hashp =
GETPOST(
'hashp',
'aZ09', 1);
168$extname =
GETPOST(
'extname',
'alpha', 1);
169$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
170$urlsource =
GETPOST(
'urlsource',
'alpha');
174if (empty($modulepart) && empty($hashp)) {
177if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
180if ($modulepart ==
'fckeditor') {
181 $modulepart =
'medias';
197$cachestring =
GETPOST(
"cache",
'aZ09');
203 if (empty($dolibarr_nocache)) {
204 $delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (
int) $cachestring < 999999) ? $cachestring :
'3600');
205 header(
'Cache-Control: max-age='.$delaycache.
', public, must-revalidate');
206 header(
'Pragma: cache');
207 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $delaycache).
' GMT');
210 header(
'Cache-Control: no-cache');
217 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
218 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
220 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
222 $tmp = explode(
'/', $ecmfile->filepath, 2);
224 if (is_numeric($tmp[0])) {
225 $tmp = explode(
'/', $tmp[1], 2);
227 $moduleparttocheck = $tmp[0];
230 if ($moduleparttocheck == $modulepart) {
232 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
238 $modulepart = $moduleparttocheck;
239 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
251$type =
'application/octet-stream';
253 $type =
GETPOST(
'type',
'alpha');
259if (preg_match(
'/html/i', $type)) {
263if (preg_match(
'/\.noexe$/i', $original_file)) {
268$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
269$original_file = str_replace(
'../',
'/', $original_file);
270$original_file = str_replace(
'..\\',
'/', $original_file);
273$refname = basename(dirname($original_file).
"/");
274if ($refname ==
'thumbs') {
276 $refname = basename(dirname(dirname($original_file)).
"/");
285if (empty($modulepart)) {
291if ($modulepart ===
'medias' && $entity != $conf->entity) {
292 $conf->entity = $entity;
293 $conf->setValues($db);
297$accessallowed = $check_access[
'accessallowed'];
298$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
299$fullpath_original_file = $check_access[
'original_file'];
303 $sqlprotectagainstexternals =
'';
305 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
312 if ($user->socid > 0) {
313 if ($sqlprotectagainstexternals) {
314 $resql = $db->query($sqlprotectagainstexternals);
316 $num = $db->num_rows($resql);
319 $obj = $db->fetch_object($resql);
320 if ($user->socid != $obj->fk_soc) {
333if (!$accessallowed) {
339if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
340 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
341 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
347if ($modulepart ==
'barcode') {
348 $generator =
GETPOST(
"generator",
"aZ09");
349 $encoding =
GETPOST(
"encoding",
"aZ09");
350 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
351 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
352 $code =
GETPOST(
"code",
'alphanohtml');
354 $code =
GETPOST(
"code",
'restricthtml');
359 if (preg_match(
'/^virtualcard_([^_]+)_(\d+)\.vcf$/', $code, $reg)) {
363 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
364 $vcffile = $conf->user->dir_temp.
'/'.$code;
366 $tmpuser =
new User($db);
367 $tmpuser->fetch(
$id);
368 $login = $tmpuser->login;
369 } elseif ($reg[1] ==
'contact' && (
int) $reg[2] > 0) {
370 $vcffile = $conf->contact->dir_temp.
'/'.$code;
375 if ($vcffile &&
$id) {
378 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
379 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.
$id.
'-'.$login,
'md5');
380 if ($encodedsecurekey !=
GETPOST(
'securekey')) {
381 $code =
'badvalueforsecurekey';
385 $code = file_get_contents($vcffile);
391 if (empty($generator) || empty($encoding)) {
392 print
'Error: Parameter "generator" or "encoding" not defined';
396 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
400 foreach ($dirbarcode as $reldir) {
405 if (!is_dir($newdir)) {
409 $result = @include_once $newdir.$generator.
'.modules.php';
416 $classname =
"mod".ucfirst($generator);
418 $module =
new $classname($db);
419 '@phan-var-force ModeleBarCode $module';
421 if ($module->encodingIsSupported($encoding)) {
422 $result = $module->buildBarCode($code, $encoding, $readable);
428 $filename = basename($fullpath_original_file);
431 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
435 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
444 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
447 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
450 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
452 readfile($fullpath_original_file_osencoded);
$id
Support class for third parties, contacts, members, users or resources.
Class to manage ECM files.
Class to manage Dolibarr users.
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.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Footer empty.
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.