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 @@ @@ -1,6 +1,7 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - 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

99
src/preferences/options.ui

@ -171,7 +171,7 @@ @@ -171,7 +171,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<width>489</width>
<height>519</height>
</rect>
</property>
@ -493,7 +493,7 @@ @@ -493,7 +493,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<width>489</width>
<height>849</height>
</rect>
</property>
@ -963,7 +963,7 @@ QGroupBox { @@ -963,7 +963,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<width>489</width>
<height>456</height>
</rect>
</property>
@ -1406,7 +1406,7 @@ QGroupBox { @@ -1406,7 +1406,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<width>504</width>
<height>384</height>
</rect>
</property>
@ -1784,8 +1784,8 @@ QGroupBox { @@ -1784,8 +1784,8 @@ QGroupBox {
<property name="geometry">
<rect>
<x>0</x>
<y>-24</y>
<width>503</width>
<y>0</y>
<width>496</width>
<height>408</height>
</rect>
</property>
@ -2161,7 +2161,7 @@ QGroupBox { @@ -2161,7 +2161,7 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<width>504</width>
<height>384</height>
</rect>
</property>
@ -2179,45 +2179,50 @@ QGroupBox { @@ -2179,45 +2179,50 @@ QGroupBox {
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupWebUiServer">
<property name="title">
<string>HTTP Server</string>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<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>
</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>
<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>
</item>
<item>
@ -2310,8 +2315,8 @@ QGroupBox { @@ -2310,8 +2315,8 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<height>384</height>
<width>86</width>
<height>16</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_36"/>

3
src/preferences/options_imp.cpp

@ -199,6 +199,7 @@ options_imp::options_imp(QWidget *parent): @@ -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(){ @@ -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(){ @@ -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());

8
src/preferences/preferences.h

@ -706,6 +706,14 @@ public: @@ -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();
}

26
src/qtlibtorrent/qbtsession.cpp

@ -68,6 +68,8 @@ @@ -68,6 +68,8 @@
#include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp>
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
@ -89,13 +91,14 @@ enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL }; @@ -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) { @@ -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;
}
}
}

5
src/qtlibtorrent/qbtsession.h

@ -241,7 +241,6 @@ private: @@ -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: @@ -269,7 +268,9 @@ private:
QPointer<QTracker> m_tracker;
TorrentSpeedMonitor *m_speedMonitor;
shutDownAction m_shutdownAct;
// Port forwarding
libtorrent::upnp *m_upnp;
libtorrent::natpmp *m_natpmp;
};
#endif

Loading…
Cancel
Save