Fix6
This commit is contained in:
38
index.js
38
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;
|
||||
|
||||
Reference in New Issue
Block a user