@mytmpvpn/mytmpvpn-cli 5.0.0 → 6.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/mytmpvpn.js +49 -46
- package/package.json +6 -6
- package/src/mytmpvpn.ts +19 -19
package/dist/mytmpvpn.js
CHANGED
|
@@ -33,18 +33,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
36
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
40
|
// Use NODE_NO_WARNINGS=1 to get rid of the fetch node deprecated API
|
|
38
41
|
// https://github.com/netlify/cli/issues/4608 -- but it hangs the process: https://github.com/nodejs/node/issues/21960
|
|
39
42
|
const fs = __importStar(require("fs"));
|
|
40
43
|
const path = __importStar(require("path"));
|
|
41
44
|
const commander_1 = require("commander");
|
|
42
|
-
const
|
|
43
|
-
|
|
45
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
46
|
+
loglevel_1.default.setDefaultLevel("info");
|
|
44
47
|
const vpnlib = __importStar(require("@mytmpvpn/mytmpvpn-common/models/vpn"));
|
|
45
48
|
const mytmpvpn_client_1 = require("@mytmpvpn/mytmpvpn-client");
|
|
46
49
|
const appconfig = __importStar(require("@mytmpvpn/mytmpvpn-client/appconfig"));
|
|
47
|
-
const
|
|
50
|
+
const userprofiles = __importStar(require("@mytmpvpn/mytmpvpn-client/userprofiles"));
|
|
48
51
|
const client = __importStar(require("@mytmpvpn/mytmpvpn-client/client"));
|
|
49
52
|
const program = new commander_1.Command();
|
|
50
53
|
function handleError(error, verbose = false) {
|
|
@@ -52,24 +55,24 @@ function handleError(error, verbose = false) {
|
|
|
52
55
|
// The request was made and the server responded with a status code
|
|
53
56
|
// that falls out of the range of 2xx
|
|
54
57
|
try {
|
|
55
|
-
|
|
58
|
+
loglevel_1.default.error(`[${error.response.status}] - ${JSON.stringify(error.response.data)}`);
|
|
56
59
|
}
|
|
57
60
|
catch (Error) {
|
|
58
|
-
|
|
61
|
+
loglevel_1.default.error(`[${error.response.status}] - ${JSON.stringify(error.message)}`);
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
loglevel_1.default.debug(error.response.headers);
|
|
61
64
|
}
|
|
62
65
|
else if (error.request) {
|
|
63
66
|
// The request was made but no response was received
|
|
64
67
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
65
68
|
// http.ClientRequest in node.js
|
|
66
|
-
|
|
69
|
+
loglevel_1.default.error(`No reponse received. Check your profile and your appConfig`);
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
69
72
|
// Something happened in setting up the request that triggered an Error
|
|
70
|
-
|
|
73
|
+
loglevel_1.default.error(`Error while setting up the request ${JSON.stringify(error)}`);
|
|
71
74
|
}
|
|
72
|
-
|
|
75
|
+
loglevel_1.default.trace(`Stack trace: ${error}`);
|
|
73
76
|
}
|
|
74
77
|
program
|
|
75
78
|
.name('mytmpvpn-cli')
|
|
@@ -77,10 +80,10 @@ program
|
|
|
77
80
|
.version('0.0.1')
|
|
78
81
|
.option('--verbose', 'Produce more logs')
|
|
79
82
|
.option('--appConfig <file>', 'Path to the application config file', appconfig.getDefaultAppConfigFile())
|
|
80
|
-
.option('--
|
|
81
|
-
.option('--profile <name>', 'Name of the profile in the user
|
|
83
|
+
.option('--userProfiles <file>', 'Path to the user profiles file', userprofiles.getDefaultUserProfilesFile())
|
|
84
|
+
.option('--profile <name>', 'Name of the profile in the user profiles file to use', userprofiles.getDefaultUsername());
|
|
82
85
|
program.on('option:verbose', function () {
|
|
83
|
-
|
|
86
|
+
loglevel_1.default.setDefaultLevel("trace");
|
|
84
87
|
});
|
|
85
88
|
program.command('list-peanuts-packs')
|
|
86
89
|
.description(`Returns the list of peanuts packs you can purchase. A peanuts pack contains a given number of peanuts.`)
|
|
@@ -91,7 +94,7 @@ program.command('list-peanuts-packs')
|
|
|
91
94
|
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
92
95
|
clientImpl.listPeanutsPacks()
|
|
93
96
|
.then(((packs) => {
|
|
94
|
-
|
|
97
|
+
loglevel_1.default.info(JSON.stringify(packs, null, 2));
|
|
95
98
|
}))
|
|
96
99
|
.catch((err) => handleError(err));
|
|
97
100
|
});
|
|
@@ -99,14 +102,14 @@ program.command('get-peanuts-balance')
|
|
|
99
102
|
.description('Get the current peanuts balance')
|
|
100
103
|
.action((_, command) => {
|
|
101
104
|
const options = command.optsWithGlobals();
|
|
102
|
-
|
|
105
|
+
loglevel_1.default.debug(`Get peanuts balance`);
|
|
103
106
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
104
107
|
appConfigFile: options.appConfig,
|
|
105
|
-
userConfigFile: options.
|
|
108
|
+
userConfigFile: options.userProfiles,
|
|
106
109
|
profileName: options.profile
|
|
107
110
|
}).then(client => {
|
|
108
111
|
client.getPeanutsBalance().then(balance => {
|
|
109
|
-
|
|
112
|
+
loglevel_1.default.info(balance);
|
|
110
113
|
}).catch((err) => {
|
|
111
114
|
handleError(err);
|
|
112
115
|
});
|
|
@@ -123,7 +126,7 @@ program.command('list-locations')
|
|
|
123
126
|
const clientImpl = new client.MyTmpVpnClientImpl(appConfig.apiUrl);
|
|
124
127
|
clientImpl.listLocations()
|
|
125
128
|
.then(((locations) => {
|
|
126
|
-
|
|
129
|
+
loglevel_1.default.info(JSON.stringify(locations, null, 2));
|
|
127
130
|
}))
|
|
128
131
|
.catch((err) => handleError(err));
|
|
129
132
|
});
|
|
@@ -137,10 +140,10 @@ program.command('create')
|
|
|
137
140
|
const options = command.optsWithGlobals();
|
|
138
141
|
const syncStr = options.sync ? "synchronously" : "asynchronously";
|
|
139
142
|
const deleteAfter = options.deleteAfter ? options.deleteAfter : undefined;
|
|
140
|
-
|
|
143
|
+
loglevel_1.default.debug(`Creating new ${options.type} vpn into ${geonameId} ${syncStr}`);
|
|
141
144
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
142
145
|
appConfigFile: options.appConfig,
|
|
143
|
-
userConfigFile: options.
|
|
146
|
+
userConfigFile: options.userProfiles,
|
|
144
147
|
profileName: options.profile
|
|
145
148
|
}).then(client => {
|
|
146
149
|
client.createVpn(Number.parseInt(geonameId), {
|
|
@@ -148,11 +151,11 @@ program.command('create')
|
|
|
148
151
|
maxPeanuts: options.peanuts, deleteAfter
|
|
149
152
|
}).then(vpn => {
|
|
150
153
|
if (!options.sync) {
|
|
151
|
-
|
|
154
|
+
loglevel_1.default.info(vpn);
|
|
152
155
|
return;
|
|
153
156
|
}
|
|
154
157
|
client.waitUntilVpnStateIs(vpn.vpnId, vpnlib.VpnState.Running).then(updatedVpn => {
|
|
155
|
-
|
|
158
|
+
loglevel_1.default.info(updatedVpn);
|
|
156
159
|
}).catch(err => {
|
|
157
160
|
handleError(err);
|
|
158
161
|
});
|
|
@@ -170,20 +173,20 @@ program.command('delete')
|
|
|
170
173
|
.action((vpnId, _, command) => {
|
|
171
174
|
const options = command.optsWithGlobals();
|
|
172
175
|
const syncStr = options.sync ? "synchronously" : "asynchronously";
|
|
173
|
-
|
|
176
|
+
loglevel_1.default.debug(`Deleting vpn ${vpnId} ${syncStr}`);
|
|
174
177
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
175
178
|
appConfigFile: options.appConfig,
|
|
176
|
-
userConfigFile: options.
|
|
179
|
+
userConfigFile: options.userProfiles,
|
|
177
180
|
profileName: options.profile
|
|
178
181
|
}).then(client => {
|
|
179
182
|
client.deleteVpn(vpnId).then(vpn => {
|
|
180
183
|
if (!options.sync) {
|
|
181
|
-
|
|
184
|
+
loglevel_1.default.info(JSON.stringify(vpn));
|
|
182
185
|
return;
|
|
183
186
|
}
|
|
184
187
|
client.waitUntilVpnStateIs(vpnId, vpnlib.VpnState.Deleted)
|
|
185
188
|
.then(updatedVpn => {
|
|
186
|
-
|
|
189
|
+
loglevel_1.default.info(updatedVpn);
|
|
187
190
|
return;
|
|
188
191
|
}).catch(err => {
|
|
189
192
|
handleError(err.response?.data || JSON.stringify(err));
|
|
@@ -200,11 +203,11 @@ program.command('get')
|
|
|
200
203
|
const options = command.optsWithGlobals();
|
|
201
204
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
202
205
|
appConfigFile: options.appConfig,
|
|
203
|
-
userConfigFile: options.
|
|
206
|
+
userConfigFile: options.userProfiles,
|
|
204
207
|
profileName: options.profile
|
|
205
208
|
}).then(client => {
|
|
206
209
|
client.getVpn(vpnId)
|
|
207
|
-
.then(result =>
|
|
210
|
+
.then(result => loglevel_1.default.info(result))
|
|
208
211
|
.catch(err => handleError(err));
|
|
209
212
|
}).catch(err => {
|
|
210
213
|
handleError(err);
|
|
@@ -214,27 +217,27 @@ program.command('download-config')
|
|
|
214
217
|
.description('Download configuration of the given vpn to the given file')
|
|
215
218
|
.argument('<vpnId>', 'vpnId to get config file from')
|
|
216
219
|
.option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
|
|
217
|
-
.option('--path <path>', 'path where the config file should be written to',
|
|
220
|
+
.option('--path <path>', 'path where the config file should be written to', userprofiles.getDefaultUserProfilesDir())
|
|
218
221
|
.action((vpnId, _, command) => {
|
|
219
222
|
const options = command.optsWithGlobals();
|
|
220
223
|
const file = options.file ? options.file : `${vpnId}.conf`;
|
|
221
224
|
const fullpath = path.join(options.path, file);
|
|
222
225
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
223
226
|
appConfigFile: options.appConfig,
|
|
224
|
-
userConfigFile: options.
|
|
227
|
+
userConfigFile: options.userProfiles,
|
|
225
228
|
profileName: options.profile
|
|
226
229
|
}).then(client => {
|
|
227
230
|
client.getVpnConfig(vpnId)
|
|
228
231
|
.then(b64 => {
|
|
229
232
|
const vpnConfig = Buffer.from(b64, 'base64');
|
|
230
|
-
|
|
233
|
+
loglevel_1.default.debug(`Writing config file to ${fullpath}`);
|
|
231
234
|
// Write the config file to the given path
|
|
232
235
|
fs.writeFile(fullpath, vpnConfig, (err) => {
|
|
233
236
|
if (err) {
|
|
234
237
|
handleError(err);
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
237
|
-
|
|
240
|
+
loglevel_1.default.info(`Config file written to ${fullpath}`);
|
|
238
241
|
});
|
|
239
242
|
}).catch(err => handleError(err));
|
|
240
243
|
}).catch(err => {
|
|
@@ -250,7 +253,7 @@ program.command('list')
|
|
|
250
253
|
const options = command.optsWithGlobals();
|
|
251
254
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
252
255
|
appConfigFile: options.appConfig,
|
|
253
|
-
userConfigFile: options.
|
|
256
|
+
userConfigFile: options.userProfiles,
|
|
254
257
|
profileName: options.profile
|
|
255
258
|
}).then(client => {
|
|
256
259
|
client.listVpns(options.state)
|
|
@@ -264,7 +267,7 @@ program.command('list')
|
|
|
264
267
|
if (options.excludeState) {
|
|
265
268
|
vpns = vpns.filter((vpn) => !options.excludeState.includes(vpn.state));
|
|
266
269
|
}
|
|
267
|
-
|
|
270
|
+
loglevel_1.default.info(JSON.stringify(vpns, null, 2));
|
|
268
271
|
})
|
|
269
272
|
.catch(err => handleError(err));
|
|
270
273
|
}).catch(err => {
|
|
@@ -282,15 +285,15 @@ program.command('wait')
|
|
|
282
285
|
handleError(`Unknown state: ${state}. Valid states: ${Object.values(vpnlib.VpnState)}`);
|
|
283
286
|
return;
|
|
284
287
|
}
|
|
285
|
-
|
|
288
|
+
loglevel_1.default.debug(`Waiting for ${vpnId} state to be (at least) ${state}`);
|
|
286
289
|
(0, mytmpvpn_client_1.getLoggedInClientFromFiles)({
|
|
287
290
|
appConfigFile: options.appConfig,
|
|
288
|
-
userConfigFile: options.
|
|
291
|
+
userConfigFile: options.userProfiles,
|
|
289
292
|
profileName: options.profile
|
|
290
293
|
}).then(client => {
|
|
291
294
|
client.waitUntilVpnStateIs(vpnId, actualState)
|
|
292
295
|
.then(vpn => {
|
|
293
|
-
|
|
296
|
+
loglevel_1.default.info(vpn);
|
|
294
297
|
})
|
|
295
298
|
.catch(err => handleError(err));
|
|
296
299
|
}).catch(err => {
|
|
@@ -304,10 +307,10 @@ program.command('register')
|
|
|
304
307
|
.action((username, password, _, command) => {
|
|
305
308
|
const options = command.optsWithGlobals();
|
|
306
309
|
var userConfigData;
|
|
307
|
-
if (fs.existsSync(options.
|
|
308
|
-
userConfigData =
|
|
310
|
+
if (fs.existsSync(options.userProfiles)) {
|
|
311
|
+
userConfigData = userprofiles.loadUserProfiles(options.userProfiles);
|
|
309
312
|
if (userConfigData.profiles[options.profile]) {
|
|
310
|
-
handleError(`Profile ${options.profile} already exists in ${options.
|
|
313
|
+
handleError(`Profile ${options.profile} already exists in ${options.userProfiles}, specify another profile name using --profile`);
|
|
311
314
|
return;
|
|
312
315
|
}
|
|
313
316
|
userConfigData.profiles[options.profile] = {
|
|
@@ -328,20 +331,20 @@ program.command('register')
|
|
|
328
331
|
}
|
|
329
332
|
(0, mytmpvpn_client_1.registerUser)(options.appConfig, { username, password })
|
|
330
333
|
.then(user => {
|
|
331
|
-
|
|
332
|
-
fs.mkdir(path.dirname(options.
|
|
334
|
+
loglevel_1.default.info(`Please confirm your identity with the code sent to ${username}`);
|
|
335
|
+
fs.mkdir(path.dirname(options.userProfiles), { recursive: true }, (err, path) => {
|
|
333
336
|
if (err) {
|
|
334
337
|
handleError(err);
|
|
335
338
|
return;
|
|
336
339
|
}
|
|
337
|
-
|
|
338
|
-
fs.writeFile(options.
|
|
340
|
+
loglevel_1.default.debug(`Directory: ${path} created`);
|
|
341
|
+
fs.writeFile(options.userProfiles, JSON.stringify(userConfigData, null, 2), (err) => {
|
|
339
342
|
if (err) {
|
|
340
343
|
handleError(err);
|
|
341
344
|
return;
|
|
342
345
|
}
|
|
343
346
|
});
|
|
344
|
-
|
|
347
|
+
loglevel_1.default.info(`A new profile has been created for ${options.profile} in ${options.userProfiles}`);
|
|
345
348
|
});
|
|
346
349
|
}).catch(err => {
|
|
347
350
|
handleError(err);
|
|
@@ -355,8 +358,8 @@ program.command('confirm-registration')
|
|
|
355
358
|
const options = command.optsWithGlobals();
|
|
356
359
|
(0, mytmpvpn_client_1.confirmUser)(options.appConfig, username, code)
|
|
357
360
|
.then(result => {
|
|
358
|
-
|
|
359
|
-
|
|
361
|
+
loglevel_1.default.debug(result);
|
|
362
|
+
loglevel_1.default.info(`User ${username} confirmed!`);
|
|
360
363
|
})
|
|
361
364
|
.catch(err => {
|
|
362
365
|
handleError(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mytmpvpn/mytmpvpn-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "MyTmpVpn CLI",
|
|
5
5
|
"main": "./dist/mytmpvpn.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "GNU GPL",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@mytmpvpn/mytmpvpn-client": "^
|
|
34
|
-
"@mytmpvpn/mytmpvpn-common": "^
|
|
33
|
+
"@mytmpvpn/mytmpvpn-client": "^10.0.2",
|
|
34
|
+
"@mytmpvpn/mytmpvpn-common": "^13.0.0",
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
36
|
-
"commander": "^14.0.
|
|
36
|
+
"commander": "^14.0.3",
|
|
37
37
|
"eslint": "^8.57.1",
|
|
38
38
|
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
39
39
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/jest": "^29.5.14",
|
|
46
|
-
"@types/node": "^24.
|
|
46
|
+
"@types/node": "^24.10.13",
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
|
-
"ts-jest": "^29.4.
|
|
48
|
+
"ts-jest": "^29.4.6",
|
|
49
49
|
"typescript": "^5.9.3"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/mytmpvpn.ts
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
import * as fs from 'fs'
|
|
5
5
|
import * as path from 'path'
|
|
6
6
|
import { Command, Option } from 'commander'
|
|
7
|
-
import
|
|
7
|
+
import log from 'loglevel'
|
|
8
8
|
log.setDefaultLevel("info")
|
|
9
9
|
|
|
10
10
|
import * as vpnlib from '@mytmpvpn/mytmpvpn-common/models/vpn'
|
|
11
11
|
import * as peanuts from '@mytmpvpn/mytmpvpn-common/models/peanuts'
|
|
12
12
|
import { confirmUser, getLoggedInClientFromFiles, registerUser } from '@mytmpvpn/mytmpvpn-client'
|
|
13
13
|
import * as appconfig from '@mytmpvpn/mytmpvpn-client/appconfig'
|
|
14
|
-
import * as
|
|
14
|
+
import * as userprofiles from '@mytmpvpn/mytmpvpn-client/userprofiles'
|
|
15
15
|
import * as client from '@mytmpvpn/mytmpvpn-client/client'
|
|
16
16
|
import { ListLocationsResponse } from '@mytmpvpn/mytmpvpn-common/models/location'
|
|
17
17
|
|
|
@@ -46,8 +46,8 @@ program
|
|
|
46
46
|
.version('0.0.1')
|
|
47
47
|
.option('--verbose', 'Produce more logs')
|
|
48
48
|
.option('--appConfig <file>', 'Path to the application config file', appconfig.getDefaultAppConfigFile())
|
|
49
|
-
.option('--
|
|
50
|
-
.option('--profile <name>', 'Name of the profile in the user
|
|
49
|
+
.option('--userProfiles <file>', 'Path to the user profiles file', userprofiles.getDefaultUserProfilesFile())
|
|
50
|
+
.option('--profile <name>', 'Name of the profile in the user profiles file to use', userprofiles.getDefaultUsername())
|
|
51
51
|
|
|
52
52
|
program.on('option:verbose', function () {
|
|
53
53
|
log.setDefaultLevel("trace")
|
|
@@ -74,7 +74,7 @@ program.command('get-peanuts-balance')
|
|
|
74
74
|
log.debug(`Get peanuts balance`)
|
|
75
75
|
getLoggedInClientFromFiles({
|
|
76
76
|
appConfigFile: options.appConfig,
|
|
77
|
-
userConfigFile: options.
|
|
77
|
+
userConfigFile: options.userProfiles,
|
|
78
78
|
profileName: options.profile
|
|
79
79
|
}).then(client => {
|
|
80
80
|
client.getPeanutsBalance().then(balance => {
|
|
@@ -114,7 +114,7 @@ program.command('create')
|
|
|
114
114
|
log.debug(`Creating new ${options.type} vpn into ${geonameId} ${syncStr}`)
|
|
115
115
|
getLoggedInClientFromFiles({
|
|
116
116
|
appConfigFile: options.appConfig,
|
|
117
|
-
userConfigFile: options.
|
|
117
|
+
userConfigFile: options.userProfiles,
|
|
118
118
|
profileName: options.profile
|
|
119
119
|
}).then(client => {
|
|
120
120
|
client.createVpn(Number.parseInt(geonameId), {
|
|
@@ -148,7 +148,7 @@ program.command('delete')
|
|
|
148
148
|
log.debug(`Deleting vpn ${vpnId} ${syncStr}`)
|
|
149
149
|
getLoggedInClientFromFiles({
|
|
150
150
|
appConfigFile: options.appConfig,
|
|
151
|
-
userConfigFile: options.
|
|
151
|
+
userConfigFile: options.userProfiles,
|
|
152
152
|
profileName: options.profile
|
|
153
153
|
}).then(client => {
|
|
154
154
|
client.deleteVpn(vpnId).then(vpn => {
|
|
@@ -176,7 +176,7 @@ program.command('get')
|
|
|
176
176
|
const options = command.optsWithGlobals()
|
|
177
177
|
getLoggedInClientFromFiles({
|
|
178
178
|
appConfigFile: options.appConfig,
|
|
179
|
-
userConfigFile: options.
|
|
179
|
+
userConfigFile: options.userProfiles,
|
|
180
180
|
profileName: options.profile
|
|
181
181
|
}).then(client => {
|
|
182
182
|
client.getVpn(vpnId)
|
|
@@ -191,14 +191,14 @@ program.command('download-config')
|
|
|
191
191
|
.description('Download configuration of the given vpn to the given file')
|
|
192
192
|
.argument('<vpnId>', 'vpnId to get config file from')
|
|
193
193
|
.option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
|
|
194
|
-
.option('--path <path>', 'path where the config file should be written to',
|
|
194
|
+
.option('--path <path>', 'path where the config file should be written to', userprofiles.getDefaultUserProfilesDir())
|
|
195
195
|
.action((vpnId, _, command) => {
|
|
196
196
|
const options = command.optsWithGlobals()
|
|
197
197
|
const file = options.file ? options.file : `${vpnId}.conf`
|
|
198
198
|
const fullpath = path.join(options.path, file)
|
|
199
199
|
getLoggedInClientFromFiles({
|
|
200
200
|
appConfigFile: options.appConfig,
|
|
201
|
-
userConfigFile: options.
|
|
201
|
+
userConfigFile: options.userProfiles,
|
|
202
202
|
profileName: options.profile
|
|
203
203
|
}).then(client => {
|
|
204
204
|
client.getVpnConfig(vpnId)
|
|
@@ -228,7 +228,7 @@ program.command('list')
|
|
|
228
228
|
const options = command.optsWithGlobals()
|
|
229
229
|
getLoggedInClientFromFiles({
|
|
230
230
|
appConfigFile: options.appConfig,
|
|
231
|
-
userConfigFile: options.
|
|
231
|
+
userConfigFile: options.userProfiles,
|
|
232
232
|
profileName: options.profile
|
|
233
233
|
}).then(client => {
|
|
234
234
|
client.listVpns(options.state)
|
|
@@ -264,7 +264,7 @@ program.command('wait')
|
|
|
264
264
|
log.debug(`Waiting for ${vpnId} state to be (at least) ${state}`)
|
|
265
265
|
getLoggedInClientFromFiles({
|
|
266
266
|
appConfigFile: options.appConfig,
|
|
267
|
-
userConfigFile: options.
|
|
267
|
+
userConfigFile: options.userProfiles,
|
|
268
268
|
profileName: options.profile
|
|
269
269
|
}).then(client => {
|
|
270
270
|
client.waitUntilVpnStateIs(vpnId, actualState)
|
|
@@ -283,11 +283,11 @@ program.command('register')
|
|
|
283
283
|
.argument('<password>', 'a password')
|
|
284
284
|
.action((username, password, _, command) => {
|
|
285
285
|
const options = command.optsWithGlobals()
|
|
286
|
-
var userConfigData:
|
|
287
|
-
if (fs.existsSync(options.
|
|
288
|
-
userConfigData =
|
|
286
|
+
var userConfigData: userprofiles.UserProfiles
|
|
287
|
+
if (fs.existsSync(options.userProfiles)) {
|
|
288
|
+
userConfigData = userprofiles.loadUserProfiles(options.userProfiles)
|
|
289
289
|
if (userConfigData.profiles[options.profile]) {
|
|
290
|
-
handleError(`Profile ${options.profile} already exists in ${options.
|
|
290
|
+
handleError(`Profile ${options.profile} already exists in ${options.userProfiles}, specify another profile name using --profile`)
|
|
291
291
|
return
|
|
292
292
|
}
|
|
293
293
|
userConfigData.profiles[options.profile] = {
|
|
@@ -309,19 +309,19 @@ program.command('register')
|
|
|
309
309
|
{ username, password })
|
|
310
310
|
.then(user => {
|
|
311
311
|
log.info(`Please confirm your identity with the code sent to ${username}`)
|
|
312
|
-
fs.mkdir(path.dirname(options.
|
|
312
|
+
fs.mkdir(path.dirname(options.userProfiles), { recursive: true }, (err, path?) => {
|
|
313
313
|
if (err) {
|
|
314
314
|
handleError(err)
|
|
315
315
|
return
|
|
316
316
|
}
|
|
317
317
|
log.debug(`Directory: ${path} created`)
|
|
318
|
-
fs.writeFile(options.
|
|
318
|
+
fs.writeFile(options.userProfiles, JSON.stringify(userConfigData, null, 2), (err) => {
|
|
319
319
|
if (err) {
|
|
320
320
|
handleError(err)
|
|
321
321
|
return
|
|
322
322
|
}
|
|
323
323
|
})
|
|
324
|
-
log.info(`A new profile has been created for ${options.profile} in ${options.
|
|
324
|
+
log.info(`A new profile has been created for ${options.profile} in ${options.userProfiles}`)
|
|
325
325
|
})
|
|
326
326
|
}).catch(err => {
|
|
327
327
|
handleError(err)
|