Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > TinyBrain | #1009210 - Block/Unblock IP Bot

JavaX source code [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Libraryless. Click here for Pure Java version (3649L/23K/79K).

!7

p {
  doEvery(10*60*1000, f subBot_cleanBlockedIPs);
}

svoid subBot_cleanBlockedIPs {
  Collection c = (Collection) get(mainBot(), "blockedIPs");
  int n = l(c);
  if (n != 0) {
    clear(c);
    print("Cleared " + n2(n, "blocked IP"));
  }
}

answer {
  if (!webAuthed()) null;
  if "block ip *" {
    call(mainBot(), "addBlockedIP", assertIPv4($1));
    ret "OK";
  }
  
  if "unblock ip *" {
    call(mainBot(), "removeBlockedIP", assertIPv4($1));
    ret "OK, blocked IPs now: " + askSelf("blocked ips");
  }
  
  if "blocked ips"
    ret structForUser(cloneList((Collection) get(mainBot(), "blockedIPs")));

  if "bad clients"
    ret str(subBot_numStalledConnections());
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1009210
Snippet name: Block/Unblock IP Bot
Eternal ID of this version: #1009210/10
Text MD5: 2b96fe7971048ffc904762da19b3ed60
Transpilation MD5: a1e10cc9515fa733f6781d1a1208067f
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-28 16:49:57
Source code size: 715 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 92 / 1293
Version history: 9 change(s)
Referenced in: [show]