diff --git a/Changelog b/Changelog index d5f8dbda6..04ed4f463 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ * Unreleased - Christophe Dumez - v2.8.0 - FEATURE: Added support for secure SMTP connection (SSL) - FEATURE: Added support for SMTP authentication + - FEATURE: Added UPnP/NAT-PMP port forward for the Web UI port - BUGFIX: Change systray icon on the fly (no restart needed) - COSMETIC: Added monochrome icon for light themes diff --git a/src/preferences/options.ui b/src/preferences/options.ui index 617629ad3..29d2d1ba2 100644 --- a/src/preferences/options.ui +++ b/src/preferences/options.ui @@ -171,7 +171,7 @@ 0 0 - 503 + 489 519 @@ -493,7 +493,7 @@ 0 0 - 503 + 489 849 @@ -963,7 +963,7 @@ QGroupBox { 0 0 - 503 + 489 456 @@ -1406,7 +1406,7 @@ QGroupBox { 0 0 - 518 + 504 384 @@ -1784,8 +1784,8 @@ QGroupBox { 0 - -24 - 503 + 0 + 496 408 @@ -2161,7 +2161,7 @@ QGroupBox { 0 0 - 518 + 504 384 @@ -2179,45 +2179,50 @@ QGroupBox { - - - HTTP Server + + + + + Port: + + + + + + + 1 + + + 65535 + + + 8080 + + + + + + + Qt::Horizontal + + + + 21 + 29 + + + + + + + + + + Use UPnP / NAT-PMP to forward the port from my router + + + true - - - - - Port: - - - - - - - 1 - - - 65535 - - - 8080 - - - - - - - Qt::Horizontal - - - - 21 - 29 - - - - - @@ -2310,8 +2315,8 @@ QGroupBox { 0 0 - 518 - 384 + 86 + 16 diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index eaa11bb6d..18c616dce 100644 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -199,6 +199,7 @@ options_imp::options_imp(QWidget *parent): // Web UI tab connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinWebUiPort, SIGNAL(valueChanged(int)), this, SLOT(enableApplyButton())); + connect(checkWebUIUPnP, SIGNAL(toggled(bool)), SLOT(enableApplyButton())); connect(textWebUiUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textWebUiPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(checkBypassLocalAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -422,6 +423,7 @@ void options_imp::saveOptions(){ if(isWebUiEnabled()) { pref.setWebUiPort(webUiPort()); + pref.setUPnPForWebUIPort(checkWebUIUPnP->isChecked()); pref.setWebUiUsername(webUiUsername()); // FIXME: Check that the password is valid (not empty at least) pref.setWebUiPassword(webUiPassword()); @@ -660,6 +662,7 @@ void options_imp::loadOptions(){ // Web UI checkWebUi->setChecked(pref.isWebUiEnabled()); spinWebUiPort->setValue(pref.getWebUiPort()); + checkWebUIUPnP->setChecked(pref.useUPnPForWebUIPort()); textWebUiUsername->setText(pref.getWebUiUsername()); textWebUiPassword->setText(pref.getWebUiPassword()); checkBypassLocalAuth->setChecked(!pref.isWebUiLocalAuthEnabled()); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index a7c634d0a..ec4f27e4c 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -706,6 +706,14 @@ public: setValue("Preferences/WebUI/Port", port); } + bool useUPnPForWebUIPort() const { + return value("Preferences/WebUI/UseUPnP", true).toBool(); + } + + void setUPnPForWebUIPort(bool enabled) { + setValue("Preferences/WebUI/UseUPnP", enabled); + } + QString getWebUiUsername() const { return value("Preferences/WebUI/Username", "admin").toString(); } diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 9e465a056..11e562665 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -68,6 +68,8 @@ #include #include #include +#include +#include #include #include #include @@ -89,13 +91,14 @@ enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL }; QBtSession::QBtSession() : m_scanFolders(ScanFoldersModel::instance(this)), preAllocateAll(false), addInPause(false), global_ratio_limit(-1), - UPnPEnabled(false), LSDEnabled(false), + LSDEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false), torrentExport(false) #ifndef DISABLE_GUI , geoipDBLoaded(false), resolve_countries(false) #endif - , m_tracker(0), m_shutdownAct(NO_SHUTDOWN) + , m_tracker(0), m_shutdownAct(NO_SHUTDOWN), + m_upnp(0), m_natpmp(0) { BigRatioTimer = new QTimer(this); BigRatioTimer->setInterval(10000); @@ -1324,19 +1327,26 @@ void QBtSession::setMaxUploadsPerTorrent(int max) { } void QBtSession::enableUPnP(bool b) { + Preferences pref; if(b) { - if(!UPnPEnabled) { + if(!m_upnp) { qDebug("Enabling UPnP / NAT-PMP"); - s->start_upnp(); - s->start_natpmp(); - UPnPEnabled = true; + m_upnp = s->start_upnp(); + m_natpmp = s->start_natpmp(); + } + // Use UPnP/NAT-PMP for Web UI too + if(pref.isWebUiEnabled() && pref.useUPnPForWebUIPort()) { + const qint16 port = pref.getWebUiPort(); + m_upnp->add_mapping(upnp::tcp, port, port); + m_natpmp->add_mapping(natpmp::tcp, port, port); } } else { - if(UPnPEnabled) { + if(m_upnp) { qDebug("Disabling UPnP / NAT-PMP"); s->stop_upnp(); s->stop_natpmp(); - UPnPEnabled = false; + m_upnp = 0; + m_natpmp = 0; } } } diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index a96137de1..2c38fb72d 100644 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -241,7 +241,6 @@ private: bool addInPause; qreal global_ratio_limit; int high_ratio_action; - bool UPnPEnabled; bool LSDEnabled; bool DHTEnabled; int current_dht_port; @@ -269,7 +268,9 @@ private: QPointer m_tracker; TorrentSpeedMonitor *m_speedMonitor; shutDownAction m_shutdownAct; - + // Port forwarding + libtorrent::upnp *m_upnp; + libtorrent::natpmp *m_natpmp; }; #endif