mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
yunomdns: broadcast on all interfaces with local IP by default + add a 'ban_interfaces' setting in config
This commit is contained in:
parent
f49666d22e
commit
a5e1d7e318
2 changed files with 17 additions and 13 deletions
23
bin/yunomdns
23
bin/yunomdns
|
@ -57,16 +57,23 @@ def main() -> bool:
|
||||||
with open("/etc/yunohost/mdns.yml", "r") as f:
|
with open("/etc/yunohost/mdns.yml", "r") as f:
|
||||||
config = yaml.safe_load(f) or {}
|
config = yaml.safe_load(f) or {}
|
||||||
|
|
||||||
required_fields = ["interfaces", "domains"]
|
required_fields = ["domains"]
|
||||||
missing_fields = [field for field in required_fields if field not in config]
|
missing_fields = [field for field in required_fields if field not in config]
|
||||||
|
interfaces = get_network_local_interfaces()
|
||||||
|
|
||||||
if missing_fields:
|
if missing_fields:
|
||||||
print(f"The fields {missing_fields} are required in mdns.yml")
|
print(f"The fields {missing_fields} are required in mdns.yml")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if config["interfaces"] is None:
|
if "interfaces" not in config:
|
||||||
print("No interface listed for broadcast.")
|
config["interfaces"] = [interface
|
||||||
return True
|
for interface, local_ips in interfaces.items()
|
||||||
|
if local_ips["ipv4"]]
|
||||||
|
|
||||||
|
if "ban_interfaces" in config:
|
||||||
|
config["interfaces"] = [interface
|
||||||
|
for interface in config["interfaces"]
|
||||||
|
if interface not in config["ban_interfaces"]]
|
||||||
|
|
||||||
# Let's discover currently published .local domains accross the network
|
# Let's discover currently published .local domains accross the network
|
||||||
zc = Zeroconf()
|
zc = Zeroconf()
|
||||||
|
@ -100,10 +107,10 @@ def main() -> bool:
|
||||||
|
|
||||||
zcs: Dict[Zeroconf, List[ServiceInfo]] = {}
|
zcs: Dict[Zeroconf, List[ServiceInfo]] = {}
|
||||||
|
|
||||||
interfaces = get_network_local_interfaces()
|
|
||||||
for interface in config["interfaces"]:
|
for interface in config["interfaces"]:
|
||||||
|
|
||||||
if interface not in interfaces:
|
if interface not in interfaces:
|
||||||
print(f"Interface {interface} of config file is not present on system.")
|
print(f"Interface {interface} listed in config file is not present on system.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ips: List[str] = interfaces[interface]["ipv4"] + interfaces[interface]["ipv6"]
|
ips: List[str] = interfaces[interface]["ipv4"] + interfaces[interface]["ipv6"]
|
||||||
|
@ -111,6 +118,10 @@ def main() -> bool:
|
||||||
# If at least one IP is listed
|
# If at least one IP is listed
|
||||||
if not ips:
|
if not ips:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
print(f"Publishing on {interface} ...")
|
||||||
|
print(ips)
|
||||||
|
|
||||||
# Create a Zeroconf object, and store the ServiceInfos
|
# Create a Zeroconf object, and store the ServiceInfos
|
||||||
zc = Zeroconf(interfaces=ips) # type: ignore
|
zc = Zeroconf(interfaces=ips) # type: ignore
|
||||||
zcs[zc] = []
|
zcs[zc] = []
|
||||||
|
|
|
@ -12,13 +12,6 @@ _generate_config() {
|
||||||
[[ "$domain" =~ ^[^.]+\.local$ ]] || continue
|
[[ "$domain" =~ ^[^.]+\.local$ ]] || continue
|
||||||
echo " - $domain"
|
echo " - $domain"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "interfaces:"
|
|
||||||
local_network_interfaces="$(ip --brief a | grep ' 10\.\| 192\.168\.' | awk '{print $1}')"
|
|
||||||
for interface in $local_network_interfaces
|
|
||||||
do
|
|
||||||
echo " - $interface"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_init_regen() {
|
do_init_regen() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue