• banTool

    From Thanatoz@VERT/SKULLKP to All on Tuesday, July 29, 2014 20:21:45
    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