This commit is contained in:
2023-06-25 14:20:15 +02:00
parent 8e439a0e68
commit 93bac87ae1
3 changed files with 10 additions and 107 deletions

View File

@@ -1,5 +1,4 @@
const { execSync } = require('child_process');
const { get } = require('./modules/fetchHandler');
const fs = require('node:fs');
const os = require('os');
@@ -26,7 +25,7 @@ async function consoleLog(message, type) {
};
try {
const response = await fetch(webhook, {
await fetch(webhook, {
method: 'POST',
headers: {
'Accept': 'application/json',
@@ -34,13 +33,6 @@ async function consoleLog(message, type) {
},
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);
@@ -79,7 +71,15 @@ async function vpnConnect(vpnName) {
await sleep(1000);
}
else {
const ip = await get('https://api.ipify.org');
const response = await fetch('https://api.ipify.org', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
});
const ipResponse = await response.json();
const ip = ipResponse.data;
consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip.data}).`, 'info');
return 0;
}

View File

@@ -1,71 +0,0 @@
const fetch = (...args) => import('node-fetch').then(({ default: fth }) => fth(...args));
const { error } = require('./logHandler');
async function get(url, token = 'none') {
const options = {
method: 'GET',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
};
return await fetch(url, options)
.then(res => res.json())
.then(json => {
return json;
})
.catch(err => error(err));
}
async function post(url, body, token = 'none') {
const options = {
method: 'POST',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
};
return await fetch(url, options)
.then(res => res.json())
.then(json => {
return json;
})
.catch(err => error(err));
}
async function patch(url, body, token = 'none') {
const options = {
method: 'PATCH',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
};
return await fetch(url, options)
.then(res => res.json())
.then(json => {
return json;
})
.catch(err => error(err));
}
async function put(url, body, token = 'none') {
const options = {
method: 'PUT',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
};
return await fetch(url, options)
.then(res => res.json())
.then(json => {
return json;
})
.catch(err => error(err));
}
module.exports = {
get,
post,
patch,
put,
};

View File

@@ -1,26 +0,0 @@
const pino = require('pino');
const logger = pino();
function log(x) {
logger.info(x);
}
function debug(x) {
logger.debug(x);
}
function warn(x) {
logger.warn(x);
}
function error(x) {
logger.error(x);
}
module.exports = {
log,
debug,
warn,
error,
};