mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 06:54:20 +00:00
Added HTTPS support (backend)
This commit is contained in:
parent
122db6a77e
commit
669d1a3a46
@ -37,6 +37,8 @@
|
||||
#include <QTime>
|
||||
#include <QList>
|
||||
#include <QDebug>
|
||||
#include <QSslCertificate>
|
||||
#include <QSslKey>
|
||||
#include <libtorrent/version.hpp>
|
||||
|
||||
#ifndef DISABLE_GUI
|
||||
@ -773,6 +775,36 @@ public:
|
||||
return pass_ha1;
|
||||
}
|
||||
|
||||
bool isWebUiHttpsEnabled() const {
|
||||
return value("Preferences/WebUI/HTTPS/Enabled", false).toBool();
|
||||
}
|
||||
|
||||
void setWebUiHttpsEnabled(bool enabled) {
|
||||
setValue("Preferences/WebUI/HTTPS/Enabled", enabled);
|
||||
}
|
||||
|
||||
QSslCertificate getWebUiHttpsCertificate() const {
|
||||
return QSslCertificate(value("Preferences/WebUI/HTTPS/Certificate").toByteArray());
|
||||
}
|
||||
|
||||
void setWebUiHttpsCertificate(QString filename) {
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
setValue("Preferences/WebUI/HTTPS/Certificate", file.readAll());
|
||||
file.close();
|
||||
}
|
||||
|
||||
QSslKey getWebUiHttpsKey() const {
|
||||
return QSslKey(value("Preferences/WebUI/HTTPS/Key").toByteArray(), QSsl::Rsa);
|
||||
}
|
||||
|
||||
void setWebUiHttpsKey(QString filename) {
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
setValue("Preferences/WebUI/HTTPS/Key", file.readAll());
|
||||
file.close();
|
||||
}
|
||||
|
||||
bool isDynDNSEnabled() const {
|
||||
return value("Preferences/DynDNS/Enabled", false).toBool();
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <QTime>
|
||||
#include <QRegExp>
|
||||
#include <QTimer>
|
||||
#include <QSslSocket>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
@ -87,6 +88,11 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent) {
|
||||
username = pref.getWebUiUsername().toLocal8Bit();
|
||||
password_ha1 = pref.getWebUiPassword().toLocal8Bit();
|
||||
m_localAuth = pref.isWebUiLocalAuthEnabled();
|
||||
m_https = pref.isWebUiHttpsEnabled();
|
||||
if (m_https) {
|
||||
m_certificate = pref.getWebUiHttpsCertificate();
|
||||
m_key = pref.getWebUiHttpsKey();
|
||||
}
|
||||
connect(this, SIGNAL(newConnection()), this, SLOT(newHttpConnection()));
|
||||
manager = new EventManager(this);
|
||||
//add torrents
|
||||
@ -141,6 +147,36 @@ HttpServer::~HttpServer()
|
||||
delete manager;
|
||||
}
|
||||
|
||||
void HttpServer::incomingConnection(int socketDescriptor)
|
||||
{
|
||||
QTcpSocket *serverSocket;
|
||||
QSslSocket *serverSslSocket;
|
||||
if (m_https)
|
||||
{
|
||||
serverSslSocket = new QSslSocket;
|
||||
serverSocket = serverSslSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
serverSocket = new QTcpSocket;
|
||||
}
|
||||
if (serverSocket->setSocketDescriptor(socketDescriptor))
|
||||
{
|
||||
if (m_https)
|
||||
{
|
||||
serverSslSocket->setProtocol(QSsl::AnyProtocol);
|
||||
serverSslSocket->setPrivateKey(m_key);
|
||||
serverSslSocket->setLocalCertificate(m_certificate);
|
||||
serverSslSocket->startServerEncryption();
|
||||
}
|
||||
addPendingConnection(serverSocket);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete serverSocket;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpServer::newHttpConnection()
|
||||
{
|
||||
QTcpSocket *socket;
|
||||
|
@ -63,6 +63,9 @@ public:
|
||||
void increaseNbFailedAttemptsForIp(QString ip);
|
||||
void resetNbFailedAttemptsForIp(QString ip);
|
||||
|
||||
private:
|
||||
void incomingConnection(int socketDescriptor);
|
||||
|
||||
private slots:
|
||||
void newHttpConnection();
|
||||
void onTimer();
|
||||
@ -75,6 +78,9 @@ private:
|
||||
QTimer *timer;
|
||||
QHash<QString, int> client_failed_attempts;
|
||||
bool m_localAuth;
|
||||
bool m_https;
|
||||
QSslCertificate m_certificate;
|
||||
QSslKey m_key;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user