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

50
LINES

< > BotCompany Repo | #1002590 // Web Auth Bot (LIVE)

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

Libraryless. Click here for Pure Java version (5722L/37K/124K).

1  
!7
2  
3  
static new L<S> authorizedDialogIDs;
4  
5  
p {
6  
  load("authorizedDialogIDs");
7  
}
8  
9  
static S html(S subUri, Map<S, S> params) {
10  
  S anonID = cast get(getMainBot(), "anonymousDialogID");
11  
  S dialogID = getDialogID();
12  
  if (empty(dialogID) || eq(dialogID, anonID))
13  
    ret "No cookie - cannot authenticate! (dialog ID: " + dialogID + ")";
14  
15  
  boolean in = authorizedDialogIDs.contains(dialogID);
16  
  if (in)
17  
    ret "You're in! " /* + ahref("Log out") */;
18  
    
19  
  S realPW = realPW();
20  
  if (empty(realPW))
21  
    ret "No password set by admin - please put password in: " + realPWFile().getAbsolutePath();
22  
    
23  
  S pw = params.get("pw");
24  
  if (nempty(pw)) {
25  
    if (neq(pw, realPW)) {
26  
      print("XXX - Alert, bad PW entered on web - XXX");
27  
      ret "Bad PW, bugger";
28  
    } else {
29  
      authorizedDialogIDs.add(dialogID);
30  
      save("authorizedDialogIDs");
31  
      ret "OK, you're in! Dialog ID: " + dialogID;
32  
    }
33  
  } else {
34  
    S formContents = tag("p", "Enter deh pass word: " + htag("input", "", "type", "password", "name", "pw", "value", params.get("pw")));
35  
    formContents += tag("input", "", "type", "submit", "value", "Submit!");
36  
    ret tag("form", formContents, "method", "POST");
37  
  }
38  
}
39  
40  
static File realPWFile() {
41  
  ret secretProgramFile("master-pw");
42  
}
43  
44  
static S realPW() {
45  
  ret trim(loadTextFile(realPWFile()));
46  
}
47  
48  
static boolean currentHttpRequestAuthorized() {
49  
  ret authorizedDialogIDs.contains(getDialogID());
50  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002590
Snippet name: Web Auth Bot (LIVE)
Eternal ID of this version: #1002590/3
Text MD5: 2208497a37730c4d907412920aa92e39
Transpilation MD5: e7c5315e3571b416d7f3c298dcacba28
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-09 12:02:02
Source code size: 1466 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 806 / 9338
Version history: 2 change(s)
Referenced in: [show references]