telegram-ssh-bot 2.0.0 → 2.3.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.
Files changed (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -22
  3. package/deploy/.env.example +86 -0
  4. package/dist/config/index.d.ts +77 -0
  5. package/dist/config/index.d.ts.map +1 -0
  6. package/dist/config/index.js +333 -0
  7. package/dist/config/index.js.map +1 -0
  8. package/dist/config/schema.d.ts +6 -0
  9. package/dist/config/schema.d.ts.map +1 -0
  10. package/dist/config/schema.js +50 -0
  11. package/dist/config/schema.js.map +1 -0
  12. package/dist/core/Bot.d.ts +91 -0
  13. package/dist/core/Bot.d.ts.map +1 -0
  14. package/dist/core/Bot.js +263 -0
  15. package/dist/core/Bot.js.map +1 -0
  16. package/dist/core/ConnectionPool.d.ts +125 -0
  17. package/dist/core/ConnectionPool.d.ts.map +1 -0
  18. package/dist/core/ConnectionPool.js +397 -0
  19. package/dist/core/ConnectionPool.js.map +1 -0
  20. package/dist/core/SSHClient.d.ts +112 -0
  21. package/dist/core/SSHClient.d.ts.map +1 -0
  22. package/dist/core/SSHClient.js +367 -0
  23. package/dist/core/SSHClient.js.map +1 -0
  24. package/dist/core/ServerManager.d.ts +80 -0
  25. package/dist/core/ServerManager.d.ts.map +1 -0
  26. package/dist/core/ServerManager.js +207 -0
  27. package/dist/core/ServerManager.js.map +1 -0
  28. package/dist/core/index.d.ts +8 -0
  29. package/dist/core/index.d.ts.map +1 -0
  30. package/dist/core/index.js +8 -0
  31. package/dist/core/index.js.map +1 -0
  32. package/dist/errors/AuthError.d.ts +30 -0
  33. package/dist/errors/AuthError.d.ts.map +1 -0
  34. package/dist/errors/AuthError.js +35 -0
  35. package/dist/errors/AuthError.js.map +1 -0
  36. package/dist/errors/BaseError.d.ts +17 -0
  37. package/dist/errors/BaseError.d.ts.map +1 -0
  38. package/dist/errors/BaseError.js +34 -0
  39. package/dist/errors/BaseError.js.map +1 -0
  40. package/dist/errors/ConfigurationError.d.ts +24 -0
  41. package/dist/errors/ConfigurationError.d.ts.map +1 -0
  42. package/dist/errors/ConfigurationError.js +24 -0
  43. package/dist/errors/ConfigurationError.js.map +1 -0
  44. package/dist/errors/PoolError.d.ts +21 -0
  45. package/dist/errors/PoolError.d.ts.map +1 -0
  46. package/dist/errors/PoolError.js +30 -0
  47. package/dist/errors/PoolError.js.map +1 -0
  48. package/dist/errors/SSHError.d.ts +24 -0
  49. package/dist/errors/SSHError.d.ts.map +1 -0
  50. package/dist/errors/SSHError.js +38 -0
  51. package/dist/errors/SSHError.js.map +1 -0
  52. package/dist/errors/StorageError.d.ts +24 -0
  53. package/dist/errors/StorageError.d.ts.map +1 -0
  54. package/dist/errors/StorageError.js +35 -0
  55. package/dist/errors/StorageError.js.map +1 -0
  56. package/dist/errors/ValidationError.d.ts +29 -0
  57. package/dist/errors/ValidationError.d.ts.map +1 -0
  58. package/dist/errors/ValidationError.js +35 -0
  59. package/dist/errors/ValidationError.js.map +1 -0
  60. package/dist/errors/index.d.ts +11 -0
  61. package/dist/errors/index.d.ts.map +1 -0
  62. package/dist/errors/index.js +18 -0
  63. package/dist/errors/index.js.map +1 -0
  64. package/dist/handlers/BaseHandler.d.ts +50 -0
  65. package/dist/handlers/BaseHandler.d.ts.map +1 -0
  66. package/dist/handlers/BaseHandler.js +87 -0
  67. package/dist/handlers/BaseHandler.js.map +1 -0
  68. package/dist/handlers/CommandHandler.d.ts +23 -0
  69. package/dist/handlers/CommandHandler.d.ts.map +1 -0
  70. package/dist/handlers/CommandHandler.js +99 -0
  71. package/dist/handlers/CommandHandler.js.map +1 -0
  72. package/dist/handlers/HealthHandler.d.ts +25 -0
  73. package/dist/handlers/HealthHandler.d.ts.map +1 -0
  74. package/dist/handlers/HealthHandler.js +51 -0
  75. package/dist/handlers/HealthHandler.js.map +1 -0
  76. package/dist/handlers/HelpHandler.d.ts +32 -0
  77. package/dist/handlers/HelpHandler.d.ts.map +1 -0
  78. package/dist/handlers/HelpHandler.js +76 -0
  79. package/dist/handlers/HelpHandler.js.map +1 -0
  80. package/dist/handlers/ServerHandler.d.ts +72 -0
  81. package/dist/handlers/ServerHandler.d.ts.map +1 -0
  82. package/dist/handlers/ServerHandler.js +272 -0
  83. package/dist/handlers/ServerHandler.js.map +1 -0
  84. package/dist/handlers/index.d.ts +9 -0
  85. package/dist/handlers/index.d.ts.map +1 -0
  86. package/dist/handlers/index.js +9 -0
  87. package/dist/handlers/index.js.map +1 -0
  88. package/dist/index.d.ts +10 -0
  89. package/dist/index.d.ts.map +1 -0
  90. package/dist/index.js +365 -0
  91. package/dist/index.js.map +1 -0
  92. package/dist/middleware/AuthMiddleware.d.ts +28 -0
  93. package/dist/middleware/AuthMiddleware.d.ts.map +1 -0
  94. package/dist/middleware/AuthMiddleware.js +49 -0
  95. package/dist/middleware/AuthMiddleware.js.map +1 -0
  96. package/dist/middleware/RateLimitMiddleware.d.ts +23 -0
  97. package/dist/middleware/RateLimitMiddleware.d.ts.map +1 -0
  98. package/dist/middleware/RateLimitMiddleware.js +34 -0
  99. package/dist/middleware/RateLimitMiddleware.js.map +1 -0
  100. package/dist/middleware/index.d.ts +6 -0
  101. package/dist/middleware/index.d.ts.map +1 -0
  102. package/dist/middleware/index.js +6 -0
  103. package/dist/middleware/index.js.map +1 -0
  104. package/dist/services/BackupService.d.ts +119 -0
  105. package/dist/services/BackupService.d.ts.map +1 -0
  106. package/dist/services/BackupService.js +313 -0
  107. package/dist/services/BackupService.js.map +1 -0
  108. package/dist/services/CryptoService.d.ts +37 -0
  109. package/dist/services/CryptoService.d.ts.map +1 -0
  110. package/dist/services/CryptoService.js +108 -0
  111. package/dist/services/CryptoService.js.map +1 -0
  112. package/dist/services/HealthService.d.ts +126 -0
  113. package/dist/services/HealthService.d.ts.map +1 -0
  114. package/dist/services/HealthService.js +213 -0
  115. package/dist/services/HealthService.js.map +1 -0
  116. package/dist/services/LoggingService.d.ts +115 -0
  117. package/dist/services/LoggingService.d.ts.map +1 -0
  118. package/dist/services/LoggingService.js +334 -0
  119. package/dist/services/LoggingService.js.map +1 -0
  120. package/dist/services/MonitoringService.d.ts +119 -0
  121. package/dist/services/MonitoringService.d.ts.map +1 -0
  122. package/dist/services/MonitoringService.js +267 -0
  123. package/dist/services/MonitoringService.js.map +1 -0
  124. package/dist/services/NotificationService.d.ts +132 -0
  125. package/dist/services/NotificationService.d.ts.map +1 -0
  126. package/dist/services/NotificationService.js +297 -0
  127. package/dist/services/NotificationService.js.map +1 -0
  128. package/dist/services/RateLimiter.d.ts +51 -0
  129. package/dist/services/RateLimiter.d.ts.map +1 -0
  130. package/dist/services/RateLimiter.js +141 -0
  131. package/dist/services/RateLimiter.js.map +1 -0
  132. package/dist/services/ValidationService.d.ts +49 -0
  133. package/dist/services/ValidationService.d.ts.map +1 -0
  134. package/dist/services/ValidationService.js +158 -0
  135. package/dist/services/ValidationService.js.map +1 -0
  136. package/dist/services/index.d.ts +12 -0
  137. package/dist/services/index.d.ts.map +1 -0
  138. package/dist/services/index.js +12 -0
  139. package/dist/services/index.js.map +1 -0
  140. package/dist/types/Bot.d.ts +63 -0
  141. package/dist/types/Bot.d.ts.map +1 -0
  142. package/dist/types/Bot.js +5 -0
  143. package/dist/types/Bot.js.map +1 -0
  144. package/dist/types/Config.d.ts +57 -0
  145. package/dist/types/Config.d.ts.map +1 -0
  146. package/dist/types/Config.js +5 -0
  147. package/dist/types/Config.js.map +1 -0
  148. package/dist/types/Errors.d.ts +37 -0
  149. package/dist/types/Errors.d.ts.map +1 -0
  150. package/dist/types/Errors.js +34 -0
  151. package/dist/types/Errors.js.map +1 -0
  152. package/dist/types/SSH.d.ts +56 -0
  153. package/dist/types/SSH.d.ts.map +1 -0
  154. package/dist/types/SSH.js +6 -0
  155. package/dist/types/SSH.js.map +1 -0
  156. package/dist/types/Server.d.ts +39 -0
  157. package/dist/types/Server.d.ts.map +1 -0
  158. package/dist/types/Server.js +5 -0
  159. package/dist/types/Server.js.map +1 -0
  160. package/dist/types/index.d.ts +10 -0
  161. package/dist/types/index.d.ts.map +1 -0
  162. package/dist/types/index.js +6 -0
  163. package/dist/types/index.js.map +1 -0
  164. package/dist/utils/commandUtils.d.ts +25 -0
  165. package/dist/utils/commandUtils.d.ts.map +1 -0
  166. package/dist/utils/commandUtils.js +94 -0
  167. package/dist/utils/commandUtils.js.map +1 -0
  168. package/dist/utils/fileUtils.d.ts +40 -0
  169. package/dist/utils/fileUtils.d.ts.map +1 -0
  170. package/dist/utils/fileUtils.js +114 -0
  171. package/dist/utils/fileUtils.js.map +1 -0
  172. package/dist/utils/index.d.ts +7 -0
  173. package/dist/utils/index.d.ts.map +1 -0
  174. package/dist/utils/index.js +7 -0
  175. package/dist/utils/index.js.map +1 -0
  176. package/dist/utils/pathUtils.d.ts +40 -0
  177. package/dist/utils/pathUtils.d.ts.map +1 -0
  178. package/dist/utils/pathUtils.js +140 -0
  179. package/dist/utils/pathUtils.js.map +1 -0
  180. package/dist/wizard/InstallationWizard.d.ts +32 -0
  181. package/dist/wizard/InstallationWizard.d.ts.map +1 -0
  182. package/dist/wizard/InstallationWizard.js +96 -0
  183. package/dist/wizard/InstallationWizard.js.map +1 -0
  184. package/dist/wizard/index.d.ts +10 -0
  185. package/dist/wizard/index.d.ts.map +1 -0
  186. package/dist/wizard/index.js +8 -0
  187. package/dist/wizard/index.js.map +1 -0
  188. package/dist/wizard/prompts.d.ts +45 -0
  189. package/dist/wizard/prompts.d.ts.map +1 -0
  190. package/dist/wizard/prompts.js +194 -0
  191. package/dist/wizard/prompts.js.map +1 -0
  192. package/dist/wizard/validators.d.ts +50 -0
  193. package/dist/wizard/validators.d.ts.map +1 -0
  194. package/dist/wizard/validators.js +107 -0
  195. package/dist/wizard/validators.js.map +1 -0
  196. package/package.json +33 -5
  197. package/scripts/build.sh +20 -0
  198. package/scripts/postinstall.js +87 -0
  199. package/scripts/release.sh +22 -0
  200. package/scripts/setup-env.d.ts +28 -0
  201. package/scripts/setup-env.js +293 -0
@@ -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;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C,CAAC;IAEH,IAAI,QAAQ,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,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,MA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U,qBAAqB,CAAC,GAAW;IAC/C,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,4BAA4B,EAAE,CAAC;IAC/D,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAE3B,+CAA+C;IAC/C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,kDAAkD;SAC1D,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,QAAQ;SACZ,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;SACtB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,25 +1,51 @@
1
1
  {
2
2
  "name": "telegram-ssh-bot",
3
- "version": "2.0.0",
3
+ "version": "2.3.0",
4
+ "description": "A Telegram bot for secure SSH server management and remote command execution",
4
5
  "type": "module",
5
6
  "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "author": "farhanzzg",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/farhanzzg/telegram-ssh.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/farhanzzg/telegram-ssh/issues"
22
+ },
23
+ "homepage": "https://github.com/farhanzzg/telegram-ssh#readme",
6
24
  "bin": {
7
25
  "telegram-ssh-bot": "./dist/index.js"
8
26
  },
9
27
  "files": [
10
28
  "dist/**/*",
11
- "README.md",
12
- "LICENSE"
29
+ "scripts/**/*",
30
+ "deploy/.env.example",
31
+ "README.md"
13
32
  ],
14
33
  "engines": {
15
34
  "node": ">=18.0.0"
16
35
  },
17
36
  "keywords": [
18
37
  "telegram",
38
+ "telegram-bot",
19
39
  "ssh",
40
+ "ssh-client",
20
41
  "bot",
21
42
  "remote",
22
- "server-management"
43
+ "server-management",
44
+ "server-administration",
45
+ "devops",
46
+ "remote-access",
47
+ "command-execution",
48
+ "terminal"
23
49
  ],
24
50
  "pkg": {
25
51
  "scripts": "dist/**/*.js",
@@ -38,11 +64,13 @@
38
64
  "dotenv": "^16.3.1",
39
65
  "joi": "^17.11.0",
40
66
  "node-telegram-bot-api": "^0.61.0",
67
+ "prompts": "^2.4.2",
41
68
  "ssh2": "^1.14.0"
42
69
  },
43
70
  "devDependencies": {
44
71
  "@types/node": "^20.10.0",
45
72
  "@types/node-telegram-bot-api": "^0.61.0",
73
+ "@types/prompts": "^2.4.9",
46
74
  "@types/ssh2": "^1.15.0",
47
75
  "@yao-pkg/pkg": "^5.11.0",
48
76
  "nodemon": "^3.0.1",
@@ -54,7 +82,7 @@
54
82
  "start": "node dist/index.js",
55
83
  "dev": "tsc --watch",
56
84
  "clean": "rm -rf dist",
57
- "postinstall": "node -e \"console.log('Telegram SSH Bot installed. Run: telegram-ssh-bot')\"",
85
+ "postinstall": "node scripts/postinstall.js",
58
86
  "build:binary": "npm run build && pkg .",
59
87
  "build:binary:linux": "npm run build && pkg . --targets node18-linux-x64",
60
88
  "build:binary:macos": "npm run build && pkg . --targets node18-macos-x64",
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Building Telegram SSH Bot..."
5
+
6
+ # Clean previous builds
7
+ rm -rf dist build
8
+
9
+ # Compile TypeScript
10
+ echo "Compiling TypeScript..."
11
+ npm run build
12
+
13
+ # Create build directory
14
+ mkdir -p build
15
+
16
+ # Build binaries for current platform
17
+ echo "Creating binary executable..."
18
+ npx pkg . --targets node18-linux-x64 --output build/telegram-ssh-bot
19
+
20
+ echo "Build complete! Binary available at: build/telegram-ssh-bot"
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-install script for npm/pnpm global installation
4
+ * Sets up the .env configuration file if it doesn't exist
5
+ */
6
+
7
+ import { envFileExists, main } from "./setup-env.js";
8
+
9
+ /**
10
+ * Check if this is a global installation
11
+ * @returns {boolean} True if running as a global install
12
+ */
13
+ function isGlobalInstall() {
14
+ // Check various npm config indicators for global install
15
+ const npmConfigGlobal = process.env.npm_config_global;
16
+ const npmPackageConfig = process.env.npm_package_config;
17
+
18
+ // npm_config_global is 'true' when installed with -g flag
19
+ if (npmConfigGlobal === "true") {
20
+ return true;
21
+ }
22
+
23
+ // Check if we're in a global node_modules directory
24
+ // This is a heuristic that works for most cases
25
+ const cwd = process.cwd();
26
+ if (
27
+ cwd.includes("node_modules") &&
28
+ (cwd.includes("/usr/local") ||
29
+ cwd.includes("/usr/lib") ||
30
+ cwd.includes("/lib/node_modules") ||
31
+ cwd.includes(".npm-global") ||
32
+ cwd.includes(".pnpm-global"))
33
+ ) {
34
+ return true;
35
+ }
36
+
37
+ // Check for pnpm global install
38
+ if (
39
+ process.env.npm_config_user_agent &&
40
+ process.env.npm_config_user_agent.includes("pnpm")
41
+ ) {
42
+ // pnpm sets different paths for global installs
43
+ if (cwd.includes("pnpm-global") || cwd.includes(".pnpm-global")) {
44
+ return true;
45
+ }
46
+ }
47
+
48
+ return false;
49
+ }
50
+
51
+ /**
52
+ * Run the postinstall script
53
+ */
54
+ function runPostinstall() {
55
+ // Only run for global installations
56
+ if (!isGlobalInstall()) {
57
+ console.log("Local installation detected. Skipping .env setup.");
58
+ console.log(
59
+ "For global installation, the .env file would be created at ~/.config/telegram-ssh-bot/.env",
60
+ );
61
+ return;
62
+ }
63
+
64
+ console.log("Global installation detected. Setting up configuration...");
65
+
66
+ // Check if .env already exists
67
+ if (envFileExists()) {
68
+ console.log("Configuration file already exists. Skipping setup.");
69
+ console.log("Configuration location: ~/.config/telegram-ssh-bot/.env");
70
+ return;
71
+ }
72
+
73
+ // Run the main setup function
74
+ const result = main({ generateKey: true, silent: false });
75
+
76
+ if (result.success) {
77
+ console.log("\nConfiguration setup complete!");
78
+ console.log(
79
+ 'Run "telegram-ssh-bot" to start the bot after configuring your credentials.',
80
+ );
81
+ } else {
82
+ console.error("Configuration setup failed:", result.message);
83
+ }
84
+ }
85
+
86
+ // Run the postinstall script
87
+ runPostinstall();
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ VERSION=$(node -p "require('./package.json').version")
5
+ echo "Creating release v${VERSION}..."
6
+
7
+ # Clean
8
+ rm -rf dist build
9
+
10
+ # Install dependencies
11
+ npm ci
12
+
13
+ # Build all targets
14
+ make release
15
+
16
+ # Create tarballs
17
+ cd build
18
+ tar -czvf telegram-ssh-bot-${VERSION}-linux-x64.tar.gz telegram-ssh-bot-linux
19
+ tar -czvf telegram-ssh-bot-${VERSION}-macos-x64.tar.gz telegram-ssh-bot-macos
20
+ zip telegram-ssh-bot-${VERSION}-win-x64.zip telegram-ssh-bot.exe
21
+
22
+ echo "Release packages created in build/"
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Type declarations for setup-env.js
3
+ */
4
+
5
+ export function getConfigDir(): string;
6
+ export function getEnvFilePath(): string;
7
+ export function getEnvExamplePath(): string | null;
8
+ export function ensureConfigDir(): string;
9
+ export function generateEncryptionKey(): string;
10
+ export function envFileExists(): boolean;
11
+ export function createEnvFile(options?: { generateKey?: boolean }): boolean;
12
+ export function writeEnvFile(values: {
13
+ botToken: string;
14
+ botChatId: string;
15
+ botOwnerIds: string[];
16
+ encryptionKey: string;
17
+ }): boolean;
18
+ export function main(options?: {
19
+ force?: boolean;
20
+ generateKey?: boolean;
21
+ silent?: boolean;
22
+ }): {
23
+ success: boolean;
24
+ created: boolean;
25
+ envPath: string;
26
+ configDir: string;
27
+ message: string;
28
+ };