mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Web UI code clean up
This commit is contained in:
parent
8e026e68d7
commit
28d1671bb8
@ -33,7 +33,6 @@
|
|||||||
#include "httpconnection.h"
|
#include "httpconnection.h"
|
||||||
#include "eventmanager.h"
|
#include "eventmanager.h"
|
||||||
#include "qbtsession.h"
|
#include "qbtsession.h"
|
||||||
#include <QTimer>
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
@ -51,15 +50,12 @@ const int BAN_TIME = 3600000; // 1 hour
|
|||||||
|
|
||||||
class UnbanTimer: public QTimer {
|
class UnbanTimer: public QTimer {
|
||||||
public:
|
public:
|
||||||
UnbanTimer(QObject *parent, const QString& peer_ip): QTimer(parent), m_peerIp(peer_ip){
|
UnbanTimer(const QString& peer_ip, QObject *parent): QTimer(parent),
|
||||||
|
m_peerIp(peer_ip) {
|
||||||
setSingleShot(true);
|
setSingleShot(true);
|
||||||
setInterval(BAN_TIME);
|
setInterval(BAN_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
~UnbanTimer() {
|
|
||||||
qDebug("||||||||||||Deleting ban timer|||||||||||||||");
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QString peerIp() const { return m_peerIp; }
|
inline QString peerIp() const { return m_peerIp; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -78,13 +74,13 @@ int HttpServer::NbFailedAttemptsForIp(const QString& ip) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HttpServer::increaseNbFailedAttemptsForIp(const QString& ip) {
|
void HttpServer::increaseNbFailedAttemptsForIp(const QString& ip) {
|
||||||
const int nb_fail = m_clientFailedAttempts.value(ip, 0);
|
const int nb_fail = m_clientFailedAttempts.value(ip, 0) + 1;
|
||||||
m_clientFailedAttempts.insert(ip, nb_fail+1);
|
m_clientFailedAttempts.insert(ip, nb_fail);
|
||||||
if(nb_fail == MAX_AUTH_FAILED_ATTEMPTS-1) {
|
if(nb_fail == MAX_AUTH_FAILED_ATTEMPTS) {
|
||||||
// Max number of failed attempts reached
|
// Max number of failed attempts reached
|
||||||
// Start ban period
|
// Start ban period
|
||||||
UnbanTimer* ubantimer = new UnbanTimer(this, ip);
|
UnbanTimer* ubantimer = new UnbanTimer(ip, this);
|
||||||
connect(ubantimer, SIGNAL(timeout()), this, SLOT(UnbanTimerEvent()));
|
connect(ubantimer, SIGNAL(timeout()), SLOT(UnbanTimerEvent()));
|
||||||
ubantimer->start();
|
ubantimer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,9 +121,8 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
|
|||||||
connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), m_eventManager, SLOT(deletedTorrent(QString)));
|
connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), m_eventManager, SLOT(deletedTorrent(QString)));
|
||||||
|
|
||||||
//set timer
|
//set timer
|
||||||
m_timer = new QTimer(this);
|
connect(&m_timer, SIGNAL(timeout()), SLOT(onTimer()));
|
||||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
|
m_timer.start(msec);
|
||||||
m_timer->start(msec);
|
|
||||||
|
|
||||||
// Additional translations for Web UI
|
// Additional translations for Web UI
|
||||||
QString a = tr("File");
|
QString a = tr("File");
|
||||||
@ -161,7 +156,6 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
|
|||||||
}
|
}
|
||||||
|
|
||||||
HttpServer::~HttpServer() {
|
HttpServer::~HttpServer() {
|
||||||
delete m_timer;
|
|
||||||
delete m_eventManager;
|
delete m_eventManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
#include <QSslCertificate>
|
#include <QSslCertificate>
|
||||||
@ -88,7 +89,7 @@ private:
|
|||||||
QByteArray m_username;
|
QByteArray m_username;
|
||||||
QByteArray m_passwordSha1;
|
QByteArray m_passwordSha1;
|
||||||
EventManager *m_eventManager;
|
EventManager *m_eventManager;
|
||||||
QTimer *m_timer;
|
QTimer m_timer;
|
||||||
QHash<QString, int> m_clientFailedAttempts;
|
QHash<QString, int> m_clientFailedAttempts;
|
||||||
bool m_localAuth;
|
bool m_localAuth;
|
||||||
#ifndef QT_NO_OPENSSL
|
#ifndef QT_NO_OPENSSL
|
||||||
|
Loading…
Reference in New Issue
Block a user