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

This commit is contained in:
Friedrich Gonzalez 2014-02-19 11:17:22 +00:00 committed by Calum Lind
parent 9eb6b7c52a
commit 49d4bb4969
3 changed files with 15 additions and 6 deletions

View File

@ -80,6 +80,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",
@ -607,6 +608,7 @@ class DelugeWeb(component.Component):
self.socket = None self.socket = None
self.top_level = TopLevel() self.top_level = TopLevel()
self.site = server.Site(self.top_level) self.site = server.Site(self.top_level)
self.interface = self.config["interface"]
self.port = self.config["port"] self.port = self.config["port"]
self.https = self.config["https"] self.https = self.config["https"]
self.pkey = self.config["pkey"] self.pkey = self.config["pkey"]
@ -649,15 +651,13 @@ 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):
check_ssl_keys() check_ssl_keys()
self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory()) self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory(), interface=self.interface)
log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0", log.info("serving on %s:%s view at https://%s:%s", self.interface, self.port, self.interface, self.port)
self.port, self.port)
def stop(self): def stop(self):
log.info("Shutting down webserver") log.info("Shutting down webserver")

View File

@ -70,6 +70,9 @@ class Web(_UI):
group.add_option("-g", "--group", dest="group", type="str", group.add_option("-g", "--group", dest="group", type="str",
help="Group to switch to. Only use it when starting as root", help="Group to switch to. Only use it when starting as root",
action="store", default=None) action="store", default=None)
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)
@ -134,6 +137,9 @@ class Web(_UI):
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

View File

@ -22,6 +22,9 @@ Set the base path that the 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
.B -i INTERFACE, --interface=INTERFACE
Binds the webserver to a specific IP address
.TP
.B -p PORT, --port=PORT .B -p PORT, --port=PORT
Sets the port to be used for the webserver Sets the port to be used for the webserver
.TP .TP