From 302921a811bb5aadd44cdd2ae4f64820a88554e9 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 22 Apr 2025 04:12:46 -0500 Subject: [PATCH] Add --delete-all option to administration script for mass paste deletion --- bin/administration | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/bin/administration b/bin/administration index 17b2e0f5..0a473ad6 100755 --- a/bin/administration +++ b/bin/administration @@ -72,6 +72,35 @@ class Administration exit("paste $pasteId successfully deleted" . PHP_EOL); } + /** + * lists all stored paste IDs + * + * @access private + */ + private function _list_ids() + { + $ids = $this->_store->getAllPastes(); + foreach ($ids as $pasteid) { + echo $pasteid, PHP_EOL; + } + exit; + } + + /** + * deletes all stored pastes (regardless of expiration) + * + * @access private + */ + private function _delete_all() + { + $ids = $this->_store->getAllPastes(); + foreach ($ids as $pasteid) { + echo "Deleting paste ID: $pasteid" . PHP_EOL; + $this->_store->delete($pasteid); + } + exit("All pastes successfully deleted" . PHP_EOL); + } + /** * removes empty directories, if current storage model uses Filesystem * @@ -124,7 +153,7 @@ class Administration { echo <<<'EOT' Usage: - administration [--delete | --empty-dirs | --help | --purge | --statistics] + administration [--delete | --empty-dirs | --help | --purge | --statistics | --list-ids] Options: -d, --delete deletes the requested paste ID @@ -133,6 +162,7 @@ Options: -h, --help displays this help message -p, --purge purge all expired pastes -s, --statistics reads all stored pastes and comments and reports statistics + -l, --list-ids lists all paste IDs EOT, PHP_EOL; exit($code); } @@ -177,7 +207,8 @@ EOT, PHP_EOL; self::_help(2); } - $this->_opts = getopt('hd:eps', array('help', 'delete:', 'empty-dirs', 'purge', 'statistics')); + $this->_opts = getopt('hd:epsl', array('help', 'delete:', 'empty-dirs', 'purge', 'statistics', 'list-ids', 'delete-all')); + if (!$this->_opts) { self::_error_echo('unsupported arguments given'); echo PHP_EOL; @@ -307,7 +338,13 @@ EOT, PHP_EOL; $class = 'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model'); $this->_store = new $class($this->_conf->getSection('model_options')); - + + if ($this->_option('l', 'list-ids') !== null) { + $this->_list_ids(); + } + if ($this->_option(null, 'delete-all') !== null) { + $this->_delete_all(); + } if (($pasteId = $this->_option('d', 'delete')) !== null) { $this->_delete($pasteId); } @@ -328,4 +365,4 @@ EOT, PHP_EOL; } } -new Administration(); +new Administration(); \ No newline at end of file