@mytmpvpn/mytmpvpn-cli 1.7.0 → 1.8.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mytmpvpn-cli
2
2
 
3
- Command Line Interface for the [`MyTmpVpn`](https://gitlab.com/mytmpvpn) project.
3
+ Command Line Interface for the [`MyTmpVpn`](https://mytmpvpn.com) service.
4
4
 
5
5
  ## Getting started
6
6
 
package/dist/mytmpvpn.js CHANGED
@@ -93,6 +93,19 @@ program.command('list-regions')
93
93
  }))
94
94
  .catch((err) => handleError(err));
95
95
  });
96
+ program.command('list-regions-detailed')
97
+ .description('Returns the detailed list of all regions where vpn can be created')
98
+ .action((_, command) => {
99
+ const options = command.optsWithGlobals();
100
+ const appConfig = (0, appconfig_1.loadAppConfig)(options.appConfig);
101
+ // We don't need authenticated user to call this API
102
+ const client = new client_1.MyTmpVpnClient(appConfig.apiUrl);
103
+ client.listRegionsDetailed()
104
+ .then(((regions) => {
105
+ log.info(JSON.stringify(regions, null, 2));
106
+ }))
107
+ .catch((err) => handleError(err));
108
+ });
96
109
  program.command('create')
97
110
  .description('Create a new vpn')
98
111
  .argument('<region>', 'region where the vpn should be created, as returned by list-regions')
@@ -172,20 +185,30 @@ program.command('get')
172
185
  program.command('download-config')
173
186
  .description('Download configuration of the given vpn to the given file')
174
187
  .argument('<vpnId>', 'vpnId to get config file from')
175
- .option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.tar.gz')
188
+ .option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
176
189
  .option('--path <path>', 'path where the config file should be written to', (0, userconfig_1.getDefaultUserConfigDir)())
177
190
  .action((vpnId, _, command) => {
178
191
  const options = command.optsWithGlobals();
179
- const file = options.file ? options.file : `${vpnId}.tar.gz`;
192
+ const file = options.file ? options.file : `${vpnId}.conf`;
180
193
  const fullpath = path.join(options.path, file);
181
194
  auth.getLoggedInClientFromFiles({ appConfigFile: options.appConfig, userConfigFile: options.userConfig, profileName: options.profile }, (err, client) => {
182
195
  if (err) {
183
196
  handleError(err);
184
197
  return;
185
198
  }
186
- client.writeVpnConfigTo(vpnId, fs.createWriteStream(fullpath))
187
- .then(() => log.info(fullpath))
188
- .catch(err => handleError(err));
199
+ client.getVpnConfig(vpnId)
200
+ .then(b64 => {
201
+ const vpnConfig = Buffer.from(b64, 'base64');
202
+ log.debug(`Writing config file to ${fullpath}`);
203
+ // Write the config file to the given path
204
+ fs.writeFile(fullpath, vpnConfig, (err) => {
205
+ if (err) {
206
+ handleError(err);
207
+ return;
208
+ }
209
+ log.info(`Config file written to ${fullpath}`);
210
+ });
211
+ }).catch(err => handleError(err));
189
212
  });
190
213
  });
191
214
  program.command('list')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mytmpvpn/mytmpvpn-cli",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "MyTmpVpn CLI",
5
5
  "main": "./dist/mytmpvpn.js",
