* 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
* 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
--- /dev/null
+<?php
+/**
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program. If not, see http://www.sun.com/cddl/cddl.html
+ *
+ * 2019 - 2020 https://://www.bananas-playground.net/projekt/selfpaste
+ */
+
+/**
+ * Use this example to create a cronjob to clean up the paste entries which are over livetime.
+ * Usually the cleanup is done at creation and works well. But if you have a high load
+ * or very low load, those lifetime limits will not be checked correctly
+ *
+ * rename this file into a php file and create a cronjob which executes this file as
+ * php cli command
+ *
+ * example runs very sunday : 0 0 * * 0 php /path/to/this/file.php
+ *
+ * you need to change PATH_TO_MANCUBUS_CLASS to find the required PHP class
+ */
+
+# Encoding and error reporting setting
+mb_http_output('UTF-8');
+mb_internal_encoding('UTF-8');
+ini_set('error_reporting',-1); // E_ALL & E_STRICT
+
+# default time setting
+date_default_timezone_set('Europe/Berlin');
+
+# PATH to mancubus.class.php
+define('PATH_TO_MANCUBUS_CLASS','/path/to/selfpaste/mancubus.class.php');
+
+# verbose output
+# false no output
+# true for output
+$verbose=false;
+
+require_once(PATH_TO_MANCUBUS_CLASS);
+
+if($verbose == true) echo "Selfpaste cleanup start\n";
+$mancubus = new Mancubus();
+$mancubus->cleanupCronjob($verbose);
+if($verbose == true) echo "Selfpaste cleanup end\n";
\ No newline at end of file
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
/**
* 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());
}
}
/**
* 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');
) continue;
if ($file->getMTime() <= $datepointInThePastInSec) {
if(is_writable($file->getPathname())) {
+ if($verbose === true) echo "Delete ".$file->getPathname()."\n";
unlink($file->getPathname());
}
}