From d58c4599b328c7b7230ffc83daf6473f9cd99816 Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Sun, 25 Jun 2023 14:11:35 +0200 Subject: [PATCH] Fix6 --- index.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 283829b..7b8dca4 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const { execSync, exec } = require('child_process'); +const { execSync } = require('child_process'); const { get } = require('./modules/fetchHandler'); const fs = require('node:fs'); const os = require('os'); @@ -20,7 +20,31 @@ async function consoleLog(message, type) { if (process.env.MCR_BOT_WEBHOOK) { const webhook = process.env.MCR_BOT_WEBHOOK; const botUsername = `m${process.env.MCR_BOT_WEBHOOK_NAME}`; - exec(`curl --silent -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{"content": "${message}", "username": "${botUsername}"}" "${webhook}"`); + const payload = { + content: message, + username: botUsername, + }; + + try { + const response = await fetch(webhook, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }); + + if (response.ok) { + console.log('Webhook message sent successfully.'); + } + else { + console.log('Failed to send webhook message:', response.status, response.statusText); + } + } + catch (error) { + console.log('Error sending webhook message:', error.message); + } } } @@ -49,7 +73,15 @@ async function vpnConnect(vpnName) { try { await execSync(`nmcli connection up "${vpnName}"`); - if (await execSync('nmcli connection show --active').toString().includes(vpnName) == true) { + const status = await execSync('nmcli connection show --active').toString().includes(vpnName); + if (!status) { + console.log('Not connected!'); + } + else { + console.log('Connected!'); + } + + if (status == true) { const ip = await get('https://api.ipify.org'); consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip.data}).`, 'info'); return 0;