Commit e962c8e2 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 9bebf2df
......@@ -7,7 +7,7 @@ const cronOne = require('node-cron');
const cronSpeed = require('node-cron');
const shellExec = require('shell-exec')
var decimalPointRegex = /\-?\d+\.\d+/g;
let fs=require('fs')
let port = 5
......@@ -58,6 +58,8 @@ app.listen(3000, () => console.log(`Example app listening on port 3000!`))
async function run() {
let whiteIp=await getWhiteIp()
let portRes = await getPort()
if (portRes === '0' || portRes === '443')
port = randomInt(4000, 60000)
......@@ -67,6 +69,41 @@ async function run() {
console.log('Reset Proxy')
}
async function doIptable(whiteIp)
{
let command=''
for (let i=0;i<whiteIp.length;i++)
{
command +='iptables -A INPUT -p tcp -s '+whiteIp[i]+' --dport 3000 -j ACCEPT'
command+='\n'
command +='iptables -A INPUT -p tcp -s '+whiteIp[i]+' --dport 22 -j ACCEPT'
command+='\n'
}
command+='iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 3000 -j DROP'
command+='\n'
command+='iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 22 -j DROP'
await createfile(command)
await execLast()
return true
}
function createfile(command) {
return new Promise(function (resolve, reject) {
fs.writeFile("iptable.sh", command, 'utf8', function (err) {
if (err) reject(err);
else resolve(command);
});
});
}
async function execLast() {
let d = await shellExec('sudo ./iptable.sh')
return true
}
async function checkProcessWork() {
let a = await shell.exec('nc -vz 127.0.0.1 ' + port).stderr;
if (a.includes('succeeded')) {
......@@ -147,6 +184,18 @@ function getPort() {
}
function getWhiteIp() {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/getWhiteIp'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(JSON.parse(body))
});
});
}
cronSpeed.schedule(' */5 * * * * *', () => {
......
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