From: Banana Date: Tue, 24 Mar 2020 21:27:26 +0000 (+0100) Subject: todo cleanup and added an example cronjob file X-Git-Tag: v1.0^2~11 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=29cfccac00921118cbb7fd73567b6d8df8a05091;p=selfpaste.git todo cleanup and added an example cronjob file --- diff --git a/CHANGELOG b/CHANGELOG index 2b8c163..e44f1dc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ tbd version 0.4-beta Beryllium * added perl as default allowed file * added shellscript to the default allowed files * added html and js to the default allowed files +* added an example cronjob file which can be used + to clean old pastes. See clean-cronjob.txt for more + detals 2020101 version 0.3-beta Lithium * Update information now included diff --git a/TODO b/TODO index 0240a0d..5ef4ac1 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,7 @@ * Documentation * code cleanup and small footprint * add force download parameter -* HTTPS for selfpaste bash client * multiple secrets -* extending allowed filetypes * creation or even access with basic auth * abstract storage to support different storage solutions * config file for client script -* proxy setting for client script -* Lifetimecheck as cronjob diff --git a/documentation/clean-cronjob.txt b/documentation/clean-cronjob.txt new file mode 100644 index 0000000..1de9791 --- /dev/null +++ b/documentation/clean-cronjob.txt @@ -0,0 +1,47 @@ +cleanupCronjob($verbose); +if($verbose == true) echo "Selfpaste cleanup end\n"; \ No newline at end of file diff --git a/webroot/lib/mancubus.class.php b/webroot/lib/mancubus.class.php index 5168548..c3af2ce 100644 --- a/webroot/lib/mancubus.class.php +++ b/webroot/lib/mancubus.class.php @@ -134,6 +134,15 @@ class Mancubus { return $ret; } + /** + * Cleans lifetime and floodfiles. + * @param boolean + */ + public function cleanupCronjob($verbose=false) { + $this->_cleanupFloodFiles($verbose); + $this->_checkLifetime($verbose); + } + /** * Check if the POST upload worked * @return array message,status @@ -291,12 +300,13 @@ class Mancubus { /** * clean up the flood tmp files. Everything older then 30 sec will be deleted. */ - private function _cleanupFloodFiles() { + private function _cleanupFloodFiles($verbose=false) { $iterator = new DirectoryIterator(SELFPASTE_UPLOAD_DIR); $now = time(); foreach ($iterator as $file) { if($file->isDot() || $file->isDir() || Summoner::startsWith($file->getFilename(),'.')) continue; if ($now - $file->getCTime() >= SELFPASTE_FLOOD_LIFETIME) { + if($verbose === true) echo "Delete ".$file->getFilename()."\n"; unlink(SELFPASTE_UPLOAD_DIR.'/'.$file->getFilename()); } } @@ -305,7 +315,7 @@ class Mancubus { /** * delete all pastes older than SELFPASTE_PASTE_LIFETIME */ - private function _checkLifetime() { + private function _checkLifetime($verbose=false) { $iterator = new RecursiveDirectoryIterator(SELFPASTE_UPLOAD_DIR); $datepointInThePastInSec = strtotime('-'.SELFPASTE_PASTE_LIFETIME.' days'); @@ -317,6 +327,7 @@ class Mancubus { ) continue; if ($file->getMTime() <= $datepointInThePastInSec) { if(is_writable($file->getPathname())) { + if($verbose === true) echo "Delete ".$file->getPathname()."\n"; unlink($file->getPathname()); } }