|
|
@ -131,8 +131,9 @@ QString HttpConnection::translateDocument(QString data) { |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respond() { |
|
|
|
void HttpConnection::respond() { |
|
|
|
//qDebug("Respond called");
|
|
|
|
//qDebug("Respond called");
|
|
|
|
int nb_fail = parent->client_failed_attempts.value(socket->peerAddress().toString(), 0); |
|
|
|
const QString &peer_ip = socket->peerAddress().toString(); |
|
|
|
if(nb_fail > 4) { |
|
|
|
const int nb_fail = parent->NbFailedAttemptsForIp(peer_ip); |
|
|
|
|
|
|
|
if(nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) { |
|
|
|
generator.setStatusLine(403, "Forbidden"); |
|
|
|
generator.setStatusLine(403, "Forbidden"); |
|
|
|
generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts.")); |
|
|
|
generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts.")); |
|
|
|
write(); |
|
|
|
write(); |
|
|
@ -142,8 +143,8 @@ void HttpConnection::respond() { |
|
|
|
qDebug("Auth: %s", qPrintable(auth.split(" ").first())); |
|
|
|
qDebug("Auth: %s", qPrintable(auth.split(" ").first())); |
|
|
|
if (QString::compare(auth.split(" ").first(), "Digest", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth.toLocal8Bit(), parser.method())) { |
|
|
|
if (QString::compare(auth.split(" ").first(), "Digest", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth.toLocal8Bit(), parser.method())) { |
|
|
|
// Update failed attempt counter
|
|
|
|
// Update failed attempt counter
|
|
|
|
parent->client_failed_attempts.insert(socket->peerAddress().toString(), nb_fail+1); |
|
|
|
parent->increaseNbFailedAttemptsForIp(peer_ip); |
|
|
|
qDebug("client IP: %s (%d failed attempts)", qPrintable(socket->peerAddress().toString()), nb_fail); |
|
|
|
qDebug("client IP: %s (%d failed attempts)", qPrintable(peer_ip), nb_fail+1); |
|
|
|
// Return unauthorized header
|
|
|
|
// Return unauthorized header
|
|
|
|
generator.setStatusLine(401, "Unauthorized"); |
|
|
|
generator.setStatusLine(401, "Unauthorized"); |
|
|
|
generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
|
generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
@ -151,7 +152,7 @@ void HttpConnection::respond() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Client sucessfuly authenticated, reset number of failed attempts
|
|
|
|
// Client sucessfuly authenticated, reset number of failed attempts
|
|
|
|
parent->client_failed_attempts.remove(socket->peerAddress().toString()); |
|
|
|
parent->resetNbFailedAttemptsForIp(peer_ip); |
|
|
|
QString url = parser.url(); |
|
|
|
QString url = parser.url(); |
|
|
|
// Favicon
|
|
|
|
// Favicon
|
|
|
|
if(url.endsWith("favicon.ico")) { |
|
|
|
if(url.endsWith("favicon.ico")) { |
|
|
|