Browse Source

FEATURE: Added UPnP/NAT-PMP port forward for the Web UI port

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
da32321f10
  1. 1
      Changelog
  2. 99
      src/preferences/options.ui
  3. 3
      src/preferences/options_imp.cpp
  4. 8
      src/preferences/preferences.h
  5. 26
      src/qtlibtorrent/qbtsession.cpp
  6. 5
      src/qtlibtorrent/qbtsession.h

1
Changelog

@ -1,6 +1,7 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.8.0 * Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.8.0
- FEATURE: Added support for secure SMTP connection (SSL) - FEATURE: Added support for secure SMTP connection (SSL)
- FEATURE: Added support for SMTP authentication - 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) - BUGFIX: Change systray icon on the fly (no restart needed)
- COSMETIC: Added monochrome icon for light themes - COSMETIC: Added monochrome icon for light themes

99
src/preferences/options.ui

@ -171,7 +171,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>503</width> <width>489</width>
<height>519</height> <height>519</height>
</rect> </rect>
</property> </property>
@ -493,7 +493,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>503</width> <width>489</width>
<height>849</height> <height>849</height>
</rect> </rect>
</property> </property>
@ -963,7 +963,7 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>503</width> <width>489</width>
<height>456</height> <height>456</height>
</rect> </rect>
</property> </property>
@ -1406,7 +1406,7 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>518</width> <width>504</width>
<height>384</height> <height>384</height>
</rect> </rect>
</property> </property>
@ -1784,8 +1784,8 @@ QGroupBox {
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-24</y> <y>0</y>
<width>503</width> <width>496</width>
<height>408</height> <height>408</height>
</rect> </rect>
</property> </property>
@ -2161,7 +2161,7 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>518</width> <width>504</width>
<height>384</height> <height>384</height>
</rect> </rect>
</property> </property>
@ -2179,45 +2179,50 @@ QGroupBox {
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QGroupBox" name="groupWebUiServer"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="title"> <item>
<string>HTTP Server</string> <widget class="QLabel" name="lblWebUiPort">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinWebUiPort">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8080</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>21</width>
<height>29</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkWebUIUPnP">
<property name="text">
<string>Use UPnP / NAT-PMP to forward the port from my router</string>
</property>
<property name="checked">
<bool>true</bool>
</property> </property>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lblWebUiPort">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinWebUiPort">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>8080</number>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>21</width>
<height>29</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -2310,8 +2315,8 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>518</width> <width>86</width>
<height>384</height> <height>16</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_36"/> <layout class="QVBoxLayout" name="verticalLayout_36"/>

3
src/preferences/options_imp.cpp

@ -199,6 +199,7 @@ options_imp::options_imp(QWidget *parent):
// Web UI tab // Web UI tab
connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkWebUi, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(spinWebUiPort, SIGNAL(valueChanged(int)), 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(textWebUiUsername, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(textWebUiPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textWebUiPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkBypassLocalAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkBypassLocalAuth, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
@ -422,6 +423,7 @@ void options_imp::saveOptions(){
if(isWebUiEnabled()) if(isWebUiEnabled())
{ {
pref.setWebUiPort(webUiPort()); pref.setWebUiPort(webUiPort());
pref.setUPnPForWebUIPort(checkWebUIUPnP->isChecked());
pref.setWebUiUsername(webUiUsername()); pref.setWebUiUsername(webUiUsername());
// FIXME: Check that the password is valid (not empty at least) // FIXME: Check that the password is valid (not empty at least)
pref.setWebUiPassword(webUiPassword()); pref.setWebUiPassword(webUiPassword());
@ -660,6 +662,7 @@ void options_imp::loadOptions(){
// Web UI // Web UI
checkWebUi->setChecked(pref.isWebUiEnabled()); checkWebUi->setChecked(pref.isWebUiEnabled());
spinWebUiPort->setValue(pref.getWebUiPort()); spinWebUiPort->setValue(pref.getWebUiPort());
checkWebUIUPnP->setChecked(pref.useUPnPForWebUIPort());
textWebUiUsername->setText(pref.getWebUiUsername()); textWebUiUsername->setText(pref.getWebUiUsername());
textWebUiPassword->setText(pref.getWebUiPassword()); textWebUiPassword->setText(pref.getWebUiPassword());
checkBypassLocalAuth->setChecked(!pref.isWebUiLocalAuthEnabled()); checkBypassLocalAuth->setChecked(!pref.isWebUiLocalAuthEnabled());

8
src/preferences/preferences.h

@ -706,6 +706,14 @@ public:
setValue("Preferences/WebUI/Port", port); 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 { QString getWebUiUsername() const {
return value("Preferences/WebUI/Username", "admin").toString(); return value("Preferences/WebUI/Username", "admin").toString();
} }

26
src/qtlibtorrent/qbtsession.cpp

@ -68,6 +68,8 @@
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -89,13 +91,14 @@ enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL };
QBtSession::QBtSession() QBtSession::QBtSession()
: m_scanFolders(ScanFoldersModel::instance(this)), : m_scanFolders(ScanFoldersModel::instance(this)),
preAllocateAll(false), addInPause(false), global_ratio_limit(-1), preAllocateAll(false), addInPause(false), global_ratio_limit(-1),
UPnPEnabled(false), LSDEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
torrentExport(false) torrentExport(false)
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #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 = new QTimer(this);
BigRatioTimer->setInterval(10000); BigRatioTimer->setInterval(10000);
@ -1324,19 +1327,26 @@ void QBtSession::setMaxUploadsPerTorrent(int max) {
} }
void QBtSession::enableUPnP(bool b) { void QBtSession::enableUPnP(bool b) {
Preferences pref;
if(b) { if(b) {
if(!UPnPEnabled) { if(!m_upnp) {
qDebug("Enabling UPnP / NAT-PMP"); qDebug("Enabling UPnP / NAT-PMP");
s->start_upnp(); m_upnp = s->start_upnp();
s->start_natpmp(); m_natpmp = s->start_natpmp();
UPnPEnabled = true; }
// 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 { } else {
if(UPnPEnabled) { if(m_upnp) {
qDebug("Disabling UPnP / NAT-PMP"); qDebug("Disabling UPnP / NAT-PMP");
s->stop_upnp(); s->stop_upnp();
s->stop_natpmp(); s->stop_natpmp();
UPnPEnabled = false; m_upnp = 0;
m_natpmp = 0;
} }
} }
} }

5
src/qtlibtorrent/qbtsession.h

@ -241,7 +241,6 @@ private:
bool addInPause; bool addInPause;
qreal global_ratio_limit; qreal global_ratio_limit;
int high_ratio_action; int high_ratio_action;
bool UPnPEnabled;
bool LSDEnabled; bool LSDEnabled;
bool DHTEnabled; bool DHTEnabled;
int current_dht_port; int current_dht_port;
@ -269,7 +268,9 @@ private:
QPointer<QTracker> m_tracker; QPointer<QTracker> m_tracker;
TorrentSpeedMonitor *m_speedMonitor; TorrentSpeedMonitor *m_speedMonitor;
shutDownAction m_shutdownAct; shutDownAction m_shutdownAct;
// Port forwarding
libtorrent::upnp *m_upnp;
libtorrent::natpmp *m_natpmp;
}; };
#endif #endif

Loading…
Cancel
Save