From 8a66b40750803c3a17966c8db1cf77b35f4c799c Mon Sep 17 00:00:00 2001 From: Henri Date: Sat, 5 Dec 2020 15:08:14 +0100 Subject: [PATCH] Allow specifying bind interface and listening port in config file --- src/wgfrontend/config.py | 16 ++++++++++++++++ src/wgfrontend/webapp.py | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wgfrontend/config.py b/src/wgfrontend/config.py index 297c8c7..56def25 100644 --- a/src/wgfrontend/config.py +++ b/src/wgfrontend/config.py @@ -53,6 +53,12 @@ class Configuration(): # The command to be executed when the WireGuard config has changed # on_change_command = # Example: on_change_command = "sudo /etc/init.d/wgfrontend_interface restart" + + # The interface to bind to for the web server + # socket_host = 0.0.0.0 + + # The port to bind to for the web server + # socket_port = 8080 # The system user to be used for the frontend user = {user} @@ -111,6 +117,16 @@ class Configuration(): """The command to be executed on config changes""" return self.config.get('on_change_command') + @property + def socket_host(self): + """The interface to bind to""" + return self.config.get('socket_host', '0.0.0.0') + + @property + def socket_port(self): + """The port to bind to""" + return int(self.config.get('socket_port', 8080)) + @property def user(self): """The configured name for the wgfrontend system user""" diff --git a/src/wgfrontend/webapp.py b/src/wgfrontend/webapp.py index fe03207..3316bf5 100644 --- a/src/wgfrontend/webapp.py +++ b/src/wgfrontend/webapp.py @@ -128,11 +128,12 @@ def run_webapp(cfg): } } if os.path.exists(cfg.sslcertfile) and os.path.exists(cfg.sslkeyfile): + # Use ssl/tls if certificate files are present cherrypy.server.ssl_module = 'builtin' cherrypy.server.ssl_certificate = cfg.sslcertfile cherrypy.server.ssl_private_key = cfg.sslkeyfile - cherrypy.config.update({'server.socket_host': '0.0.0.0', - 'server.socket_port': 8080, + cherrypy.config.update({'server.socket_host': cfg.socket_host, + 'server.socket_port': cfg.socket_port, }) cherrypy.tree.mount(app, config=app_conf) if setupenv.is_root():