Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions admin/forms/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@
<option value="64">PLG_SYSTEM_BFSTOP_INFO</option>
<option value="128">PLG_SYSTEM_BFSTOP_DEBUG</option>
</field>
<field name="logMaxSize" type="number" default="5"
min="1" max="1024" step="1" filter="integer"
label="COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_LABEL"
description="COM_BFSTOP_SETTINGS_LOG_MAX_SIZE_DESC" />
<field name="logKeepDays" type="number" default="28"
min="0" max="3650" step="1" filter="integer"
label="COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_LABEL"
description="COM_BFSTOP_SETTINGS_LOG_KEEP_DAYS_DESC" />
<field name="unknownUsernameMode" type="list" default="hash"
label="COM_BFSTOP_SETTINGS_UNKNOWN_USERNAME_MODE_LABEL"
description="COM_BFSTOP_SETTINGS_UNKNOWN_USERNAME_MODE_DESC">
Expand Down
16 changes: 16 additions & 0 deletions admin/language/de-DE/de-DE.com_bfstop.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"%3$s\">Einstellungen</a> 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 <a href=\"%2$s\">Einstellungen</a> 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 <a href=\"%s\">Einstellungen</a> 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."
16 changes: 16 additions & 0 deletions admin/language/en-GB/en-GB.com_bfstop.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"%3$s\">Settings</a>."
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 <a href=\"%2$s\">Settings</a>, 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 <a href=\"%s\">Settings</a>, 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."
78 changes: 78 additions & 0 deletions admin/src/Controller/LogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/*
* @package BFStop Component (com_bfstop) for Joomla!
* @author Bernhard Froehler
* @copyright (C) Bernhard Froehler
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
**/

namespace Codeling\Component\Bfstop\Administrator\Controller;

defined('_JEXEC') or die;

use Codeling\Component\Bfstop\Administrator\Helper\LogHelper;
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\Log\Log;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;

class LogController extends BaseController
{
/**
* Checks the token and the permission to delete; sets the redirect and
* returns false if the request has to be refused.
*/
private function checkRequest($listUrl)
{
$this->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');
}
}
15 changes: 15 additions & 0 deletions admin/src/View/Log/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,13 +27,25 @@ 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);
}

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();
}
Expand Down
31 changes: 30 additions & 1 deletion admin/tmpl/log/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
?>
<div class="alert alert-info">
<?php echo ($this->keepDays > 0)
? Text::sprintf('COM_BFSTOP_LOG_AUTOPRUNE_ENABLED', $this->keepDays, $this->maxSizeMB, $settingsUrl)
: Text::sprintf('COM_BFSTOP_LOG_AUTOPRUNE_DISABLED', $this->maxSizeMB, $settingsUrl); ?>
</div>
<form method="post" name="adminForm" id="adminForm">
<input type="hidden" name="task" value="unblock" />
<input type="hidden" name="task" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
Expand All @@ -26,3 +34,24 @@
</div>
</div>
</form>
<?php if ($this->canDelete): ?>
<div class="modal fade" id="bfstopClearLogModal" tabindex="-1" aria-labelledby="bfstopClearLogModalTitle" aria-hidden="true">
<div class="modal-dialog">
<form method="post" class="modal-content" action="<?php echo Route::_('index.php?option=com_bfstop&view=log'); ?>">
<div class="modal-header">
<h3 class="modal-title" id="bfstopClearLogModalTitle"><?php echo Text::_('COM_BFSTOP_LOG_CLEAR_TITLE'); ?></h3>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<?php echo Text::_('JCLOSE'); ?>"></button>
</div>
<div class="modal-body p-3">
<p><?php echo Text::_('COM_BFSTOP_LOG_CLEAR_DESC'); ?></p>
</div>
<div class="modal-footer">
<input type="hidden" name="task" value="log.clear" />
<?php echo HTMLHelper::_('form.token'); ?>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo Text::_('JCANCEL'); ?></button>
<button type="submit" class="btn btn-danger"><?php echo Text::_('COM_BFSTOP_LOG_CLEAR_CONFIRM'); ?></button>
</div>
</form>
</div>
</div>
<?php endif; ?>
Loading