diff --git a/.gitignore b/.gitignore index 5436205d..25a2816b 100644 --- a/.gitignore +++ b/.gitignore @@ -361,9 +361,9 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd -/hacktv_updsrv/ServiceLogPost/1626307222_warning_812bf30600b002bb -/hacktv_updsrv/ServiceVault/wtv-music/midi /zefie_wtvp_minisrv/ServiceVault/wtv-home/6969.html /zefie_wtvp_minisrv/user_config.json /zefie_wtvp_minisrv/ServiceVault/wtv-home/home.zefie.html -/zefie_wtvp_minisrv/UserServiceVault/wtv-update +/zefie_wtvp_minisrv/UserServiceVault/*-*/ +/zefie_wtvp_minisrv/ServiceLogPost/*.log +/zefie_wtvp_minisrv/SessionStore/*.json diff --git a/user_config_README.md b/user_config_README.md index 3748eb9e..2db88a4f 100644 --- a/user_config_README.md +++ b/user_config_README.md @@ -6,10 +6,13 @@ ### `config` section Some values are available that are not defined in `config.json` by default. I will attempt to cover them here. ``` + "service_name": "CoolTV", + "service_owner": "CoolDude", "service_logo": "WebTVLogoJewel.gif", "service_splash_logo": "file://ROM/images/SplashLogo1.gif" ``` -You can set the image to be loaded in the top left in place of the WebTV or MSN logo, as well as the main Splash image shown on login. +You can set the service name and service owner, which will be used across the service when referencing itself. +You can set the image to be loaded in the top left in place of the WebTV or HackTV logo, as well as the main Splash image shown on login. If an absolute path (`wtv-url:/`, `file://` url, or `http(s)://` url) is not passed, the server will search for the specified filename in `wtv-star/images` of any Service Vault. You'll want to keep the filesizes low. ``` "post_debug": true diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js index 4a9518e3..ccbdee86 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js @@ -1,8 +1,13 @@ var gourl = "wtv-head-waiter:/login?"; -if (request_headers.query.relogin) gourl += "relogin=true"; -if (request_headers.query.reconnect) gourl += "reconnect=true"; if (socket.ssid) { + if (ssid_sessions[socket.ssid].loadSessionData() == true) { + console.log(" * Loaded session data from disk for", filterSSID(socket.ssid)) + ssid_sessions[socket.ssid].setSessionData("registered", (ssid_sessions[socket.ssid].getSessionData("registered") == true) ? true : false); + } else { + ssid_sessions[socket.ssid].session_data = {}; + ssid_sessions[socket.ssid].setSessionData("registered", false); + } if (ssid_sessions[socket.ssid].data_store) { if (ssid_sessions[socket.ssid].data_store.sockets) { var i = 0; @@ -15,23 +20,27 @@ if (socket.ssid) { } } }); - if (i > 0 && zdebug) console.log(" # Closed", i, "previous sockets for", filterSSID(socket.ssid)); + if (i > 0 && zdebug) console.log(" # Closed", i, "previous sockets for", filterSSID(socket.ssid)); } } - if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { + if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { + if (zdebug) console.log(" # Recreating primary WTVSec login instance for", filterSSID(socket.ssid)); delete ssid_sessions[socket.ssid].data_store.wtvsec_login; } ssid_sessions[socket.ssid].data_store.wtvsec_login = new WTVSec(); ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge(); - ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]); + ssid_sessions[socket.ssid].data_store.wtvsec_login.set_incarnation(request_headers["wtv-incarnation"] || 1); } else { console.log(" * Something bad happened (we don't know the client ssid???)"); - var errpage = doErrorCode(400) + var errpage = doErrorPage(400) headers = errpage[0]; data = errpage[1]; } +if (request_headers.query.relogin && ssid_sessions[socket.ssid].getSessionData("registered")) gourl += "relogin=true"; +if (request_headers.query.reconnect && ssid_sessions[socket.ssid].getSessionData("registered")) gourl += "reconnect=true"; + if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { var prereg_contype = "text/html"; @@ -110,7 +119,6 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { gourl = null; } - if (!file_path != null && !zquiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id); headers = "200 OK\n" @@ -126,7 +134,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { if (bf0app_update) headers += getServiceString('wtv-star', { "no_star_word": true }) + "\n"; else headers += getServiceString('wtv-star') + "\n"; - + if (request_headers.query.reconnect && !ssid_sessions[socket.ssid].session_data.registered) headers += getServiceString('wtv-register') + "\n"; headers += getServiceString('wtv-flashrom') + "\n"; if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n"; else headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n"; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js index 3d365613..27008043 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js @@ -1,10 +1,10 @@ var irc_nick = ""; headers = "200 OK"; if (request_headers.query.nick) headers += "\n" + ssid_sessions[socket.ssid].setIRCNick(request_headers.query.nick); -else if (!ssid_sessions[socket.ssid].get("wtv-irc-nick")) ssid_sessions[socket.ssid].setIRCNick(minisrv_config.config.service_name + '_' + Math.floor(Math.random() * 100000)).substring(0, 16); +else if (!ssid_sessions[socket.ssid].getSessionData("subscriber_irc_nick")) ssid_sessions[socket.ssid].getSessionData("subscriber_username") || ssid_sessions[socket.ssid].setIRCNick(minisrv_config.config.service_name + '_' + Math.floor(Math.random() * 100000)).substring(0, 16); headers += "\nContent-Type: text/html"; -var irc_nick = ssid_sessions[socket.ssid].get("wtv-irc-nick"); +var irc_nick = ssid_sessions[socket.ssid].getSessionData("subscriber_irc_nick") || ssid_sessions[socket.ssid].getSessionData("subscriber_username"); data = ` diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js new file mode 100644 index 00000000..36a46124 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/add.js @@ -0,0 +1,15 @@ +if (socket.ssid) { + if (request_headers.post_data) { + if (ssid_sessions[socket.ssid]) { + ssid_sessions[socket.ssid].addCookie(cookie_data); + headers = "200 OK\n"; + headers += "Content-Type: text/html"; + } + } +} + +if (!headers) { + var errpage = doErrorPage(400) + headers = errpage[0]; + data = errpage[1]; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js new file mode 100644 index 00000000..8a9c38ff --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/get.js @@ -0,0 +1,18 @@ +if (request_headers.post_data) { + if (request_headers.query.domain && request_headers.query.path) { + if (socket.ssid) { + if (ssid_sessions[socket.ssid]) { + + data = ssid_sessions[socket.ssid].getCookieString(unescape(request_headers.query.domain), unescape(request_headers.query.path)); + headers = "200 OK\n"; + headers += "Content-Type: text/plain"; + } + } + } +} + +if (!headers) { + var errpage = doErrorPage(400) + headers = errpage[0]; + data = errpage[1]; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/list.js b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/list.js index 11931a83..e3f6a46b 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/list.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-cookie/list.js @@ -1,6 +1,14 @@ +if (socket.ssid) { + if (ssid_sessions[socket.ssid]) { -headers =`200 OK -Connection: Keep-Alive -Content-type: text/plain` + data = ssid_sessions[socket.ssid].listCookies(); + headers = "200 OK\n"; + headers += "Content-Type: text/plain"; + } +} -data=`.passporttest.com/ppsecure.passporttest.com/` \ No newline at end of file +if (!headers) { + var errpage = doErrorPage(400) + headers = errpage[0]; + data = errpage[1]; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js index 6f587ad3..f64e9c35 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login-stage-two.js @@ -24,6 +24,8 @@ if (socket.ssid !== null) { if (challenge_response.toString(CryptoJS.enc.Base64) == client_challenge_response) { console.log(" * wtv-challenge-response success for " + filterSSID(socket.ssid)); wtvsec_login.PrepareTicket(); + if (!ssid_sessions[socket.ssid].getSessionData("registered")) gourl = "wtv-register:/splash"; + } else { console.log(" * wtv-challenge-response FAILED for " + filterSSID(socket.ssid)); if (zdebug) console.log("Response Expected:", challenge_response.toString(CryptoJS.enc.Base64)); @@ -39,66 +41,97 @@ if (socket.ssid !== null) { if (gourl) { headers = `200 OK -Connection: Keep-Alive +Connection: Close wtv-open-isp-disabled: false -wtv-visit: ${gourl} +`; + if (!ssid_sessions[socket.ssid].session_data.registered && !request_headers.query.guest_mode) { + headers += `wtv-encrypted: true +wtv-ticket: ${wtvsec_login.ticket_b64} +${getServiceString('wtv-register')} +${getServiceString('wtv-head-waiter')} +${getServiceString('wtv-star')} +wtv-boot-url: wtv-register:/splash +` + } + headers += `wtv-visit: ${gourl} Content-type: text/html`; data = ''; } else { - var namerand = Math.floor(Math.random() * 100000); - var nickname = (minisrv_config.config.service_name + '_' + namerand) - var userid = '1' + Math.floor(Math.random() * 1000000000000000000); + if (request_headers.query.guest_mode) { + var namerand = Math.floor(Math.random() * 100000); + var nickname = (minisrv_config.config.service_name + '_' + namerand) + var human_name = nickname; + var userid = '1' + Math.floor(Math.random() * 1000000000000000000); + var messenger_enabled = 0; + var messenger_authorized = 0; + var home_url = "wtv-home:/home?"; + } else if (!ssid_sessions[socket.ssid].getSessionData("registered")) { + var errpage = doErrorPage(400); + headers = errpage[0]; + data = errpage[1]; + } else { + var userid = ssid_sessions[socket.ssid].getSessionData("subscriber_userid") + var nickname = ssid_sessions[socket.ssid].getSessionData("subscriber_username"); + var human_name = ssid_sessions[socket.ssid].getSessionData("subscriber_name"); + var messenger_enabled = ssid_sessions[socket.ssid].getSessionData("messenger_enabled") || 0; + var messenger_authorized = ssid_sessions[socket.ssid].getSessionData("messenger_authorized") || 0; + var home_url = "wtv-home:/splash?"; + } var offline_user_list = CryptoJS.enc.Latin1.parse("\n\t\n").toString(CryptoJS.enc.Base64); data = ''; headers = `200 OK Connection: Keep-Alive wtv-encrypted: true wtv-client-time-zone: GMT -0000 +wtv-client-time-dst-rule: GMT wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT wtv-country: US wtv-language-header: en-US,en wtv-visit: client:closeallpanels wtv-expire-all: client:closeallpanels +wtv-transition-override: off +wtv-force-lightweight-targets: webtv.net:/ +wtv-smartcard-inserted-message: Contacting service +wtv-bypass-proxy: false wtv-offline-user-list: ${offline_user_list} -wtv-bypass-proxy: true +wtv-messenger-authorized: ${messenger_authorized} +wtv-messenger-enable: ${messenger_enabled} +wtv-noback-all: wtv- +wtv-service: reset +`+ getServiceString('all', { "exceptions": ["wtv-register"] } ) + ` +user-id: ${userid} +wtv-human-name: ${human_name} +${ssid_sessions[socket.ssid].setIRCNick(nickname)} +wtv-domain: wtv.zefie.com +wtv-input-timeout: 14400 wtv-ticket: ${wtvsec_login.ticket_b64} wtv-messagewatch-checktimeoffset: off wtv-input-timeout: 14400 wtv-connection-timeout: 90 wtv-fader-timeout: 900 -wtv-ssl-log-url: wtv-log:/log wtv-smartcard-inserted-message: Contacting service -user-id: ${userid} -wtv-transition-override: off -wtv-allow-dsc: true -wtv-messenger-enable: 0 -wtv-noback-all: wtv- -wtv-service: reset -`+ getServiceString('all') + ` -wtv-boot-url: wtv-1800:/preregister?relogin=true -wtv-human-name: ${nickname} -${ssid_sessions[socket.ssid].setIRCNick(nickname)} -wtv-home-url: wtv-home:/home? -wtv-domain: wtv.zefie.com wtv-inactive-timeout: 0 wtv-connection-timeout: 90 wtv-show-time-enabled: true wtv-fader-timeout: 900 wtv-tourist-enabled: true -wtv-connection-timeout: 180 +wtv-boot-url: wtv-1800:/preregister?relogin=true +wtv-allow-dsc: true +wtv-home-url: wtv-home:/home? +` + if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect) { + headers += "\nwtv-settings-url: wtv-setup:/get"; + } + headers += ` +wtv-log-url: wtv-log:/log +wtv-ssl-log-url: wtv-log:/log wtv-ssl-timeout: 240 wtv-login-timeout: 7200 wtv-open-isp-disabled: false -wtv-log-url: wtv-log:/log +wtv-offline-mail-enable: false wtv-demo-mode: 0 wtv-wink-deferrer-retries: 3 -wtv-offline-mail-enable: false -wtv-name-server: 8.8.8.8 -`; - if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect) { - headers += "wtv-settings-url: wtv-setup:/get\n"; - } - headers += `wtv-visit: wtv-home:/splash? +wtv-visit: ${home_url} Content-Type: text/html`; } \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js index df2b929c..9cd4cfd0 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js @@ -1,72 +1,59 @@ -var challenge_response, challenge_header = ''; +var challenge_response, challenge_header = ""; var gourl = "wtv-head-waiter:/login-stage-two?"; if (request_headers.query.relogin) gourl += "relogin=true"; if (request_headers.query.reconnect) gourl += "reconnect=true"; +var send_to_relogin = true; -if (socket.ssid !== null) { - var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login"); - if (request_headers["wtv-ticket"]) { - if (wtvsec_login.ticket_b64 == null) { - if (request_headers["wtv-ticket"].length > 8) { - wtvsec_login.DecodeTicket(request_headers["wtv-ticket"]); - wtvsec_login.ticket_b64 = request_headers["wtv-ticket"]; - } - } - } else { - if (wtvsec_login) { - challenge_response = wtvsec_login.challenge_response; - 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); - wtvsec_login.PrepareTicket(); - } else { - challenge_header = "wtv-challenge: " + wtvsec_login.IssueChallenge(); +if (socket.ssid) { + if (ssid_sessions[socket.ssid]) { + if (request_headers["wtv-ticket"]) { + if (ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 == null) { + if (request_headers["wtv-ticket"].length > 8) { + ssid_sessions[socket.ssid].data_store.wtvsec_login.DecodeTicket(request_headers["wtv-ticket"]); + ssid_sessions[socket.ssid].data_store.wtvsec_login.ticket_b64 = request_headers["wtv-ticket"]; + send_to_relogin = false; } - } else { - challenge_header = "wtv-challenge: " + wtvsec_login.IssueChallenge(); } } else { - wtvsec_login = new WTVSec(); - - } + if (ssid_sessions[socket.ssid].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); + ssid_sessions[socket.ssid].data_store.wtvsec_login.PrepareTicket(); + send_to_relogin = false; + } else { + challenge_header = "wtv-challenge: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge(); + send_to_relogin = false; + } + } else { + challenge_header = "wtv-challenge: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.IssueChallenge(); + send_to_relogin = false; + } + } + } } } -/* -if (request_headers) { - var cookiedata = {}; - Object.keys(request_headers).forEach(function (k) { - switch (k) { - case "wtv-capability-flags": - case "wtv-system-version": - case "wtv-client-rom-type": - case "wtv-client-bootrom-version": - case "wtv-system-chipversion": - case "wtv-system-sysconfig": - case "wtv-system-cpuspeed": - cookiedata[k] = request_headers[k]; - break; - } - }); -} -*/ +if (!send_to_relogin) { -if (challenge_header != '') { 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 -${challenge_header} +wtv-log-url: wtv-log:/log`; + if (challenge_header != "") headers += "\n" + challenge_header; + headers += ` wtv-relogin-url: wtv-1800:/preregister?relogin=true wtv-reconnect-url: wtv-1800:/preregister?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 @@ -74,5 +61,5 @@ wtv-expire-all: wtv-head-waiter: wtv-expire-all: wtv-1800: wtv-visit: wtv-1800:/preregister?relogin=true Content-type: text/html`; - + data = ''; } \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js b/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js index a005cf10..8de6389e 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js @@ -15,7 +15,7 @@ if (ssid_sessions[socket.ssid].get('box-does-psuedo-encryption')) { data = ` -Home for minisrv +Home for ${ssid_sessions[socket.ssid].getSessionData("subscriber_username") || "minisrv"} @@ -24,14 +24,14 @@ function go() { location.href=document.access.url.value; } -

Welcome to `+ z_title + `

+

Welcome to `+ z_title + `

Encryption Status: ${cryptstatus}
Connection Speed: &rate;