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

57
LINES

< > BotCompany Repo | #1009210 // Block/Unblock IP Bot

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

Libraryless. Click here for Pure Java version (4494L/30K/101K).

!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"));
  }
}

html {
  if (!webAuthed(params)) ret "Not authed";
  ret subBot_serveText(answer_privileged(params.get('q)));
}

sS answer(S s) {
  if (!webAuthed()) null;
  ret answer_privileged(s);
}

sS answer_privileged(S s) {
  new Matches m;
  
  if "block ip *" {
    call(mainBot(), "addBlockedIP", assertIPv4($1));
    ret "OK";
  }
  
  if "unblock all ips" {
    clear((Collection) get(mainBot(), "blockedIPs"));
    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());
    
  if "whitelist ip *" {
    Cl<S> whiteList = cast get(mainBot(), "whiteListedIPs");
    add(whiteList, assertIPv4($1));
    ret "OK, white listed IPs now: " + whiteList;
  }
  
  null; 
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009210
Snippet name: Block/Unblock IP Bot
Eternal ID of this version: #1009210/17
Text MD5: ebbee2e9a9def68fd3fcc0ad5a0c3821
Transpilation MD5: b512fb5b97bf1ce8441a276fefafe412
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-26 15:46:21
Source code size: 1231 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 502 / 4394
Version history: 16 change(s)
Referenced in: [show references]