From 30ac59482138c4e43ac14b899512ddd921dfcf37 Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Wed, 28 Feb 2024 11:52:31 +0100 Subject: [PATCH] wip configuration --- imageroot/actions/configure-module/10validate | 18 ++++++++ .../actions/configure-module/20configure | 21 +++++++++ .../configure-module/validate-input.json | 44 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100755 imageroot/actions/configure-module/10validate create mode 100755 imageroot/actions/configure-module/20configure create mode 100644 imageroot/actions/configure-module/validate-input.json diff --git a/imageroot/actions/configure-module/10validate b/imageroot/actions/configure-module/10validate new file mode 100755 index 0000000..88fbb8e --- /dev/null +++ b/imageroot/actions/configure-module/10validate @@ -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 diff --git a/imageroot/actions/configure-module/20configure b/imageroot/actions/configure-module/20configure new file mode 100755 index 0000000..918309f --- /dev/null +++ b/imageroot/actions/configure-module/20configure @@ -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") diff --git a/imageroot/actions/configure-module/validate-input.json b/imageroot/actions/configure-module/validate-input.json new file mode 100644 index 0000000..e319457 --- /dev/null +++ b/imageroot/actions/configure-module/validate-input.json @@ -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" + ] +}