2003-04-10 21:35:31 +00:00
|
|
|
<?php
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
* @version $Id$
|
|
|
|
* @copyright (c) 2005 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2006-05-05 17:56:33 +00:00
|
|
|
* @ignore
|
2005-04-09 12:26:45 +00:00
|
|
|
*/
|
2003-04-10 21:35:31 +00:00
|
|
|
define('IN_PHPBB', true);
|
|
|
|
$phpbb_root_path = './';
|
2003-09-07 13:46:51 +00:00
|
|
|
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
2007-04-30 10:46:17 +00:00
|
|
|
|
|
|
|
if (isset($_GET['avatar']))
|
|
|
|
{
|
|
|
|
require($phpbb_root_path . 'config.' . $phpEx);
|
|
|
|
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
|
|
|
|
require($phpbb_root_path . 'includes/cache.' . $phpEx);
|
|
|
|
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
|
|
|
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
|
|
|
|
|
|
|
$db = new $sql_db();
|
|
|
|
$cache = new cache();
|
|
|
|
|
|
|
|
// Connect to DB
|
|
|
|
if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
2007-04-30 11:42:19 +00:00
|
|
|
unset($dbpasswd);
|
2007-04-30 10:46:17 +00:00
|
|
|
|
|
|
|
$config = $cache->obtain_config();
|
|
|
|
$filename = $_GET['avatar'];
|
|
|
|
$avatar_group = false;
|
|
|
|
if ($filename[0] === 'g')
|
|
|
|
{
|
|
|
|
$avatar_group = true;
|
|
|
|
$filename = substr($filename, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// '==' is not a bug - . as the first char is as bad as no dot at all
|
|
|
|
if (strpos($filename, '.') == false)
|
|
|
|
{
|
|
|
|
header('HTTP/1.0 403 forbidden');
|
|
|
|
if (!empty($cache))
|
|
|
|
{
|
|
|
|
$cache->unload();
|
|
|
|
}
|
|
|
|
$db->sql_close();
|
|
|
|
exit;
|
|
|
|
}
|
2007-05-09 16:12:37 +00:00
|
|
|
|
|
|
|
$ext = substr(strrchr($filename, '.'), 1);
|
2007-04-30 10:46:17 +00:00
|
|
|
$filename = intval($filename);
|
|
|
|
|
|
|
|
if (!in_array($ext, array('png', 'gif', 'jpg', 'jpeg')))
|
|
|
|
{
|
|
|
|
// no way such an avatar could exist. They are not following the rules, stop the show.
|
|
|
|
header("HTTP/1.0 403 forbidden");
|
|
|
|
if (!empty($cache))
|
|
|
|
{
|
|
|
|
$cache->unload();
|
|
|
|
}
|
|
|
|
$db->sql_close();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$filename)
|
|
|
|
{
|
|
|
|
// no way such an avatar could exist. They are not following the rules, stop the show.
|
|
|
|
header("HTTP/1.0 403 forbidden");
|
|
|
|
if (!empty($cache))
|
|
|
|
{
|
|
|
|
$cache->unload();
|
|
|
|
}
|
|
|
|
$db->sql_close();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext);
|
|
|
|
|
|
|
|
if (!empty($cache))
|
|
|
|
{
|
|
|
|
$cache->unload();
|
|
|
|
}
|
|
|
|
$db->sql_close();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implicit else: we are not in avatar mode
|
2006-06-06 20:53:46 +00:00
|
|
|
include($phpbb_root_path . 'common.' . $phpEx);
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2003-10-19 15:17:35 +00:00
|
|
|
$download_id = request_var('id', 0);
|
2007-04-30 10:46:17 +00:00
|
|
|
$mode = request_var('mode', '');
|
2004-02-28 21:16:15 +00:00
|
|
|
$thumbnail = request_var('t', false);
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2006-08-11 13:21:51 +00:00
|
|
|
// Start session management, do not update session page.
|
|
|
|
$user->session_begin(false);
|
2003-04-10 21:35:31 +00:00
|
|
|
$auth->acl($user->data);
|
2004-02-28 21:16:15 +00:00
|
|
|
$user->setup('viewtopic');
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2003-05-25 13:07:19 +00:00
|
|
|
if (!$download_id)
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
|
|
|
trigger_error('NO_ATTACHMENT_SELECTED');
|
|
|
|
}
|
|
|
|
|
2004-05-02 13:06:57 +00:00
|
|
|
if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
|
|
|
trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
|
|
|
|
}
|
2003-10-19 15:17:35 +00:00
|
|
|
|
2006-09-13 16:08:36 +00:00
|
|
|
$sql = 'SELECT attach_id, in_message, post_msg_id, extension, is_orphan, poster_id
|
2003-11-04 22:05:38 +00:00
|
|
|
FROM ' . ATTACHMENTS_TABLE . "
|
2003-06-18 17:57:44 +00:00
|
|
|
WHERE attach_id = $download_id";
|
2003-10-19 15:17:35 +00:00
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
2006-05-26 15:04:27 +00:00
|
|
|
$attachment = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2006-05-26 15:04:27 +00:00
|
|
|
if (!$attachment)
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
|
|
|
trigger_error('ERROR_NO_ATTACHMENT');
|
|
|
|
}
|
|
|
|
|
2004-05-02 13:06:57 +00:00
|
|
|
if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
|
|
|
|
{
|
|
|
|
trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
|
|
|
|
}
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2004-05-02 13:06:57 +00:00
|
|
|
$row = array();
|
2006-09-13 16:08:36 +00:00
|
|
|
|
|
|
|
if ($attachment['is_orphan'])
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2006-09-13 16:08:36 +00:00
|
|
|
// We allow admins having attachment permissions to see orphan attachments...
|
|
|
|
$own_attachment = ($auth->acl_get('a_attach') || $attachment['poster_id'] == $user->data['user_id']) ? true : false;
|
|
|
|
|
|
|
|
if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
|
2006-08-11 13:21:51 +00:00
|
|
|
{
|
2006-09-13 16:08:36 +00:00
|
|
|
trigger_error('ERROR_NO_ATTACHMENT');
|
|
|
|
}
|
2006-08-11 13:21:51 +00:00
|
|
|
|
2006-12-27 17:43:55 +00:00
|
|
|
// Obtain all extensions...
|
|
|
|
$extensions = $cache->obtain_attach_extensions(true);
|
2006-09-13 16:08:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!$attachment['in_message'])
|
|
|
|
{
|
|
|
|
//
|
|
|
|
$sql = 'SELECT p.forum_id, f.forum_password, f.parent_id
|
|
|
|
FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
|
|
|
|
WHERE p.post_id = ' . $attachment['post_msg_id'] . '
|
|
|
|
AND p.forum_id = f.forum_id';
|
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
2006-08-11 13:21:51 +00:00
|
|
|
$row = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
|
2006-09-13 16:08:36 +00:00
|
|
|
// Global announcement?
|
2007-05-03 14:29:22 +00:00
|
|
|
$f_download = (!$row) ? $auth->acl_getf_global('f_download') : $auth->acl_get('f_download', $row['forum_id']);
|
2006-09-13 16:08:36 +00:00
|
|
|
|
2007-05-03 14:29:22 +00:00
|
|
|
if ($auth->acl_get('u_download') && $f_download)
|
2006-09-13 16:08:36 +00:00
|
|
|
{
|
2007-05-03 14:29:22 +00:00
|
|
|
if ($row && $row['forum_password'])
|
2006-09-13 16:08:36 +00:00
|
|
|
{
|
|
|
|
// Do something else ... ?
|
|
|
|
login_forum_box($row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-05-02 13:06:57 +00:00
|
|
|
{
|
2006-09-13 16:08:36 +00:00
|
|
|
trigger_error('SORRY_AUTH_VIEW_ATTACH');
|
2004-05-02 13:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2006-12-27 17:43:55 +00:00
|
|
|
$row['forum_id'] = false;
|
2006-09-13 16:08:36 +00:00
|
|
|
if (!$auth->acl_get('u_pm_download'))
|
|
|
|
{
|
|
|
|
trigger_error('SORRY_AUTH_VIEW_ATTACH');
|
|
|
|
}
|
2003-04-10 21:35:31 +00:00
|
|
|
}
|
2006-09-13 16:08:36 +00:00
|
|
|
|
2006-12-27 17:43:55 +00:00
|
|
|
// disallowed?
|
2006-09-13 16:08:36 +00:00
|
|
|
$extensions = array();
|
|
|
|
if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
|
2004-05-02 13:06:57 +00:00
|
|
|
{
|
2006-09-13 16:08:36 +00:00
|
|
|
trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
|
2004-05-02 13:06:57 +00:00
|
|
|
}
|
2003-04-10 21:35:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-23 22:25:46 +00:00
|
|
|
if (!download_allowed())
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['LINKAGE_FORBIDDEN']);
|
|
|
|
}
|
|
|
|
|
2003-10-19 15:17:35 +00:00
|
|
|
$download_mode = (int) $extensions[$attachment['extension']]['download_mode'];
|
2003-04-10 21:35:31 +00:00
|
|
|
|
2004-12-12 14:07:02 +00:00
|
|
|
// Fetching filename here to prevent sniffing of filename
|
2006-09-13 16:08:36 +00:00
|
|
|
$sql = 'SELECT attach_id, is_orphan, in_message, post_msg_id, extension, physical_filename, real_filename, mimetype
|
2004-12-12 14:07:02 +00:00
|
|
|
FROM ' . ATTACHMENTS_TABLE . "
|
|
|
|
WHERE attach_id = $download_id";
|
|
|
|
$result = $db->sql_query_limit($sql, 1);
|
2006-05-26 15:04:27 +00:00
|
|
|
$attachment = $db->sql_fetchrow($result);
|
|
|
|
$db->sql_freeresult($result);
|
2004-12-12 14:07:02 +00:00
|
|
|
|
2006-05-26 15:04:27 +00:00
|
|
|
if (!$attachment)
|
2004-12-12 14:07:02 +00:00
|
|
|
{
|
|
|
|
trigger_error('ERROR_NO_ATTACHMENT');
|
|
|
|
}
|
2006-05-26 15:04:27 +00:00
|
|
|
|
2004-12-12 14:07:02 +00:00
|
|
|
$attachment['physical_filename'] = basename($attachment['physical_filename']);
|
2006-08-11 13:21:51 +00:00
|
|
|
$display_cat = $extensions[$attachment['extension']]['display_cat'];
|
2004-12-12 14:07:02 +00:00
|
|
|
|
2003-04-10 21:35:31 +00:00
|
|
|
if ($thumbnail)
|
|
|
|
{
|
2003-11-16 21:53:56 +00:00
|
|
|
$attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
|
2003-04-10 21:35:31 +00:00
|
|
|
}
|
2006-09-13 16:08:36 +00:00
|
|
|
else if (($display_cat == ATTACHMENT_CATEGORY_NONE || $display_cat == ATTACHMENT_CATEGORY_IMAGE) && !$attachment['is_orphan'])
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2003-10-19 15:17:35 +00:00
|
|
|
// Update download count
|
2003-11-04 22:05:38 +00:00
|
|
|
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
|
2003-04-10 21:35:31 +00:00
|
|
|
SET download_count = download_count + 1
|
|
|
|
WHERE attach_id = ' . $attachment['attach_id'];
|
|
|
|
$db->sql_query($sql);
|
|
|
|
}
|
|
|
|
|
2007-04-30 10:46:17 +00:00
|
|
|
if ($mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && strpos(strtolower($user->browser), 'msie') !== false)
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2007-04-30 10:46:17 +00:00
|
|
|
wrap_img_in_html(append_sid('./download.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Determine the 'presenting'-method
|
|
|
|
if ($download_mode == PHYSICAL_LINK)
|
|
|
|
{
|
|
|
|
// This presenting method should no longer be used
|
|
|
|
if (!@is_dir($phpbb_root_path . $config['upload_path']))
|
|
|
|
{
|
|
|
|
trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
|
|
|
|
}
|
|
|
|
|
2007-05-09 16:12:37 +00:00
|
|
|
redirect($phpbb_root_path . $config['upload_path'] . '/' . $attachment['physical_filename']);
|
|
|
|
exit;
|
2007-04-30 10:46:17 +00:00
|
|
|
}
|
|
|
|
else
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2007-04-30 10:46:17 +00:00
|
|
|
send_file_to_browser($attachment, $config['upload_path'], $extensions[$attachment['extension']]['display_cat']);
|
|
|
|
exit;
|
2003-04-10 21:35:31 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-30 10:46:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simplified function to deliver avatars
|
|
|
|
* The argument needs to be checked before calling this function.
|
|
|
|
*/
|
|
|
|
function send_avatar_to_browser($file)
|
2003-04-10 21:35:31 +00:00
|
|
|
{
|
2007-04-30 10:46:17 +00:00
|
|
|
global $config, $phpbb_root_path;
|
2007-05-03 14:29:22 +00:00
|
|
|
|
2007-04-30 10:46:17 +00:00
|
|
|
$prefix = $config['avatar_salt'] . '_';
|
2007-05-03 14:29:22 +00:00
|
|
|
$image_dir = $config['avatar_path'];
|
|
|
|
|
2007-04-30 11:42:19 +00:00
|
|
|
// worst-case default
|
|
|
|
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
|
2007-04-30 10:46:17 +00:00
|
|
|
|
2007-05-03 14:29:22 +00:00
|
|
|
// Adjust image_dir path (no trailing slash)
|
|
|
|
if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\')
|
2007-04-30 10:46:17 +00:00
|
|
|
{
|
2007-05-03 14:29:22 +00:00
|
|
|
$image_dir = substr($image_dir, 0, -1) . '/';
|
2007-04-30 10:46:17 +00:00
|
|
|
}
|
2007-05-03 14:29:22 +00:00
|
|
|
$image_dir = str_replace(array('../', '..\\', './', '.\\'), '', $image_dir);
|
|
|
|
|
|
|
|
if ($image_dir && ($image_dir[0] == '/' || $image_dir[0] == '\\'))
|
2007-04-30 10:46:17 +00:00
|
|
|
{
|
2007-05-03 14:29:22 +00:00
|
|
|
$image_dir = '';
|
2007-04-30 10:46:17 +00:00
|
|
|
}
|
2007-05-03 14:29:22 +00:00
|
|
|
$file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file;
|
2007-04-30 10:46:17 +00:00
|
|
|
|
|
|
|
if ((@file_exists($file_path) && @is_readable($file_path)) || headers_sent())
|
|
|
|
{
|
|
|
|
header('Pragma: public');
|
|
|
|
|
2007-05-03 14:29:22 +00:00
|
|
|
$image_data = getimagesize($file_path);
|
2007-04-30 10:46:17 +00:00
|
|
|
header('Content-Type: ' . image_type_to_mime_type($image_data[2]));
|
|
|
|
|
|
|
|
if (strpos(strtolower($browser), 'msie') !== false)
|
|
|
|
{
|
|
|
|
header('Content-Disposition: attachment; ' . header_filename($file));
|
2007-05-03 14:29:22 +00:00
|
|
|
|
2007-04-30 10:46:17 +00:00
|
|
|
if (strpos(strtolower($browser), 'msie 6.0') !== false)
|
|
|
|
{
|
|
|
|
header('Expires: -1');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header('Content-Disposition: inline; ' . header_filename($file));
|
|
|
|
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
|
|
|
|
}
|
|
|
|
|
|
|
|
$size = @filesize($file_path);
|
|
|
|
if ($size)
|
|
|
|
{
|
|
|
|
header("Content-Length: $size");
|
|
|
|
}
|
|
|
|
|
|
|
|
readfile($file_path);
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header('HTTP/1.0 404 not found');
|
|
|
|
}
|
2003-04-10 21:35:31 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 10:46:17 +00:00
|
|
|
/**
|
|
|
|
* Wraps an url into a simple html page. Used to display attachments in IE.
|
|
|
|
* this is a workaround for now; might be moved to template system later
|
|
|
|
* direct any complaints to 1 Microsoft Way, Redmond
|
|
|
|
*/
|
|
|
|
function wrap_img_in_html($src, $title)
|
|
|
|
{
|
|
|
|
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">';
|
|
|
|
echo '<html>';
|
|
|
|
echo '<head>';
|
|
|
|
echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
|
|
|
|
echo '<title>' . $title . '</title>';
|
|
|
|
echo '</head>';
|
|
|
|
echo '<body>';
|
|
|
|
echo '<div>';
|
|
|
|
echo '<img src="' . $src . '" alt="' . $title . '" />';
|
|
|
|
echo '</div>';
|
|
|
|
echo '</body>';
|
|
|
|
echo '</html>';
|
|
|
|
}
|
2003-09-07 13:46:51 +00:00
|
|
|
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
|
|
|
* Send file to browser
|
|
|
|
*/
|
2003-09-07 13:46:51 +00:00
|
|
|
function send_file_to_browser($attachment, $upload_dir, $category)
|
|
|
|
{
|
2004-12-12 14:07:02 +00:00
|
|
|
global $user, $db, $config, $phpbb_root_path;
|
2003-09-07 13:46:51 +00:00
|
|
|
|
2004-12-12 14:07:02 +00:00
|
|
|
$filename = $phpbb_root_path . $upload_dir . '/' . $attachment['physical_filename'];
|
2003-09-07 13:46:51 +00:00
|
|
|
|
2003-10-19 15:17:35 +00:00
|
|
|
if (!@file_exists($filename))
|
2003-09-07 13:46:51 +00:00
|
|
|
{
|
|
|
|
trigger_error($user->lang['ERROR_NO_ATTACHMENT'] . '<br /><br />' . sprintf($user->lang['FILE_NOT_FOUND_404'], $filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Correct the mime type - we force application/octetstream for all files, except images
|
|
|
|
// Please do not change this, it is a security precaution
|
2006-09-13 16:08:36 +00:00
|
|
|
if (strpos($attachment['mimetype'], 'image') !== 0)
|
2003-09-07 13:46:51 +00:00
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
$attachment['mimetype'] = (strpos(strtolower($user->browser), 'msie') !== false || strpos(strtolower($user->browser), 'opera') !== false) ? 'application/octetstream' : 'application/octet-stream';
|
2003-09-07 13:46:51 +00:00
|
|
|
}
|
|
|
|
|
2005-04-30 14:36:33 +00:00
|
|
|
if (@ob_get_length())
|
2004-12-12 14:07:02 +00:00
|
|
|
{
|
|
|
|
@ob_end_clean();
|
|
|
|
}
|
2003-09-07 13:46:51 +00:00
|
|
|
|
|
|
|
// Now send the File Contents to the Browser
|
|
|
|
$size = @filesize($filename);
|
2006-07-06 16:46:53 +00:00
|
|
|
|
|
|
|
// To correctly display further errors we need to make sure we are using the correct headers for both (unsetting content-length may not work)
|
|
|
|
|
|
|
|
// Check if headers already sent or not able to get the file contents.
|
2006-08-20 19:50:08 +00:00
|
|
|
if (headers_sent() || !@file_exists($filename) || !@is_readable($filename))
|
2003-10-19 15:17:35 +00:00
|
|
|
{
|
2006-03-21 19:23:34 +00:00
|
|
|
// PHP track_errors setting On?
|
|
|
|
if (!empty($php_errormsg))
|
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
|
2006-03-21 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
2006-07-06 16:46:53 +00:00
|
|
|
trigger_error('UNABLE_TO_DELIVER_FILE');
|
2003-10-19 15:17:35 +00:00
|
|
|
}
|
2003-09-07 13:46:51 +00:00
|
|
|
|
2006-07-06 16:46:53 +00:00
|
|
|
// Now the tricky part... let's dance
|
|
|
|
header('Pragma: public');
|
|
|
|
|
2006-10-30 19:51:56 +00:00
|
|
|
/**
|
|
|
|
* Commented out X-Sendfile support. To not expose the physical filename within the header if xsendfile is absent we need to look into methods of checking it's status.
|
|
|
|
*
|
|
|
|
* Try X-Sendfile since it is much more server friendly - only works if the path is *not* outside of the root path...
|
|
|
|
* lighttpd has core support for it. An apache2 module is available at http://celebnamer.celebworld.ws/stuff/mod_xsendfile/
|
|
|
|
*
|
|
|
|
* Not really ideal, but should work fine...
|
|
|
|
* <code>
|
|
|
|
* if (strpos($upload_dir, '/') !== 0 && strpos($upload_dir, '../') === false)
|
2006-11-02 15:23:33 +00:00
|
|
|
* {
|
|
|
|
* header('X-Sendfile: ' . $filename);
|
|
|
|
* }
|
2006-10-30 19:51:56 +00:00
|
|
|
* </code>
|
|
|
|
*/
|
2006-08-20 19:50:08 +00:00
|
|
|
|
2006-09-04 20:35:46 +00:00
|
|
|
// Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.
|
2006-10-23 21:07:45 +00:00
|
|
|
header('Content-Type: ' . $attachment['mimetype']);
|
2007-04-30 10:46:17 +00:00
|
|
|
|
2007-04-30 11:42:19 +00:00
|
|
|
if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie') !== false))
|
2007-04-30 10:46:17 +00:00
|
|
|
{
|
|
|
|
header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
|
2007-04-30 11:42:19 +00:00
|
|
|
if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false))
|
2007-04-30 10:46:17 +00:00
|
|
|
{
|
|
|
|
header('expires: -1');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
|
|
|
|
}
|
|
|
|
|
2006-07-06 16:46:53 +00:00
|
|
|
if ($size)
|
|
|
|
{
|
2006-08-20 19:50:08 +00:00
|
|
|
header("Content-Length: $size");
|
2006-07-06 16:46:53 +00:00
|
|
|
}
|
2006-08-20 19:50:08 +00:00
|
|
|
|
2006-11-21 15:08:18 +00:00
|
|
|
// Try to deliver in chunks
|
|
|
|
@set_time_limit(0);
|
|
|
|
|
|
|
|
$fp = @fopen($filename, 'rb');
|
|
|
|
|
|
|
|
if ($fp !== false)
|
|
|
|
{
|
|
|
|
while (!feof($fp))
|
|
|
|
{
|
2006-11-21 15:44:44 +00:00
|
|
|
echo fread($fp, 8192);
|
2006-11-21 15:08:18 +00:00
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
}
|
2006-07-06 16:46:53 +00:00
|
|
|
|
2003-10-19 15:17:35 +00:00
|
|
|
flush();
|
2003-09-07 13:46:51 +00:00
|
|
|
exit;
|
|
|
|
}
|
2003-11-23 22:25:46 +00:00
|
|
|
|
2007-02-06 19:09:43 +00:00
|
|
|
/**
|
2006-10-23 21:07:45 +00:00
|
|
|
* Get a browser friendly UTF-8 encoded filename
|
|
|
|
*/
|
|
|
|
function header_filename($file)
|
|
|
|
{
|
2007-04-30 11:42:19 +00:00
|
|
|
$user_agent = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
|
2007-02-18 13:42:08 +00:00
|
|
|
|
|
|
|
// There be dragons here.
|
|
|
|
// Not many follows the RFC...
|
|
|
|
if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false)
|
2006-10-23 21:07:45 +00:00
|
|
|
{
|
|
|
|
return "filename=" . rawurlencode($file);
|
|
|
|
}
|
2007-02-06 19:09:43 +00:00
|
|
|
|
|
|
|
// follow the RFC for extended filename for the rest
|
|
|
|
return "filename*=UTF-8''" . rawurlencode($file);
|
2006-10-23 21:07:45 +00:00
|
|
|
}
|
|
|
|
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
|
|
|
* Check if downloading item is allowed
|
|
|
|
*/
|
2003-11-23 22:25:46 +00:00
|
|
|
function download_allowed()
|
|
|
|
{
|
|
|
|
global $config, $user, $db;
|
|
|
|
|
|
|
|
if (!$config['secure_downloads'])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-06 16:46:53 +00:00
|
|
|
$url = (!empty($_SERVER['HTTP_REFERER'])) ? trim($_SERVER['HTTP_REFERER']) : trim(getenv('HTTP_REFERER'));
|
2003-11-23 22:25:46 +00:00
|
|
|
|
2004-02-28 21:16:15 +00:00
|
|
|
if (!$url)
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
|
|
|
return ($config['secure_allow_empty_referer']) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split URL into domain and script part
|
2006-07-06 16:46:53 +00:00
|
|
|
$url = @parse_url($url);
|
|
|
|
|
|
|
|
if ($url === false)
|
|
|
|
{
|
|
|
|
return ($config['secure_allow_empty_referer']) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hostname = $url['host'];
|
2003-11-23 22:25:46 +00:00
|
|
|
unset($url);
|
|
|
|
|
2004-02-28 21:16:15 +00:00
|
|
|
$allowed = ($config['secure_allow_deny']) ? false : true;
|
2003-11-23 22:25:46 +00:00
|
|
|
$iplist = array();
|
|
|
|
|
2006-07-06 16:46:53 +00:00
|
|
|
if (($ip_ary = @gethostbynamel($hostname)) !== false)
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
foreach ($ip_ary as $ip)
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
if ($ip)
|
|
|
|
{
|
|
|
|
$iplist[] = $ip;
|
|
|
|
}
|
2003-11-23 22:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for own server...
|
2006-05-26 15:04:27 +00:00
|
|
|
$server_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME');
|
|
|
|
|
|
|
|
// Forcing server vars is the only way to specify/override the protocol
|
|
|
|
if ($config['force_server_vars'] || !$server_name)
|
|
|
|
{
|
|
|
|
$server_name = $config['server_name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('#^.*?' . preg_quote($server_name, '#') . '.*?$#i', $hostname))
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
|
|
|
$allowed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get IP's and Hostnames
|
|
|
|
if (!$allowed)
|
|
|
|
{
|
|
|
|
$sql = 'SELECT site_ip, site_hostname, ip_exclude
|
|
|
|
FROM ' . SITELIST_TABLE;
|
|
|
|
$result = $db->sql_query($sql);
|
|
|
|
|
|
|
|
while ($row = $db->sql_fetchrow($result))
|
|
|
|
{
|
2004-02-28 21:16:15 +00:00
|
|
|
$site_ip = trim($row['site_ip']);
|
|
|
|
$site_hostname = trim($row['site_hostname']);
|
|
|
|
|
|
|
|
if ($site_ip)
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
|
|
|
foreach ($iplist as $ip)
|
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
if (preg_match('#^' . str_replace('*', '.*?', preg_quote($site_ip, '#')) . '$#i', $ip))
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
2004-02-28 21:16:15 +00:00
|
|
|
if ($row['ip_exclude'])
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
|
|
|
$allowed = ($config['secure_allow_deny']) ? false : true;
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$allowed = ($config['secure_allow_deny']) ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-28 21:16:15 +00:00
|
|
|
if ($site_hostname)
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
2006-07-06 16:46:53 +00:00
|
|
|
if (preg_match('#^' . str_replace('*', '.*?', preg_quote($site_hostname, '#')) . '$#i', $hostname))
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
2004-02-28 21:16:15 +00:00
|
|
|
if ($row['ip_exclude'])
|
2003-11-23 22:25:46 +00:00
|
|
|
{
|
|
|
|
$allowed = ($config['secure_allow_deny']) ? false : true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$allowed = ($config['secure_allow_deny']) ? true : false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$db->sql_freeresult($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $allowed;
|
|
|
|
}
|
|
|
|
|
2003-04-10 21:35:31 +00:00
|
|
|
?>
|