Skip to content

Commit

Permalink
wip configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Feb 28, 2024
1 parent a679758 commit 30ac594
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
18 changes: 18 additions & 0 deletions imageroot/actions/configure-module/10validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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

agent.set_weight(os.path.basename(__file__), 0)

request = json.load(sys.stdin)

# TODO: validate interface and dhcp-server start and end
21 changes: 21 additions & 0 deletions imageroot/actions/configure-module/20configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import sys

request = json.load(sys.stdin)

# write dnsmasq configuration to easy json file, will be used by UI
open("config.json", "w").write(json.dumps(request))

# 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")
file.write("interface=" + request["interface"] + "\n")
if (request["dhcp-server"]["enabled"]):
file.write("dhcp-range=" + request["dhcp-server"]["start"] + "," + request["dhcp-server"]["end"] + "," + str(request["dhcp-server"]["lease"]) + "h\n")
44 changes: 44 additions & 0 deletions imageroot/actions/configure-module/validate-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "http://schema.nethserver.org/dnsmasq/configure-module.json",
"title": "Configure dnsmasq",
"description": "Configure dnsmasq module",
"type": "object",
"properties": {
"interface": {
"type": "string",
"description": "Network interface, a list is provided by the 'get-available-interfaces' action"
},
"dhcp-server": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable DHCP server"
},
"start": {
"type": "string",
"format": "ipv4"
},
"end": {
"type": "string",
"format": "ipv4"
},
"lease": {
"type": "integer",
"minimum": 1
}
},
"required": [
"enabled",
"start",
"end",
"lease"
]
}
},
"required": [
"interface",
"dhcp-server"
]
}

0 comments on commit 30ac594

Please sign in to comment.