From 407bb7b7da5d07809e99fad7bdf7c8457d9281a2 Mon Sep 17 00:00:00 2001 From: scherepanov Date: Wed, 3 Jan 2024 01:19:17 +0400 Subject: [PATCH] 0.0.2 --- package.json | 5 ++- src/module/vm/commands.ts | 6 ++-- src/module/vm/questions.ts | 64 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c5579b2..e2145e1 100644 --- a/package.json +++ b/package.json @@ -94,11 +94,14 @@ "testEnvironment": "node" }, "bin": { - "devserver": "./dist/src/devserver.js" + "devserver.sh": "./src/devserver.js" }, "pkg": { "scripts": "dist/**/*.js", "targets": [ "node18-macos-arm64" ], "outputPath": "pkg" + }, + "exports": { + "./package.json": "./package.json" } } diff --git a/src/module/vm/commands.ts b/src/module/vm/commands.ts index 5aa63bc..b7e8491 100644 --- a/src/module/vm/commands.ts +++ b/src/module/vm/commands.ts @@ -73,9 +73,9 @@ export class VmCreateCommand extends CommandRunner { password_hash: createHash('sha512').update(answers.password).digest('hex'), // eslint-disable-next-line newline-per-chained-call code_server_password_hash: createHash('sha256').update(answers.password).digest('hex'), - public_port: [], - public_port_username: 'web', - public_port_password_hash: apacheMd5('web'), + public_port: answers.public_port.split(","), + public_port_username: answers.public_port_username, + public_port_password_hash: apacheMd5(answers.public_port_password), }); }); console.log(`Virtual machine created, ID: ${vm.$id}`); diff --git a/src/module/vm/questions.ts b/src/module/vm/questions.ts index 8f583f0..27e7a31 100644 --- a/src/module/vm/questions.ts +++ b/src/module/vm/questions.ts @@ -1,3 +1,4 @@ +import { ID } from 'node-appwrite'; import { uniqueNamesGenerator, adjectives, animals } from 'unique-names-generator'; export const questionsVmCreate = [ @@ -27,7 +28,7 @@ export const questionsVmCreate = [ { type: 'input', name: 'username', - message: 'Username (1 - 32 symbols)', + message: 'System Username (1 - 32 symbols)', default: 'developer', validate(value: string | any[]) { if (value.length < 3) { @@ -43,12 +44,71 @@ export const questionsVmCreate = [ { type: 'password', name: 'password', - message: 'Password (only the hash will be used)', + message: 'System Password (will be hashed)', mask: '*', validate(value: string) { if (!value) { return "Password can't be empty"; } + if (value.length < 8) { + return 'Minimum length: 8'; + } + return true; + }, + }, + { + type: 'input', + name: 'public_port', + message: 'Public Port(s) (3rd party access)', + default: 'none', + validate(value: string) { + if (value) { + const ports = value.split(","); + for (var i = 0; i < ports.length; i++) { + if (parseInt(ports[i]) < 1025) { + return 'Minimum port is: 1025'; + } + if (parseInt(ports[i]) > 65535) { + return 'Maximum port is: 65535'; + } + } + } + + return true; + }, + }, + { + type: 'input', + name: 'public_port_username', + message: 'Public Username (1 - 32 symbols)', + default: 'web', + when: (current: { public_port: any; }) => { + return !!current.public_port && current.public_port != 'none'; + }, + validate(value: string | any[]) { + if (value.length < 3) { + return 'Minimum length: 3'; + } + if (value.length > 32) { + return 'Maximum length: 32'; + } + + return true; + }, + }, + { + type: 'public_port_password', + name: 'public_port_password', + message: 'Public Password (will be hashed)', + mask: '*', + when: (current: { public_port: any; }) => { + return !!current.public_port && current.public_port != 'none'; + }, + validate(value: string) { + if (!value) { + return "Password can't be empty"; + } + return true; }, },