phpBB

Code Changes

File: download/file.php

  Unmodified   Added   Modified   Removed
Line 31Line 31

if (isset($_GET['avatar']))
{


if (isset($_GET['avatar']))
{

 
	require($phpbb_root_path . 'includes/startup.' . $phpEx);

	require($phpbb_root_path . 'config.' . $phpEx);

if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))

	require($phpbb_root_path . 'config.' . $phpEx);

if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))

Line 42Line 43
	require($phpbb_root_path . 'includes/cache.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);

	require($phpbb_root_path . 'includes/cache.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);

 
	require($phpbb_root_path . 'includes/functions.' . $phpEx);


$db = new $sql_db();
$cache = new cache();


$db = new $sql_db();
$cache = new cache();

Line 57Line 59
	$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';

$config = $cache->obtain_config();

	$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';

$config = $cache->obtain_config();

	$filename = $_GET['avatar'];

	$filename = request_var('avatar', '');

	$avatar_group = false;
$exit = false;


	$avatar_group = false;
$exit = false;


	if ($filename[0] === 'g')

	if (isset($filename[0]) && $filename[0] === 'g')

	{
$avatar_group = true;
$filename = substr($filename, 1);

	{
$avatar_group = true;
$filename = substr($filename, 1);

Line 70Line 72
	// '==' is not a bug - . as the first char is as bad as no dot at all
if (strpos($filename, '.') == false)
{

	// '==' 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');

		send_status_line(403, 'Forbidden');

		$exit = true;
}


		$exit = true;
}


Line 84Line 86
	if (!$exit && !in_array($ext, array('png', 'gif', 'jpg', 'jpeg')))
{
// no way such an avatar could exist. They are not following the rules, stop the show.

	if (!$exit && !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");

		send_status_line(403, 'Forbidden');

		$exit = true;
}


		$exit = true;
}


Line 94Line 96
		if (!$filename)
{
// no way such an avatar could exist. They are not following the rules, stop the show.

		if (!$filename)
{
// no way such an avatar could exist. They are not following the rules, stop the show.

			header("HTTP/1.0 403 Forbidden");

			send_status_line(403, 'Forbidden');

		}
else
{

		}
else
{

Line 118Line 120

if (!$download_id)
{


if (!$download_id)
{

 
	send_status_line(404, 'Not Found');

	trigger_error('NO_ATTACHMENT_SELECTED');
}

if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
{

	trigger_error('NO_ATTACHMENT_SELECTED');
}

if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
{

 
	send_status_line(404, 'Not Found');

	trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}


	trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}


Line 135Line 139

if (!$attachment)
{


if (!$attachment)
{

 
	send_status_line(404, 'Not Found');

	trigger_error('ERROR_NO_ATTACHMENT');
}

if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
{

	trigger_error('ERROR_NO_ATTACHMENT');
}

if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
{

 
	send_status_line(404, 'Not Found');

	trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}


	trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
}


Line 152Line 158

if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
{


if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
{

 
		send_status_line(404, 'Not Found');

		trigger_error('ERROR_NO_ATTACHMENT');
}


		trigger_error('ERROR_NO_ATTACHMENT');
}


Line 163Line 170
	if (!$attachment['in_message'])
{
//

	if (!$attachment['in_message'])
{
//

		$sql = 'SELECT p.forum_id, f.forum_password, f.parent_id

		$sql = 'SELECT p.forum_id, f.forum_name, 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';

			FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
WHERE p.post_id = ' . $attachment['post_msg_id'] . '
AND p.forum_id = f.forum_id';

Line 184Line 191
		}
else
{

		}
else
{

 
			send_status_line(403, 'Forbidden');

			trigger_error('SORRY_AUTH_VIEW_ATTACH');
}
}

			trigger_error('SORRY_AUTH_VIEW_ATTACH');
}
}

Line 192Line 200
		$row['forum_id'] = false;
if (!$auth->acl_get('u_pm_download'))
{

		$row['forum_id'] = false;
if (!$auth->acl_get('u_pm_download'))
{

			header('HTTP/1.0 403 Forbidden');

			send_status_line(403, 'Forbidden');

			trigger_error('SORRY_AUTH_VIEW_ATTACH');
}


			trigger_error('SORRY_AUTH_VIEW_ATTACH');
}


Line 215Line 223

if (!$allowed)
{


if (!$allowed)
{

			header('HTTP/1.0 403 Forbidden');

			send_status_line(403, 'Forbidden');

			trigger_error('ERROR_NO_ATTACHMENT');
}
}

			trigger_error('ERROR_NO_ATTACHMENT');
}
}

Line 224Line 232
	$extensions = array();
if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
{

	$extensions = array();
if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
{

 
		send_status_line(404, 'Forbidden');

		trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
}
}

if (!download_allowed())
{

		trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
}
}

