add config option to allow binding to a specific address

original idea by @OH2LAK (see #367)
This commit is contained in:
Jakob Ketterl 2024-01-18 00:59:43 +01:00
parent 4ef27b5064
commit 6aabff034a
3 changed files with 17 additions and 4 deletions

View file

@ -6,6 +6,10 @@ log_level = INFO
[web]
port = 8073
ipv6 = true
# Uncomment bind_address to bind OpenWebRX to a specific IP-address.
# By default, OpenWebRX will bind to all interfaces.
# Use ::1 for localhost only, or any other configured address to bind to that address only.
#bind_address = ::1
[aprs]
# path to the aprs symbols repository (get it here: https://github.com/hessu/aprs-symbols)

View file

@ -27,11 +27,11 @@ import socket
class ThreadedHttpServer(ThreadingMixIn, HTTPServer):
def __init__(self, web_port, RequestHandlerClass, use_ipv6):
bind_address = "0.0.0.0"
def __init__(self, web_port, RequestHandlerClass, use_ipv6, bind_address=None):
if bind_address is None:
bind_address = "::" if use_ipv6 else "0.0.0.0"
if use_ipv6:
self.address_family = socket.AF_INET6
bind_address = "::"
super().__init__((bind_address, web_port), RequestHandlerClass)
@ -135,7 +135,9 @@ Support and info: https://groups.io/g/openwebrx
Services.start()
try:
server = ThreadedHttpServer(coreConfig.get_web_port(), RequestHandler, coreConfig.get_web_ipv6())
server = ThreadedHttpServer(
coreConfig.get_web_port(), RequestHandler, coreConfig.get_web_ipv6(), coreConfig.get_web_bind_address()
)
logger.info("Ready to serve requests.")
server.serve_forever()
except SignalException:

View file

@ -1,6 +1,7 @@
from owrx.config import ConfigError
from configparser import ConfigParser
from pathlib import Path
from typing import Optional
import os
@ -16,6 +17,8 @@ class CoreConfig(object):
"web": {
"port": 8073,
"ipv6": True,
# won't work this way because values must be strings, but this is effectively the way it behaves.
#"bind_address": None,
},
"aprs": {
"symbols_path": "/usr/share/aprs-symbols/png"
@ -64,6 +67,7 @@ class CoreConfig(object):
self.log_level = config.get("core", "log_level")
self.web_port = config.getint("web", "port")
self.web_ipv6 = config.getboolean("web", "ipv6")
self.web_bind_address = config.get("web", "bind_address", fallback=None)
self.aprs_symbols_path = config.get("aprs", "symbols_path")
@staticmethod
@ -81,6 +85,9 @@ class CoreConfig(object):
def get_web_ipv6(self) -> bool:
return self.web_ipv6
def get_web_bind_address(self) -> Optional[str]:
return self.web_bind_address
def get_data_directory(self) -> str:
return self.data_directory