2004-10-20 23:06:45 +02:00
|
|
|
<?php
|
2007-04-13 14:55:55 +02:00
|
|
|
/* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2013-06-04 19:36:41 +02:00
|
|
|
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
2005-11-01 16:58:51 +01:00
|
|
|
* Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
|
2012-12-30 15:13:49 +01:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
2010-04-21 10:47:58 +02:00
|
|
|
* Copyright (C) 2010 Pierre Morin <pierre.morin@auguria.net>
|
2010-10-08 18:56:14 +02:00
|
|
|
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
2004-07-12 11:46:13 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-07-12 11:46:13 +02:00
|
|
|
* (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
|
2011-08-01 01:19:04 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-12 11:46:13 +02:00
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
*/
|
|
|
|
|
|
2007-04-13 14:55:55 +02:00
|
|
|
/**
|
2008-11-24 21:09:23 +01:00
|
|
|
* \file htdocs/document.php
|
|
|
|
|
* \brief Wrapper to download data files
|
2010-02-28 15:16:46 +01:00
|
|
|
* \remarks Call of this wrapper is made with URL:
|
2009-02-24 03:41:21 +01:00
|
|
|
* document.php?modulepart=repfichierconcerne&file=pathrelatifdufichier
|
2008-11-24 21:09:23 +01:00
|
|
|
*/
|
2004-12-28 16:02:48 +01:00
|
|
|
|
2009-12-30 13:09:24 +01:00
|
|
|
define('NOTOKENRENEWAL',1); // Disables token renewal
|
2010-01-12 11:26:05 +01:00
|
|
|
// Pour autre que bittorrent, on charge environnement + info issus de logon (comme le user)
|
2011-04-27 19:10:29 +02:00
|
|
|
if (isset($_GET["modulepart"]) && $_GET["modulepart"] == 'bittorrent' && ! defined("NOLOGIN"))
|
2010-02-28 15:16:46 +01:00
|
|
|
{
|
|
|
|
|
define("NOLOGIN",1);
|
|
|
|
|
define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
|
|
|
|
|
}
|
2009-12-30 13:09:24 +01:00
|
|
|
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
|
|
|
|
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
|
|
|
|
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
2009-02-18 18:04:00 +01:00
|
|
|
|
2011-07-09 02:15:16 +02:00
|
|
|
/**
|
2013-04-15 15:43:25 +02:00
|
|
|
* Header empty
|
2011-07-09 02:15:16 +02:00
|
|
|
*
|
2013-04-15 15:43:25 +02:00
|
|
|
* @return void
|
2011-07-09 02:15:16 +02:00
|
|
|
*/
|
2007-11-19 19:34:53 +01:00
|
|
|
function llxHeader() { }
|
2013-04-15 15:43:25 +02:00
|
|
|
/**
|
|
|
|
|
* Footer empty
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
function llxFooter() { }
|
2007-11-19 19:34:53 +01:00
|
|
|
|
2013-04-28 18:46:34 +02:00
|
|
|
|
2012-08-23 01:43:44 +02:00
|
|
|
require 'main.inc.php'; // Load $user and permissions
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
2011-04-27 19:10:29 +02:00
|
|
|
|
|
|
|
|
$encoding = '';
|
2012-04-07 10:18:09 +02:00
|
|
|
$action=GETPOST('action','alpha');
|
|
|
|
|
$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP).
|
|
|
|
|
$modulepart=GETPOST('modulepart','alpha');
|
|
|
|
|
$urlsource=GETPOST('urlsource','alpha');
|
2012-04-18 01:01:46 +02:00
|
|
|
$entity=GETPOST('entity')?GETPOST('entity','int'):$conf->entity;
|
2011-04-27 19:10:29 +02:00
|
|
|
|
2011-06-15 13:35:33 +02:00
|
|
|
// Security check
|
|
|
|
|
if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
|
|
|
|
|
|
2010-12-18 04:27:01 +01:00
|
|
|
|
|
|
|
|
/*
|
2011-04-27 19:10:29 +02:00
|
|
|
* Action
|
2010-12-18 04:27:01 +01:00
|
|
|
*/
|
|
|
|
|
|
2011-04-27 19:10:29 +02:00
|
|
|
// None
|
2008-08-04 00:50:32 +02:00
|
|
|
|
2011-04-27 19:10:29 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
2011-04-26 23:06:45 +02:00
|
|
|
|
2008-08-04 00:50:32 +02:00
|
|
|
// Define mime type
|
|
|
|
|
$type = 'application/octet-stream';
|
2012-02-27 17:02:56 +01:00
|
|
|
if (GETPOST('type','alpha')) $type=GETPOST('type','alpha');
|
2008-08-04 00:50:32 +02:00
|
|
|
else $type=dol_mimetype($original_file);
|
|
|
|
|
|
2012-09-07 17:23:16 +02:00
|
|
|
// Define attachment (attachment=true to force choice popup 'open'/'save as')
|
|
|
|
|
$attachment = true;
|
2012-09-03 18:01:07 +02:00
|
|
|
if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false;
|
2012-09-07 17:23:16 +02:00
|
|
|
if (isset($_GET["attachment"])) $attachment = GETPOST("attachment")?true:false;
|
|
|
|
|
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
|
2012-09-03 17:01:03 +02:00
|
|
|
|
2012-09-07 17:23:16 +02:00
|
|
|
// Suppression de la chaine de caractere ../ dans $original_file
|
|
|
|
|
$original_file = str_replace("../","/", $original_file);
|
|
|
|
|
|
|
|
|
|
// Find the subdirectory name as the reference
|
2007-01-31 18:52:54 +01:00
|
|
|
$refname=basename(dirname($original_file)."/");
|
2005-08-25 12:20:13 +02:00
|
|
|
|
2010-11-07 13:33:32 +01:00
|
|
|
// Security check
|
2013-04-25 10:06:54 +02:00
|
|
|
if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
|
2013-05-16 15:46:54 +02:00
|
|
|
$check_access = dol_check_secure_access_document($modulepart,$original_file,$entity,$refname);
|
2013-04-25 10:06:54 +02:00
|
|
|
$accessallowed = $check_access['accessallowed'];
|
2013-04-22 15:00:29 +02:00
|
|
|
$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
|
2013-06-04 22:03:11 +02:00
|
|
|
$original_file = $check_access['original_file'];
|
2012-04-18 01:01:46 +02:00
|
|
|
|
2007-01-31 18:52:54 +01:00
|
|
|
// Basic protection (against external users only)
|
2007-11-19 19:34:53 +01:00
|
|
|
if ($user->societe_id > 0)
|
2007-01-31 18:52:54 +01:00
|
|
|
{
|
|
|
|
|
if ($sqlprotectagainstexternals)
|
|
|
|
|
{
|
|
|
|
|
$resql = $db->query($sqlprotectagainstexternals);
|
|
|
|
|
if ($resql)
|
|
|
|
|
{
|
2009-04-29 22:16:13 +02:00
|
|
|
$num=$db->num_rows($resql);
|
2010-04-21 20:35:40 +02:00
|
|
|
$i=0;
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
{
|
|
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
if ($user->societe_id != $obj->fk_soc)
|
|
|
|
|
{
|
|
|
|
|
$accessallowed=0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
2007-01-31 18:52:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-12 21:47:50 +02:00
|
|
|
// Security:
|
2008-01-21 00:18:18 +01:00
|
|
|
// Limite acces si droits non corrects
|
2005-02-08 13:03:12 +01:00
|
|
|
if (! $accessallowed)
|
|
|
|
|
{
|
2009-04-29 22:16:13 +02:00
|
|
|
accessforbidden();
|
2005-02-08 13:03:12 +01:00
|
|
|
}
|
2004-12-28 16:02:48 +01:00
|
|
|
|
2007-04-12 21:47:50 +02:00
|
|
|
// Security:
|
2009-02-18 18:04:00 +01:00
|
|
|
// On interdit les remontees de repertoire ainsi que les pipe dans
|
2007-04-12 21:47:50 +02:00
|
|
|
// les noms de fichiers.
|
2009-10-24 08:10:00 +02:00
|
|
|
if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
|
2007-04-12 21:47:50 +02:00
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
dol_syslog("Refused to deliver file ".$original_file);
|
2011-04-27 19:10:29 +02:00
|
|
|
$file=basename($original_file); // Do no show plain path of original_file in shown error message
|
|
|
|
|
dol_print_error(0,$langs->trans("ErrorFileNameInvalid",$file));
|
2007-04-12 21:47:50 +02:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 18:04:00 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
clearstatcache();
|
2006-06-10 20:43:11 +02:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
$filename = basename($original_file);
|
2006-04-27 23:25:56 +02:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
// Output file on browser
|
|
|
|
|
dol_syslog("document.php download $original_file $filename content-type=$type");
|
|
|
|
|
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
|
2007-01-31 18:52:54 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
// This test if file exists should be useless. We keep it to find bug more easily
|
|
|
|
|
if (! file_exists($original_file_osencoded))
|
2012-05-30 04:11:00 +02:00
|
|
|
{
|
2012-09-03 17:01:03 +02:00
|
|
|
dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2009-02-18 18:04:00 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
// Les drois sont ok et fichier trouve, on l'envoie
|
2009-02-18 18:04:00 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
|
if ($encoding) header('Content-Encoding: '.$encoding);
|
|
|
|
|
if ($type) header('Content-Type: '.$type.(preg_match('/text/',$type)?'; charset="'.$conf->file->character_set_client:''));
|
2012-09-03 18:01:07 +02:00
|
|
|
// Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, atachment=need user action to open)
|
2012-09-03 17:01:03 +02:00
|
|
|
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
|
|
|
|
|
else header('Content-Disposition: inline; filename="'.$filename.'"');
|
|
|
|
|
header('Content-Length: ' . dol_filesize($original_file));
|
|
|
|
|
// Ajout directives pour resoudre bug IE
|
|
|
|
|
header('Cache-Control: Public, must-revalidate');
|
|
|
|
|
header('Pragma: public');
|
2009-02-18 18:04:00 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
//ob_clean();
|
|
|
|
|
//flush();
|
2011-12-31 02:50:37 +01:00
|
|
|
|
2012-09-03 17:01:03 +02:00
|
|
|
readfile($original_file_osencoded);
|
2004-12-28 16:02:48 +01:00
|
|
|
|
2013-06-26 16:45:42 +02:00
|
|
|
if (is_object($db)) $db->close();
|