Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const crypto = require('crypto');
|
||||
module.exports = {
|
||||
name:"banHandler",
|
||||
check: async function(req){
|
||||
return new Promise(async (resolve,reject) => {
|
||||
let hash = req.headers["cf-connecting-ip"] == undefined ? crypto.createHash('md5').update("localhost").digest('hex') : crypto.createHash('md5').update(req.headers["cf-connecting-ip"]).digest('hex')
|
||||
let ban = await commands.get("query").function("SELECT idBan from tbl_bans WHERE dtIpHash = ?",[hash])
|
||||
if(ban.length == 0){
|
||||
resolve()
|
||||
return
|
||||
}else{
|
||||
reject()
|
||||
return
|
||||
}
|
||||
})
|
||||
},
|
||||
ban: async function(req){
|
||||
if(req.headers["cf-connecting-ip"] != undefined){
|
||||
if(config.banhandler.whitelisted.includes(req.headers["cf-connecting-ip"]))
|
||||
return
|
||||
}
|
||||
let hash = req.headers["cf-connecting-ip"] == undefined ? crypto.createHash('md5').update("localhost").digest('hex') : crypto.createHash('md5').update(req.headers["cf-connecting-ip"]).digest('hex')
|
||||
await commands.get("query").function("INSERT INTO tbl_bans (dtIpHash,dtTimestamp) VALUES (?,?)",[hash, new Date().getTime()])
|
||||
ignorelist[hash] = hash
|
||||
},
|
||||
unban: async function(hash){
|
||||
await commands.get("query").function("DELETE FROM tbl_bans WHERE dtIpHash = ?",[hash])
|
||||
delete ignorelist[hash]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user