From: Banana Date: Sun, 22 Dec 2019 15:47:54 +0000 (+0100) Subject: lifetime of a paste X-Git-Tag: v0.2-beta~2 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=d7efd2ca0f3dfac2d4f8bc0d7451fdbbb7fe054a;p=selfpaste.git lifetime of a paste --- diff --git a/CHANGELOG b/CHANGELOG index 50a6da4..2f6db08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ TBA version 0.2 Helium * Using https://www.jwz.org/base64-shortlinks/ more correctly * Simple flood protection + * Lifetime for each paste. + * Deletion of paste older than the lifetime 20191221 version 0.1 Hydrogen diff --git a/TODO b/TODO index 97f40df..0f6dee6 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,6 @@ * Documentation -* lifetime -* deletion of old ones * add force download parameter * HTTPS for selfpaste bash client * multiple secrets * extending allowed filetypes -* creation or even access with basic auth -* flood protection \ No newline at end of file +* creation or even access with basic auth \ No newline at end of file diff --git a/documentation/lifetime.txt b/documentation/lifetime.txt new file mode 100644 index 0000000..f010fe2 --- /dev/null +++ b/documentation/lifetime.txt @@ -0,0 +1,3 @@ +The default lifetime of a paste is 7 days. Anything older will be deleted. + +The default flood prevention time maximum is 30 sec. \ No newline at end of file diff --git a/webroot/config.default.php b/webroot/config.default.php index bfd7566..16a9508 100644 --- a/webroot/config.default.php +++ b/webroot/config.default.php @@ -23,3 +23,7 @@ define('SELFPASTE_ALLOWED_FILETYPES','text/plain,text/comma-separated-values,tex # needed to respond with the correct link for your paste # please NO / at the end define('SELFPASTE_URL','http://your.tld/path/selfpaste/webroot'); +# time in seconds how long a paste will be available. Default 7 days = 604800 sec +define('SELFPASTE_PASTE_LIFETIME',604800); +# time in seconds how long the flood protection should take action. Default 30sec +define('SELFPASTE_FLOOD_LIFETIME',30); diff --git a/webroot/lib/mancubus.class.php b/webroot/lib/mancubus.class.php index c14e6e7..861a866 100644 --- a/webroot/lib/mancubus.class.php +++ b/webroot/lib/mancubus.class.php @@ -124,6 +124,8 @@ class Mancubus { $ret = $this->_checkAllowedFiletype(); $ret = $this->_checkStorage(); $ret = $this->_moveUploadedFile(); + + $this->_checkLifetime(); } catch (Exception $e) { $ret['message'] = $e->getMessage(); @@ -294,9 +296,28 @@ class Mancubus { $now = time(); foreach ($iterator as $file) { if($file->isDot() || $file->isDir() || Summoner::startsWith($file->getFilename(),'.')) continue; - if ($now - $file->getCTime() >= 30) { // 30 sec + if ($now - $file->getCTime() >= SELFPASTE_FLOOD_LIFETIME) { unlink(SELFPASTE_UPLOAD_DIR.'/'.$file->getFilename()); } } } + + /** + * delete all pastes older than SELFPASTE_PASTE_LIFETIME + */ + private function _checkLifetime() { + $iterator = new RecursiveDirectoryIterator(SELFPASTE_UPLOAD_DIR); + $now = time(); + + foreach (new RecursiveIteratorIterator($iterator) as $file) { + $fname = $file->getFilename(); + if($file->isDir() + || Summoner::startsWith($file->getFilename(),'.') + || isset($fname[4]) + ) continue; + if ($now - $file->getCTime() >= SELFPASTE_PASTE_LIFETIME) { + unlink(SELFPASTE_UPLOAD_DIR.'/'.$fname); + } + } + } } \ No newline at end of file