From: Matthias Schmidt Date: Wed, 10 Mar 2021 10:41:17 +0000 (+0100) Subject: Support filtering the list of user authentication failures (#4062) X-Git-Tag: 5.4.0_Alpha_1~181 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aca2c9bf869c47811b23ad9fabeefa9f2a9fde94;p=GitHub%2FWoltLab%2FWCF.git Support filtering the list of user authentication failures (#4062) Filtering by IP address is not supported due storing IPv4 addresses in IPv6 format but displaying them in as IPv4 so that (partial) IPv4 addresses cannot be (easily) searched for. See #3395 --- diff --git a/wcfsetup/install/files/acp/templates/userAuthenticationFailureList.tpl b/wcfsetup/install/files/acp/templates/userAuthenticationFailureList.tpl index cddec7e82e..3b689cf465 100644 --- a/wcfsetup/install/files/acp/templates/userAuthenticationFailureList.tpl +++ b/wcfsetup/install/files/acp/templates/userAuthenticationFailureList.tpl @@ -14,9 +14,77 @@ {/hascontent} +
+
+

{lang}wcf.global.filter{/lang}

+ +
+
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ + {event name='filterFields'} +
+ +
+ + {csrfToken} +
+
+
+ {hascontent}
- {content}{pages print=true assign=pagesLinks controller='UserAuthenticationFailureList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}{/content} + {content} + {pages print=true assign=pagesLinks controller='UserAuthenticationFailureList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$filterLinkParameters"} + {/content}
{/hascontent} diff --git a/wcfsetup/install/files/lib/acp/page/UserAuthenticationFailureListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserAuthenticationFailureListPage.class.php index 4947137761..ed06679251 100644 --- a/wcfsetup/install/files/lib/acp/page/UserAuthenticationFailureListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserAuthenticationFailureListPage.class.php @@ -4,6 +4,7 @@ namespace wcf\acp\page; use wcf\data\user\authentication\failure\UserAuthenticationFailureList; use wcf\page\SortablePage; +use wcf\system\WCF; /** * Shows a list of user authentication failures. @@ -51,4 +52,99 @@ class UserAuthenticationFailureListPage extends SortablePage * @inheritDoc */ public $objectListClassName = UserAuthenticationFailureList::class; + + /** + * @var string[] + * @since 5.4 + */ + public $filter = [ + 'environment' => '', + 'endDate' => '', + 'startDate' => '', + 'username' => '', + 'userAgent' => '', + 'validationError' => '', + ]; + + /** + * @inheritDoc + */ + public function readParameters() + { + parent::readParameters(); + + if (isset($_REQUEST['filter']) && \is_array($_REQUEST['filter'])) { + foreach ($_REQUEST['filter'] as $key => $value) { + if (\array_key_exists($key, $this->filter)) { + $this->filter[$key] = $value; + } + } + } + } + + /** + * @inheritDoc + */ + protected function initObjectList() + { + parent::initObjectList(); + + if ($this->filter['environment'] !== '') { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.environment = ?', + [$this->filter['environment']] + ); + } + if ($this->filter['endDate'] !== '') { + $endDate = @\strtotime($this->filter['endDate']); + if ($endDate > 0) { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.time <= ?', + [$endDate] + ); + } + } + if ($this->filter['startDate'] !== '') { + $startDate = @\strtotime($this->filter['startDate']); + if ($startDate > 0) { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.time >= ?', + [$startDate] + ); + } + } + if ($this->filter['username'] !== '') { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.username LIKE ?', + ['%' . \addcslashes($this->filter['username'], '_%') . '%'] + ); + } + if ($this->filter['userAgent'] !== '') { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.userAgent LIKE ?', + ['%' . \addcslashes($this->filter['userAgent'], '_%') . '%'] + ); + } + if ($this->filter['validationError'] !== '') { + $this->objectList->getConditionBuilder()->add( + 'user_authentication_failure.validationError = ?', + [$this->filter['validationError']] + ); + } + } + + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); + + $filterLinkParameters = \http_build_query(['filter' => \array_filter($this->filter)], '', '&'); + + WCF::getTPL()->assign([ + 'filter' => $this->filter, + 'filterLinkParameters' => $filterLinkParameters ? '&' . $filterLinkParameters : '', + ]); + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 1451e1c815..b5f3de49ce 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3238,6 +3238,8 @@ aus Sicherheitsgründen erforderlich, dass {if LANGUAGE_USE_INFORMAL_VARIANT}du{ + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index fbf131379d..f7d2f1e8ab 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3162,6 +3162,8 @@ the lost password form + +