From 741959f9882c132ce178f54adb771ef3f37884a2 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sun, 22 Jan 2023 10:48:32 +0100 Subject: [PATCH] Re #1328 - add `-6` flag to enable IPv6 --- changedetectionio/changedetection.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/changedetectionio/changedetection.py b/changedetectionio/changedetection.py index a252473f..b0106513 100755 --- a/changedetectionio/changedetection.py +++ b/changedetectionio/changedetection.py @@ -31,11 +31,13 @@ def sigterm_handler(_signo, _stack_frame): def main(): global datastore global app - ssl_mode = False + + datastore_path = None + do_cleanup = False host = '' + ipv6_enabled = False port = os.environ.get('PORT') or 5000 - do_cleanup = False - datastore_path = None + ssl_mode = False # On Windows, create and use a default path. if os.name == 'nt': @@ -46,7 +48,7 @@ def main(): datastore_path = os.path.join(os.getcwd(), "../datastore") try: - opts, args = getopt.getopt(sys.argv[1:], "Ccsd:h:p:", "port") + opts, args = getopt.getopt(sys.argv[1:], "6Ccsd:h:p:", "port") except getopt.GetoptError: print('backend.py -s SSL enable -h [host] -p [port] -d [datastore path]') sys.exit(2) @@ -66,6 +68,10 @@ def main(): if opt == '-d': datastore_path = arg + if opt == '-6': + print ("Enabling IPv6 listen support") + ipv6_enabled = True + # Cleanup (remove text files that arent in the index) if opt == '-c': do_cleanup = True @@ -133,13 +139,15 @@ def main(): from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1, x_host=1) + s_type = socket.AF_INET6 if ipv6_enabled else socket.AF_INET + if ssl_mode: # @todo finalise SSL config, but this should get you in the right direction if you need it. - eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port), socket.AF_INET6), + eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port), s_type), certfile='cert.pem', keyfile='privkey.pem', server_side=True), app) else: - eventlet.wsgi.server(eventlet.listen((host, int(port)), socket.AF_INET6), app) + eventlet.wsgi.server(eventlet.listen((host, int(port)), s_type), app)