[#2951] [#1908] [WebUI] Add bind interface option for server

This commit is contained in:
Calum Lind 2017-01-10 20:20:44 +00:00
parent c3a02e5291
commit 8a48ec0126
3 changed files with 25 additions and 16 deletions

View File

@ -102,6 +102,7 @@ CONFIG_DEFAULTS = {
# Server Settings
"base": "/",
"interface": "0.0.0.0",
"port": 8112,
"https": False,
"pkey": "ssl/daemon.pkey",
@ -665,9 +666,8 @@ class DelugeWeb(component.Component):
reactor.run()
def start_normal(self):
self.socket = reactor.listenTCP(self.port, self.site)
log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0",
self.port, self.port)
self.socket = reactor.listenTCP(self.port, self.site, interface=self.interface)
log.info("Serving on %s:%s view at http://%s:%s", self.interface, self.port, self.interface, self.port)
def start_ssl(self):
log.debug("Enabling SSL with PKey: %s, Cert: %s", self.pkey, self.cert)
@ -680,8 +680,8 @@ class DelugeWeb(component.Component):
options = CertificateOptions(privateKey=private_key, certificate=certificate, method=SSL.SSLv23_METHOD)
options.getContext().set_options(SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3)
self.socket = reactor.listenSSL(self.port, self.site, options)
log.info("Serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0", self.port, self.port)
self.socket = reactor.listenSSL(self.port, self.site, options, interface=self.interface)
log.info("Serving on %s:%s view at https://%s:%s", self.interface, self.port, self.interface, self.port)
def stop(self):
log.info("Shutting down webserver")

View File

@ -47,11 +47,11 @@ class WebUI(UI):
class Web(_UI):
help = """Starts the Deluge web interface"""
def __init__(self):
super(Web, self).__init__("web")
self.__server = None
group = OptionGroup(self.parser, "Web Options")
group.add_option("-b", "--base", dest="base",
help="Set the base path that the ui is running on (proxying)",
@ -59,6 +59,9 @@ class Web(_UI):
group.add_option("-f", "--fork", dest="fork",
help="Fork the web interface process into the background",
action="store_true", default=False)
group.add_option("-i", "--interface", dest="interface", type="str",
help="Binds the webserver to a specific IP address",
action="store", default=None)
group.add_option("-p", "--port", dest="port", type="int",
help="Sets the port to be used for the webserver",
action="store", default=None)
@ -75,14 +78,14 @@ class Web(_UI):
group.add_option("--ssl", dest="ssl", action="store_true",
help="Forces the webserver to use ssl", default=False)
self.parser.add_option_group(group)
@property
def server(self):
return self.__server
def start(self):
super(Web, self).start()
import deluge.common
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/
# Section 1.7
@ -91,28 +94,31 @@ class Web(_UI):
# or shell invoking the program.
if os.fork():
os._exit(0)
# setsid() to become a process group and session group leader.
os.setsid()
# fork() again so the parent, (the session group leader), can exit.
if os.fork():
os._exit(0)
# chdir() to esnure that our process doesn't keep any directory in
# use that may prevent a filesystem unmount.
import deluge.configmanager
os.chdir(deluge.configmanager.get_config_dir())
import server
self.__server = server.DelugeWeb()
if self.options.base:
self.server.base = self.options.base
if self.options.interface:
self.server.interface = self.options.interface
if self.options.port:
self.server.port = self.options.port
if self.options.ssl:
self.server.https = self.options.ssl

View File

@ -25,6 +25,9 @@ Set the base path that the web ui is running on (proxying)
.B -f, --fork
Fork the web interface process into the background
.TP
.BI -i\ ip_address \fR,\ \fB--interface= ip_address
Binds the webserver to a specific IP address
.TP
.BI -p\ port \fR,\ \fB--port= port
Sets the port to be used for the webserver
.TP