if (!download_allowed())
{

	header('HTTP/1.0 403 Forbidden');

	send_status_line(403, 'Forbidden');

	trigger_error($user->lang['LINKAGE_FORBIDDEN']);
}


	trigger_error($user->lang['LINKAGE_FORBIDDEN']);
}


Line 246Line 255

if (!$attachment)
{


if (!$attachment)
{

 
	send_status_line(404, 'Not Found');

	trigger_error('ERROR_NO_ATTACHMENT');
}


	trigger_error('ERROR_NO_ATTACHMENT');
}


$attachment['physical_filename'] = basename($attachment['physical_filename']);

$attachment['physical_filename'] = utf8_basename($attachment['physical_filename']);

$display_cat = $extensions[$attachment['extension']]['display_cat'];

if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))

$display_cat = $extensions[$attachment['extension']]['display_cat'];

if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))

Line 266Line 276
{
$attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
}

{
$attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
}

else if (($display_cat == ATTACHMENT_CATEGORY_NONE || $display_cat == ATTACHMENT_CATEGORY_IMAGE) && !$attachment['is_orphan'])

else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHMENT_CATEGORY_IMAGE*/) && !$attachment['is_orphan'])

{
// Update download count
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '

{
// Update download count
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '

Line 275Line 285
	$db->sql_query($sql);
}


	$db->sql_query($sql);
}


if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && ((strpos(strtolower($user->browser), 'msie') !== false) && (strpos(strtolower($user->browser), 'msie 8.0') === false)))

if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && (strpos(strtolower($user->browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7))

{
wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);

{
wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);

 
	file_gc();

}
else
{

}
else
{

Line 287Line 298
		// This presenting method should no longer be used
if (!@is_dir($phpbb_root_path . $config['upload_path']))
{

		// This presenting method should no longer be used
if (!@is_dir($phpbb_root_path . $config['upload_path']))
{

 
			send_status_line(500, 'Internal Server Error');

			trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
}


			trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
}


Line 332Line 344
		$image_data = @getimagesize($file_path);
header('Content-Type: ' . image_type_to_mime_type($image_data[2]));


		$image_data = @getimagesize($file_path);
header('Content-Type: ' . image_type_to_mime_type($image_data[2]));


		if (strpos(strtolower($browser), 'msie') !== false && strpos(strtolower($browser), 'msie 8.0') === false)

		if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7))

		{
header('Content-Disposition: attachment; ' . header_filename($file));


		{
header('Content-Disposition: attachment; ' . header_filename($file));


Line 375Line 387
	}
else
{

	}
else
{

		header('HTTP/1.0 404 not found');

		send_status_line(404, 'Not Found');

	}
}


	}
}


Line 411Line 423

if (!@file_exists($filename))
{


if (!@file_exists($filename))
{

		trigger_error($user->lang['ERROR_NO_ATTACHMENT'] . '<br /><br />' . sprintf($user->lang['FILE_NOT_FOUND_404'], $filename));


		send_status_line(404, 'Not Found');
trigger_error('ERROR_NO_ATTACHMENT');

	}

// Correct the mime type - we force application/octetstream for all files, except images

	}

