From fe758de3e796c0fc4c1003e46ca509ce6ff4e020 Mon Sep 17 00:00:00 2001 From: powerjungle Date: Thu, 26 Jan 2023 09:58:13 +0100 Subject: [PATCH] server: add options to choose the address to bind to Sometimes a user might want to bind to localhost only for testing or have multiple interfaces per IP version and only one must be used. --- syncplay/ep_server.py | 7 +++++-- syncplay/messages_de.py | 2 ++ syncplay/messages_en.py | 2 ++ syncplay/messages_eo.py | 2 ++ syncplay/messages_es.py | 2 ++ syncplay/messages_fr.py | 2 ++ syncplay/messages_it.py | 2 ++ syncplay/messages_pt_BR.py | 2 ++ syncplay/messages_pt_PT.py | 2 ++ syncplay/messages_ru.py | 2 ++ syncplay/messages_tr.py | 2 ++ syncplay/messages_zh_CN.py | 2 ++ syncplay/server.py | 2 ++ 13 files changed, 29 insertions(+), 2 deletions(-) diff --git a/syncplay/ep_server.py b/syncplay/ep_server.py index a329ab0c0..14cf9d8d3 100644 --- a/syncplay/ep_server.py +++ b/syncplay/ep_server.py @@ -38,6 +38,7 @@ def failed4(f): def main(): argsGetter = ConfigurationGetter() args = argsGetter.getConfiguration() + factory = SyncFactory( args.port, args.password, @@ -53,12 +54,14 @@ def main(): args.stats_db_file, args.tls ) + if args.disable_ipv6 is False: - endpoint6 = TCP6ServerEndpoint(reactor, int(args.port)) + endpoint6 = TCP6ServerEndpoint(reactor, int(args.port), interface=args.interface_ipv6) endpoint6.listen(factory).addCallbacks(isListening6, failed6) if args.disable_ipv4 is False: - endpoint4 = TCP4ServerEndpoint(reactor, int(args.port)) + endpoint4 = TCP4ServerEndpoint(reactor, int(args.port), interface=args.interface_ipv4) endpoint4.listen(factory).addCallbacks(isListening4, failed4) + if ServerStatus.listening6 or ServerStatus.listening4: reactor.run() else: diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index 3aa6fc769..458dce6eb 100755 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -501,6 +501,8 @@ "server-messed-up-motd-too-long": "Die Nachricht des Tages ist zu lang - Maximal {} Zeichen, aktuell {}.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Unbekannter Befehl {}", # message diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index 1fc4c961b..34271f4cd 100644 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -502,6 +502,8 @@ "server-messed-up-motd-too-long": "Message of the Day is too long - maximum of {} chars, {} given.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Unknown command {}", # message diff --git a/syncplay/messages_eo.py b/syncplay/messages_eo.py index 1c10ba18d..16105cd31 100644 --- a/syncplay/messages_eo.py +++ b/syncplay/messages_eo.py @@ -505,6 +505,8 @@ "server-messed-up-motd-too-long": "Mesaĝo de tago estas tro longa – maksimuma kvanto estas {} signoj, sed {} estas donitaj.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Nekonata ordono {}", # message diff --git a/syncplay/messages_es.py b/syncplay/messages_es.py index 980a7723b..050fbe36d 100644 --- a/syncplay/messages_es.py +++ b/syncplay/messages_es.py @@ -501,6 +501,8 @@ "server-messed-up-motd-too-long": "El mensaje del día es muy largo - máximo de {} caracteres, se recibieron {}.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Comando desconocido {}", # message diff --git a/syncplay/messages_fr.py b/syncplay/messages_fr.py index 88ae72f4c..93670ad8b 100644 --- a/syncplay/messages_fr.py +++ b/syncplay/messages_fr.py @@ -502,6 +502,8 @@ "server-messed-up-motd-too-long": "Le message du jour est trop long: {}caractères maximum, {} donnés.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Commande inconnue {}", # message diff --git a/syncplay/messages_it.py b/syncplay/messages_it.py index 8629ccadf..5067f1098 100755 --- a/syncplay/messages_it.py +++ b/syncplay/messages_it.py @@ -501,6 +501,8 @@ "server-messed-up-motd-too-long": "Il messaggio del giorno è troppo lungo - numero massimo di caratteri è {}, {} trovati.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Comando non riconosciuto {}", # message diff --git a/syncplay/messages_pt_BR.py b/syncplay/messages_pt_BR.py index 3322d8725..647e9efef 100644 --- a/syncplay/messages_pt_BR.py +++ b/syncplay/messages_pt_BR.py @@ -502,6 +502,8 @@ "server-messed-up-motd-too-long": "A Mensagem do Dia é muito longa - máximo de {} caracteres, {} foram dados.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Comando desconhecido: {}", # message diff --git a/syncplay/messages_pt_PT.py b/syncplay/messages_pt_PT.py index 1039d6029..e94fb3584 100644 --- a/syncplay/messages_pt_PT.py +++ b/syncplay/messages_pt_PT.py @@ -501,6 +501,8 @@ "server-messed-up-motd-too-long": "A Mensagem do Dia é muito longa - máximo de {} caracteres, {} foram dados.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Comando desconhecido: {}", # message diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index 623141fb6..fb5e67c7d 100755 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -498,6 +498,8 @@ "server-messed-up-motd-too-long": "MOTD-сообщение слишком длинное: максимальная длина - {} символ(ов), текущая длина - {} символ(ов).", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Неизвестная команда: {}", # message diff --git a/syncplay/messages_tr.py b/syncplay/messages_tr.py index 524b17b2b..d3e36a4bc 100644 --- a/syncplay/messages_tr.py +++ b/syncplay/messages_tr.py @@ -502,6 +502,8 @@ "server-messed-up-motd-too-long": "Günün Mesajı çok uzun - maksimum {} karakter olmalı, {} verildi.", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "Bilinmeyen komut {}", # message diff --git a/syncplay/messages_zh_CN.py b/syncplay/messages_zh_CN.py index d180e7d05..6d043eda7 100644 --- a/syncplay/messages_zh_CN.py +++ b/syncplay/messages_zh_CN.py @@ -502,6 +502,8 @@ "server-messed-up-motd-too-long": "每日信息过长 - 最大{}个chars, 给出的长度{}", "server-do-not-listen-on-ipv4": "Don't listen on IPv4 when starting the server.", "server-do-not-listen-on-ipv6": "Don't listen on IPv6 when starting the server.", + "server-interface-ipv4": "The IP address to bind to for IPv4. Leaving it empty defaults to using all.", + "server-interface-ipv6": "The IP address to bind to for IPv6. Leaving it empty defaults to using all.", # Server errors "unknown-command-server-error": "未知命令 {}", # message diff --git a/syncplay/server.py b/syncplay/server.py index e9193a5d2..3de9b8d22 100755 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -891,3 +891,5 @@ def _prepareArgParser(self): self._argparser.add_argument('--tls', metavar='path', type=str, nargs='?', help=getMessage("server-startTLS-argument")) self._argparser.add_argument('--disable-ipv4', action='store_true', help=getMessage("server-do-not-listen-on-ipv4")) self._argparser.add_argument('--disable-ipv6', action='store_true', help=getMessage("server-do-not-listen-on-ipv6")) + self._argparser.add_argument('--interface-ipv4', metavar='interfaceIPv4', type=str, nargs='?', help=getMessage("server-interface-ipv4"), default='') + self._argparser.add_argument('--interface-ipv6', metavar='interfaceIPv6', type=str, nargs='?', help=getMessage("server-interface-ipv6"), default='')