Comparing version 1.0.1 to 1.0.2
34
index.js
@@ -6,13 +6,15 @@ import { spawn, exec } from 'node:child_process'; | ||
import chalk from 'chalk'; | ||
export class VpnGot { | ||
export class VPNFetch { | ||
configFile; | ||
loginFile; | ||
verbose; | ||
tableId; | ||
interface; | ||
constructor(configFile, loginFile) { | ||
constructor(configFile, loginFile, verbose = false) { | ||
this.configFile = configFile; | ||
this.loginFile = loginFile; | ||
this.verbose = verbose; | ||
} | ||
async getNewTableId() { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
const command = `ip route show table all | \\ | ||
@@ -27,6 +29,10 @@ grep "table" | \\ | ||
if (err) { | ||
console.log('err', err); | ||
if (this.verbose) { | ||
console.log('err', err); | ||
} | ||
resolve('10'); | ||
} | ||
console.log('stdout', stdout); | ||
if (this.verbose) { | ||
console.log('stdout', stdout); | ||
} | ||
const existingIds = stdout | ||
@@ -44,7 +50,3 @@ .toString() | ||
const __filename = fileURLToPath(import.meta.url); | ||
// 👇️ "/home/john/Desktop/javascript" | ||
const __dirname = path.dirname(__filename); | ||
console.log('directory-name 👉️', __dirname); | ||
// 👇️ "/home/borislav/Desktop/javascript/dist/index.html" | ||
console.log(path.join(__dirname, '/dist', 'index.html')); | ||
return new Promise(async (resolve, reject) => { | ||
@@ -70,7 +72,11 @@ this.tableId = await this.getNewTableId(); | ||
.forEach((line) => { | ||
const data = line.trim(); | ||
console.log('data', data); | ||
const data = line.toString().trim(); | ||
if (this.verbose) { | ||
console.log(data); | ||
} | ||
if (data.toString().includes('[[network interface]]')) { | ||
this.interface = data.toString().split(':')[1]?.trim(); | ||
console.log('data.toString()', data.toString()); | ||
if (this.verbose) { | ||
console.log('Echo from route_up.sh:', data.toString()); | ||
} | ||
console.log(chalk.green(`Sucessfully created VPN interface on ${this.interface}`)); | ||
@@ -82,3 +88,5 @@ } | ||
if (data.toString().includes('Initialization Sequence Completed')) { | ||
console.log(chalk.green(data.toString().trim())); | ||
if (this.verbose) { | ||
console.log('Openvpn completed:', chalk.green(data.toString().trim())); | ||
} | ||
resolve(this); | ||
@@ -85,0 +93,0 @@ } |
34
index.ts
@@ -9,5 +9,9 @@ import { spawn, exec } from 'node:child_process' | ||
interface?: string | ||
constructor(private configFile: string, private loginFile: string) {} | ||
constructor( | ||
private configFile: string, | ||
private loginFile: string, | ||
private verbose = false | ||
) {} | ||
async getNewTableId(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
const command = `ip route show table all | \\ | ||
@@ -22,6 +26,10 @@ grep "table" | \\ | ||
if (err) { | ||
console.log('err', err) | ||
if (this.verbose) { | ||
console.log('err', err) | ||
} | ||
resolve('10') | ||
} | ||
console.log('stdout', stdout) | ||
if (this.verbose) { | ||
console.log('stdout', stdout) | ||
} | ||
const existingIds = stdout | ||
@@ -67,7 +75,12 @@ .toString() | ||
.forEach((line: string) => { | ||
const data = line.trim() | ||
console.log('data', data) | ||
const data = line.toString().trim() | ||
if (this.verbose) { | ||
console.log(data) | ||
} | ||
if (data.toString().includes('[[network interface]]')) { | ||
this.interface = data.toString().split(':')[1]?.trim() | ||
console.log('data.toString()', data.toString()) | ||
if (this.verbose) { | ||
console.log('Echo from route_up.sh:', data.toString()) | ||
} | ||
console.log( | ||
@@ -83,3 +96,8 @@ chalk.green( | ||
if (data.toString().includes('Initialization Sequence Completed')) { | ||
console.log(chalk.green(data.toString().trim())) | ||
if (this.verbose) { | ||
console.log( | ||
'Openvpn completed:', | ||
chalk.green(data.toString().trim()) | ||
) | ||
} | ||
resolve(this) | ||
@@ -86,0 +104,0 @@ } |
{ | ||
"version": "1.0.2", | ||
"devDependencies": { | ||
@@ -13,3 +14,2 @@ "@types/chalk": "^2.2.0", | ||
"type":"module", | ||
"version": "1.0.1", | ||
"description": "Start multiple vpn servers and make network requests through them", | ||
@@ -16,0 +16,0 @@ "main": "index.js", |
@@ -23,13 +23,31 @@ | ||
```js | ||
import { VPNFetch } from 'vpn-fetch' | ||
import { readdir } from 'fs/promises' | ||
(async ()=>{ | ||
const configFiles = await readdir('/etc/openvpn/ovpn_tcp') | ||
const randomConfig = configFiles[Math.floor(Math.random() * configFiles.length)] | ||
const randomConfig1 = configFiles[Math.floor(Math.random() * configFiles.length)] | ||
const vpnFetch = new VPNFetch( | ||
'/etc/openvpn/ovpn_tcp/' + randomConfig, | ||
const vpnFetch1 = new VPNFetch( | ||
'/etc/openvpn/ovpn_tcp/' + randomConfig1, | ||
'./login_information' | ||
) | ||
await vpnFetch.connect() | ||
const response = await vpnFetch.get('https://ifconfig.me/ip') | ||
console.log('IP:', response.body) | ||
await vpnFetch1.connect() | ||
const randomConfig2 = configFiles[Math.floor(Math.random() * configFiles.length)] | ||
const vpnFetch2 = new VPNFetch( | ||
'/etc/openvpn/ovpn_tcp/' + randomConfig2, | ||
'./login_information' | ||
) | ||
await vpnFetch2.connect() | ||
const response1 = await vpnFetch1.get('https://ifconfig.me/ip') | ||
console.log('IP 1:', response1.body) | ||
const response2 = await vpnFetch2.get('https://ifconfig.me/ip') | ||
console.log('IP 2:', response2.body) | ||
})() | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22886
328
53