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

View File

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