Skip to content

Commit

Permalink
Make download script work with new configuration.
Browse files Browse the repository at this point in the history
Fix stats for files.
  • Loading branch information
vampy committed Dec 18, 2014
1 parent 659f764 commit c478f64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
44 changes: 7 additions & 37 deletions download.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,11 @@
*/
require_once(__DIR__ . DIRECTORY_SEPARATOR . "config.php");

$dir = isset($_GET['type']) ? $_GET['type'] : null;
$file = isset($_GET['file']) ? $_GET['file'] : null;

// Make sure directory is not unsafe
if (!preg_match('/^[a-z]+$/i', $dir))
{
// Directory is unsafe - throw a 404 error
header("HTTP/1.0 404 Not Found");
exit;
}

// Make sure file name is not unsafe
if (!preg_match('/^[\w\-\ ]+\.[a-z0-9]+$/i', $file))
{
// File is unsafe - throw a 404 error
header("HTTP/1.0 404 Not Found");
exit;
}

if ($dir !== 'assets')
{
$assets_path = $dir . '/' . $file;
}
else
{
$assets_path = $file;
}
$assets_path = filter_var($file, FILTER_SANITIZE_URL);

// TODO probably the best solutions is not to redirect to the file, but instead output the file from here
// Don't bother checking if the file exists - if it doesn't exist, you'll get
// a 404 error anyways after redirecting. Yes, this may make the stats below
// inaccurate, but the actual 404's that used to be thrown here were relatively
Expand All @@ -70,7 +47,7 @@
}
catch(DBException $e)
{
header("HTTP/1.0 404 Not Found");
http_response_code(404);
exit;
}

Expand All @@ -90,7 +67,7 @@
}
catch(DBException $e)
{
header("HTTP/1.0 404 Not Found");
http_response_code(404);
exit('Failed to update statistics');
}
}
Expand All @@ -106,17 +83,10 @@
}
catch(DBException $e)
{
header("HTTP/1.0 404 Not Found");
http_response_code(404);
exit;
}

// Redirect to actual resource, FIXME
//if ($dir === 'xml')
//{
// header('Location: http://stkaddons.net/xml/' . $file);
//}
//else
//{
// header('Location: http://downloads.tuxfamily.org/stkaddons/assets/' . $assetpath);
//}
// Redirect to actual resource,
header('Location: ' . ROOT_LOCATION . 'downloads/' . $assets_path);
exit;
1 change: 1 addition & 0 deletions downloads
3 changes: 1 addition & 2 deletions install/htaccess.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ RewriteCond %{QUERY_STRING} ^type=(karts|tracks|arenas)&name=([a-z0-9\-_]+)$
RewriteRule addons.php %1/%2? [L,NC,R=301]

# Pass download links to the download script
RewriteRule ^dl/([^/]+)/([^/]+) /download.php?type=$1&file=$2 [NC,L]
RewriteRule ^dl/([^/]+) /download.php?type=assets&file=$1 [NC,L]
RewriteRule ^dl/(.+) /download.php?file=$1 [NC,L]

# cache images docs for 14 days
<IfModule mod_headers.c>
Expand Down

0 comments on commit c478f64

Please sign in to comment.