From b991396917965066c382cbbaffa107b5e042fdc7 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 25 Oct 2023 01:16:41 +0800 Subject: [PATCH] Updates, test fixes --- add-sftp.jps | 30 ++++++++++++++++++++---------- scripts/add-sftp-user.cs | 9 +++++---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/add-sftp.jps b/add-sftp.jps index d5f1715..202e011 100644 --- a/add-sftp.jps +++ b/add-sftp.jps @@ -14,21 +14,31 @@ globals: actions: add_sftp_user: - script: /scripts/add-sftp-user.cs?_r=${fn.random} + script: /scripts/add-sftp-user.cs?_r=${fn.random}&enable_ssh=${settings.enable_ssh} success: email: | - SFTP Host: ${globals.sftpHost} - Port: ${globals.sftpPort} - Username: ${globals.username} + Connection Details
+  
+ SFTP Host: ${globals.sftpHost}
+ Port: ${globals.sftpPort}
+  
+ Login Credentials
+  
+ Username: ${globals.username}
Password: ${globals.password} text: en: | - SFTP Host: ${globals.sftpHost} - Port: ${globals.sftpPort} - Username: ${globals.username} + Connection Details\n + \n + SFTP Host: ${globals.sftpHost}\n + Port: ${globals.sftpPort}\n + \n + Login Credentials\n + \n + Username: ${globals.username}\n Password: ${globals.password} - + settings: sftpForm: fields: @@ -36,14 +46,14 @@ settings: inputType: text name: username caption: Username - placeholder: ${globals.username} + placeholder: "user${fn.random(10000,99999)}" disabled: true required: false - type: string inputType: password name: password caption: Password - placeholder: ${fn.password(min)} + placeholder: "${fn.password(min)}" disabled: true required: false - type: string diff --git a/scripts/add-sftp-user.cs b/scripts/add-sftp-user.cs index 18e7872..357f663 100644 --- a/scripts/add-sftp-user.cs +++ b/scripts/add-sftp-user.cs @@ -5,7 +5,8 @@ var ROOT_DIRECTORY = "/var/www/webroot/ROOT"; var ENABLE_SSH = "${request.enable_ssh}" == "true"; // Check if user already exists -if (jelastic.env.control.ExecCmdById('${env.envName}', '${nodes.cp.master.id}', 'id ' + USERNAME).result == 0) { +var userCheckResponse = jelastic.env.control.ExecCmdById('${env.envName}', '${nodes.cp.master.id}', 'id ' + USERNAME); +if (userCheckResponse.result == 0) { return { result: 99, error: "User " + USERNAME + " already exists." @@ -39,7 +40,7 @@ if (!ENABLE_SSH) { // Restart SSHD to apply changes cmd.push("systemctl restart sshd"); -return jelastic.env.control.ExecCmdById('${env.envName}', '${nodes.cp.master.id}', cmd.join(" && ")); +var response = jelastic.env.control.ExecCmdById('${env.envName}', '${nodes.cp.master.id}', cmd.join(" && ")); // If the command execution was successful, return the SFTP details if (response && response.result == 0) { @@ -48,7 +49,7 @@ if (response && response.result == 0) { message: "SFTP User Created Successfully!\n\n" + "Username: " + USERNAME + "\n" + "Password: " + PASSWORD + "\n" + - "SFTP Host: " + "${env.domain}" + "\n" + // Assuming env.domain provides the domain of the environment + "SFTP Host: " + "${env.domain}" + "\n" + "Port: 22" // Standard SFTP port }; } else { @@ -56,4 +57,4 @@ if (response && response.result == 0) { result: response.result, error: response.error || "An error occurred while creating the SFTP user." }; -} \ No newline at end of file +}