telegram-ssh-bot 2.2.0 → 2.4.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/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +27 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/core/ConnectionPool.d.ts.map +1 -1
- package/dist/core/ConnectionPool.js +28 -22
- package/dist/core/ConnectionPool.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/services/BackupService.d.ts +1 -1
- package/dist/services/BackupService.d.ts.map +1 -1
- package/dist/services/BackupService.js +3 -9
- package/dist/services/BackupService.js.map +1 -1
- package/dist/services/ValidationService.d.ts.map +1 -1
- package/dist/services/ValidationService.js +2 -2
- package/dist/services/ValidationService.js.map +1 -1
- package/dist/utils/pathUtils.d.ts +5 -0
- package/dist/utils/pathUtils.d.ts.map +1 -1
- package/dist/utils/pathUtils.js +35 -0
- package/dist/utils/pathUtils.js.map +1 -1
- package/dist/wizard/InstallationWizard.d.ts +32 -0
- package/dist/wizard/InstallationWizard.d.ts.map +1 -0
- package/dist/wizard/InstallationWizard.js +96 -0
- package/dist/wizard/InstallationWizard.js.map +1 -0
- package/dist/wizard/index.d.ts +10 -0
- package/dist/wizard/index.d.ts.map +1 -0
- package/dist/wizard/index.js +8 -0
- package/dist/wizard/index.js.map +1 -0
- package/dist/wizard/prompts.d.ts +45 -0
- package/dist/wizard/prompts.d.ts.map +1 -0
- package/dist/wizard/prompts.js +194 -0
- package/dist/wizard/prompts.js.map +1 -0
- package/dist/wizard/validators.d.ts +50 -0
- package/dist/wizard/validators.d.ts.map +1 -0
- package/dist/wizard/validators.js +107 -0
- package/dist/wizard/validators.js.map +1 -0
- package/package.json +3 -1
- package/scripts/setup-env.d.ts +28 -0
- package/scripts/setup-env.js +61 -5
package/dist/utils/pathUtils.js
CHANGED
|
@@ -54,6 +54,41 @@ export function validatePath(inputPath, basePath) {
|
|
|
54
54
|
}
|
|
55
55
|
return { valid: true, data: normalized };
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Validate a private key path (less restrictive than validatePath)
|
|
59
|
+
* Private keys are typically in ~/.ssh/ directory
|
|
60
|
+
*/
|
|
61
|
+
export function validatePrivateKeyPath(inputPath) {
|
|
62
|
+
if (!inputPath || inputPath.trim().length === 0) {
|
|
63
|
+
return { valid: false, error: "Private key path cannot be empty" };
|
|
64
|
+
}
|
|
65
|
+
const trimmed = inputPath.trim();
|
|
66
|
+
// Check for null bytes
|
|
67
|
+
if (trimmed.includes("\0")) {
|
|
68
|
+
return { valid: false, error: "Invalid null byte in path" };
|
|
69
|
+
}
|
|
70
|
+
// Check for path traversal attempts (but allow .. in home directory context)
|
|
71
|
+
// Only block absolute path traversal
|
|
72
|
+
const resolved = path.resolve(trimmed);
|
|
73
|
+
// Check forbidden paths - never allow access to system critical files
|
|
74
|
+
for (const forbidden of FORBIDDEN_PATHS) {
|
|
75
|
+
if (resolved.startsWith(forbidden)) {
|
|
76
|
+
return { valid: false, error: "Access to path is forbidden" };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Validate that the path looks like a private key file
|
|
80
|
+
// Common private key extensions and names
|
|
81
|
+
const validExtensions = [".pem", ".key", ""];
|
|
82
|
+
const validNames = ["id_rsa", "id_dsa", "id_ecdsa", "id_ed25519"];
|
|
83
|
+
const basename = path.basename(resolved);
|
|
84
|
+
const hasValidExtension = validExtensions.some((ext) => basename.endsWith(ext)) ||
|
|
85
|
+
validNames.some((name) => basename.startsWith(name));
|
|
86
|
+
if (!hasValidExtension && !basename.includes("_")) {
|
|
87
|
+
// Allow files with underscores (common for custom key names)
|
|
88
|
+
// Just warn about extension but don't block
|
|
89
|
+
}
|
|
90
|
+
return { valid: true, data: resolved };
|
|
91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,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation Wizard - Main wizard class
|
|
3
|
+
* Orchestrates the interactive configuration setup process
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Installation wizard class
|
|
7
|
+
* Handles the interactive setup process for first-time configuration
|
|
8
|
+
*/
|
|
9
|
+
export declare class InstallationWizard {
|
|
10
|
+
private readonly envPath;
|
|
11
|
+
constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Check if the wizard should run
|
|
14
|
+
* Returns true if .env file is missing or required variables are missing
|
|
15
|
+
*/
|
|
16
|
+
static shouldRun(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Run the installation wizard
|
|
19
|
+
* Guides user through configuration and creates .env file
|
|
20
|
+
*/
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Save the configuration to .env file
|
|
24
|
+
*/
|
|
25
|
+
private saveConfiguration;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if the installation wizard should run
|
|
29
|
+
* Convenience function for external use
|
|
30
|
+
*/
|
|
31
|
+
export declare function shouldRunWizard(): boolean;
|
|
32
|
+
//# sourceMappingURL=InstallationWizard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstallationWizard.d.ts","sourceRoot":"","sources":["../../src/wizard/InstallationWizard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;IAMjC;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,OAAO;IAmB3B;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C1B;;OAEG;YACW,iBAAiB;CAahC;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation Wizard - Main wizard class
|
|
3
|
+
* Orchestrates the interactive configuration setup process
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { generateEncryptionKey, getEnvFilePath, writeEnvFile, } from "../../scripts/setup-env.js";
|
|
7
|
+
import { displaySummary, promptConfirmation, runPrompts } from "./prompts.js";
|
|
8
|
+
/**
|
|
9
|
+
* Installation wizard class
|
|
10
|
+
* Handles the interactive setup process for first-time configuration
|
|
11
|
+
*/
|
|
12
|
+
export class InstallationWizard {
|
|
13
|
+
envPath;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.envPath = getEnvFilePath();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if the wizard should run
|
|
19
|
+
* Returns true if .env file is missing or required variables are missing
|
|
20
|
+
*/
|
|
21
|
+
static shouldRun() {
|
|
22
|
+
const envPath = getEnvFilePath();
|
|
23
|
+
// If .env file doesn't exist, wizard should run
|
|
24
|
+
if (!existsSync(envPath)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// Check for required environment variables
|
|
28
|
+
const requiredVars = ["BOT_TOKEN", "BOT_CHAT_ID", "ENCRYPTION_KEY"];
|
|
29
|
+
for (const varName of requiredVars) {
|
|
30
|
+
if (!process.env[varName]) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Run the installation wizard
|
|
38
|
+
* Guides user through configuration and creates .env file
|
|
39
|
+
*/
|
|
40
|
+
async run() {
|
|
41
|
+
try {
|
|
42
|
+
// Collect configuration from user
|
|
43
|
+
const config = await runPrompts(generateEncryptionKey);
|
|
44
|
+
// Display summary
|
|
45
|
+
displaySummary(config, this.envPath);
|
|
46
|
+
// Confirm and save
|
|
47
|
+
const confirmed = await promptConfirmation();
|
|
48
|
+
if (!confirmed) {
|
|
49
|
+
console.log("");
|
|
50
|
+
console.log("Configuration not saved. Running wizard again...");
|
|
51
|
+
console.log("");
|
|
52
|
+
// Run wizard again
|
|
53
|
+
await this.run();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Write the .env file
|
|
57
|
+
await this.saveConfiguration(config);
|
|
58
|
+
console.log("");
|
|
59
|
+
console.log("✓ Configuration saved successfully!");
|
|
60
|
+
console.log(` File: ${this.envPath}`);
|
|
61
|
+
console.log("");
|
|
62
|
+
console.log("Starting application...");
|
|
63
|
+
console.log("");
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof Error) {
|
|
67
|
+
if (error.message === "User cancelled the wizard") {
|
|
68
|
+
console.log("");
|
|
69
|
+
console.log("Wizard cancelled. Exiting...");
|
|
70
|
+
process.exit(0);
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Wizard failed with unknown error");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Save the configuration to .env file
|
|
79
|
+
*/
|
|
80
|
+
async saveConfiguration(config) {
|
|
81
|
+
writeEnvFile({
|
|
82
|
+
botToken: config.botToken,
|
|
83
|
+
botChatId: config.botChatId,
|
|
84
|
+
botOwnerIds: config.botOwnerIds,
|
|
85
|
+
encryptionKey: config.encryptionKey,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if the installation wizard should run
|
|
91
|
+
* Convenience function for external use
|
|
92
|
+
*/
|
|
93
|
+
export function shouldRunWizard() {
|
|
94
|
+
return InstallationWizard.shouldRun();
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=InstallationWizard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstallationWizard.js","sourceRoot":"","sources":["../../src/wizard/InstallationWizard.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,YAAY,GACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE9E;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACZ,OAAO,CAAS;IAEjC;QACE,IAAI,CAAC,OAAO,GAAG,cAAc,EAAE,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,SAAS;QACd,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;QAEjC,gDAAgD;QAChD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,2CAA2C;QAC3C,MAAM,YAAY,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC;QACpE,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG;QACP,IAAI,CAAC;YACH,kCAAkC;YAClC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,qBAAqB,CAAC,CAAC;YAEvD,kBAAkB;YAClB,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAErC,mBAAmB;YACnB,MAAM,SAAS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,CAAC,SAAS;YAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,kBAAkB,CAAC,SAAS,EAAE,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation Wizard Module
|
|
3
|
+
* Provides interactive configuration setup for first-time users
|
|
4
|
+
*/
|
|
5
|
+
export { InstallationWizard, shouldRunWizard } from "./InstallationWizard.js";
|
|
6
|
+
export { displaySummary, promptConfirmation, runPrompts } from "./prompts.js";
|
|
7
|
+
export type { WizardConfig } from "./prompts.js";
|
|
8
|
+
export { parseOwnerIds, validateBotToken, validateChatId, validateEncryptionKey, validateOwnerIds, } from "./validators.js";
|
|
9
|
+
export type { ValidationResult } from "./validators.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wizard/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Installation Wizard Module
|
|
3
|
+
* Provides interactive configuration setup for first-time users
|
|
4
|
+
*/
|
|
5
|
+
export { InstallationWizard, shouldRunWizard } from "./InstallationWizard.js";
|
|
6
|
+
export { displaySummary, promptConfirmation, runPrompts } from "./prompts.js";
|
|
7
|
+
export { parseOwnerIds, validateBotToken, validateChatId, validateEncryptionKey, validateOwnerIds, } from "./validators.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wizard/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive prompt definitions for the installation wizard
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wizard configuration values collected from user
|
|
6
|
+
*/
|
|
7
|
+
export interface WizardConfig {
|
|
8
|
+
botToken: string;
|
|
9
|
+
botChatId: string;
|
|
10
|
+
botOwnerIds: string[];
|
|
11
|
+
encryptionKey: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Display the welcome banner
|
|
15
|
+
*/
|
|
16
|
+
export declare function displayWelcomeBanner(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Display a summary of the collected configuration
|
|
19
|
+
*/
|
|
20
|
+
export declare function displaySummary(config: WizardConfig, envPath: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Prompt for bot token with validation
|
|
23
|
+
*/
|
|
24
|
+
export declare function promptBotToken(): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Prompt for chat ID with validation
|
|
27
|
+
*/
|
|
28
|
+
export declare function promptChatId(): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Prompt for owner IDs (optional)
|
|
31
|
+
*/
|
|
32
|
+
export declare function promptOwnerIds(): Promise<string[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Prompt for encryption key choice and value
|
|
35
|
+
*/
|
|
36
|
+
export declare function promptEncryptionKey(generateKey: () => string): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Prompt for confirmation to save configuration
|
|
39
|
+
*/
|
|
40
|
+
export declare function promptConfirmation(): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Run all prompts to collect wizard configuration
|
|
43
|
+
*/
|
|
44
|
+
export declare function runPrompts(generateKey: () => string): Promise<WizardConfig>;
|
|
45
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/wizard/prompts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;AAOD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAS3C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAc1E;AAsBD;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAiBtD;AAED;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAiBpD;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAyBxD;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAgDjB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAa3D;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAcjF"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive prompt definitions for the installation wizard
|
|
3
|
+
*/
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import { validateBotToken, validateChatId, validateOwnerIds, validateEncryptionKey, } from "./validators.js";
|
|
6
|
+
/**
|
|
7
|
+
* Display the welcome banner
|
|
8
|
+
*/
|
|
9
|
+
export function displayWelcomeBanner() {
|
|
10
|
+
console.log("");
|
|
11
|
+
console.log("╔═══════════════════════════════════════════════════════════════╗");
|
|
12
|
+
console.log("║ Telegram SSH Bot - Installation Wizard ║");
|
|
13
|
+
console.log("╚═══════════════════════════════════════════════════════════════╝");
|
|
14
|
+
console.log("");
|
|
15
|
+
console.log("Welcome! This wizard will help you set up your bot configuration.");
|
|
16
|
+
console.log("Press Ctrl+C at any time to exit.");
|
|
17
|
+
console.log("");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Display a summary of the collected configuration
|
|
21
|
+
*/
|
|
22
|
+
export function displaySummary(config, envPath) {
|
|
23
|
+
console.log("");
|
|
24
|
+
console.log("─────────────────────────────────────────────");
|
|
25
|
+
console.log("Configuration Summary:");
|
|
26
|
+
console.log("─────────────────────────────────────────────");
|
|
27
|
+
console.log(` BOT_TOKEN: ${maskToken(config.botToken)}`);
|
|
28
|
+
console.log(` BOT_CHAT_ID: ${config.botChatId}`);
|
|
29
|
+
console.log(` BOT_OWNER_IDS: ${config.botOwnerIds.length > 0 ? config.botOwnerIds.join(", ") : "(none)"}`);
|
|
30
|
+
console.log(` ENCRYPTION_KEY: ${maskEncryptionKey(config.encryptionKey)}`);
|
|
31
|
+
console.log("─────────────────────────────────────────────");
|
|
32
|
+
console.log(`Config location: ${envPath}`);
|
|
33
|
+
console.log("");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Mask a bot token for display (show first 10 chars and last 4)
|
|
37
|
+
*/
|
|
38
|
+
function maskToken(token) {
|
|
39
|
+
if (token.length <= 14) {
|
|
40
|
+
return token.substring(0, 4) + "...";
|
|
41
|
+
}
|
|
42
|
+
return token.substring(0, 10) + "..." + token.substring(token.length - 4);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mask an encryption key for display
|
|
46
|
+
*/
|
|
47
|
+
function maskEncryptionKey(key) {
|
|
48
|
+
if (key.length <= 16) {
|
|
49
|
+
return "[hidden]";
|
|
50
|
+
}
|
|
51
|
+
return key.substring(0, 8) + "..." + key.substring(key.length - 8);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Prompt for bot token with validation
|
|
55
|
+
*/
|
|
56
|
+
export async function promptBotToken() {
|
|
57
|
+
const response = await prompts({
|
|
58
|
+
type: "password",
|
|
59
|
+
name: "token",
|
|
60
|
+
message: "Enter your Telegram Bot Token",
|
|
61
|
+
hint: "Get this from @BotFather on Telegram",
|
|
62
|
+
validate: (value) => {
|
|
63
|
+
const result = validateBotToken(value);
|
|
64
|
+
return result.valid ? true : result.error || "Invalid token";
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
if (response.token === undefined) {
|
|
68
|
+
throw new Error("User cancelled the wizard");
|
|
69
|
+
}
|
|
70
|
+
return response.token.trim();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Prompt for chat ID with validation
|
|
74
|
+
*/
|
|
75
|
+
export async function promptChatId() {
|
|
76
|
+
const response = await prompts({
|
|
77
|
+
type: "text",
|
|
78
|
+
name: "chatId",
|
|
79
|
+
message: "Enter your Chat ID",
|
|
80
|
+
hint: "Use @userinfobot to find your Chat ID",
|
|
81
|
+
validate: (value) => {
|
|
82
|
+
const result = validateChatId(value);
|
|
83
|
+
return result.valid ? true : result.error || "Invalid chat ID";
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (response.chatId === undefined) {
|
|
87
|
+
throw new Error("User cancelled the wizard");
|
|
88
|
+
}
|
|
89
|
+
return response.chatId.trim();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Prompt for owner IDs (optional)
|
|
93
|
+
*/
|
|
94
|
+
export async function promptOwnerIds() {
|
|
95
|
+
const response = await prompts({
|
|
96
|
+
type: "text",
|
|
97
|
+
name: "ownerIds",
|
|
98
|
+
message: "Enter Owner IDs (comma-separated, optional)",
|
|
99
|
+
hint: "These users will have full bot access. Press Enter to skip.",
|
|
100
|
+
validate: (value) => {
|
|
101
|
+
const result = validateOwnerIds(value);
|
|
102
|
+
return result.valid ? true : result.error || "Invalid owner IDs";
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (response.ownerIds === undefined) {
|
|
106
|
+
throw new Error("User cancelled the wizard");
|
|
107
|
+
}
|
|
108
|
+
const trimmed = response.ownerIds.trim();
|
|
109
|
+
if (!trimmed) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
return trimmed
|
|
113
|
+
.split(",")
|
|
114
|
+
.map((id) => id.trim())
|
|
115
|
+
.filter((id) => id.length > 0);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Prompt for encryption key choice and value
|
|
119
|
+
*/
|
|
120
|
+
export async function promptEncryptionKey(generateKey) {
|
|
121
|
+
// First, ask if user wants to auto-generate or enter manually
|
|
122
|
+
const choiceResponse = await prompts({
|
|
123
|
+
type: "select",
|
|
124
|
+
name: "choice",
|
|
125
|
+
message: "Encryption Key",
|
|
126
|
+
choices: [
|
|
127
|
+
{
|
|
128
|
+
title: "Auto-generate a secure key (recommended)",
|
|
129
|
+
value: "generate",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
title: "Enter my own key",
|
|
133
|
+
value: "manual",
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
initial: 0,
|
|
137
|
+
});
|
|
138
|
+
if (choiceResponse.choice === undefined) {
|
|
139
|
+
throw new Error("User cancelled the wizard");
|
|
140
|
+
}
|
|
141
|
+
const choice = choiceResponse.choice;
|
|
142
|
+
if (choice === "generate") {
|
|
143
|
+
const key = generateKey();
|
|
144
|
+
console.log(` Generated key: ${key}`);
|
|
145
|
+
return key;
|
|
146
|
+
}
|
|
147
|
+
// Manual entry
|
|
148
|
+
const keyResponse = await prompts({
|
|
149
|
+
type: "password",
|
|
150
|
+
name: "key",
|
|
151
|
+
message: "Enter your encryption key",
|
|
152
|
+
hint: "Must be exactly 64 hex characters (32 bytes)",
|
|
153
|
+
validate: (value) => {
|
|
154
|
+
const result = validateEncryptionKey(value);
|
|
155
|
+
return result.valid ? true : result.error || "Invalid encryption key";
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
if (keyResponse.key === undefined) {
|
|
159
|
+
throw new Error("User cancelled the wizard");
|
|
160
|
+
}
|
|
161
|
+
return keyResponse.key.trim();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Prompt for confirmation to save configuration
|
|
165
|
+
*/
|
|
166
|
+
export async function promptConfirmation() {
|
|
167
|
+
const response = await prompts({
|
|
168
|
+
type: "confirm",
|
|
169
|
+
name: "confirm",
|
|
170
|
+
message: "Save this configuration?",
|
|
171
|
+
initial: true,
|
|
172
|
+
});
|
|
173
|
+
if (response.confirm === undefined) {
|
|
174
|
+
throw new Error("User cancelled the wizard");
|
|
175
|
+
}
|
|
176
|
+
return response.confirm;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Run all prompts to collect wizard configuration
|
|
180
|
+
*/
|
|
181
|
+
export async function runPrompts(generateKey) {
|
|
182
|
+
displayWelcomeBanner();
|
|
183
|
+
const botToken = await promptBotToken();
|
|
184
|
+
const botChatId = await promptChatId();
|
|
185
|
+
const botOwnerIds = await promptOwnerIds();
|
|
186
|
+
const encryptionKey = await promptEncryptionKey(generateKey);
|
|
187
|
+
return {
|
|
188
|
+
botToken,
|
|
189
|
+
botChatId,
|
|
190
|
+
botOwnerIds,
|
|
191
|
+
encryptionKey,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/wizard/prompts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAiBzB;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAoB,EAAE,OAAe;IAClE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,uBAAuB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,uBAAuB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OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,WAAyB;IACxD,oBAAoB,EAAE,CAAC;IAEvB,MAAM,QAAQ,GAAG,MAAM,cAAc,EAAE,CAAC;IACxC,MAAM,SAAS,GAAG,MAAM,YAAY,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;IAC3C,MAAM,aAAa,GAAG,MAAM,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAE7D,OAAO;QACL,QAAQ;QACR,SAAS;QACT,WAAW;QACX,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input validation functions for the installation wizard
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validation result interface
|
|
6
|
+
*/
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validate Telegram bot token format
|
|
13
|
+
* Expected format: \d+:[A-Za-z0-9_-]+
|
|
14
|
+
* Example: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
|
|
15
|
+
*
|
|
16
|
+
* @param token - The bot token to validate
|
|
17
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateBotToken(token: string): ValidationResult;
|
|
20
|
+
/**
|
|
21
|
+
* Validate Telegram chat ID
|
|
22
|
+
* Must be a numeric string (can be negative for groups/channels)
|
|
23
|
+
*
|
|
24
|
+
* @param chatId - The chat ID to validate
|
|
25
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateChatId(chatId: string): ValidationResult;
|
|
28
|
+
/**
|
|
29
|
+
* Validate owner IDs (comma-separated list of numeric IDs)
|
|
30
|
+
*
|
|
31
|
+
* @param ownerIds - Comma-separated owner IDs to validate
|
|
32
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateOwnerIds(ownerIds: string): ValidationResult;
|
|
35
|
+
/**
|
|
36
|
+
* Validate encryption key
|
|
37
|
+
* Must be a 64-character hex string
|
|
38
|
+
*
|
|
39
|
+
* @param key - The encryption key to validate
|
|
40
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateEncryptionKey(key: string): ValidationResult;
|
|
43
|
+
/**
|
|
44
|
+
* Parse owner IDs string into array
|
|
45
|
+
*
|
|
46
|
+
* @param ownerIds - Comma-separated owner IDs
|
|
47
|
+
* @returns Array of owner ID strings
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseOwnerIds(ownerIds: string): string[];
|
|
50
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/wizard/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAkBhE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAa/D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAsBnE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAgBnE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CASxD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input validation functions for the installation wizard
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Validate Telegram bot token format
|
|
6
|
+
* Expected format: \d+:[A-Za-z0-9_-]+
|
|
7
|
+
* Example: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
|
|
8
|
+
*
|
|
9
|
+
* @param token - The bot token to validate
|
|
10
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
11
|
+
*/
|
|
12
|
+
export function validateBotToken(token) {
|
|
13
|
+
if (!token || token.trim().length === 0) {
|
|
14
|
+
return { valid: false, error: "Bot token is required" };
|
|
15
|
+
}
|
|
16
|
+
const trimmed = token.trim();
|
|
17
|
+
// Telegram bot token format: number:alphanumeric_chars
|
|
18
|
+
const tokenRegex = /^\d+:[A-Za-z0-9_-]+$/;
|
|
19
|
+
if (!tokenRegex.test(trimmed)) {
|
|
20
|
+
return {
|
|
21
|
+
valid: false,
|
|
22
|
+
error: "Invalid token format. Expected format: 123456789:ABCdefGHI...",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return { valid: true };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate Telegram chat ID
|
|
29
|
+
* Must be a numeric string (can be negative for groups/channels)
|
|
30
|
+
*
|
|
31
|
+
* @param chatId - The chat ID to validate
|
|
32
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
33
|
+
*/
|
|
34
|
+
export function validateChatId(chatId) {
|
|
35
|
+
if (!chatId || chatId.trim().length === 0) {
|
|
36
|
+
return { valid: false, error: "Chat ID is required" };
|
|
37
|
+
}
|
|
38
|
+
const trimmed = chatId.trim();
|
|
39
|
+
// Chat ID must be numeric (can be negative for groups/channels)
|
|
40
|
+
if (!/^-?\d+$/.test(trimmed)) {
|
|
41
|
+
return { valid: false, error: "Chat ID must be a number" };
|
|
42
|
+
}
|
|
43
|
+
return { valid: true };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validate owner IDs (comma-separated list of numeric IDs)
|
|
47
|
+
*
|
|
48
|
+
* @param ownerIds - Comma-separated owner IDs to validate
|
|
49
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
50
|
+
*/
|
|
51
|
+
export function validateOwnerIds(ownerIds) {
|
|
52
|
+
if (!ownerIds || ownerIds.trim().length === 0) {
|
|
53
|
+
// Owner IDs are optional - empty is valid
|
|
54
|
+
return { valid: true };
|
|
55
|
+
}
|
|
56
|
+
const trimmed = ownerIds.trim();
|
|
57
|
+
const ids = trimmed.split(",").map((id) => id.trim());
|
|
58
|
+
for (const id of ids) {
|
|
59
|
+
if (id.length === 0) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!/^\d+$/.test(id)) {
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
error: "Owner IDs must be numbers separated by commas",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { valid: true };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validate encryption key
|
|
73
|
+
* Must be a 64-character hex string
|
|
74
|
+
*
|
|
75
|
+
* @param key - The encryption key to validate
|
|
76
|
+
* @returns ValidationResult indicating success or failure with error message
|
|
77
|
+
*/
|
|
78
|
+
export function validateEncryptionKey(key) {
|
|
79
|
+
if (!key || key.trim().length === 0) {
|
|
80
|
+
return { valid: false, error: "Encryption key is required" };
|
|
81
|
+
}
|
|
82
|
+
const trimmed = key.trim();
|
|
83
|
+
// Must be exactly 64 hex characters (32 bytes)
|
|
84
|
+
if (!/^[a-fA-F0-9]{64}$/.test(trimmed)) {
|
|
85
|
+
return {
|
|
86
|
+
valid: false,
|
|
87
|
+
error: "Encryption key must be exactly 64 hex characters",
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return { valid: true };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse owner IDs string into array
|
|
94
|
+
*
|
|
95
|
+
* @param ownerIds - Comma-separated owner IDs
|
|
96
|
+
* @returns Array of owner ID strings
|
|
97
|
+
*/
|
|
98
|
+
export function parseOwnerIds(ownerIds) {
|
|
99
|
+
if (!ownerIds || ownerIds.trim().length === 0) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
return ownerIds
|
|
103
|
+
.split(",")
|
|
104
|
+
.map((id) => id.trim())
|
|
105
|
+
.filter((id) => id.length > 0);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/wizard/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;IAC1D,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,uDAAuD;IACvD,MAAM,UAAU,GAAG,sBAAsB,CAAC;IAE1C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,+DAA+D;SACvE,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC;IACxD,CAAC;IAED,MAAM,OAAO,GAAG,MAA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