diff --git a/index.js b/index.js index 5d0f402..283829b 100644 --- a/index.js +++ b/index.js @@ -47,18 +47,14 @@ async function vpnConnect(vpnName) { const maxAttempts = process.env.RETRIES; for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { - execSync(`nmcli connection up "${vpnName}"`); + await execSync(`nmcli connection up "${vpnName}"`); - const status = await execSync('nmcli connection show --active') - .toString() - .includes(vpnName); - console.log('Is connected: ' + status); - if (status == true) { + if (await execSync('nmcli connection show --active').toString().includes(vpnName) == true) { const ip = await get('https://api.ipify.org'); consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip.data}).`, 'info'); return 0; } - else if (status == false) { + else { consoleLog(`[${host}] Failed to connect to VPN: ${vpnName}. Retrying (attempt ${attempt} of ${maxAttempts})...`, 'error'); await sleep(1000); }