@zerothreatai/cli 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -11
- package/dist/src/actions/license-service.js +1 -1
- package/dist/src/commands/install-docker.js +57 -0
- package/dist/src/config/api-config.js +12 -4
- package/dist/src/menu.js +9 -1
- package/dist/src/services/api-service.js +2 -1
- package/dist/src/services/license-api-service.js +2 -1
- package/dist/src/utils/network-error.js +9 -0
- package/package.json +2 -3
- package/.env.prod +0 -2
package/dist/index.js
CHANGED
|
@@ -8,17 +8,12 @@ const commander_1 = require("commander");
|
|
|
8
8
|
const menu_js_1 = __importDefault(require("./src/menu.js"));
|
|
9
9
|
const start_setup_js_1 = require("./src/commands/start-setup.js");
|
|
10
10
|
const dotenv_1 = require("dotenv");
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.version("1.0.0");
|
|
18
|
-
commander_1.program
|
|
19
|
-
.command("menu")
|
|
20
|
-
.description("Show main menu")
|
|
21
|
-
.action(menu_js_1.default);
|
|
11
|
+
if (process.env.WORKING_ENVIRONMENT)
|
|
12
|
+
(0, dotenv_1.config)({
|
|
13
|
+
path: `.env`,
|
|
14
|
+
});
|
|
15
|
+
commander_1.program.name("zt").description("ZEROTHREAT AI CLI").version("1.0.0");
|
|
16
|
+
commander_1.program.command("menu").description("Show main menu").action(menu_js_1.default);
|
|
22
17
|
commander_1.program.command("start-setup").action(start_setup_js_1.startSetup);
|
|
23
18
|
if (!process.argv.slice(2).length) {
|
|
24
19
|
(0, menu_js_1.default)();
|
|
@@ -57,7 +57,6 @@ async function runCompose(args) {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
async function firstIgnition(licenseKey, emailId) {
|
|
60
|
-
console.log(">> Running first docker setup ...");
|
|
61
60
|
let token = '';
|
|
62
61
|
const acrTokenService = new acr_token_service_1.default();
|
|
63
62
|
const machineId = (0, get_mac_1.getMachineId)();
|
|
@@ -68,6 +67,7 @@ async function firstIgnition(licenseKey, emailId) {
|
|
|
68
67
|
if (app_constants_1.dockerComposeAcr) {
|
|
69
68
|
COMPOSE_FILE = app_constants_1.dockerComposeAcr;
|
|
70
69
|
}
|
|
70
|
+
console.log(">> Setting up application ...");
|
|
71
71
|
await ensureNetwork();
|
|
72
72
|
await pullImages();
|
|
73
73
|
await runCompose(["up", "-d"]);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.installDocker = installDocker;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const ask_que_1 = require("../utils/ask-que");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
12
|
+
async function installDocker() {
|
|
13
|
+
try {
|
|
14
|
+
// Check OS
|
|
15
|
+
const platform = process.platform;
|
|
16
|
+
if (platform !== 'linux') {
|
|
17
|
+
console.log('Error: Linux/Ubuntu is required for this installation.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Check if Docker is available
|
|
21
|
+
try {
|
|
22
|
+
await execAsync('docker --version');
|
|
23
|
+
console.log(chalk_1.default.greenBright.bold('✓ System requirements are met. Docker is already installed.'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
console.log(chalk_1.default.red('Docker is not installed.'));
|
|
28
|
+
}
|
|
29
|
+
// Ask user permission to install Docker
|
|
30
|
+
const answer = await (0, ask_que_1.ask)(chalk_1.default.yellowBright.bold('Do you want to install Docker? (yes/no): '));
|
|
31
|
+
if (answer.toLowerCase() !== 'yes' && answer.toLowerCase() !== 'y') {
|
|
32
|
+
console.log('Installation cancelled.');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk_1.default.bold('Installing Docker...'));
|
|
36
|
+
const commands = [
|
|
37
|
+
'sudo apt update',
|
|
38
|
+
'sudo apt install apt-transport-https ca-certificates curl software-properties-common -y',
|
|
39
|
+
'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg',
|
|
40
|
+
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null',
|
|
41
|
+
'sudo apt update',
|
|
42
|
+
'sudo apt install docker-ce -y',
|
|
43
|
+
'sudo usermod -aG docker ${USER}',
|
|
44
|
+
];
|
|
45
|
+
for (const cmd of commands) {
|
|
46
|
+
console.log(`Running: ${cmd}`);
|
|
47
|
+
await execAsync(cmd);
|
|
48
|
+
}
|
|
49
|
+
// Check if Docker is available
|
|
50
|
+
await execAsync('docker --version');
|
|
51
|
+
console.log(chalk_1.default.greenBright.bold('✓ System requirements are met. ✓ Docker installed successfully.'));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(chalk_1.default.redBright.bold('Error during system check:', error));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
;
|
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.API_CONFIG = void 0;
|
|
4
4
|
const API_CONFIG = () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
if (!process.env.WORKING_ENVIRONMENT) {
|
|
6
|
+
return {
|
|
7
|
+
licenseApi: `http://localhost:3201/api/license`,
|
|
8
|
+
onPremLicenseCloudeApi: `https://api.zerothreat.ai/api/on-prem/license`,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return {
|
|
13
|
+
licenseApi: process.env.LICENSE_API,
|
|
14
|
+
onPremLicenseCloudeApi: process.env.CLOUD_API,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
9
17
|
};
|
|
10
18
|
exports.API_CONFIG = API_CONFIG;
|
package/dist/src/menu.js
CHANGED
|
@@ -8,6 +8,7 @@ const inquirer_1 = __importDefault(require("inquirer"));
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const start_setup_1 = require("./commands/start-setup");
|
|
10
10
|
const deactivate_1 = __importDefault(require("./commands/deactivate"));
|
|
11
|
+
const install_docker_1 = require("./commands/install-docker");
|
|
11
12
|
async function showMenu() {
|
|
12
13
|
console.clear();
|
|
13
14
|
// Header with description
|
|
@@ -22,7 +23,7 @@ async function showMenu() {
|
|
|
22
23
|
console.log(chalk_1.default.gray('║') + chalk_1.default.gray(' modern web apps & APIs through continuous pentesting, actionable ') + chalk_1.default.gray('║'));
|
|
23
24
|
console.log(chalk_1.default.gray('║') + chalk_1.default.gray(' insights, and coverage for 40,000+ vulnerabilities. ') + chalk_1.default.gray('║'));
|
|
24
25
|
console.log(chalk_1.default.gray('║') + ' '.repeat(78) + chalk_1.default.gray('║'));
|
|
25
|
-
console.log(chalk_1.default.gray('║') + chalk_1.default.bold.green(' 🛡️ On-Premise Installation Tool
|
|
26
|
+
console.log(chalk_1.default.gray('║') + chalk_1.default.bold.green(' 🛡️ On-Premise Installation Tool ') + chalk_1.default.gray('║'));
|
|
26
27
|
console.log(chalk_1.default.gray('║') + ' '.repeat(78) + chalk_1.default.gray('║'));
|
|
27
28
|
console.log(chalk_1.default.gray('╚' + '═'.repeat(78) + '╝'));
|
|
28
29
|
console.log();
|
|
@@ -35,6 +36,10 @@ async function showMenu() {
|
|
|
35
36
|
name: "action",
|
|
36
37
|
message: chalk_1.default.bold.cyan("Select an action:"),
|
|
37
38
|
choices: [
|
|
39
|
+
{
|
|
40
|
+
name: chalk_1.default.green("⚙️ Install Prerequisite Software for Linux Environment"),
|
|
41
|
+
value: "System Check"
|
|
42
|
+
},
|
|
38
43
|
{
|
|
39
44
|
name: chalk_1.default.green("🔑 Activate License & Setup"),
|
|
40
45
|
value: "Start Setup"
|
|
@@ -65,6 +70,9 @@ async function showMenu() {
|
|
|
65
70
|
case "Deactivate License":
|
|
66
71
|
await (0, deactivate_1.default)();
|
|
67
72
|
break;
|
|
73
|
+
case "System Check":
|
|
74
|
+
await (0, install_docker_1.installDocker)();
|
|
75
|
+
break;
|
|
68
76
|
default:
|
|
69
77
|
console.log("Exiting...");
|
|
70
78
|
console.clear();
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
|
+
const network_error_1 = __importDefault(require("../utils/network-error"));
|
|
8
9
|
class ApiService {
|
|
9
10
|
client;
|
|
10
11
|
constructor(config) {
|
|
@@ -42,7 +43,7 @@ class ApiService {
|
|
|
42
43
|
return new Error(`${error.response.data?.message || 'Unknown error'}`);
|
|
43
44
|
}
|
|
44
45
|
if (error.request) {
|
|
45
|
-
return new
|
|
46
|
+
return new network_error_1.default('Network Error: No response received');
|
|
46
47
|
}
|
|
47
48
|
return new Error(`Request Error: ${error.message}`);
|
|
48
49
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.LicenseType = exports.LicenseStatus = void 0;
|
|
7
7
|
const api_service_1 = __importDefault(require("./api-service"));
|
|
8
8
|
const api_config_1 = require("../config/api-config");
|
|
9
|
+
const network_error_1 = __importDefault(require("../utils/network-error"));
|
|
9
10
|
var LicenseStatus;
|
|
10
11
|
(function (LicenseStatus) {
|
|
11
12
|
LicenseStatus[LicenseStatus["Active"] = 1] = "Active";
|
|
@@ -53,7 +54,7 @@ class LicenseApiService extends api_service_1.default {
|
|
|
53
54
|
return res;
|
|
54
55
|
}
|
|
55
56
|
catch (error) {
|
|
56
|
-
if (error.code === 'ECONNREFUSED') {
|
|
57
|
+
if (error.code === 'ECONNREFUSED' || error instanceof network_error_1.default) {
|
|
57
58
|
const fallbackService = new api_service_1.default({
|
|
58
59
|
baseURL: (0, api_config_1.API_CONFIG)().onPremLicenseCloudeApi,
|
|
59
60
|
timeout: 15000,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerothreatai/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node build.js",
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
"node-machine-id": "^1.1.12"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
".env.prod"
|
|
29
|
+
"dist"
|
|
31
30
|
],
|
|
32
31
|
"bin": {
|
|
33
32
|
"zt": "./dist/index.js"
|
package/.env.prod
DELETED