generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from NethServer/feat-7210
Inhibit DNS service if Samba is installed Refs NethServer/dev#7210
- Loading branch information
Showing
10 changed files
with
138 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import sys | ||
import agent | ||
import network | ||
|
||
# Read configuration from a JSON file or initialize it. | ||
try: | ||
config = json.load(open("config.json")) | ||
except FileNotFoundError: | ||
print(agent.SD_NOTICE, "Generating a new config.json file...", file=sys.stderr) | ||
config = { | ||
"interface": "", | ||
"dhcp-server": { | ||
"enabled": False, | ||
"start": "", | ||
"end": "", | ||
"lease": 12 | ||
}, | ||
"dns-server": { | ||
"enabled": False, | ||
"primary-server": "", | ||
"secondary-server": "" | ||
}, | ||
} | ||
json.dump(config, fp=open("config.json", "w")) | ||
|
||
|
||
# Lookup local Samba DCs. They want to bind DNS port 53 like us. | ||
local_samba_dcs = network.get_local_samba_dcs() | ||
|
||
# convert json to configuration file | ||
with open("dnsmasq.d/00config.conf", "w") as file: | ||
file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n") | ||
# write interface only if dhcp-server or dns-server are enabled | ||
if config["dhcp-server"]["enabled"] or config["dns-server"]["enabled"]: | ||
file.write("interface=" + config["interface"] + "\n") | ||
|
||
# write dhcp-server configuration | ||
if config["dhcp-server"]["enabled"]: | ||
file.write("dhcp-range=set:default," + config["dhcp-server"]["start"] + "," + config["dhcp-server"]["end"] + "," + str(config["dhcp-server"]["lease"]) + "h\n") | ||
|
||
# write dns-server configuration, if no local Samba DC is present | ||
if len(local_samba_dcs) > 0: | ||
print("Local Active Directory DC found, DNS feature is blocked.", local_samba_dcs, file=sys.stderr) | ||
file.write("port=0\n") | ||
elif config["dns-server"]["enabled"]: | ||
file.write("server=" + config["dns-server"]["primary-server"] + "\n") | ||
if config["dns-server"]["secondary-server"] != "": | ||
file.write("server=" + config["dns-server"]["secondary-server"] + "\n") | ||
else: | ||
# shut down dns server if not enabled | ||
file.write("port=0\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import os | ||
import sys | ||
import agent | ||
|
||
data = json.load(sys.stdin) | ||
|
||
# skip if the event comes from another node | ||
if os.environ['NODE_ID'] != str(data['node']): | ||
sys.exit(0) | ||
|
||
agent.run_helper('systemctl', 'try-restart', os.getenv('MODULE_ID')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import os | ||
import sys | ||
import agent | ||
|
||
data = json.load(sys.stdin) | ||
|
||
# skip if the event comes from another node | ||
if os.environ['NODE_ID'] != str(data['node']): | ||
sys.exit(0) | ||
|
||
agent.run_helper('systemctl', 'try-restart', os.getenv('MODULE_ID')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters