const http = require('http'); const url = require('url'); const fs = require('fs'); const querystring = require('querystring'); const service = require('./core.js');

const current_attacks = []; const list_attacks = [];

const server = http.createServer(function (req, res) { const parsedUrl = url.parse(req.url); const path = parsedUrl.pathname;

if (path === '/') { fs.readFile(__dirname + '/html/index.html', function (err, data) { if (err) { res.writeHead(500, { 'Content-Type': 'text/plain' }); res.end('Error loading index.html'); } else { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(data); } }); } else if (path === '/attack') { const { number, loops } = querystring.parse(parsedUrl.query); if (!Number(number) || number.toString().length < 11) { return res.end(JSON.stringify({ "success": false, "text": Номер телефона не указан либо не является корректным })); } if (!Number(loops) || !loops) { return res.end(JSON.stringify({ "success": false, "text": Параментр loop отсутсвует либо не является корректным })); } else { count = 0; list_attacks.push({ number: Number(number), loop: Number(loops), startedAt: Date.now() }); service.start(number); current_attacks[number] = setInterval(async function () { service.start(number); count++; if (count == loops - 1) { clearInterval(current_attacks[number]); for (let key in list_attacks) { if (list_attacks[key].number == number) { list_attacks.splice(key, 1); } } } }, 30000); return res.end(JSON.stringify({ "success": true, "text": Атака на номер +${number} успешно запущена })); } } else if (path === '/stop') { const { number } = querystring.parse(parsedUrl.query); if (number) { if (current_attacks[number]) { clearInterval(current_attacks[number]); for (let key in list_attacks) { if (list_attacks[key].number == number) { list_attacks.splice(key, 1); } } res.end(JSON.stringify({ success: true, text: Атака на номер +${number} успешно прекращена })); } else { return res.end(JSON.stringify({ success: false, text: Нет активных атак по номеру +${number} })); } } else { return res.end(JSON.stringify({ success: false, text: Параментр number не указал либо не является корректным })); } } else if (path === '/list') { if (list_attacks.length === 0) { result = { success: false, text: Список активных атак пуст } return res.end(JSON.stringify(result)); } else { result = { success: true, result: list_attacks } return res.end(JSON.stringify(result)); } } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('404 Not Found'); } });

const port = process.env.PORT || 3000;

server.listen(port, function () { console.log([INFO] Server started on ${port}); if (process.platform === 'darwin') { open(http://localhost:${port}/); } else if (process.platform === 'win32') { open(http://localhost:${port}/); } });

Сделай этот код без использования сторонних библиотек const express = requireexpress;const arguments = requireyargsargv;const open = requireopen;const service = requirecorejs;const current_attacks = ;

原文地址: https://www.cveoy.top/t/topic/bG2T 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录