File size: 5,739 Bytes
59485cb 3c60980 59485cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
'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.config = config;
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);
//console.log(req.hostname)
next();
});
app.post('/')
app.get("/apikey",api.index);
app.use(express.static(__dirname+'/webpage/public'));
/*app.use(
helmet.contentSecurityPolicy({
useDefaults: true,
directives: {
"img-src": ["'self'", "https: data:"]
}
})
)*/
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"});
}
// res.status(200);
//next();
return res.redirect(fLink.url);
}
})
app.get('/', function(req, res) {
//res.set("Content-Security-Policy", "default-src 'self'");
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 });
});
///////////////////////////////////////////////////////////
//========= Create website for dashboard/uptime =========//
///////////////////////////////////////////////////////////
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");
// bank
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));
});
};
// --------------------------> END <-------------------------------// |