Commit bcba4f10 authored by Ahmad Nemati's avatar Ahmad Nemati

jkjk

parent c384f33d
let groups = 0
let generation = 0
const express = require('express') const express = require('express')
const app = express() const app = express()
const port = 3000 const port = 4000
const shell = require('shelljs') const shell = require('shelljs')
const cron = require('node-cron'); const cron = require('node-cron');
const cronRemover = require('node-cron'); const cronRemover = require('node-cron');
const request = require('request');
const fs = require('fs') const fs = require('fs')
const cronSpeed = require('node-cron'); const cronSpeed = require('node-cron');
const shellExec = require('shell-exec') const shellExec = require('shell-exec')
...@@ -12,6 +15,8 @@ app.get('/', (req, res) => { ...@@ -12,6 +15,8 @@ app.get('/', (req, res) => {
res.send('Hello World!') res.send('Hello World!')
run() run()
}) })
const cryptLib = require('@skavinvarnan/cryptlib');
const key = "6*sN_rZxHD4!X$=T";
app.get('/ip/:ip/', (req, res) => { app.get('/ip/:ip/', (req, res) => {
// console.log(req.params.acc) // console.log(req.params.acc)
...@@ -36,12 +41,12 @@ async function addBaship(ip) { ...@@ -36,12 +41,12 @@ async function addBaship(ip) {
} }
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) //app.listen(port, () => console.log(`Example app listening on port ${port}!`))
async function run() { async function run() {
let a = await shell.exec('cd .. && cd mt && sudo ./server1.sh', {silent: true}).stdout; let a = await shell.exec('cd .. && cd mt && sudo ./server1.sh', {silent: true}).stdout;
// await shell.exec('iptables -A INPUT -s 95.156.255.148 -p ICMP --icmp-type 8 -j ACCEPT && iptables -A INPUT -p ICMP --icmp-type 8 -j DROP', {silent: true}).stdout; // await shell.exec('iptables -A INPUT -s 95.156.255.148 -p ICMP --icmp-type 8 -j ACCEPT && iptables -A INPUT -p ICMP --icmp-type 8 -j DROP', {silent: true}).stdout;
console.log('Reset Proxy') console.log('Reset Proxy')
} }
...@@ -57,11 +62,11 @@ cron.schedule('*/10 * * * * *', () => { ...@@ -57,11 +62,11 @@ cron.schedule('*/10 * * * * *', () => {
checkProcessWork() checkProcessWork()
}); });
postRequest()
cronRemover.schedule(' */1 * * * *', () => { cronRemover.schedule(' */1 * * * *', () => {
remover() remover()
addIp() postRequest()
}); });
...@@ -102,6 +107,7 @@ function addIp() { ...@@ -102,6 +107,7 @@ function addIp() {
}); });
}); });
} }
function getIp() { function getIp() {
...@@ -116,6 +122,30 @@ function getIp() { ...@@ -116,6 +122,30 @@ function getIp() {
} }
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() { async function calculateSpeed() {
...@@ -126,7 +156,6 @@ async function calculateSpeed() { ...@@ -126,7 +156,6 @@ async function calculateSpeed() {
d = d.match(decimalPointRegex) d = d.match(decimalPointRegex)
if (d.includes('kbit/s')) { if (d.includes('kbit/s')) {
d[0] = 1 d[0] = 1
d[1] = 1 d[1] = 1
...@@ -162,6 +191,6 @@ function sendRate(rx, tx) { ...@@ -162,6 +191,6 @@ function sendRate(rx, tx) {
cronSpeed.schedule(' */5 * * * * *', () => { cronSpeed.schedule(' */5 * * * * *', () => {
calculateSpeed() calculateSpeed()
}); });
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"start": "node ./bin/www" "start": "node ./bin/www"
}, },
"dependencies": { "dependencies": {
"@skavinvarnan/cryptlib": "^1.0.3",
"express": "~4.16.0", "express": "~4.16.0",
"hcloud-js": "^1.2.0", "hcloud-js": "^1.2.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
......
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