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 ($hashp ==
'shared') {
183if ($modulepart ==
'fckeditor') {
184 $modulepart =
'medias';
200$cachestring =
GETPOST(
"cache",
'aZ09');
206 if (empty($dolibarr_nocache)) {
207 $delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (
int) $cachestring < 999999) ? $cachestring :
'3600');
208 header(
'Cache-Control: max-age='.$delaycache.
', public, must-revalidate');
209 header(
'Pragma: cache');
210 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $delaycache).
' GMT');
213 header(
'Cache-Control: no-cache');
219if (!empty($hashp) && $hashp !=
'shared') {
220 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
221 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
223 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
225 $tmp = explode(
'/', $ecmfile->filepath, 2);
227 if (is_numeric($tmp[0])) {
228 $tmp = explode(
'/', $tmp[1], 2);
230 $moduleparttocheck = $tmp[0];
233 if ($moduleparttocheck == $modulepart) {
235 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
241 $modulepart = $moduleparttocheck;
242 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
254$type =
'application/octet-stream';
256 $type =
GETPOST(
'type',
'alpha');
262if (preg_match(
'/html/i', $type)) {
266if (preg_match(
'/\.noexe$/i', $original_file)) {
271$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
272$original_file = str_replace(
'../',
'/', $original_file);
273$original_file = str_replace(
'..\\',
'/', $original_file);
276$refname = basename(dirname($original_file).
"/");
277if ($refname ==
'thumbs') {
279 $refname = basename(dirname(dirname($original_file)).
"/");
288if (empty($modulepart)) {
294if ($modulepart ===
'medias' && $entity != $conf->entity) {
295 $conf->entity = $entity;
296 $conf->setValues($db);
300$accessallowed = $check_access[
'accessallowed'];
301$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
302$fullpath_original_file = $check_access[
'original_file'];
304if (!empty($hashp) && $hashp !=
'shared') {
306 $sqlprotectagainstexternals =
'';
308 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
315 if ($user->socid > 0) {
316 if ($sqlprotectagainstexternals) {
317 $resql = $db->query($sqlprotectagainstexternals);
319 $num = $db->num_rows($resql);
322 $obj = $db->fetch_object($resql);
323 if ($user->socid != $obj->fk_soc) {
336if (!$accessallowed) {
342if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
343 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
344 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
350if ($modulepart ==
'barcode') {
351 $generator =
GETPOST(
"generator",
"aZ09");
352 $encoding =
GETPOST(
"encoding",
"aZ09");
353 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
354 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
355 $code =
GETPOST(
"code",
'alphanohtml');
357 $code =
GETPOST(
"code",
'restricthtml');
362 if (preg_match(
'/^virtualcard_([^_]+)_(\d+)\.vcf$/', $code, $reg)) {
366 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
367 $vcffile = $conf->user->dir_temp.
'/'.$code;
369 $tmpuser =
new User($db);
370 $tmpuser->fetch(
$id);
371 $login = $tmpuser->login;
372 } elseif ($reg[1] ==
'contact' && (
int) $reg[2] > 0) {
373 $vcffile = $conf->contact->dir_temp.
'/'.$code;
378 if ($vcffile &&
$id) {
381 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
382 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.
$id.
'-'.$login,
'md5');
383 if ($encodedsecurekey !=
GETPOST(
'securekey')) {
384 $code =
'badvalueforsecurekey';
388 $code = file_get_contents($vcffile);
394 if (empty($generator) || empty($encoding)) {
395 print
'Error: Parameter "generator" or "encoding" not defined';
399 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
403 foreach ($dirbarcode as $reldir) {
408 if (!is_dir($newdir)) {
412 $result = @include_once $newdir.$generator.
'.modules.php';
419 $classname =
"mod".ucfirst($generator);
421 $module =
new $classname($db);
422 '@phan-var-force ModeleBarCode $module';
424 if ($module->encodingIsSupported($encoding)) {
425 $result = $module->buildBarCode($code, $encoding, $readable);
431 $filename = basename($fullpath_original_file);
434 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
438 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
447 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
450 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
453 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
455 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.