mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Expose WebUI ban counter to users
This commit is contained in:
committed by
sledgehammer999
parent
544d3f9025
commit
b19153287b
@@ -232,6 +232,7 @@ void AppController::preferencesAction()
|
||||
for (const Utils::Net::Subnet &subnet : asConst(pref->getWebUiAuthSubnetWhitelist()))
|
||||
authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet);
|
||||
data["bypass_auth_subnet_whitelist"] = authSubnetWhitelistStringList.join("\n");
|
||||
data["web_ui_max_auth_fail_count"] = pref->getWebUIMaxAuthFailCount();
|
||||
data["web_ui_session_timeout"] = pref->getWebUISessionTimeout();
|
||||
// Use alternative Web UI
|
||||
data["alternative_webui_enabled"] = pref->isAltWebUiEnabled();
|
||||
@@ -601,6 +602,8 @@ void AppController::setPreferencesAction()
|
||||
// recognize new lines and commas as delimiters
|
||||
pref->setWebUiAuthSubnetWhitelist(it.value().toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts));
|
||||
}
|
||||
if (hasKey("web_ui_max_auth_fail_count"))
|
||||
pref->setWebUIMaxAuthFailCount(it.value().toInt());
|
||||
if (hasKey("web_ui_session_timeout"))
|
||||
pref->setWebUISessionTimeout(it.value().toInt());
|
||||
// Use alternative Web UI
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "isessionmanager.h"
|
||||
|
||||
constexpr int BAN_TIME = 3600000; // 1 hour
|
||||
constexpr int MAX_AUTH_FAILED_ATTEMPTS = 5;
|
||||
|
||||
void AuthController::loginAction()
|
||||
{
|
||||
@@ -74,7 +73,8 @@ void AuthController::loginAction()
|
||||
LogMsg(tr("WebAPI login success. IP: %1").arg(clientAddr));
|
||||
}
|
||||
else {
|
||||
increaseFailedAttempts();
|
||||
if (Preferences::instance()->getWebUIMaxAuthFailCount() > 0)
|
||||
increaseFailedAttempts();
|
||||
setResult(QLatin1String("Fails."));
|
||||
LogMsg(tr("WebAPI login failure. Reason: invalid credentials, attempt count: %1, IP: %2, username: %3")
|
||||
.arg(QString::number(failedAttemptsCount()), clientAddr, usernameFromWeb)
|
||||
@@ -82,7 +82,7 @@ void AuthController::loginAction()
|
||||
}
|
||||
}
|
||||
|
||||
void AuthController::logoutAction()
|
||||
void AuthController::logoutAction() const
|
||||
{
|
||||
sessionManager()->sessionEnd();
|
||||
}
|
||||
@@ -108,10 +108,12 @@ int AuthController::failedAttemptsCount() const
|
||||
|
||||
void AuthController::increaseFailedAttempts()
|
||||
{
|
||||
Q_ASSERT(Preferences::instance()->getWebUIMaxAuthFailCount() > 0);
|
||||
|
||||
FailedLogin &failedLogin = m_clientFailedLogins[sessionManager()->clientId()];
|
||||
++failedLogin.failedAttemptsCount;
|
||||
|
||||
if (failedLogin.failedAttemptsCount == MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
if (failedLogin.failedAttemptsCount >= Preferences::instance()->getWebUIMaxAuthFailCount()) {
|
||||
// Max number of failed attempts reached
|
||||
// Start ban period
|
||||
failedLogin.bannedAt = QDateTime::currentMSecsSinceEpoch() / 1000;
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void loginAction();
|
||||
void logoutAction();
|
||||
void logoutAction() const;
|
||||
|
||||
private:
|
||||
bool isBanned() const;
|
||||
|
||||
@@ -729,6 +729,12 @@
|
||||
<div class="formRow" style="padding-left: 30px; padding-top: 5px;">
|
||||
<textarea id="bypass_auth_subnet_whitelist_textarea" rows="5" cols="48" placeholder="Example: 172.17.32.0/24, fdff:ffff:c8::/40"></textarea>
|
||||
</div>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="webUIMaxAuthFailCountInput">QBT_TR(Ban client after consecutive failures:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
|
||||
<td><input type="number" id="webUIMaxAuthFailCountInput" style="width: 4em;" min="0" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td><label for="webUISessionTimeoutInput">QBT_TR(Session timeout:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
|
||||
@@ -1719,6 +1725,7 @@
|
||||
$('bypass_auth_subnet_whitelist_checkbox').setProperty('checked', pref.bypass_auth_subnet_whitelist_enabled);
|
||||
$('bypass_auth_subnet_whitelist_textarea').setProperty('value', pref.bypass_auth_subnet_whitelist);
|
||||
updateBypasssAuthSettings();
|
||||
$('webUIMaxAuthFailCountInput').setProperty('value', pref.web_ui_max_auth_fail_count.toInt());
|
||||
$('webUISessionTimeoutInput').setProperty('value', pref.web_ui_session_timeout.toInt());
|
||||
|
||||
// Use alternative Web UI
|
||||
@@ -2082,6 +2089,7 @@
|
||||
settings.set('bypass_local_auth', $('bypass_local_auth_checkbox').getProperty('checked'));
|
||||
settings.set('bypass_auth_subnet_whitelist_enabled', $('bypass_auth_subnet_whitelist_checkbox').getProperty('checked'));
|
||||
settings.set('bypass_auth_subnet_whitelist', $('bypass_auth_subnet_whitelist_textarea').getProperty('value'));
|
||||
settings.set('web_ui_max_auth_fail_count', $('webUIMaxAuthFailCountInput').getProperty('value'));
|
||||
settings.set('web_ui_session_timeout', $('webUISessionTimeoutInput').getProperty('value'));
|
||||
|
||||
// Use alternative Web UI
|
||||
|
||||
Reference in New Issue
Block a user