• banTool

    From Thanatoz@VERT/SKULLKP to All on Tue Jul 29 20:21:45 2014
    So I wrote a script that auto-expires the bans in ip.can and ip-silent.canãit is called banTool and you pass it the days for the ban to last and theãfile(full path) and it will scan it and throw some comments in the file forã"book keeping". I have it set to run at 00:01 each day and I have seen noãproblems yet.ã(I would just check out to make sure that the permanent ban line is up nearãthe top of the file after the first run)ãIt runs fine as both a native event or with slightly fancier display fromãjsexecãããDo you see any tweaks or anything wrong with it?ããThanatozãããbanTool.jsããvar fileName;ãvar after;ãvar canFile;ãvar file = [];ãvar permanent = false;ãvar expires = [];ãvar currentExpire;ãvar now = strftime("%y-%j", time());ãvar label = "; banTool: ";ããif(typeof server == "undefined")ã{ã writeln("\n\n\n\n\n");ã writeln(" @ @@@@@ @ ");ã writeln(" @ @ @ ");ã writeln(" @ @ @ ");ã writeln(" @@@@ @@@ @ @ @@ @ @@@ @@@ @ ");ã writeln(" @ @ @ @@ @@ @ @ @ @ @ @ @ ");ã writeln(" @ @ @ @@ @ @ @ @ @ @ @ @ ");ã writeln(" @@@@ @@@ @ @ @ @ @@@ @@@ @ ");ã}ãelseã{ ã writeln("banTool started");ã}ããif( argv[0] === undefined || argv[1] === undefined)ã{ã writeln("\n Proper usage is bantool.js ## drive:\path\filename.can");ã writeln(" ## is how long this current bunch of bans are to last");ã writeln(" file is the full path and file name of the file to beãtrimmed");ã writeln("\n This utility will only run once per day and is reccomendedãto run at 00:01");ã exit(255);ã}ãelse ã{ã after = argv[0];ã fileName = argv[1];ã canFile = new File(fileName);ã if (!canFile.exists)ã {ã writeln("\n Please supply the name of a can file that exists orãthe full path and file name to the file");ã exit(254);ã }ã}ãã// Read in the can fileãwriteln("\n Starting processing on "+fileName+"\n\n");ãcanFile.open("r+");ãfile = canFile.readAll();ãcanFile.close();ãã// Scan the can file and set the expiresãcurrentExpire = argv[0];ãfor(var i = file.length - 1; i >= 0; i--)ã{ã if( file[i].charAt(0) != ";" )ã {ã // do nothing as not a commentã }ã else if( file[i].indexOf(label+"Permanent") === 0 )ã {ã permanent = true;ã currentExpire = -1;ã }ã else if(file[i].indexOf(label+"Last ran on") === 0 ) // Do nothing ifãalready ran todayã {ã var last = file[i].match(/\d\d\-\d+/i).toString();ã if ( now === last )ã {ã writeln("\n "+fileName+" has already been trimmedãtoday.\n\nThis script will now exit");ã exit(0);ã }ã elseã {ã file[i] = label + "bans above will expire in "+after+ "ãdays.";ã currentExpire = after;ã }ã }ã else if( file[i].indexOf(label + "bans above will expire in") === 0)ã {ã currentExpire = parseInt(file[i].match(/\d+/i)) -1 ;ã file[i] = label + "bans above will expire in "+currentExpire+ "ãdays.";ã }ã elseã {ã // some other comments.ã }ã expires[i] = currentExpire;ã}ããfile[file.length] = " ";ãexpires[expires.length] = -2;ããwriteln("\n Starting writing out new file version.\n");ãcanFile.open("w");ãvar firstNonComment;ãfor(var i = 0; i < file.length; i++)ã{ã if(!permanent && firstNonComment === undefined && file[i].charAt(0) ===ã";")ã {ã if( file[i].indexOf("FAHKS") >=0 ||ã file[i].indexOf(label) >=0 ||ã file[i].indexOf("HTTP Scan") >= 0 )ã {ã firstNonComment = i;ã }ã else if (file[i+1].charAt(0) === ";")ã {ã
    // do nothingã }ã elseã {ã firstNonComment = i+1;ã }ã }ã ã if(expires[i] === -1 )ã {ã canFile.writeln(file[i]);ã }ã else if (!permanent && firstNonComment === i)ã {ã canFile.writeln(label + "Permanent bans go above this line");ã if(expires[i] > 0)ã canFile.writeln(file[i]);ã }ã else if (expires[i] > 0)ã {ã canFile.writeln(file[i]);ã }ã ã}ãcanFile.writeln(label +"Last ran on " + now);ãcanFile.close();ãã---ã þ Synchronet þ From the ashes the dreaded Skull Keep arises again. skullkp.synchro.netã