5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('../env.inc.php');
29 require_once $gfcommon.'include/pre.php';
30 require_once $gfcommon.'frs/FRSPackage.class.php';
31 require_once $gfcommon.'frs/FRSRelease.class.php';
32 require_once $gfcommon.'frs/FRSFile.class.php';
34 $arr=explode('/',getStringFromServer('REQUEST_URI'));
37 $res=db_query_params ('SELECT frs_file.filename,frs_package.is_public,frs_package.package_id,
38 frs_file.file_id,groups.unix_group_name,groups.group_id,frs_release.release_id
39 FROM frs_package,frs_release,frs_file,groups
40 WHERE frs_release.release_id=frs_file.release_id
41 AND groups.group_id=frs_package.group_id
42 AND frs_release.package_id=frs_package.package_id
43 AND frs_file.file_id=$1',
46 if (db_numrows($res) < 1) {
47 Header("Status: 404");
51 $group_id = db_result($res,0,'group_id');
52 $package_id = db_result($res,0,'package_id');
53 $release_id = db_result($res,0,'release_id');
55 $Group =& group_get_object($group_id);
56 if (!$Group || !is_object($Group) || $Group->isError()) {
60 $Package = new FRSPackage($Group,$package_id);
61 if (!$Package || !is_object($Package)) {
62 exit_error('Error','Error Getting Package');
63 } else if ($Package->isError()) {
64 exit_error('Error', $Package->getErrorMessage());
66 $is_public = $Package->isPublic();
68 $Release = new FRSRelease($Package,$release_id);
69 if (!$Release || !is_object($Release) || $Release->isError()) {
70 exit_error('Error','Error Getting Release');
73 $File = new FRSFile($Release,$file_id);
74 if (!$File || !is_object($File) || $File->isError()) {
75 exit_error('Error','Error Getting File');
77 $filename = $File->getName();
80 // Members of projects can see all packages
81 // Non-members can only see public packages
83 if (!session_loggedin() || !user_ismember($group_id)) {
84 exit_permission_denied();
87 if ($GLOBALS['sys_block_anonymous_downloads']) {
88 if (!session_loggedin()) {
89 exit_permission_denied();
93 $filepath=forge_get_config('upload_dir').'/'.$Group->getUnixName().'/'.$Package->getFileName().'/'.$Release->getFileName().'/'.$File->getName();
94 if (file_exists($filepath)) {
95 Header('Content-disposition: attachment; filename="'.str_replace('"', '', $filename).'"');
96 Header("Content-type: application/binary");
97 $length = filesize($filepath);
98 Header("Content-length: $length");
100 readfile_chunked($filepath);
102 if (session_loggedin()) {
103 $s =& session_get_user();
109 $ip=getStringFromServer('REMOTE_ADDR');
110 $res=db_query_params("INSERT INTO frs_dlstats_file (ip_address,file_id,month,day,user_id)
111 VALUES ($1, $2, $3, $4, $5)", array($ip,$file_id,date('Ym'),date('d'),$us));
113 Header("Status: 404");