// Correct the mime type - we force application/octetstream for all files, except images

Line 437Line 450
		// PHP track_errors setting On?
if (!empty($php_errormsg))
{

		// PHP track_errors setting On?
if (!empty($php_errormsg))
{

 
			send_status_line(500, 'Internal Server Error');

			trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
}


			trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
}


 
		send_status_line(500, 'Internal Server Error');

		trigger_error('UNABLE_TO_DELIVER_FILE');
}


		trigger_error('UNABLE_TO_DELIVER_FILE');
}


Line 462Line 477
	*/

// Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.

	*/

// Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.

	$is_ie8 = (strpos(strtolower($user->browser), 'msie 8.0') !== false);
header('Content-Type: ' . $attachment['mimetype'] . (($is_ie8) ? '; authoritative=true;' : ''));

	header('Content-Type: ' . $attachment['mimetype']);






	if (empty($user->browser) || (!$is_ie8 && (strpos(strtolower($user->browser), 'msie') !== false)))













	if (phpbb_is_greater_ie_version($user->browser, 7))
{
header('X-Content-Type-Options: nosniff');
}

if ($category == ATTACHMENT_CATEGORY_FLASH && request_var('view', 0) === 1)
{
// We use content-disposition: inline for flash files and view=1 to let it correctly play with flash player 10 - any other disposition will fail to play inline
header('Content-Disposition: inline');
}
else
{
if (empty($user->browser) || ((strpos(strtolower($user->browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7)))

	{
header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false))

	{
header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false))

Line 476Line 502
	else
{
header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));

	else
{
header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));

		if ($is_ie8 && (strpos($attachment['mimetype'], 'image') !== 0))

			if (phpbb_is_greater_ie_version($user->browser, 7) && (strpos($attachment['mimetype'], 'image') !== 0))

		{
header('X-Download-Options: noopen');
}
}

		{
header('X-Download-Options: noopen');
}
}


if ($size)
{
header("Content-Length: $size");

 
	}

// Close the db connection before sending the file

	}

// Close the db connection before sending the file

Line 492Line 514

if (!set_modified_headers($attachment['filetime'], $user->browser))
{


if (!set_modified_headers($attachment['filetime'], $user->browser))
{

 
		// Send Content-Length only if set_modified_headers() does not send
// status 304 - Not Modified
if ($size)
{
header("Content-Length: $size");
}


		// Try to deliver in chunks
@set_time_limit(0);


		// Try to deliver in chunks
@set_time_limit(0);


Line 652Line 681
{
// let's see if we have to send the file at all
$last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false;

{
// let's see if we have to send the file at all
$last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false;

	if ((strpos(strtolower($browser), 'msie 6.0') === false) && (strpos(strtolower($browser), 'msie 8.0') === false))


		
if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie_version($browser, 7))

	{

	{

		if ($last_load !== false && $last_load <= $stamp)

		if ($last_load !== false && $last_load >= $stamp)

		{

		{

			if (@php_sapi_name() === 'CGI')
{
header('Status: 304 Not Modified', true, 304);
}
else
{
header('HTTP/1.0 304 Not Modified', true, 304);
}

			send_status_line(304, 'Not Modified');








			// seems that we need those too ... browsers
header('Pragma: public');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));

			// seems that we need those too ... browsers
header('Pragma: public');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));

Line 686Line 709
	}
$db->sql_close();
exit;

	}
$db->sql_close();
exit;

 
}

/**
* Check if the browser is internet explorer version 7+
*
* @param string $user_agent User agent HTTP header
* @param int $version IE version to check against
*
* @return bool true if internet explorer version is greater than $version
*/
function phpbb_is_greater_ie_version($user_agent, $version)
{
if (preg_match('/msie (\d+)/', strtolower($user_agent), $matches))
{
$ie_version = (int) $matches[1];
return ($ie_version > $version);
}
else
{
return false;
}

}

?>

}

?>