Commit ace3acd9 authored by Ahmad Nemati's avatar Ahmad Nemati

sds

parents
Pipeline #19 failed with stages
{
"name": "untitled25",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"node-cron": "^2.0.3",
"request": "^2.88.0",
"shelljs": "^0.8.3"
}
}
addIp()
function addIp() {
const request = require('request');
let url = 'http://127.0.0.1:3000/start/'
return new Promise(function (resolve, reject) {
request(url, {timeout: 15000}, function (error, res, body) {
resolve(body)
});
});
}
const cron = require('node-cron');
const notWork = require('node-cron');
let express = require('express');
let app = express();
let server = require('http').createServer(app);
let enable = true
let base=3
const shell = require('shelljs')
cron.schedule(' */1 * * * * *', () => {
if (enable) {
console.log('Cpu: ' + randomInt(1, 5) + ' Ram:' + randomInt(1, 10))
}
});
function runDisablePing()
{
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;
}
notWork.schedule(' */1 * * * * *', () => {
if (!enable) {
if (base >100)
{
runDisablePing()
return
}
base=base+5
console.log('Cpu: ' + randomInt(base > 100 ? 100 : base, base > 100 ? 100 : base+5) + ' Ram:' + randomInt(base > 100 ? 100 : base, base > 100 ? 100 : base+5))
}
});
server.listen(3000, () => {
})
app.get('/', (req, res) => {
if (enable)
res.send('server is up!!')
})
app.get('/start', (req, res) => {
enable=false
res.send('ok')
})
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low) + low)
}
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