*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file htdocs/webportal/controllers/document.controller.class.php
* \ingroup webportal
* \brief This file is a controller for documents
*/
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
/**
* Class for DocumentController
*/
class DocumentController extends Controller
{
/**
* @var string Action
*/
public $action;
/**
* @var boolean Is Attachment
*/
public $attachment;
/**
* @var string Encoding
*/
public $encoding;
/**
* @var int Entity
*/
public $entity;
/**
* @var string File name
*/
public $filename;
/**
* @var string Full path of original file
*/
public $fullpath_original_file;
/**
* @var string Full path of original file with encoded for OS
*/
public $fullpath_original_file_osencoded;
/**
* @var string Module of document ('module', 'module_user_temp', 'module_user' or 'module_temp'). Example: 'medias', 'invoice', 'logs', 'tax-vat', ...
*/
public $modulepart;
/**
* @var string Relative path with filename, relative to modulepart.
*/
public $original_file;
/**
* @var string Mime type of file
*/
public $type;
/**
* Init
*
* @return void
*/
public function init()
{
global $conf, $hookmanager;
define('MAIN_SECURITY_FORCECSP', "default-src: 'none'");
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
$context = Context::getInstance();
$encoding = '';
$action = GETPOST('action', 'aZ09');
$original_file = GETPOST('file', 'alphanohtml'); // Do not use urldecode here ($_GET are already decoded by PHP).
$modulepart = GETPOST('modulepart', 'alpha');
$entity = GETPOSTINT('entity') ? GETPOSTINT('entity') : $conf->entity;
$socId = GETPOSTINT('soc_id');
// Security check
if (empty($modulepart)) {
httponly_accessforbidden('Bad link. Bad value for parameter modulepart', 400);
exit;
}
if (empty($original_file)) {
httponly_accessforbidden('Bad link. Missing identification to find file (original_file)', 400);
exit;
}
// get original file
$ecmfile = '';
// Define attachment (attachment=true to force choice popup 'open'/'save as')
$attachment = true;
if (preg_match('/\.(html|htm)$/i', $original_file)) {
$attachment = false;
}
if (GETPOSTISSET("attachment")) {
$attachment = GETPOST("attachment", 'alpha') ? true : false;
}
if (getDolGlobalString('MAIN_DISABLE_FORCE_SAVEAS')) {
$attachment = false;
}
// Define mime type
if (GETPOST('type', 'alpha')) {
$type = GETPOST('type', 'alpha');
} else {
$type = dol_mimetype($original_file);
}
// Security: Force to octet-stream if file is a dangerous file. For example when it is a .noexe file
// We do not force if file is a javascript to be able to get js from website module with