mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Merge pull request #10175 from Chocobo1/cert
Load WebUI certificate & key from file path
This commit is contained in:
@@ -39,11 +39,6 @@
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
#include <QSslCertificate>
|
||||
#include <QSslKey>
|
||||
#endif
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/global.h"
|
||||
#include "base/net/portforwarder.h"
|
||||
@@ -223,8 +218,8 @@ void AppController::preferencesAction()
|
||||
data["web_ui_port"] = pref->getWebUiPort();
|
||||
data["web_ui_upnp"] = pref->useUPnPForWebUIPort();
|
||||
data["use_https"] = pref->isWebUiHttpsEnabled();
|
||||
data["ssl_key"] = QString::fromLatin1(pref->getWebUiHttpsKey());
|
||||
data["ssl_cert"] = QString::fromLatin1(pref->getWebUiHttpsCertificate());
|
||||
data["web_ui_https_cert_path"] = pref->getWebUIHttpsCertificatePath();
|
||||
data["web_ui_https_key_path"] = pref->getWebUIHttpsKeyPath();
|
||||
// Authentication
|
||||
data["web_ui_username"] = pref->getWebUiUsername();
|
||||
data["bypass_local_auth"] = !pref->isWebUiLocalAuthEnabled();
|
||||
@@ -518,18 +513,10 @@ void AppController::setPreferencesAction()
|
||||
pref->setUPnPForWebUIPort(m["web_ui_upnp"].toBool());
|
||||
if (m.contains("use_https"))
|
||||
pref->setWebUiHttpsEnabled(m["use_https"].toBool());
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (m.contains("ssl_key")) {
|
||||
QByteArray raw_key = m["ssl_key"].toString().toLatin1();
|
||||
if (!QSslKey(raw_key, QSsl::Rsa).isNull())
|
||||
pref->setWebUiHttpsKey(raw_key);
|
||||
}
|
||||
if (m.contains("ssl_cert")) {
|
||||
QByteArray raw_cert = m["ssl_cert"].toString().toLatin1();
|
||||
if (!QSslCertificate(raw_cert).isNull())
|
||||
pref->setWebUiHttpsCertificate(raw_cert);
|
||||
}
|
||||
#endif
|
||||
if ((it = m.find(QLatin1String("web_ui_https_cert_path"))) != m.constEnd())
|
||||
pref->setWebUIHttpsCertificatePath(it.value().toString());
|
||||
if ((it = m.find(QLatin1String("web_ui_https_key_path"))) != m.constEnd())
|
||||
pref->setWebUIHttpsKeyPath(it.value().toString());
|
||||
// Authentication
|
||||
if (m.contains("web_ui_username"))
|
||||
pref->setWebUiUsername(m["web_ui_username"].toString());
|
||||
|
||||
@@ -28,11 +28,14 @@
|
||||
|
||||
#include "webui.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include "base/http/server.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/net/dnsupdater.h"
|
||||
#include "base/net/portforwarder.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/net.h"
|
||||
#include "webapplication.h"
|
||||
|
||||
WebUI::WebUI()
|
||||
@@ -77,11 +80,18 @@ void WebUI::configure()
|
||||
m_httpServer->close();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (pref->isWebUiHttpsEnabled()) {
|
||||
const QByteArray certs = pref->getWebUiHttpsCertificate();
|
||||
const QByteArray key = pref->getWebUiHttpsKey();
|
||||
bool success = m_httpServer->setupHttps(certs, key);
|
||||
const auto readData = [](const QString &path) -> QByteArray
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return {};
|
||||
return file.read(Utils::Net::MAX_SSL_FILE_SIZE);
|
||||
};
|
||||
const QByteArray cert = readData(pref->getWebUIHttpsCertificatePath());
|
||||
const QByteArray key = readData(pref->getWebUIHttpsKeyPath());
|
||||
|
||||
const bool success = m_httpServer->setupHttps(cert, key);
|
||||
if (success)
|
||||
logger->addMessage(tr("Web UI: HTTPS setup successful"));
|
||||
else
|
||||
@@ -90,7 +100,6 @@ void WebUI::configure()
|
||||
else {
|
||||
m_httpServer->disableHttps();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_httpServer->isListening()) {
|
||||
const auto address = (serverAddressString == "*" || serverAddressString.isEmpty())
|
||||
|
||||
@@ -682,18 +682,18 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ssl_key_textarea">QBT_TR(Key:)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
<label for="ssl_cert_text">QBT_TR(Certificate:)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea id="ssl_key_textarea" rows="5" cols="70"></textarea>
|
||||
<input type="text" id="ssl_cert_text" style="width: 30em;" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ssl_cert_textarea">QBT_TR(Certificate:)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
<label for="ssl_key_text">QBT_TR(Key:)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea id="ssl_cert_textarea" rows="5" cols="70"></textarea>
|
||||
<input type="text" id="ssl_key_text" style="width: 30em;" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -1043,8 +1043,8 @@
|
||||
// Web UI tab
|
||||
var updateHttpsSettings = function() {
|
||||
var isUseHttpsEnabled = $('use_https_checkbox').getProperty('checked');
|
||||
$('ssl_key_textarea').setProperty('disabled', !isUseHttpsEnabled);
|
||||
$('ssl_cert_textarea').setProperty('disabled', !isUseHttpsEnabled);
|
||||
$('ssl_cert_text').setProperty('disabled', !isUseHttpsEnabled);
|
||||
$('ssl_key_text').setProperty('disabled', !isUseHttpsEnabled);
|
||||
};
|
||||
|
||||
var updateBypasssAuthSettings = function() {
|
||||
@@ -1330,8 +1330,8 @@
|
||||
$('webui_port_value').setProperty('value', pref.web_ui_port);
|
||||
$('webui_upnp_checkbox').setProperty('checked', pref.web_ui_upnp);
|
||||
$('use_https_checkbox').setProperty('checked', pref.use_https);
|
||||
$('ssl_key_textarea').setProperty('value', pref.ssl_key);
|
||||
$('ssl_cert_textarea').setProperty('value', pref.ssl_cert);
|
||||
$('ssl_cert_text').setProperty('value', pref.web_ui_https_cert_path);
|
||||
$('ssl_key_text').setProperty('value', pref.web_ui_https_key_path);
|
||||
updateHttpsSettings();
|
||||
|
||||
// Authentication
|
||||
@@ -1646,8 +1646,8 @@
|
||||
settings.set('web_ui_port', web_ui_port);
|
||||
settings.set('web_ui_upnp', $('webui_upnp_checkbox').getProperty('checked'));
|
||||
settings.set('use_https', $('use_https_checkbox').getProperty('checked'));
|
||||
settings.set('ssl_key', $('ssl_key_textarea').getProperty('value'));
|
||||
settings.set('ssl_cert', $('ssl_cert_textarea').getProperty('value'));
|
||||
settings.set('web_ui_https_cert_path', $('ssl_cert_text').getProperty('value'));
|
||||
settings.set('web_ui_https_key_path', $('ssl_key_text').getProperty('value'));
|
||||
|
||||
// Authentication
|
||||
var web_ui_username = $('webui_username_text').getProperty('value');
|
||||
|
||||
Reference in New Issue
Block a user