@bprotsyk/aso-core 2.0.43 → 2.0.44
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.
|
@@ -15,6 +15,7 @@ export declare class ServerUtil {
|
|
|
15
15
|
sftpConfig: ISFTP;
|
|
16
16
|
constructor(sftpConfig: ISFTP);
|
|
17
17
|
connectSSH(): Promise<void>;
|
|
18
|
+
ensureConnected(): Promise<void>;
|
|
18
19
|
exec(command: string, options?: any): Promise<string>;
|
|
19
20
|
generateSSHKey(): Promise<string>;
|
|
20
21
|
createDirectories(): Promise<void>;
|
package/lib/utils/server-util.js
CHANGED
|
@@ -33,9 +33,15 @@ class ServerUtil {
|
|
|
33
33
|
password: this.sftpConfig.password,
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
async ensureConnected() {
|
|
37
|
+
if (!this.ssh.isConnected()) {
|
|
38
|
+
await this.connectSSH(); // Підключення, якщо ще не підключено
|
|
39
|
+
}
|
|
40
|
+
}
|
|
36
41
|
// Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
|
|
37
42
|
async exec(command, options) {
|
|
38
|
-
|
|
43
|
+
await this.ensureConnected();
|
|
44
|
+
if (this.ssh.isConnected()) {
|
|
39
45
|
return (await this.ssh.execCommand(command, options)).stdout;
|
|
40
46
|
}
|
|
41
47
|
else {
|
|
@@ -164,13 +170,13 @@ class ServerUtil {
|
|
|
164
170
|
await this.ssh.execCommand(`apt-get install -y certbot python3-certbot-nginx;`);
|
|
165
171
|
return true;
|
|
166
172
|
}
|
|
167
|
-
// creating a SSL certificate
|
|
168
173
|
async setupSSL(email, host) {
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
// Прямий виклик this.ssh.execCommand
|
|
175
|
+
let certbotResponse = await this.ssh.execCommand(`certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`);
|
|
176
|
+
if (certbotResponse.stdout.includes(`Some challenges have failed.`)) {
|
|
171
177
|
throw new Error("Certbot encountered an error");
|
|
172
178
|
}
|
|
173
|
-
await this.
|
|
179
|
+
await this.ssh.execCommand(`echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`);
|
|
174
180
|
}
|
|
175
181
|
// Git
|
|
176
182
|
async refresh() {
|
package/package.json
CHANGED
package/src/utils/server-util.ts
CHANGED
|
@@ -46,9 +46,17 @@ export class ServerUtil {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
async ensureConnected(): Promise<void> {
|
|
50
|
+
if (!this.ssh.isConnected()) {
|
|
51
|
+
await this.connectSSH(); // Підключення, якщо ще не підключено
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
49
56
|
// Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
|
|
50
57
|
async exec(command: string, options?: any): Promise<string> {
|
|
51
|
-
|
|
58
|
+
await this.ensureConnected();
|
|
59
|
+
if (this.ssh.isConnected()) {
|
|
52
60
|
return (await this.ssh.execCommand(command, options)).stdout;
|
|
53
61
|
} else {
|
|
54
62
|
return await new Promise<string>((resolve) => {
|
|
@@ -198,18 +206,22 @@ export class ServerUtil {
|
|
|
198
206
|
|
|
199
207
|
return true;
|
|
200
208
|
}
|
|
201
|
-
|
|
209
|
+
|
|
202
210
|
async setupSSL(email: string, host: string): Promise<void> {
|
|
203
|
-
|
|
211
|
+
// Прямий виклик this.ssh.execCommand
|
|
212
|
+
let certbotResponse = await this.ssh.execCommand(
|
|
204
213
|
`certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`
|
|
205
214
|
);
|
|
206
|
-
|
|
215
|
+
|
|
216
|
+
if (certbotResponse.stdout.includes(`Some challenges have failed.`)) {
|
|
207
217
|
throw new Error("Certbot encountered an error");
|
|
208
218
|
}
|
|
209
|
-
|
|
219
|
+
|
|
220
|
+
await this.ssh.execCommand(
|
|
210
221
|
`echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`
|
|
211
222
|
);
|
|
212
223
|
}
|
|
224
|
+
|
|
213
225
|
|
|
214
226
|
// Git
|
|
215
227
|
async refresh(): Promise<boolean> {
|