From 42e59d55245628cd23ea92cc438b7db97da7de0f Mon Sep 17 00:00:00 2001 From: Venkat Chimata Date: Sun, 22 Sep 2024 11:59:26 +0530 Subject: [PATCH] Add system-password to the schema With this addition, a desired password can be configured through ucentral config Signed-off-by: Venkat Chimata --- renderer/renderer.uc | 8 ++++++++ renderer/templates/unit.uc | 5 ++++- schema/unit.yml | 4 ++++ schemareader.uc | 11 +++++++++++ ucentral.schema.full.json | 4 ++++ ucentral.schema.json | 3 +++ ucentral.schema.pretty.json | 4 ++++ 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/renderer/renderer.uc b/renderer/renderer.uc index 1b2e254..c3f6f89 100644 --- a/renderer/renderer.uc +++ b/renderer/renderer.uc @@ -996,6 +996,14 @@ let shell = { } system("(echo " + passwd + "; sleep 1; echo " + passwd + ") | passwd root"); conn.call("ucentral", "password", { passwd }); + }, + + /** + * Set system password + */ + system_password: function(passwd) { + system("(echo " + passwd + "; sleep 1; echo " + passwd + ") | passwd root"); + conn.call("ucentral", "password", { passwd }); } }; diff --git a/renderer/templates/unit.uc b/renderer/templates/unit.uc index c93fef9..1a8401f 100644 --- a/renderer/templates/unit.uc +++ b/renderer/templates/unit.uc @@ -14,6 +14,9 @@ set system.@system[-1].timezone={{ s(unit.timezone) }} {% endif %} set system.@system[-1].leds_off={{ b(!unit.leds_active) }} {% -shell.password(unit.random_password); +if (unit.system_password) + shell.system_password(unit.system_password); +else + shell.password(unit.random_password); services.set_enabled("led", true); %} diff --git a/schema/unit.yml b/schema/unit.yml index 4f68949..e29c38c 100644 --- a/schema/unit.yml +++ b/schema/unit.yml @@ -37,6 +37,10 @@ properties: The device shall create a random root password and tell the gateway about it. type: boolean default: false + system-password: + description: + System-config string that holds the password for main (root / admin) user to apply. + type: string beacon-advertisement: description: The TIP vendor IEs that shall be added to beacons diff --git a/schemareader.uc b/schemareader.uc index d645261..90c26b7 100644 --- a/schemareader.uc +++ b/schemareader.uc @@ -164,6 +164,17 @@ function instantiateUnit(location, value, errors) { obj.random_password = false; } + function parseSystemPassword(location, value, errors) { + if (type(value) != "string") + push(errors, [ location, "must be of type string" ]); + + return value; + } + + if (exists(value, "system-password")) { + obj.system_password = parseSystemPassword(location + "/system-password", value["system-password"], errors); + } + function parseBeaconAdvertisement(location, value, errors) { if (type(value) == "object") { let obj = {}; diff --git a/ucentral.schema.full.json b/ucentral.schema.full.json index 3aadbbd..04eed56 100644 --- a/ucentral.schema.full.json +++ b/ucentral.schema.full.json @@ -49,6 +49,10 @@ "type": "boolean", "default": false }, + "system-password": { + "description": "System-config string that holds the password for main (root / admin) user to apply.", + "type": "string" + }, "beacon-advertisement": { "description": "The TIP vendor IEs that shall be added to beacons", "type": "object", diff --git a/ucentral.schema.json b/ucentral.schema.json index 195e9fa..e55c423 100644 --- a/ucentral.schema.json +++ b/ucentral.schema.json @@ -84,6 +84,9 @@ "type": "boolean", "default": false }, + "system-password": { + "type": "string" + }, "beacon-advertisement": { "type": "object", "properties": { diff --git a/ucentral.schema.pretty.json b/ucentral.schema.pretty.json index a65fdbf..338beda 100644 --- a/ucentral.schema.pretty.json +++ b/ucentral.schema.pretty.json @@ -94,6 +94,10 @@ "type": "boolean", "default": false }, + "system-password": { + "description": "System-config string that holds the password for main (root / admin) user to apply.", + "type": "string" + }, "beacon-advertisement": { "description": "The TIP vendor IEs that shall be added to beacons", "type": "object",