summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorPeter Lejeck <peter.lejeck@gmail.com>2014-01-18 08:41:21 +0100
committerPeter Lejeck <peter.lejeck@gmail.com>2014-01-18 08:41:21 +0100
commitb753bc91a39deb93970706dbd4abce84bbe3bb46 (patch)
tree64ac7b443fa4d9455c9edabdb87653c037d88548 /static
parent70707eb27ac6b556ac910db5a1c7f0e4ea38647d (diff)
Add double-dot handling. Fixes #1
Diffstat (limited to 'static')
-rw-r--r--static/includes/settings.inc.php11
-rw-r--r--static/upload.php11
2 files changed, 21 insertions, 1 deletions
diff --git a/static/includes/settings.inc.php b/static/includes/settings.inc.php
index 41f7679..3155a60 100644
--- a/static/includes/settings.inc.php
+++ b/static/includes/settings.inc.php
@@ -17,4 +17,15 @@ define('POMF_DB_PASS', '***');
define('POMF_FILES_ROOT', '/mnt/disk1/pomf/files/');
// How many times to retry when exists() before giving up
define('POMF_FILES_RETRIES', 30);
+
+/**
+ * Double-dot extensions
+ */
+$doubledots = array_map('strrev', array(
+ 'tar.gz',
+ 'tar.bz',
+ 'tar.bz2',
+ 'tar.xz'
+));
+
?>
diff --git a/static/upload.php b/static/upload.php
index 3da7174..5fd553e 100644
--- a/static/upload.php
+++ b/static/upload.php
@@ -10,11 +10,20 @@ include_once 'includes/database.inc.php';
* @return string
*/
function generate_name ($file) {
+ global $doubledots;
// We start at N retries, and --N until we give up
$tries = POMF_FILES_RETRIES;
// We rip out the extension using pathinfo
- // TODO: figure out a solution for .tar.gz and similar files? This has now been ghetto fixed, read below!
$ext = pathinfo($file->name, PATHINFO_EXTENSION);
+
+ // And if we realize it's actually a doubledot
+ // we just override $ext
+ $revname = strrev($file->name);
+ foreach ($doubledots as $ddot) {
+ if (stripos($revname, $ddot) === 0) {
+ $ext = strrev($ddot);
+ }
+ }
do {
// If we run out of tries, throw an exception. Should be caught and JSONified.
if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name');