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';
160$action =
GETPOST(
'action',
'aZ09');
161$original_file =
GETPOST(
'file',
'alphanohtml');
162$hashp =
GETPOST(
'hashp',
'aZ09', 1);
163$extname =
GETPOST(
'extname',
'alpha', 1);
164$modulepart =
GETPOST(
'modulepart',
'alpha', 1);
165$urlsource =
GETPOST(
'urlsource',
'alpha');
169if (empty($modulepart) && empty($hashp)) {
172if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
175if ($modulepart ==
'fckeditor') {
176 $modulepart =
'medias';
192$cachestring =
GETPOST(
"cache",
'aZ09');
198 if (empty($dolibarr_nocache)) {
199 $delaycache = ((is_numeric($cachestring) && (int) $cachestring > 1 && (
int) $cachestring < 999999) ? $cachestring :
'3600');
200 header(
'Cache-Control: max-age='.$delaycache.
', public, must-revalidate');
201 header(
'Pragma: cache');
202 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + (
int) $delaycache).
' GMT');
205 header(
'Cache-Control: no-cache');
212 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
213 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
215 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
217 $tmp = explode(
'/', $ecmfile->filepath, 2);
219 if (is_numeric($tmp[0])) {
220 $tmp = explode(
'/', $tmp[1], 2);
222 $moduleparttocheck = $tmp[0];
225 if ($moduleparttocheck == $modulepart) {
227 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
233 $modulepart = $moduleparttocheck;
234 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
246$type =
'application/octet-stream';
248 $type =
GETPOST(
'type',
'alpha');
254if (preg_match(
'/html/i', $type)) {
258if (preg_match(
'/\.noexe$/i', $original_file)) {
263$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
264$original_file = str_replace(
'../',
'/', $original_file);
265$original_file = str_replace(
'..\\',
'/', $original_file);
268$refname = basename(dirname($original_file).
"/");
269if ($refname ==
'thumbs') {
271 $refname = basename(dirname(dirname($original_file)).
"/");
280if (empty($modulepart)) {
286if ($modulepart ===
'medias' && $entity !=
$conf->entity) {
287 $conf->entity = $entity;
288 $conf->setValues($db);
292$accessallowed = $check_access[
'accessallowed'];
293$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
294$fullpath_original_file = $check_access[
'original_file'];
298 $sqlprotectagainstexternals =
'';
300 if (
getDolGlobalString(
'TAKEPOS_AUTO_ORDER') && in_array($modulepart, array(
'product',
'category'))) {
307 if ($user->socid > 0) {
308 if ($sqlprotectagainstexternals) {
309 $resql = $db->query($sqlprotectagainstexternals);
311 $num = $db->num_rows($resql);
314 $obj = $db->fetch_object($resql);
315 if ($user->socid != $obj->fk_soc) {
328if (!$accessallowed) {
334if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
335 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
336 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
342if ($modulepart ==
'barcode') {
343 $generator =
GETPOST(
"generator",
"aZ09");
344 $encoding =
GETPOST(
"encoding",
"aZ09");
345 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
346 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
347 $code =
GETPOST(
"code",
'alphanohtml');
349 $code =
GETPOST(
"code",
'restricthtml');
354 if (preg_match(
'/^virtualcard_([^_]+)_(\d+)\.vcf$/', $code, $reg)) {
358 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
359 $vcffile =
$conf->user->dir_temp.
'/'.$code;
361 $tmpuser =
new User($db);
362 $tmpuser->fetch(
$id);
363 $login = $tmpuser->login;
364 } elseif ($reg[1] ==
'contact' && (
int) $reg[2] > 0) {
365 $vcffile =
$conf->contact->dir_temp.
'/'.$code;
370 if ($vcffile &&
$id) {
373 if ($reg[1] ==
'user' && (
int) $reg[2] > 0) {
374 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.
$id.
'-'.$login,
'md5');
375 if ($encodedsecurekey !=
GETPOST(
'securekey')) {
376 $code =
'badvalueforsecurekey';
380 $code = file_get_contents($vcffile);
386 if (empty($generator) || empty($encoding)) {
387 print
'Error: Parameter "generator" or "encoding" not defined';
391 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"),
$conf->modules_parts[
'barcode']);
395 foreach ($dirbarcode as $reldir) {
400 if (!is_dir($newdir)) {
404 $result = @include_once $newdir.$generator.
'.modules.php';
411 $classname =
"mod".ucfirst($generator);
413 $module =
new $classname($db);
414 '@phan-var-force ModeleBarCode $module';
416 if ($module->encodingIsSupported($encoding)) {
417 $result = $module->buildBarCode($code, $encoding, $readable);
423 $filename = basename($fullpath_original_file);
426 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
430 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
439 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
442 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
445 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
447 readfile($fullpath_original_file_osencoded);
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.