Commit dbe6f6e5 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent cde34922
Pipeline #46 failed with stages
......@@ -30,16 +30,9 @@ app.get('/test', (req, res) => {
})
async function addNewIp(req, res) {
res.send('Hello World!')
console.log(req.params.ip)
addBaship(req.params.ip)
}
async function addBaship(ip) {
return await shell.exec(' ip addr add ' + ip + ' dev eth0').stderr;
}
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
......@@ -65,95 +58,35 @@ cron.schedule('*/10 * * * * *', () => {
postRequest()
cronRemover.schedule(' */1 * * * *', () => {
remover()
postRequest()
});
async function remover() {
let work = await getWork()
if (work === 'false') {
let ip = await getIp()
console.log(ip)
var contents = await fs.readFileSync('./token.txt', 'utf8');
let Hetzner = require('./Hetzner')
let het = new Hetzner(contents)
await het.removeByIp(ip)
}
return true
}
function getWork() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/work/'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
function addIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/add/'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
function postRequest() {
function getIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getIp/'
let url = 'http://admin.fcfglobal.co:3000/addOvhIp/'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
function postRequest() {
let data = {generation: generation, groups: groups}
data = JSON.stringify(data)
data = cryptLib.encryptPlainTextWithRandomIV(data, key)
var options = {
method: 'POST',
url: 'http://admin.fcfglobal.co:3000/addIp',
headers: {'content-type': 'application/x-www-form-urlencoded'},
body: 'data=' + Buffer.from(data).toString('base64')
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (error)
console.log(error)
resolve(true)
});
});
}
async function calculateSpeed() {
let d = await shellExec('vnstat -tr')
let d = await shellExec('vnstat -i ens3 -tr')
d = d.stdout
d = d.match(decimalPointRegex)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment