diff --git a/admin/forms/settings.xml b/admin/forms/settings.xml index 6d9cfea..2b2f4e0 100644 --- a/admin/forms/settings.xml +++ b/admin/forms/settings.xml @@ -170,6 +170,14 @@ + + diff --git a/admin/language/de-DE/de-DE.com_bfstop.ini b/admin/language/de-DE/de-DE.com_bfstop.ini index 130e64e..968d0b9 100644 --- a/admin/language/de-DE/de-DE.com_bfstop.ini +++ b/admin/language/de-DE/de-DE.com_bfstop.ini @@ -123,3 +123,19 @@ COM_BFSTOP_SETTINGS_IPV6_PREFIX_LABEL="Genauigkeit bei IPv6" COM_BFSTOP_SETTINGS_IPV6_PREFIX_DESC="Ein Client mit IPv6-Adresse kontrolliert meist ein ganzes Netz und kann nach Belieben zu einer anderen Adresse darin wechseln. Fehlgeschlagene Logins und Sperren von IPv6-Clients werden deshalb pro Netz dieser Größe statt pro Adresse erfasst. /64 ist die Größe eines üblichen Heim- oder Mobilfunkanschlusses. Wähle eine einzelne Adresse nur, wenn du weißt, dass Clients deiner Seite sich ihr /64 mit anderen teilen, die nicht mitgesperrt werden sollen." COM_BFSTOP_SETTINGS_IPV6_PREFIX_64="/64 (empfohlen)" COM_BFSTOP_SETTINGS_IPV6_PREFIX_128="Einzelne Adresse (/128)" +COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_LABEL="Größenlimit der Logdatei (MB)" +COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_DESC="Wird die Logdatei größer, wird sie in eine zweite Datei verschoben (plg_system_bfstop.1.log.php im Log-Verzeichnis), die die vorherige ersetzt. Die Logdateien zusammen belegen also nie viel mehr als das Doppelte dieser Größe." +COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_LABEL="Logeinträge behalten (Tage)" +COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_DESC="Logeinträge, die älter als diese Anzahl an Tagen sind, werden automatisch gelöscht (einmal täglich, auch wenn das Logging inzwischen deaktiviert wurde). Bei 0 werden Einträge behalten, bis das Größenlimit erreicht ist." +COM_BFSTOP_LOG_AUTOPRUNE_ENABLED="Logeinträge, die älter als %1$d Tage sind, werden automatisch gelöscht, und die Logdatei wird rotiert, sobald sie %2$d MB überschreitet. Dies kann im Tab 'Erweitert' der Einstellungen geändert werden." +COM_BFSTOP_LOG_AUTOPRUNE_DISABLED="Alte Logeinträge werden derzeit nicht nach Alter gelöscht, sondern nur wenn die Logdatei rotiert wird, sobald sie %1$d MB überschreitet. Um das zu ändern, 'Logeinträge behalten' in den Einstellungen setzen, oder die Buttons 'Log bereinigen' und 'Log leeren' verwenden." +COM_BFSTOP_LOG_PRUNE_BUTTON="Log bereinigen" +COM_BFSTOP_LOG_PRUNE_DISABLED="Zum Bereinigen ist eine Aufbewahrungsdauer nötig: 'Logeinträge behalten' in den Einstellungen setzen, oder stattdessen das Log leeren." +COM_BFSTOP_LOG_PRUNE_N_DELETED="%1$d Logeinträge, die älter als %2$d Tage waren, wurden gelöscht." +COM_BFSTOP_LOG_PRUNE_N_DELETED_0="Es gab keine Logeinträge, die älter als %2$d Tage waren." +COM_BFSTOP_LOG_PRUNE_N_DELETED_1="Ein Logeintrag, der älter als %2$d Tage war, wurde gelöscht." +COM_BFSTOP_LOG_CLEAR_BUTTON="Log leeren" +COM_BFSTOP_LOG_CLEAR_TITLE="Log leeren" +COM_BFSTOP_LOG_CLEAR_DESC="Alle Logeinträge werden unwiderruflich gelöscht, auch die der vorherigen Logdatei. Sperren und fehlgeschlagene Anmeldungen sind nicht betroffen." +COM_BFSTOP_LOG_CLEAR_CONFIRM="Leeren" +COM_BFSTOP_LOG_CLEARED="Das Log wurde geleert." diff --git a/admin/language/en-GB/en-GB.com_bfstop.ini b/admin/language/en-GB/en-GB.com_bfstop.ini index b147ad9..cc7b6b1 100644 --- a/admin/language/en-GB/en-GB.com_bfstop.ini +++ b/admin/language/en-GB/en-GB.com_bfstop.ini @@ -175,3 +175,19 @@ COM_BFSTOP_SETTINGS_IPV6_PREFIX_LABEL="IPv6 Tracking Granularity" COM_BFSTOP_SETTINGS_IPV6_PREFIX_DESC="A client with an IPv6 address usually controls a whole network and can switch to another address in it at will. Failed logins and blocks of IPv6 clients are therefore tracked per network of this size instead of per address. /64 is the size of a typical home or mobile connection. Choose a single address only if you know that clients on your site share their /64 with others whom you don't want to be blocked together." COM_BFSTOP_SETTINGS_IPV6_PREFIX_64="/64 (recommended)" COM_BFSTOP_SETTINGS_IPV6_PREFIX_128="Single address (/128)" +COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_LABEL="Log File Size Limit (MB)" +COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_DESC="Once the log file is bigger than this, it is moved to a second file (plg_system_bfstop.1.log.php in the logs directory), replacing the previous one. So the log files together never take much more than twice this size." +COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_LABEL="Keep Log Entries (Days)" +COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_DESC="Log entries older than this number of days are deleted automatically (once a day, even if logging is disabled in the meantime). Set to 0 to keep entries until the size limit is reached." +COM_BFSTOP_LOG_AUTOPRUNE_ENABLED="Log entries older than %1$d days are deleted automatically, and the log file is rotated once it exceeds %2$d MB. You can change this in the 'Advanced' tab of the Settings." +COM_BFSTOP_LOG_AUTOPRUNE_DISABLED="Old log entries are currently not deleted by age, only when the log file is rotated once it exceeds %1$d MB. To change this, set 'Keep Log Entries' in the Settings, or use the 'Prune Log' and 'Clear Log' buttons." +COM_BFSTOP_LOG_PRUNE_BUTTON="Prune Log" +COM_BFSTOP_LOG_PRUNE_DISABLED="Pruning needs a retention: set 'Keep Log Entries' in the Settings, or clear the log instead." +COM_BFSTOP_LOG_PRUNE_N_DELETED="%1$d log entries older than %2$d days were deleted." +COM_BFSTOP_LOG_PRUNE_N_DELETED_0="There were no log entries older than %2$d days." +COM_BFSTOP_LOG_PRUNE_N_DELETED_1="One log entry older than %2$d days was deleted." +COM_BFSTOP_LOG_CLEAR_BUTTON="Clear Log" +COM_BFSTOP_LOG_CLEAR_TITLE="Clear the Log" +COM_BFSTOP_LOG_CLEAR_DESC="All log entries will be permanently deleted, including those of the previous log file. This cannot be undone. Blocks and failed login entries are not affected." +COM_BFSTOP_LOG_CLEAR_CONFIRM="Clear" +COM_BFSTOP_LOG_CLEARED="The log was cleared." diff --git a/admin/src/Controller/LogController.php b/admin/src/Controller/LogController.php new file mode 100644 index 0000000..ed81baf --- /dev/null +++ b/admin/src/Controller/LogController.php @@ -0,0 +1,78 @@ +checkToken(); + if (!Factory::getApplication()->getIdentity()->authorise('core.delete', 'com_bfstop')) + { + $this->setRedirect($listUrl, Text::_('COM_BFSTOP_NOT_AUTHORISED'), 'error'); + return false; + } + return true; + } + + /** + * Does what the plugin does once a day: moves a log file which is too + * big out of the way, and removes the entries older than the retention. + */ + function prune() + { + $listUrl = Route::_('index.php?option=com_bfstop&view=log', false); + if (!$this->checkRequest($listUrl)) + { + return; + } + $keepDays = (int) ParamHelper::get('logKeepDays', 'params', LoggerHelper::DefaultKeepDays); + if ($keepDays < 1) + { + $this->setRedirect($listUrl, Text::sprintf('COM_BFSTOP_LOG_PRUNE_DISABLED', + Route::_('index.php?option=com_bfstop&view=settings', false)), 'warning'); + return; + } + $maxMB = (int) ParamHelper::get('logMaxSize', 'params', LoggerHelper::DefaultMaxSizeMB); + LoggerHelper::rotateIfTooBig(LoggerHelper::maxBytesFromMegabytes($maxMB)); + $deleted = LoggerHelper::pruneByAge($keepDays); + LogHelper::getLogger()->log("Manually pruned $deleted log entries older than $keepDays days", Log::INFO); + $this->setRedirect($listUrl, + Text::plural('COM_BFSTOP_LOG_PRUNE_N_DELETED', $deleted, $keepDays), 'message'); + } + + function clear() + { + $listUrl = Route::_('index.php?option=com_bfstop&view=log', false); + if (!$this->checkRequest($listUrl)) + { + return; + } + $logger = LogHelper::getLogger(); + LoggerHelper::deleteLogFiles(); + // the new log file starts with a note on what happened to the old one + $logger->log('The log was cleared manually', Log::INFO); + $this->setRedirect($listUrl, Text::_('COM_BFSTOP_LOG_CLEARED'), 'message'); + } +} diff --git a/admin/src/View/Log/HtmlView.php b/admin/src/View/Log/HtmlView.php index 588e718..02c2ff5 100644 --- a/admin/src/View/Log/HtmlView.php +++ b/admin/src/View/Log/HtmlView.php @@ -11,6 +11,9 @@ defined('_JEXEC') or die; use Codeling\Component\Bfstop\Administrator\Helper\ToolbarHelper as BfstopToolbarHelper; +use Codeling\Component\Bfstop\Administrator\Helper\ParamHelper; +use Codeling\Plugin\System\Bfstop\Helper\LoggerHelper; +use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; @@ -24,6 +27,13 @@ function display($tpl = null) $state = $this->get('State'); $this->sortColumn = $state->get('list.ordering'); $this->sortDirection = $state->get('list.direction'); + $this->keepDays = (int) ParamHelper::get('logKeepDays', 'params', LoggerHelper::DefaultKeepDays); + $this->maxSizeMB = max(1, (int) ParamHelper::get('logMaxSize', 'params', LoggerHelper::DefaultMaxSizeMB)); + $this->canDelete = Factory::getApplication()->getIdentity()->authorise('core.delete', 'com_bfstop'); + if ($this->canDelete) + { + Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.modal'); + } $this->addToolBar(); parent::display($tpl); } @@ -31,6 +41,11 @@ function display($tpl = null) protected function addToolBar() { ToolbarHelper::title(Text::_('COM_BFSTOP_HEADING_LOGS'), 'bfstop'); + if ($this->canDelete) + { + ToolbarHelper::custom('log.prune', 'refresh', '', 'COM_BFSTOP_LOG_PRUNE_BUTTON', false); + ToolbarHelper::modal('bfstopClearLogModal', 'icon-trash', 'COM_BFSTOP_LOG_CLEAR_BUTTON'); + } ToolbarHelper::divider(); BfstopToolbarHelper::addOptions(); } diff --git a/admin/tmpl/log/default.php b/admin/tmpl/log/default.php index d68224b..a476f59 100644 --- a/admin/tmpl/log/default.php +++ b/admin/tmpl/log/default.php @@ -8,10 +8,18 @@ defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; +$settingsUrl = Route::_('index.php?option=com_bfstop&view=settings', false); ?> +
+ keepDays > 0) + ? Text::sprintf('COM_BFSTOP_LOG_AUTOPRUNE_ENABLED', $this->keepDays, $this->maxSizeMB, $settingsUrl) + : Text::sprintf('COM_BFSTOP_LOG_AUTOPRUNE_DISABLED', $this->maxSizeMB, $settingsUrl); ?> +
- + @@ -26,3 +34,24 @@
+canDelete): ?> + +