6
6
  "bin": {
@@ -27,8 +27,8 @@
27
27
  "dependencies": {
28
28
  "commander": "^9.4.1",
29
29
  "loglevel": "^1.8.1",
30
- "@mytmpvpn/mytmpvpn-client": "^2.2.0",
31
- "@mytmpvpn/mytmpvpn-common": "^2.1.0"
30
+ "@mytmpvpn/mytmpvpn-client": "^2.2.1",
31
+ "@mytmpvpn/mytmpvpn-common": "^2.1.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jest": "^29.2.2",
package/src/mytmpvpn.ts CHANGED
@@ -47,6 +47,7 @@ program
47
47
  .option('--appConfig <file>', 'Path to the application config file', getDefaultAppConfigFile())
48
48
  .option('--userConfig <file>', 'Path to the user config file', getDefaultUserConfigFile())
49
49
  .option('--profile <name>', 'Name of the profile in the user config file to use', getDefaultUserProfile())
50
+
50
51
  program.on('option:verbose', function () {
51
52
  log.setDefaultLevel("trace")
52
53
  })
@@ -194,20 +195,30 @@ program.command('get')
194
195
  program.command('download-config')
195
196
  .description('Download configuration of the given vpn to the given file')
196
197
  .argument('<vpnId>', 'vpnId to get config file from')
197
- .option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.tar.gz')
198
+ .option('--file <file>', 'file where the config should be downloaded to. Default is <vpnId>.conf')
198
199
  .option('--path <path>', 'path where the config file should be written to', getDefaultUserConfigDir())
199
200
  .action((vpnId, _, command) => {
200
201
  const options = command.optsWithGlobals()
201
- const file = options.file ? options.file : `${vpnId}.tar.gz`
202
+ const file = options.file ? options.file : `${vpnId}.conf`
202
203
  const fullpath = path.join(options.path, file)
203
204
  auth.getLoggedInClientFromFiles({ appConfigFile: options.appConfig, userConfigFile: options.userConfig, profileName: options.profile }, (err, client) => {
204
205
  if (err) {
205
206
  handleError(err)
206
207
  return
207
208
  }
208
- client.writeVpnConfigTo(vpnId, fs.createWriteStream(fullpath))
209
- .then(() => log.info(fullpath))
210
- .catch(err => handleError(err))
209
+ client.getVpnConfig(vpnId)
210
+ .then(b64 => {
211
+ const vpnConfig = Buffer.from(b64, 'base64')
212
+ log.debug(`Writing config file to ${fullpath}`)
213
+ // Write the config file to the given path
214
+ fs.writeFile(fullpath, vpnConfig, (err) => {
215
+ if (err) {
216
+ handleError(err)
217
+ return
218
+ }
219
+ log.info(`Config file written to ${fullpath}`)
220
+ })
221
+ }).catch(err => handleError(err))
211
222
  })
212
223
  })
213
224
 
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+
3
+ if test $# -ne 1; then
4
+ 1>&2 echo "Usage: $(basename $0) <region ID>"
5
+ exit 1
6
+ fi
7
+
8
+ mytmpvpn="npx @mytmpvpn/mytmpvpn-cli@latest"
9
+
10
+ region=$1
11
+
12
+ # Create VPN and get VPN ID
13
+ vpnId=$(${mytmpvpn} create ${region} --sync | grep vpnId | cut -d \' -f 2)
14
+
15
+ err=$?
16
+ if test $err -ne 0; then
17
+ exit 1
18
+ fi
19
+
20
+ # Get config file
21
+ path_config_file=$(${mytmpvpn} download-config ${vpnId})
22
+
23
+ err=$?
24
+ if test $err -ne 0; then
25
+ exit 1
26
+ fi
27
+
28
+ # De-tar config file
29
+ tar xvf ${path_config_file} --directory $(dirname ${path_config_file})
30
+
31
+ err=$?
32
+ if test $err -ne 0; then
33
+ exit 1
34
+ fi
35
+
36
+ # Get IP address
37
+ old_ip_addr=$(curl ifconfig.me)
38
+
39
+ # Connect to VPN
40
+ sudo wg-quick up ~/.config/mytmpvpn/${vpnId}/mytmpvpn-wg.conf
41
+
42
+ err=$?
43
+ if test $err -ne 0; then
44
+ exit 1
45
+ fi
46
+
47
+ # Test connection
48
+ ping 8.8.8.8 -c 4
49
+
50
+ err=$?
51
+ if test $err -ne 0; then
52
+ exit 1
53
+ fi
54
+
55
+ # Test different IP address
56
+ new_ip_addr=$(curl ifconfig.me)
57
+
58
+ if test "${old_ip_addr}" == "${new_ip_addr}"; then
59
+ 1>&2 echo "external IP address has not changed: old IP ${old_ip_addr} new ${new_ip_addr}"
60
+ exit 1
61
+ fi
62
+ # Test region
63
+
64
+ # disconnect from VPN
65
+ sudo wg-quick down mytmpvpn-wg
66
+ sudo ip link delete mytmpvpn-wg
67
+
68
+ err=$?
69
+ if test $err -ne 0; then
70
+ exit 1
71
+ fi
72
+
73
+ # delete VPN
74
+ ${mytmpvpn} delete ${vpnId}
75
+
76
+ err=$?
77
+ if test $err -ne 0; then
78
+ exit 1
79
+ fi