2 module.exports.IpBanCollecion = function()
4 var config = require("./configure.js");
5 var MySQLPool = new require("./mysql_pool.js");
6 var pool = new MySQLPool({
9 password : config.db_password,
10 port : config.db_port,
11 database : config.db_name,
14 this.IsBaned = function(ip){
15 return collection[ip] == "r";
17 this.IsBlockedToWrite = function(ip){
18 return ip in collection;
20 this.GetText = function(){
22 for(var key in collection)
24 if(collection[key] == "")
27 text += key + ":" + collection[key] + "\r\n";
31 this.Update = function(text,callfunc){
33 var async = require("async");
36 pool.query("TRUNCATE TABLE ipbanlist",null,next);
38 function(result,next){
39 var items = new Array();
40 lines = text.split("\r\n");
41 for(var i = 0; i < lines.length; i++)
43 var token = lines[i].split(":");
50 collection[ip] = token[1];
51 items.push(new Array(ip,collection[ip]));
53 pool.query("INSERT INTO ipbanlist VALUES ?",[items],next);
57 function GetIpBanList(callfunc)
59 var async = require("async");
62 pool.query("SELECT * FROM ipbanlist",null,next);
64 function(result,next){
65 for(var i = 0; i < result.length; i++)
66 collection[result[i].ip] = result[i].type;