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).

1  
!7
2  
3  
p {
4  
  doEvery(10*60*1000, f subBot_cleanBlockedIPs);
5  
}
6  
7  
svoid subBot_cleanBlockedIPs {
8  
  Collection c = (Collection) get(mainBot(), "blockedIPs");
9  
  int n = l(c);
10  
  if (n != 0) {
11  
    clear(c);
12  
    print("Cleared " + n2(n, "blocked IP"));
13  
  }
14  
}
15  
16  
html {
17  
  if (!webAuthed(params)) ret "Not authed";
18  
  ret subBot_serveText(answer_privileged(params.get('q)));
19  
}
20  
21  
sS answer(S s) {
22  
  if (!webAuthed()) null;
23  
  ret answer_privileged(s);
24  
}
25  
26  
sS answer_privileged(S s) {
27  
  new Matches m;
28  
  
29  
  if "block ip *" {
30  
    call(mainBot(), "addBlockedIP", assertIPv4($1));
31  
    ret "OK";
32  
  }
33  
  
34  
  if "unblock all ips" {
35  
    clear((Collection) get(mainBot(), "blockedIPs"));
36  
    ret "OK";
37  
  }
38  
  
39  
  if "unblock ip *" {
40  
    call(mainBot(), "removeBlockedIP", assertIPv4($1));
41  
    ret "OK, blocked IPs now: " + askSelf("blocked ips");
42  
  }
43  
  
44  
  if "blocked ips"
45  
    ret structForUser(cloneList((Collection) get(mainBot(), "blockedIPs")));
46  
47  
  if "bad clients"
48  
    ret str(subBot_numStalledConnections());
49  
    
50  
  if "whitelist ip *" {
51  
    Cl<S> whiteList = cast get(mainBot(), "whiteListedIPs");
52  
    add(whiteList, assertIPv4($1));
53  
    ret "OK, white listed IPs now: " + whiteList;
54  
  }
55  
  
56  
  null; 
57  
}

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: 505 / 4399
Version history: 16 change(s)
Referenced in: [show references]