|
|
@ -45,24 +45,33 @@ WebUI::WebUI(QObject *parent) |
|
|
|
|
|
|
|
|
|
|
|
void WebUI::init() |
|
|
|
void WebUI::init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
|
|
|
|
Logger* const logger = Logger::instance(); |
|
|
|
Logger* const logger = Logger::instance(); |
|
|
|
|
|
|
|
Preferences* const pref = Preferences::instance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const quint16 oldPort = m_port; |
|
|
|
|
|
|
|
m_port = pref->getWebUiPort(); |
|
|
|
|
|
|
|
|
|
|
|
if (pref->isWebUiEnabled()) { |
|
|
|
if (pref->isWebUiEnabled()) { |
|
|
|
const quint16 port = pref->getWebUiPort(); |
|
|
|
// UPnP/NAT-PMP
|
|
|
|
if (m_port != port) { |
|
|
|
if (pref->useUPnPForWebUIPort()) { |
|
|
|
Net::PortForwarder::instance()->deletePort(port); |
|
|
|
if (m_port != oldPort) { |
|
|
|
m_port = port; |
|
|
|
Net::PortForwarder::instance()->deletePort(oldPort); |
|
|
|
|
|
|
|
Net::PortForwarder::instance()->addPort(m_port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (httpServer_) { |
|
|
|
|
|
|
|
if (httpServer_->serverPort() != m_port) |
|
|
|
|
|
|
|
httpServer_->close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|
|
|
|
Net::PortForwarder::instance()->deletePort(oldPort); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// http server
|
|
|
|
|
|
|
|
if (!httpServer_) { |
|
|
|
webapp_ = new WebApplication(this); |
|
|
|
webapp_ = new WebApplication(this); |
|
|
|
httpServer_ = new Http::Server(webapp_, this); |
|
|
|
httpServer_ = new Http::Server(webapp_, this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
if (httpServer_->serverPort() != m_port) |
|
|
|
|
|
|
|
httpServer_->close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifndef QT_NO_OPENSSL |
|
|
|
#ifndef QT_NO_OPENSSL |
|
|
|
if (pref->isWebUiHttpsEnabled()) { |
|
|
|
if (pref->isWebUiHttpsEnabled()) { |
|
|
@ -87,9 +96,9 @@ void WebUI::init() |
|
|
|
if (!httpServer_->isListening()) { |
|
|
|
if (!httpServer_->isListening()) { |
|
|
|
bool success = httpServer_->listen(QHostAddress::Any, m_port); |
|
|
|
bool success = httpServer_->listen(QHostAddress::Any, m_port); |
|
|
|
if (success) |
|
|
|
if (success) |
|
|
|
logger->addMessage(tr("The Web UI is listening on port %1").arg(m_port)); |
|
|
|
logger->addMessage(tr("Web UI: Now listening on port %1").arg(m_port)); |
|
|
|
else |
|
|
|
else |
|
|
|
logger->addMessage(tr("Web UI Error - Unable to bind Web UI to port %1").arg(m_port), Log::CRITICAL); |
|
|
|
logger->addMessage(tr("Web UI: Unable to bind to port %1").arg(m_port), Log::CRITICAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DynDNS
|
|
|
|
// DynDNS
|
|
|
@ -103,20 +112,17 @@ void WebUI::init() |
|
|
|
if (dynDNSUpdater_) |
|
|
|
if (dynDNSUpdater_) |
|
|
|
delete dynDNSUpdater_; |
|
|
|
delete dynDNSUpdater_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Use UPnP/NAT-PMP for Web UI
|
|
|
|
|
|
|
|
if (pref->useUPnPForWebUIPort()) |
|
|
|
|
|
|
|
Net::PortForwarder::instance()->addPort(m_port); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Net::PortForwarder::instance()->deletePort(m_port); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|
|
|
|
Net::PortForwarder::instance()->deletePort(oldPort); |
|
|
|
|
|
|
|
|
|
|
|
if (httpServer_) |
|
|
|
if (httpServer_) |
|
|
|
delete httpServer_; |
|
|
|
delete httpServer_; |
|
|
|
|
|
|
|
|
|
|
|
if (webapp_) |
|
|
|
if (webapp_) |
|
|
|
delete webapp_; |
|
|
|
delete webapp_; |
|
|
|
|
|
|
|
|
|
|
|
if (dynDNSUpdater_) |
|
|
|
if (dynDNSUpdater_) |
|
|
|
delete dynDNSUpdater_; |
|
|
|
delete dynDNSUpdater_; |
|
|
|
Net::PortForwarder::instance()->deletePort(m_port); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|