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

!7

static new L<S> authorizedDialogIDs;

p {
  load("authorizedDialogIDs");
}

static S html(S subUri, Map<S, S> params) {
  S anonID = cast get(getMainBot(), "anonymousDialogID");
  S dialogID = getDialogID();
  if (empty(dialogID) || eq(dialogID, anonID))
    ret "No cookie - cannot authenticate! (dialog ID: " + dialogID + ")";

  boolean in = authorizedDialogIDs.contains(dialogID);
  if (in)
    ret "You're in! " /* + ahref("Log out") */;
    
  S realPW = realPW();
  if (empty(realPW))
    ret "No password set by admin - please put password in: " + realPWFile().getAbsolutePath();
    
  S pw = params.get("pw");
  if (nempty(pw)) {
    if (neq(pw, realPW)) {
      print("XXX - Alert, bad PW entered on web - XXX");
      ret "Bad PW, bugger";
    } else {
      authorizedDialogIDs.add(dialogID);
      save("authorizedDialogIDs");
      ret "OK, you're in! Dialog ID: " + dialogID;
    }
  } else {
    S formContents = tag("p", "Enter deh pass word: " + htag("input", "", "type", "password", "name", "pw", "value", params.get("pw")));
    formContents += tag("input", "", "type", "submit", "value", "Submit!");
    ret tag("form", formContents, "method", "POST");
  }
}

static File realPWFile() {
  ret secretProgramFile("master-pw");
}

static S realPW() {
  ret trim(loadTextFile(realPWFile()));
}

static boolean currentHttpRequestAuthorized() {
  ret authorizedDialogIDs.contains(getDialogID());
}

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: 807 / 9338
Version history: 2 change(s)
Referenced in: #1002017 - Eleutheria Main, including Slack Bot (LIVE)
#1002591 - Eleu Sister Main for tinybrain.de
#1002595 - webAuthed
#1004182 - x30 for Android [stage 3, Java, LIVE]
#1004183 - Boot-up code for JavaX/Android (backup)
#1007390 - x30 for Android (backup before multiport)
#1008823 - Woody File Server [web bot]
#1008831 - masterPW
#1010474 - Diagram Server
#1011958 - standaloneWebAuth
#1013896 - Eleutheria Main for butter.botcompany.de + Stefan's OS (LIVE)
#1013928 - redirectToWebAuth
#1015408 - General File Server (authed upload, anonymous download)
#1022823 - Eleutheria Main for butter.botcompany.de as Dyn Module [dev.]
#1023951 - agi.blue Standalone with GUI [OK]
#1024026 - Eleutheria Main for butter.botcompany.de (backup without Stefan's OS)
#3000201 - Answer for stefanreich (>> list all files)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000377 - Answer for stefanreich (>> timing eleu?)
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)