Просмотр файла download.php

Размер файла: 5.53Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. if (defined('IN_PHPBB'))
  7. {
  8. die('Hacking attempt');
  9. exit;
  10. }
  11.  
  12. define('IN_PHPBB', true);
  13. $phpbb_root_path = './';
  14. include($phpbb_root_path . 'extension.inc');
  15. include($phpbb_root_path . 'common.' . $phpEx);
  16.  
  17. $download_id = get_var('id', 0);
  18. $thumbnail = get_var('thumb', 0);
  19. $attach_name = htmlspecialchars(trim($HTTP_GET_VARS['n']));
  20.  
  21. $userdata = session_pagestart($user_ip, PAGE_INDEX);
  22. init_userprefs($userdata);
  23.  
  24. if (empty($attach_name))
  25. {
  26. message_die(GENERAL_ERROR, $lang['No_attachment_selected']);
  27. }
  28.  
  29. if ($attach_config['disable_mod'] && $userdata['user_level'] != ADMIN)
  30. {
  31. message_die(GENERAL_MESSAGE, $lang['Attachment_feature_disabled']);
  32. }
  33. $sql = "SELECT *
  34. FROM " . ATTACHMENTS_DESC_TABLE . "
  35. WHERE physical_filename = '" . str_replace("\'", "''", $attach_name) . "'";
  36.  
  37. if (!($result = $db->sql_query($sql)))
  38. {
  39. message_die(GENERAL_ERROR, 'Could not query attachment informations', '', __LINE__, __FILE__, $sql);
  40. }
  41.  
  42. if (!($attachment = $db->sql_fetchrow($result)))
  43. {
  44. message_die(GENERAL_MESSAGE, $lang['Error_no_attachment']);
  45. }
  46.  
  47. $attachment['physical_filename'] = basename($attachment['physical_filename']);
  48.  
  49. $db->sql_freeresult($result);
  50.  
  51. $authorised = false;
  52.  
  53. $sql = 'SELECT *
  54. FROM ' . ATTACHMENTS_TABLE . '
  55. WHERE attach_id = ' . (int) $attachment['attach_id'];
  56.  
  57. if (!($result = $db->sql_query($sql)))
  58. {
  59. message_die(GENERAL_ERROR, 'Could not query attachment informations', '', __LINE__, __FILE__, $sql);
  60. }
  61.  
  62. $auth_pages = $db->sql_fetchrowset($result);
  63. $num_auth_pages = $db->sql_numrows($result);
  64.  
  65. for ($i = 0; $i < $num_auth_pages && $authorised == false; $i++)
  66. {
  67. $auth_pages[$i]['post_id'] = intval($auth_pages[$i]['post_id']);
  68.  
  69. if ($auth_pages[$i]['post_id'] != 0)
  70. {
  71. $sql = 'SELECT forum_id
  72. FROM ' . POSTS_TABLE . '
  73. WHERE post_id = ' . (int) $auth_pages[$i]['post_id'];
  74.  
  75. if ( !($result = $db->sql_query($sql)) )
  76. {
  77. message_die(GENERAL_ERROR, 'Could not query post information', '', __LINE__, __FILE__, $sql);
  78. }
  79.  
  80. $row = $db->sql_fetchrow($result);
  81.  
  82. $forum_id = $row['forum_id'];
  83.  
  84. $is_auth = array();
  85. $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
  86.  
  87. if ($is_auth['auth_download'])
  88. {
  89. $authorised = TRUE;
  90. }
  91. }
  92. else
  93. {
  94. if ( (intval($attach_config['allow_pm_attach'])) && ( ($userdata['user_id'] == $auth_pages[$i]['user_id_2']) || ($userdata['user_id'] == $auth_pages[$i]['user_id_1']) ) || ($userdata['user_level'] == ADMIN) )
  95. {
  96. $authorised = TRUE;
  97. }
  98. }
  99. }
  100.  
  101.  
  102. if (!$authorised)
  103. {
  104. message_die(GENERAL_MESSAGE, $lang['Sorry_auth_view_attach']);
  105. }
  106.  
  107. $sql = "SELECT e.extension, g.download_mode
  108. FROM " . EXTENSION_GROUPS_TABLE . " g, " . EXTENSIONS_TABLE . " e
  109. WHERE (g.allow_group = 1) AND (g.group_id = e.group_id)";
  110.  
  111. if ( !($result = $db->sql_query($sql)) )
  112. {
  113. message_die(GENERAL_ERROR, 'Could not query Allowed Extensions.', '', __LINE__, __FILE__, $sql);
  114. }
  115.  
  116. $rows = $db->sql_fetchrowset($result);
  117. $num_rows = $db->sql_numrows($result);
  118.  
  119. for ($i = 0; $i < $num_rows; $i++)
  120. {
  121. $extension = strtolower(trim($rows[$i]['extension']));
  122. $allowed_extensions[] = $extension;
  123. $download_mode[$extension] = $rows[$i]['download_mode'];
  124. }
  125.  
  126. if (!in_array($attachment['extension'], $allowed_extensions) && $userdata['user_level'] != ADMIN)
  127. {
  128. message_die(GENERAL_MESSAGE, sprintf($lang['Extension_disabled_after_posting'], $attachment['extension']));
  129. }
  130.  
  131. $download_mode = intval($download_mode[$attachment['extension']]);
  132.  
  133. if ($thumbnail)
  134. {
  135. $attachment['physical_filename'] = THUMB_DIR . '/t_' . $attachment['physical_filename'];
  136. }
  137.  
  138. if (!$thumbnail)
  139. {
  140. $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . '
  141. SET download_count = download_count + 1
  142. WHERE attach_id = ' . (int) $attachment['attach_id'];
  143. if (!$db->sql_query($sql))
  144. {
  145. message_die(GENERAL_ERROR, 'Couldn\'t update attachment download count', '', __LINE__, __FILE__, $sql);
  146. }
  147. }
  148.  
  149. $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
  150. $server_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['server_name']));
  151. $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : '';
  152. $script_name = preg_replace('/^\/?(.*?)\/?$/', '/\1', trim($board_config['script_path']));
  153.  
  154. if ($script_name[strlen($script_name)] != '/')
  155. {
  156. $script_name .= '/';
  157. }
  158.  
  159. if (intval($attach_config['allow_ftp_upload']))
  160. {
  161. if (trim($attach_config['download_path']) == '')
  162. {
  163. message_die(GENERAL_ERROR, 'Physical Download not possible with the current Attachment Setting');
  164. }
  165. $url = trim($attach_config['download_path']) . '/' . $attachment['physical_filename'];
  166. $redirect_path = $url;
  167. }
  168. else
  169. {
  170. $url = $upload_dir . '/' . $attachment['physical_filename'];
  171. // $url = preg_replace('/^\/?(.*?\/)?$/', '\1', trim($url));
  172. $redirect_path = $server_protocol . $server_name . $server_port . $script_name . $url;
  173. }
  174.  
  175. if (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')))
  176. {
  177. header('Refresh: 0; URL=' . $redirect_path);
  178. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="refresh" content="0; url=' . $redirect_path . '"><title>Redirect</title></head><body><div align="center">If your browser does not support meta redirection please click <a href="' . $redirect_path . '">HERE</a> to be redirected</div></body></html>';
  179. exit;
  180. }
  181.  
  182. header('Location: ' . $redirect_path);
  183. exit;
  184.  
  185. ?>