Files
minisrv/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js
zefie 1165b245ce v0.9.33
- numerous bug fixes
 - wtv-mail system
 - user account updates
 - viewergen alpha (experimental webtv viewer patcher on pc_service)
 - implement wtv-favorites with huge help from @JarHead4
 - add wtv-ticket store api
 - Bump vm2 from 3.9.5 to 3.9.7 in /zefie_wtvp_minisrv
 - fix bf0app default rom
 - Add wtv-1800 service to wtv-1800:/noflash
 - handle webtvism:
   - allow get/post variables to be the same name multiple times
   - rather than overwrite, the server will now change the variable from a string to an array.
 - Rewrite script processing a bit
   - Instead of using eval() we now use a proper VM Context
   - As a result, any scripting errors will now give a more useful filename and line number.
   - However, some things may break, if they are dependant on variables we are not allowing in the context.
 - BREAKING CHANGES:
   - `ssid_sessions[socket.ssid]` is now `session_data`
   - `require` is no longer allowed in user scripts
 - add star service
 - change how we handle modules for services in the VM
 - fixed wtv-disk:/sync always failed the first time
 - implement production-like wtv-star handling (when a service port becomes unavailable, it requests the url over the wtv-star port to show an error page)
 - renamed WTVDownloadList.js to WTVDisk.js
 - a bit more work on WTVNews (created class)
 - probably more stuff I can't remember
2022-11-29 08:29:25 -05:00

78 lines
2.5 KiB
JavaScript

var minisrv_service_file = true;
session_data.setUserLoggedIn(false);
var challenge_response, challenge_header = "";
if (socket.ssid !== null) session_data.switchUserID(0);
var gourl = "wtv-head-waiter:/ValidateLogin?initial_login=true&";
if (request_headers.query.relogin) gourl += "relogin=true";
else if (request_headers.query.reconnect) gourl += "reconnect=true";
if (request_headers.query.guest_login) {
if (request_headers.query.relogin || request_headers.query.reconnect) gourl += "&";
gourl += "guest_login=true";
if (request_headers.query.skip_splash) gourl += "&skip_splash=true";
}
var send_to_relogin = true;
if (socket.ssid) {
if (session_data) {
if (request_headers["wtv-ticket"]) {
if (session_data.data_store.wtvsec_login.ticket_b64 == null) {
if (request_headers["wtv-ticket"].length > 8) {
session_data.data_store.wtvsec_login.DecodeTicket(request_headers["wtv-ticket"]);
session_data.data_store.wtvsec_login.ticket_b64 = request_headers["wtv-ticket"];
send_to_relogin = false;
}
}
} else {
if (session_data.data_store.wtvsec_login) {
var client_challenge_response = request_headers["wtv-challenge-response"] || null;
if (challenge_response && client_challenge_response) {
if (challenge_response.toString(CryptoJS.enc.Base64).substring(0, 85) == client_challenge_response.substring(0, 85)) {
console.log(" * wtv-challenge-response success for " + socket.ssid);
session_data.data_store.wtvsec_login.PrepareTicket();
send_to_relogin = false;
} else {
challenge_header = "wtv-challenge: " + session_data.data_store.wtvsec_login.IssueChallenge();
send_to_relogin = false;
}
} else {
challenge_header = "wtv-challenge: " + session_data.data_store.wtvsec_login.IssueChallenge();
send_to_relogin = false;
}
}
}
}
}
if (!send_to_relogin) {
headers = `200 OK
Connection: Keep-Alive
Expires: Wed, 09 Oct 1991 22:00:00 GMT
wtv-expire-all: wtv-head-waiter:
`+ getServiceString('wtv-log') + `
wtv-log-url: wtv-log:/log`;
if (challenge_header != "") headers += "\n" + challenge_header;
headers += `
wtv-country: US
wtv-language-header: en-US,en
wtv-relogin-url: wtv-head-waiter:/relogin?relogin=true
wtv-reconnect-url: wtv-head-waiter:/relogin?reconnect=true
wtv-visit: ${gourl}
Content-type: text/html`;
data = '';
} else {
headers = `200 OK
Connection: Keep-Alive
Expires: Wed, 09 Oct 1991 22:00:00 GMT
wtv-expire-all: wtv-head-waiter:
wtv-expire-all: wtv-1800:
wtv-visit: wtv-head-waiter:/relogin?relogin=true
Content-type: text/html`;
data = '';
}