31define(
'MAIN_SECURITY_FORCECSP',
"default-src 'none'; form-action 'none'; frame-ancestors 'self'");
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' && isset($_GET[
'file']) && 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);
111$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 0));
112if (is_numeric($entity) && $entity > 0) {
115 define(
"DOLENTITY", $entity);
140function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
153function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
157require
'main.inc.php';
165require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
167$action =
GETPOST(
'action',
'aZ09');
168$original_file =
GETPOST(
'file',
'alphanohtml');
169$hashp =
GETPOST(
'hashp',
'aZ09', 1);
170$extname =
GETPOST(
'extname',
'alpha', 1);
171$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
172$urlsource =
GETPOST(
'urlsource',
'alpha');
173$entity = ($entity > 0 ? $entity :
$conf->entity);
176if (empty($modulepart) && empty($hashp)) {
179if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
182if ($hashp ==
'shared') {
185if ($modulepart ==
'fckeditor') {
186 $modulepart =
'medias';
202$cachestring =
GETPOST(
"cache",
'aZ09');
208 $delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (
int) $cachestring < 999999) ? $cachestring :
'3600');
209 header(
'Cache-Control: max-age='.$delaycache.
', public, must-revalidate');
210 header(
'Pragma: cache');
211 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $delaycache).
' GMT');
215if (!empty($hashp) && $hashp !=
'shared') {
216 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
217 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
219 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
221 $tmp = explode(
'/', $ecmfile->filepath, 2);
223 if (is_numeric($tmp[0])) {
224 $tmp = explode(
'/', $tmp[1], 2);
226 $moduleparttocheck = $tmp[0];
229 if ($moduleparttocheck == $modulepart) {
231 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
237 $modulepart = $moduleparttocheck;
238 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
250$type =
'application/octet-stream';
252 $type =
GETPOST(
'type',
'alpha');
258if (preg_match(
'/html/i', $type)) {
262if (preg_match(
'/\.noexe$/i', $original_file)) {
267$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
268$original_file = str_replace(
'../',
'/', $original_file);
269$original_file = str_replace(
'..\\',
'/', $original_file);
272$refname = basename(dirname($original_file).
"/");
273if ($refname ==
'thumbs') {
275 $refname = basename(dirname(dirname($original_file)).
"/");
284if (empty($modulepart)) {
290if ($modulepart ===
'medias' && $entity !=
$conf->entity) {
291 $conf->entity = $entity;
296$accessallowed = $check_access[
'accessallowed'];
297$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
298$fullpath_original_file = $check_access[
'original_file'];
300if (!empty($hashp) && $hashp !=
'shared') {
302 $sqlprotectagainstexternals =
'';
304 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
311 if ($user->socid > 0) {
312 if ($sqlprotectagainstexternals) {
313 $resql =
$db->query($sqlprotectagainstexternals);
315 $num =
$db->num_rows($resql);
318 $obj =
$db->fetch_object($resql);
319 if ($user->socid != $obj->fk_soc) {
332if (!$accessallowed) {
338if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
339 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
340 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
345if ($modulepart ==
'barcode') {
346 $generator =
GETPOST(
"generator",
"aZ09");
347 $encoding =
GETPOST(
"encoding",
"aZ09");
348 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
349 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
350 $code =
GETPOST(
"code",
'alphanohtml');
352 $code =
GETPOST(
"code",
'restricthtml');
357 if (preg_match(
'/^virtualcard_([^_]+)_(\d+)\.vcf$/', $code, $reg)) {
361 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
362 $vcffile =
$conf->user->dir_temp.
'/'.$code;
365 $tmpuser->fetch(
$id);
366 $login = $tmpuser->login;
367 } elseif ($reg[1] ==
'contact' && (
int) $reg[2] > 0) {
368 $vcffile =
$conf->contact->dir_temp.
'/'.$code;
373 if ($vcffile &&
$id) {
376 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
377 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.
$id.
'-'.$login,
'md5');
378 if ($encodedsecurekey !=
GETPOST(
'securekey')) {
379 $code =
'badvalueforsecurekey';
383 $code = file_get_contents($vcffile);
389 if (empty($generator) || empty($encoding)) {
390 print
'Error: Parameter "generator" or "encoding" not defined';
394 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"),
$conf->modules_parts[
'barcode']);
398 foreach ($dirbarcode as $reldir) {
403 if (!is_dir($newdir)) {
407 $result = @include_once $newdir.$generator.
'.modules.php';
414 $classname =
"mod".ucfirst($generator);
416 $module =
new $classname(
$db);
417 '@phan-var-force ModeleBarCode $module';
419 if ($module->encodingIsSupported($encoding)) {
423 $result = $module->buildBarCode($code, $encoding, $readable);
429 $filename = basename($fullpath_original_file);
432 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
436 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
445 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
448 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
451 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
453 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.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
if(is_numeric( $entity) &&$entity > 0) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Header empty.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Footer empty.