|
'use strict'; |
|
var starttime = new Date().getTime(); |
|
const express = require("express"); |
|
const cors = require("cors"); |
|
const fs = require("fs-extra"); |
|
const helmet = require("helmet"); |
|
const server = require("./server.js"); |
|
const app = express(); |
|
const rateLimit = require("express-rate-limit"); |
|
const getIP = require('ipware')().get_ip; |
|
const checkIPBlocked = require('./blockIp.js'); |
|
const axios = require('axios'); |
|
const blockedIPs = JSON.parse(fs.readFileSync('./blockedIP.json', { encoding: 'utf-8' })); |
|
const checkAPI = require("./public/API_KEY/data/checkKey.js"); |
|
const api = require("./public/API_KEY/data/api_key.js"); |
|
const APIKEY = require("./public/API_KEY/data/data_apikey.json"); |
|
|
|
global.checkAPI = checkAPI.checkKey |
|
|
|
global.APIKEY = APIKEY; |
|
|
|
const handleBlockIP = rateLimit({ |
|
windowMs: 60 * 1000, |
|
max: 100, |
|
handler: function (req, res, next) { |
|
const ipInfo = getIP(req); |
|
const ip = ipInfo.clientIp; |
|
if (!blockedIPs.includes(ip)) { |
|
blockedIPs.push(ip); |
|
fs.writeFileSync('./blockedIP.json', JSON.stringify(blockedIPs, null, 2)); |
|
console.log(`[ RATE LIMIT ] → Đã block IP: ${ip}`); |
|
} |
|
next(); |
|
} |
|
}); |
|
app.use(handleBlockIP); |
|
app.use(checkIPBlocked); |
|
app.use(helmet()); |
|
app.use(express.json()); |
|
app.use(cors()); |
|
app.use(function(req, res, next) { |
|
var ipInfo = getIP(req); |
|
var color = ["\x1b[31m", "\x1b[32m", "\x1b[33m", '\x1b[34m', '\x1b[35m', '\x1b[36m', '\x1b[37m', "\x1b[38;5;205m", "\x1b[38;5;51m", "\x1b[38;5;197m", "\x1b[38;5;120m", "\x1b[38;5;208m", "\x1b[38;5;220m", "\x1b[38;5;251m"]; |
|
var more = color[Math.floor(Math.random() * color.length)]; |
|
console.log(more + '[ IP ] → ' + ipInfo.clientIp + ' - Đã yêu cầu tới folder:' +req.url); |
|
|
|
next(); |
|
}); |
|
app.post('/') |
|
app.get("/apikey",api.index); |
|
|
|
app.use(express.static(__dirname+'/webpage/public')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/go', async (req, res, next) => { |
|
|
|
const path = require('path').join(__dirname, '/public/toolsbot/data/data.json'); |
|
var database =require(__dirname+'/public/toolsbot/data/data.json'); |
|
|
|
const { id } = req.query; |
|
if(!id) return res.json({ error: 'thiếu dữ liệu!'} ); |
|
if(id) { |
|
const fLink = database.find(i => i.id == id); |
|
if(fLink == undefined) { |
|
return res.json({error:"cannot find link"}); |
|
} |
|
|
|
|
|
return res.redirect(fLink.url); |
|
} |
|
|
|
}) |
|
|
|
app.get('/', function(req, res) { |
|
|
|
res.sendFile(__dirname + '/webpage/index.html'); |
|
|
|
}).listen(app.get('port'), function() { |
|
console.log('\x1b[36m=====================================================\n\x1b[38;5;220m[ START ] \x1b[33m→\x1b[38;5;119m Máy chủ đang chạy trên PORT\x1b[38;5;208m', app.get('port'), '\n\x1b[36m=====================================================\n'); |
|
}); |
|
|
|
app.use(function (req, res, next) { |
|
|
|
var d = req.query.apikey |
|
var c=checkAPI.checkKey(d); |
|
|
|
|
|
if (c.error == 1) return res.json({error:`${c.msg}`}) |
|
|
|
next(); |
|
}); |
|
|
|
app.use("/", server); |
|
app.set("json spaces", 4); |
|
app.use((error, req, res, next) => { |
|
res.status(error.status).json({ message: error.message }); |
|
}); |
|
|
|
|
|
|
|
async function upts() { |
|
const link = "https://29b9b42f-46e6-461b-8986-914334265f7c-00-2k4h2stdmewpp.teams.replit.dev/"; |
|
try { |
|
await axios.get(link) |
|
console.log("- monitoring...[ UPTPAGE ]") |
|
} catch(e) {console.log(e)} |
|
} |
|
setInterval(upts,60000) |
|
async function haha() |
|
{ |
|
const vid = await axios.get(`https://megu-4.haimothaihai.repl.co/anime-video`); |
|
const vidlink = vid.data.url; |
|
console.log("request: megu-4") |
|
} |
|
setInterval(haha, 60*1000*60*10); |
|
app.set('port', (process.env.PORT || 7860)); |
|
|
|
|
|
var totaltime = (new Date().getTime() - starttime)/1000; |
|
console.log("\x1b[38;5;220m[ LOADING ] \x1b[33m→\x1b[35m Thời gian khởi động: "+Math.round(totaltime*100)/100+" ms"); |
|
console.log("\x1b[38;5;205m[ RAIDEN API ] \x1b[33m→\x1b[38;5;51m Khởi động API của TuanDz thành công"); |
|
|
|
async function bank() { |
|
const { writeFileSync } = require('fs-extra'); |
|
const { join } = require('path'); |
|
const pathData = join(__dirname, "public", "bank", "data", "bank.json"); |
|
const user = require('./public/bank/data/bank.json'); |
|
if(user[0] == undefined ) return |
|
while(true) { |
|
for (let id of user) { |
|
var userData = user.find(i => i.senderID == id.senderID); |
|
var money = userData.data.money; |
|
userData.data.money = parseInt(money) + parseInt(money) * 0.005 |
|
writeFileSync(pathData, JSON.stringify(user, null, 2)); |
|
} |
|
console.log("\x1b[38;5;220m[ BANKING ] \x1b[33m→ \x1b[35mĐang trong quá trình xử lí banking ..."); |
|
await new Promise(resolve => setTimeout(resolve, 60 * 60 * 1000)) |
|
} |
|
} |
|
bank() |
|
const { spawn, execSync, exec } = require("child_process"); |
|
function startBot(message) { |
|
(message) ? console.log(message) : ""; |
|
|
|
const child = spawn("node main.js", { |
|
cwd: __dirname, |
|
stdio: "inherit", |
|
shell: true |
|
}); |
|
|
|
child.on("close", (codeExit) => { |
|
if (codeExit != 0 || global.countRestart && global.countRestart < 5) { |
|
startBot("Restarting..."); |
|
global.countRestart += 1; |
|
return; |
|
} else return; |
|
}); |
|
|
|
child.on("error", function (error) { |
|
console.log("An error occurred: " + JSON.stringify(error)); |
|
}); |
|
}; |
|
|
|
|