From 0d991d5eac95c4c224a94cb10fd2be6d5af32c0e Mon Sep 17 00:00:00 2001 From: zefie Date: Mon, 7 Feb 2022 20:24:16 -0500 Subject: [PATCH] user account updates - move user accounts to subdir - add password support - implemented basics of multi-user support - Can add users, edit them, and log in with them (password or not) - Cannot delete users (with service) yet --- .../ServiceVault/wtv-1800/noflash.js | 1 + .../wtv-1800/offer-open-isp-suggest.js | 1 + .../ServiceVault/wtv-1800/preregister.js | 1 + .../ServiceVault/wtv-1800/unauthorized.js | 5 +- .../wtv-head-waiter/ValidateLogin.js | 83 ++++++++ .../wtv-head-waiter/choose-user.js | 141 ++++++++++++++ .../wtv-head-waiter/images/NameBanner.gif | Bin 0 -> 813 bytes .../wtv-head-waiter/images/NameStrip.gif | Bin 0 -> 117 bytes .../wtv-head-waiter/images/PasswordBanner.gif | Bin 0 -> 1267 bytes .../wtv-head-waiter/login-stage-two.js | 161 +++++++-------- .../ServiceVault/wtv-head-waiter/login.js | 5 +- .../ServiceVault/wtv-head-waiter/password.js | 58 ++++++ .../ServiceVault/wtv-home/Credits-Legal.js | 109 +++++++++++ .../ServiceVault/wtv-home/Credits-Privacy.js | 118 +++++++++++ .../wtv-register/ValidateAccountInfo.js | 4 +- .../ServiceVault/wtv-setup/accounts.js | 133 +++++++++++++ .../ServiceVault/wtv-setup/add-user-name.js | 136 +++++++++++++ .../wtv-setup/add-user-password.js | 150 ++++++++++++++ .../ServiceVault/wtv-setup/add-user.js | 134 +++++++++++++ .../ServiceVault/wtv-setup/edit-password.js | 167 ++++++++++++++++ .../ServiceVault/wtv-setup/edit-user-begin.js | 164 ++++++++++++++++ .../ServiceVault/wtv-setup/edit-user-name.js | 151 ++++++++++++++ .../wtv-setup/images/AccountBanner.gif | Bin 0 -> 3470 bytes .../wtv-setup/serve-billing-overview.js | 24 +-- .../ServiceVault/wtv-setup/setup.js | 40 ++-- .../wtv-setup/validate-add-user-done.js | 63 ++++++ .../wtv-setup/validate-add-user.js | 184 ++++++++++++++++++ .../wtv-setup/validate-change-name.js | 39 ++++ .../wtv-setup/validate-change-password.js | 75 +++++++ zefie_wtvp_minisrv/WTVClientSessionData.js | 159 +++++++++++++-- zefie_wtvp_minisrv/WTVMail.js | 2 +- zefie_wtvp_minisrv/WTVRegister.js | 12 +- zefie_wtvp_minisrv/app.js | 32 +++ zefie_wtvp_minisrv/config.json | 14 +- zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj | 16 ++ 35 files changed, 2228 insertions(+), 154 deletions(-) create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/ValidateLogin.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/choose-user.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameBanner.gif create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameStrip.gif create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/PasswordBanner.gif create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/password.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Legal.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Privacy.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/accounts.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-name.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-password.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-password.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-begin.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-name.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/images/AccountBanner.gif create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user-done.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-name.js create mode 100644 zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-password.js diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js index 87a0ede3..66f7b4b3 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/noflash.js @@ -15,6 +15,7 @@ if (wtvsec_login) { headers = `200 OK Connection: Keep-Alive minisrv-use-carriage-return: false +minisrv-no-mail-count: true wtv-initial-key: ` + wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + ` Content-Type: text/tellyscript wtv-service: reset diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/offer-open-isp-suggest.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/offer-open-isp-suggest.js index 6b76eb8d..b8bb0262 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/offer-open-isp-suggest.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/offer-open-isp-suggest.js @@ -10,6 +10,7 @@ if (request_headers["wtv-ticket"]) { headers = `200 OK Connection: Keep-Alive +minisrv-no-mail-count: true wtv-expire-all: wtv- wtv-open-isp-disabled: false wtv-visit: `+ gourl + ` diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js index a0bd573c..7d4919c3 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/preregister.js @@ -150,6 +150,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) { headers = "200 OK\n" + headers += "minisrv-no-mail-count: true\n"; if (bf0app_update) headers += "minisrv-use-carriage-return: false\n"; headers += "Connection: Keep-Alive\n"; headers += "wtv-initial-key: " + ssid_sessions[socket.ssid].data_store.wtvsec_login.challenge_key.toString(CryptoJS.enc.Base64) + "\n"; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/unauthorized.js b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/unauthorized.js index b1f0349f..b65d2d5a 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-1800/unauthorized.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-1800/unauthorized.js @@ -1,7 +1,8 @@ var minisrv_service_file = true; headers = `200 OK -Content-type: text/html`; +Content-type: text/html +minisrv-no-mail-count: true`; data = ` @@ -16,7 +17,7 @@ hspace=0 vspace=0 fontsize="large"
- + diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/ValidateLogin.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/ValidateLogin.js new file mode 100644 index 00000000..9499c468 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/ValidateLogin.js @@ -0,0 +1,83 @@ +var minisrv_service_file = true; + +var challenge_response, challenge_header = ''; +var gourl; +var wtvsec_login = null; + +var user_id = (request_headers.query.user_id) ? request_headers.query.user_id : ssid_sessions[socket.ssid].user_id; + +if (socket.ssid !== null && user_id !== null) ssid_sessions[socket.ssid].switchUserID(user_id); + +if (socket.ssid !== null && !ssid_sessions[socket.ssid].get("wtvsec_login")) { + wtvsec_login = new WTVSec(minisrv_config); + wtvsec_login.IssueChallenge(); + wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]); + ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); +} else { + wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login"); +} + +if (socket.ssid !== null) { + if (wtvsec_login.ticket_b64 == null) { + 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) == client_challenge_response) { + console.log(" * wtv-challenge-response success for " + wtvshared.filterSSID(socket.ssid)); + wtvsec_login.PrepareTicket(); + gourl = "wtv-head-waiter:/login-stage-two?"; + } else { + console.log(" * wtv-challenge-response FAILED for " + wtvshared.filterSSID(socket.ssid)); + if (minisrv_config.config.debug_flags.debug) console.log("Response Expected:", challenge_response.toString(CryptoJS.enc.Base64)); + if (minisrv_config.config.debug_flags.debug) console.log("Response Received:", client_challenge_response) + gourl = "wtv-head-waiter:/login?reissue_challenge=true"; + } + } else { + gourl = "wtv-head-waiter:/login?no_response=true"; + } + } else { + gourl = "wtv-head-waiter:/login-stage-two?"; + } +} + +if (user_id && !request_headers.query.initial_login && !request_headers.query.user_login) { + if (request_headers.query.password == "") { + headers = `500 Please enter your password and try again +minisrv-no-mail-count: true +`; + } else if (ssid_sessions[socket.ssid].validateUserPassword(request_headers.query.password)) { + ssid_sessions[socket.ssid].setSessionData('password_valid', true) + headers = `200 OK +minisrv-no-mail-count: true +Content-Type: text/html +wtv-visit: ${gourl} +`; + } else { + headers = `500 The password you entered was incorrect. Please retype it and try again. +minisrv-no-mail-count: true +`; + } +} else { + if (ssid_sessions[socket.ssid].getNumberOfUserAccounts() > 1 && user_id === 0 && request_headers.query.initial_login) { + gourl = "wtv-head-waiter:/choose-user?" + } else { + var limitedLogin = (!ssid_sessions[socket.ssid].lockdown && (!ssid_sessions[socket.ssid].getSessionData('password_valid') && ssid_sessions[socket.ssid].getUserPasswordEnabled())); + var limitedLoginRegistered = (limitedLogin && ssid_sessions[socket.ssid].isRegistered()); + } + headers = `200 OK +wtv-connection-close: true +Connection: close +minisrv-no-mail-count: true +Content-Type: text/html`; + if (client_challenge_response) { + headers += ` +wtv-encrypted: true +wtv-ticket: ${wtvsec_login.ticket_b64} +`; + } + console.log(ssid_sessions[socket.ssid]) + if (limitedLoginRegistered) gourl = "wtv-head-waiter:/password?"; + headers += ` +wtv-visit: ${gourl}`; + +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/choose-user.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/choose-user.js new file mode 100644 index 00000000..52db8877 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/choose-user.js @@ -0,0 +1,141 @@ +var minisrv_service_file = true; +if (socket.ssid !== null) ssid_sessions[socket.ssid].switchUserID(0); + +headers = `200 OK +minisrv-no-mail-count: true +wtv-expire-all: wtv-head-waiter:/ValidateLogin +wtv-noback-all: wtv- +Content-Type: text/html` + +data = ` + + + +Choose your name + + + + + + + + + +
+
+ + +
+ +
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + +
+ + + + + + +
+ + +Choose your name + +
+ + +
+ +
+ + +
+ + + + + + + + + + + +
+
`; + +var accounts = ssid_sessions[socket.ssid].listPrimaryAccountUsers(); +var accounts_listed = 0; +for (const [key, value] of Object.entries(accounts)) { + data += ""; + if (key == "subscriber") var user_id = 0 + else var user_id = key.replace("user", ''); + data += ``; + if (key == "subscriber") data += `${value['subscriber_username']}`; + else data += `${value['subscriber_username']}` + data += " "; + data += "" // todo + data += ` +
+ + +
+ +
+ + +
+`; + accounts_listed++; +}; + +while (accounts_listed < minisrv_config.config.user_accounts.max_users_per_account) { + data += `
+ + +
+ +
+ +`; + if (accounts_listed != minisrv_config.config.user_accounts.max_users_per_account - 1) { + data += `
+`; + } + accounts_listed++; +} + +data += ` +
+
+ + + + + +
+
+ + +`; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameBanner.gif b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameBanner.gif new file mode 100644 index 0000000000000000000000000000000000000000..4e41e41b513fce9ca1f4c505012a158194cb181c GIT binary patch literal 813 zcmV+|1Je9QNk%w1VKM-H0KxzODlbDsOJ+1WQaeIiCMr2iRdXL9E-*GtA^8LW000L7 zEC2ui05Sl506+u&c)Hxa0K7@71EdIMLa0Vzjn7b=h3O5!z@jNB&yL~JmZZ@{i|2+O zY)Cu}eieXkMj#+TDS>oKtqPRKXEMU=dI2_(wn1QBl#@($TnZEdn}w;kPG*Yuygsf4 z2i-*g(+7?&`wY^7HhB&vT(35%P&AEd$f2L5LSlKqOEg%sEmLpcq1Il>o$$hfI&c zdKfAA3G)7~9YJPy{COBjvgAZb8Lnk~kglUTT#}9@qmxVG4=EG}KpO#5lBJnLmW{bc z;^WE%9#lRNCjjUWr932tB4DtMu>;FSJ?Owqk_QxmzI|wN0GW(pgAA^K%AnAfw{YWf zIh#R2oV#}ODmoxeNFZ(E!USTA!_R>{glTxI2t#PDkp6rcy^zw1<;$3{%t(Bb^U=?s zH&W$b0PVR-q({zQD-v+G!xUL-7rmo#Xug{&68SWB!D4gOjhbhNCrRV z=@MNUVCJWYW#l1YHat|4W;wlH_Uh{(2><{)?qFq| literal 0 HcmV?d00001 diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameStrip.gif b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/images/NameStrip.gif new file mode 100644 index 0000000000000000000000000000000000000000..8a6930bb84354b8457d941b9f828f40b435f60cb GIT binary patch literal 117 zcmZ?wbh9u|>}TL%Sj52a|NnmjGha~&C1GJ<9v&WUZf*uJ&;gMkH4My761(pFGdShB zdT&H$(1{ZX8huZ8l*X@Im*YKmp7!}I9Lr1By_XXId_du~nvRs?k;O%vo<{S1)JvkK Q1g*E$F04&A}i!C}u7}RH0zAMu?BB*9E1(I7&loOtDR?fHhkSoF?yhk$6r! zZY4Q<3;-bwad>+Q1p|qKAyNTgk5Z6=3P)2!6L??(U6ulj3Myzx3@STSmR1*FY=o+( zg%6*r3Y-jfcvL7cRE-KvNv?c2EiWe|i^LBW9g)z{($mz?kG9wgguC3`-rvlu2eB^6 zw%^_4#RhoUz3AxSY$_|dxPhy%J&V9>?C^K`jrn0GfC?P$AXwPq2_27Y6BPQ{bSKiP zAMz5Kup|EJ&>eE@1Qs!Opnw2Gr%VFTI7mVi0|;#ausG=Cod?TUg3!r;3qWuARLMCo z#DR(_A~o!Am{3KBUQ%p1`$?5sMg~pXJ>)qLhu5!Q!-^G~^TX7tXnB!fSAvT=vs>o~ z$V!9Xs(&8*{P`0jM3SUqYia<7uV4uz4)E-Wqr-6EMkz?2}4!DJlfFF%g&qv_NRNO@-J?0?@A42ihYZoXX z4J0R82Fepgxz|%vcM+xF1vi9N-iR}7F%w5HmEadHF04RRfkiChVjC;1;*1NcwKW$q z1cWB#lv74YC6%saU`$$Q6}TieMfE41#tvQf^!rA=2Q=%STYllFJ@>)qXq(J<`mO4vye%K7GoYjb&l~P zJdpb128zEuDyf+^;n?45QYm#W4UJ*t#`O?wv92muc&vU>Ro&A&$ZA#roywsvtk8PAa1 zGi8GKCnE@x`B-iS#lc&5DNHo#E)*+504f{n)-1B|betm<%l@WtnJkA)!4|@p_;4}1 zRPo?12J1X7L1GjjU?bv|gGEX}Mr!7>M9FDN1(te>wSp-~c$Yy7$=9+Qfwdd$K6$mSDNjIwopWzj}8uCL>gE)?$ z1dq=F1VcbtJcUNN=>eTpWgb0dx7A+h`Vs9qY9yC2CrJC^@)8ox&vQIlacZrALa7G4 zuXp4aJJ7S!0dpP6dGX~Yy#N{`B+jT_dN)uB10M%e=}g}EmRZo{%+3_Hfh*A`!-B7@ zL<#Rpm8=e(mwVE3b5*T+GwVup{6=2tpQiq|ATQkyLpp>^nwAh6sHV&frE4lp$JDvLI)%O06R$qG4ucc literal 0 HcmV?d00001 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 7f8b0cd7..3f7bf2b6 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 @@ -1,47 +1,14 @@ var minisrv_service_file = true; +var gourl = null; -var challenge_response, challenge_header = ''; -var gourl; - -if (socket.ssid != null && !ssid_sessions[socket.ssid].get("wtvsec_login")) { - var wtvsec_login = new WTVSec(minisrv_config); - wtvsec_login.IssueChallenge(); - wtvsec_login.set_incarnation(request_headers["wtv-incarnation"]); - ssid_sessions[socket.ssid].set("wtvsec_login", wtvsec_login); -} else { - var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login"); -} - -if (socket.ssid !== null) { - if (wtvsec_login.ticket_b64 == null) { - 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) == client_challenge_response) { - console.log(" * wtv-challenge-response success for " + wtvshared.filterSSID(socket.ssid)); - wtvsec_login.PrepareTicket(); - - } else { - console.log(" * wtv-challenge-response FAILED for " + wtvshared.filterSSID(socket.ssid)); - if (minisrv_config.config.debug_flags.debug) console.log("Response Expected:", challenge_response.toString(CryptoJS.enc.Base64)); - if (minisrv_config.config.debug_flags.debug) console.log("Response Received:", client_challenge_response) - gourl = "wtv-head-waiter:/login?reissue_challenge=true"; - } - } else { - gourl = "wtv-head-waiter:/login?no_response=true"; - } - } -} - -if (!ssid_sessions[socket.ssid].getSessionData("registered") && (!request_headers.query.guest_login || !minisrv_config.config.allow_guests)) gourl = "wtv-register:/splash?"; +if (!ssid_sessions[socket.ssid].isRegistered() && (!request_headers.query.guest_login || !minisrv_config.config.allow_guests)) gourl = "wtv-register:/splash?"; if (gourl) { headers = `200 OK wtv-open-isp-disabled: false `; - if (!ssid_sessions[socket.ssid].getSessionData("registered") && (!request_headers.query.guest_login || !minisrv_config.config.allow_guests)) { + if (!ssid_sessions[socket.ssid].isRegistered() && (!request_headers.query.guest_login || !minisrv_config.config.allow_guests)) { headers += `wtv-encrypted: true -wtv-ticket: ${wtvsec_login.ticket_b64} ${getServiceString('wtv-register')} ${getServiceString('wtv-head-waiter')} ${getServiceString('wtv-star')} @@ -77,91 +44,111 @@ else { var messenger_authorized = ssid_sessions[socket.ssid].getSessionData("messenger_authorized") || 0; var home_url = "wtv-home:/splash?"; } + var limitedLogin = ssid_sessions[socket.ssid].lockdown; + var limitedLoginRegistered = (limitedLogin || (ssid_sessions[socket.ssid].isRegistered() && ssid_sessions[socket.ssid].getSessionData('password_valid'))); var offline_user_list = CryptoJS.enc.Latin1.parse("\n\t\n").toString(CryptoJS.enc.Base64); + + if (limitedLoginRegistered) var home_url = "wtv-head-waiter:/password?"; + data = ''; + headers = `200 OK Connection: Keep-Alive -wtv-encrypted: true -wtv-client-time-zone: GMT -0000 +wtv-expire-all: wtv-head-waiter: +`; + + if (!limitedLogin) { + headers += `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-noback-all: wtv- 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`; - if (!ssid_sessions[socket.ssid].lockdown) { - headers += ` -wtv-offline-user-list: ${offline_user_list} -wtv-messenger-authorized: ${messenger_authorized} -wtv-messenger-enable: ${messenger_enabled}`; - } - headers += ` -wtv-noback-all: wtv- -wtv-service: reset +wtv-ssl-timeout: 240 +wtv-login-timeout: 7200 `; - if (!ssid_sessions[socket.ssid].lockdown) { - headers += getServiceString('all', { "exceptions": ["wtv-register"] }); - } else { - headers += getServiceString('wtv-1800') + "\n"; - headers += getServiceString('wtv-head-waiter') + "\n"; - headers += getServiceString('wtv-star') + "\n"; - } - headers += ` -wtv-ticket: ${wtvsec_login.ticket_b64}`; - if (!ssid_sessions[socket.ssid].lockdown) { - headers += ` + if (!limitedLogin) { + + headers += getServiceString('all', { "exceptions": ["wtv-register"] }); + headers += `wtv-offline-user-list: ${offline_user_list} +wtv-messenger-authorized: ${messenger_authorized} +wtv-messenger-enable: ${messenger_enabled} +wtv-messagewatch-checktimeoffset: off +`; + } else { + /* + headers += getServiceString('wtv-1800') + "\n"; + headers += getServiceString('wtv-head-waiter') + "\n"; + headers += getServiceString('wtv-log') + "\n"; + headers += getServiceString('wtv-star') + "\n"; + headers += getServiceString('wtv-flashrom') + "\n"; + */ + headers += `wtv-messenger-authorized: 0 +wtv-messenger-enable: 0 +`; + } + + headers += `wtv-log-url: wtv-log:/log +wtv-ssl-log-url: wtv-log:/log +`; + + if (!limitedLogin) { + headers += `wtv-bypass-proxy: false user-id: ${userid} wtv-human-name: ${human_name} ${ssid_sessions[socket.ssid].setIRCNick(nickname)} wtv-domain: ${minisrv_config.config.domain_name} -wtv-messagewatch-checktimeoffset: off wtv-input-timeout: 14400 wtv-connection-timeout: 1440 wtv-fader-timeout: 1440 -wtv-inactive-timeout: 1440`; - } else { - headers += ` -user-id: 0 -wtv-human-name: Unauthorized User -wtv-domain: ${minisrv_config.config.domain_name} -wtv-input-timeout: 30 -wtv-connection-timeout: 60 -wtv-fader-timeout: 60 -wtv-inactive-timeout: 60`; - } +wtv-inactive-timeout: 1440 +`; + } + /* + else { + headers += `wtv-bypass-proxy: true + user-id: 0 + wtv-human-name: Unauthorized User + wtv-domain: ${minisrv_config.config.domain_name} + wtv-input-timeout: 30 + wtv-connection-timeout: 60 + wtv-fader-timeout: 60 + wtv-inactive-timeout: 60`; + } + */ - headers += "\nwtv-relogin-url: wtv-head-waiter:/relogin?relogin=true"; - if (request_headers.query.guest_login) headers += "&guest_login=true"; + if (!limitedLogin) { + headers += "\nwtv-relogin-url: wtv-head-waiter:/relogin?relogin=true"; + if (request_headers.query.guest_login) headers += "&guest_login=true"; - headers += "\nwtv-reconnect-url: wtv-head-waiter:/login-stage-two?reconnect=true"; - if (request_headers.query.guest_login) headers += "&guest_login=true"; + headers += "\nwtv-reconnect-url: wtv-head-waiter:/login-stage-two?reconnect=true"; + if (request_headers.query.guest_login) headers += "&guest_login=true"; - headers += "\nwtv-boot-url: wtv-head-waiter:/relogin?relogin=true"; - if (request_headers.query.guest_login) headers += "&guest_login=true"; + headers += "\nwtv-boot-url: wtv-head-waiter:/relogin?relogin=true"; + if (request_headers.query.guest_login) headers += "&guest_login=true"; - if (!ssid_sessions[socket.ssid].lockdown) headers += "\nwtv-home-url: wtv-home:/home?"; + headers += "\nwtv-home-url: wtv-home:/home?"; + } - if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect && !ssid_sessions[socket.ssid].lockdown) - headers += "\nwtv-settings-url: wtv-setup:/get"; + if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect && !limitedLogin) + headers += "\nwtv-settings-url: wtv-setup:/get\n"; - headers += ` + if (!limitedLogin) { + headers += `wtv-force-lightweight-targets: webtv.net:/ wtv-show-time-enabled: true wtv-allow-dsc: true wtv-tourist-enabled: true -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-offline-mail-enable: false wtv-demo-mode: 0 wtv-wink-deferrer-retries: 3 wtv-name-server: 8.8.8.8`; - + } + } if (!request_headers.query.reconnect) headers += "\nwtv-visit: " + home_url; headers += "\nContent-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 77a2a638..784284dc 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/login.js @@ -1,8 +1,9 @@ var minisrv_service_file = true; var challenge_response, challenge_header = ""; +if (socket.ssid !== null) ssid_sessions[socket.ssid].switchUserID(0); -var gourl = "wtv-head-waiter:/login-stage-two?"; +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"; @@ -55,6 +56,8 @@ wtv-expire-all: wtv-head-waiter: 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} diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/password.js b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/password.js new file mode 100644 index 00000000..4dc80581 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-head-waiter/password.js @@ -0,0 +1,58 @@ +var minisrv_service_file = true; + +headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html +wtv-visit: client:closeallpanels +wtv-expire-all: client:closeallpanels`; + +data = `Password + + +

+ +
+ +
+
+
+
+
+
+ + + + + + +
+ + Type your password +
+
+ +
+
+ +Password + +
+ +
+
+ +
+
+
+ + + +
+
+ + +`; diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Legal.js b/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Legal.js new file mode 100644 index 00000000..587537f0 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Legal.js @@ -0,0 +1,109 @@ +var minisrv_service_file = true; + +headers = `200 OK +Connection: Keep-Alive +wtv-mail-count: ${ssid_sessions[socket.ssid].mailstore.countUnreadMessages(0)} +Content-Type: text/html` + +data = ` + + + +WebTV Terms of Service + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + + + +
+ + + +
WebTV Terms of Service
+(Release date January 21, 2022)
+
+
+ +

General
+

This is a recreation of the WebTV service, originally hosted by WebTV Networks, Inc. This server has no affiliation with WebTV Networks, and all original assets and pages belong to them.

+

Rules
+

You must follow these rules, or your privilege to access this service may be revoked.

+
    +
  • Do not harass other users
  • +
  • Do not impersonate others on the network
  • +
  • Do not send spam e-mail
  • +
  • Do not attempt to access unauthorized areas of the network
  • +
  • Do not attempt to disrupt or otherwise negatively impact the service for others
  • +
  • All users must be over 13 years of age, or be accompanied by a parent or guardian at all times
  • +
+

Failure to abide by one or more of these rules may require your access to be terminated.

+

Service Termination
+

If you break one or more of the rules listed above, your access to the service may be revoked. Disclosure of your termination reason will be decided on a case-by-case basis. Any attempt for a banned user to regain access to the server will be dealt with immediately. If you know of a banned user who is still on the network, please report it to us on Discord at JarHead#3922. All decisions are final, and will not be reverted.

+ +

These terms can change at any time, without warning. Your continued usage of the service is an agreement to these Terms of Service. If you do not agree to these terms, please disconnect immediately and get in contact on Discord at JarHead#3922 so your account can be terminated.

+
+
+
+ + +
+
+ + +
+
+ + + +
+
+ + +
+
+
+
+ + +`; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Privacy.js b/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Privacy.js new file mode 100644 index 00000000..82952562 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-home/Credits-Privacy.js @@ -0,0 +1,118 @@ +var minisrv_service_file = true; + +headers = `200 OK +Connection: Keep-Alive +wtv-mail-count: ${ssid_sessions[socket.ssid].mailstore.countUnreadMessages(0)} +Content-Type: text/html` + +data = ` + + + +WebTV Service Privacy Statement + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + + + +
+ + + +
WebTV Service Privacy Statement
+(Release date January 21, 2022)
+
+
+ +

The purpose of this WebTV server is to recreate the 1999 WebTV experience using pages and assets from that era. There will be inaccuracies in some areas. If you do find any, please report them to JarHead#3922 on Discord.

+

With Whom Personal Information Is Shared and What Is Collected
+

When you register with a WebTV account on this server, you are sharing the following:

+
    +
  • Your WebTV SSID (Silicon Serial ID)
  • +
  • Your name
  • +
  • Your ZIP Code
  • +
  • Pages you access
  • +
+

This information is shared with the server operators.

+

Your Silicon Serial ID
+

Your Silicon Serial ID (SSID) is used to identify you on the network. Anyone with your SSID can impersonate you on the network, so don't share it. This ID is stored on our servers when you sign up, however it will not be shared with anyone except the server operators.

+

Your Name
+

The name that you enter while signing up will be stored on our servers, however it will not be shared with anyone except the server operators.

+

Your ZIP Code
+

The ZIP Code you enter to set weather info will be stored on our servers, and will only be sent to The Weather Channel to get current data. You are not required to enter a ZIP code, however it is required to fully utilize weather forecasting.

+

Pages you access
+

All pages you visit and images you download will be temporarily logged for security reasons. This includes WebTV Network pages and Internet Web sites. This information can not be traced back to you, and will only be viewable to server operators for a short time. IRC Chat messages will not be logged, however server operators can see what servers you are connecting to.

+

How We Help Protect Children's Privacy
+

We do not knowingly collect information from children under the age of 13 to comply with COPPA. If the account creator is under 13, the main user and all secondary accounts will be terminated. All secondary users under 13 must be accompanied by a parent or guardian while using this service.

+ +

This Privacy Statement can change at any time, and without warning. If you do not agree with this Privacy Statement, please disconnect and contact JarHead#3922 on Discord to terminate your account.

+
+
+
+ + +
+
+ + +
+
+ + + +
+
+ + +
+
+
+
+ + +`; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-register/ValidateAccountInfo.js b/zefie_wtvp_minisrv/ServiceVault/wtv-register/ValidateAccountInfo.js index 26dff84d..d568599b 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-register/ValidateAccountInfo.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-register/ValidateAccountInfo.js @@ -11,8 +11,8 @@ if (!request_headers.query.registering) { if (!request_headers.query.registering) errpage = wtvshared.doErrorPage(400); else if (!request_headers.query.subscriber_name) errpage = wtvshared.doErrorPage(400, "Please enter your name. This can be your real name, or your well-known online alias."); else if (!request_headers.query.subscriber_username) errpage = wtvshared.doErrorPage(400, "Please enter a username."); - else if (request_headers.query.subscriber_username.length < 5) errpage = wtvshared.doErrorPage(400, "Please choose a username with 5 or more characters."); - else if (request_headers.query.subscriber_username.length > 16) errpage = wtvshared.doErrorPage(400, "Please choose a username with 16 or less characters."); + else if (request_headers.query.subscriber_username.length < minisrv_config.config.user_accounts.min_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with " + minisrv_config.config.user_accounts.min_length + " or more characters."); + else if (request_headers.query.subscriber_username.length > minisrv_config.config.user_accounts.max_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with " + minisrv_config.config.user_accounts.max_length + " or less characters."); else if (!wtvr.checkUsernameSanity(request_headers.query.subscriber_username)) errpage = wtvshared.doErrorPage(400, "The username you have chosen contains invalid characters. Please choose a username with only letters, numbers, _ or -. Also, please be sure your username begins with a letter."); else if (!wtvr.checkUsernameAvailable(request_headers.query.subscriber_username, ssid_sessions)) errpage = wtvshared.doErrorPage(400, "The username you have selected is already in use. Please select another username."); else if (!request_headers.query.subscriber_contact) errpage = wtvshared.doErrorPage(400, "Please enter your contact information."); diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/accounts.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/accounts.js new file mode 100644 index 00000000..6defc337 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/accounts.js @@ -0,0 +1,133 @@ +var minisrv_service_file = true; +ssid_sessions[socket.ssid].loadSessionData(); + +if (ssid_sessions[socket.ssid].user_id != 0) { + var errpage = doErrorPage(400, "You are not authorized to edit the primary account."); + headers = errpage[0]; + data = errpage[1]; +} else { + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html` + + data = ` + + + +Users setup + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + + +
+ + + +
+ +WebTV users +
+
+
+ + +Subscriber: +

`; + var accounts = ssid_sessions[socket.ssid].listPrimaryAccountUsers(); + + if (Object.keys(accounts).length > 1) data += "Additional users:"; + + data += "

"; + + data += `
+ +${accounts.subscriber.subscriber_username} + +

`; + + if (Object.keys(accounts).length > 1) { + delete accounts.subscriber; + for (const [key, value] of Object.entries(accounts)) { + data += ` +${value.subscriber_username} +`; + + }; + } + data += ` + +
+

+ +
+ + +
+ +
+ + +
+ +
+ + + + += minisrv_config.config.user_accounts.max_users_per_account) ? 'disabled="disabled" text=gray' : 'USESTYLE'} +TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button2" WIDTH=103> + + + + +
+ + +`; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-name.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-name.js new file mode 100644 index 00000000..850ec0ca --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-name.js @@ -0,0 +1,136 @@ +var minisrv_service_file = true; + + +if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account."); +else if (ssid_sessions[socket.ssid].getNumberOfUserAccounts() > minisrv_config.config.user_accounts.max_users_per_account) errpage = wtvshared.doErrorPage(400, "You are not authorized to add more than " + minisrv_config.config.user_accounts.max_users_per_account + " account${minisrv_config.config.user_accounts.max_users_per_account > 1 ? 's' : ''}."); +else if (!request_headers.query.user_name) errpage = wtvshared.doErrorPage(400, "Please enter a username."); + +if (errpage) { + headers = errpage[0]; + data = errpage[1]; +} else { + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html` + + data = ` + + + +Adding a User + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +User's Internet name + +
+ +
+ + + + + +
+ + +
+Type an Internet
+name`; + if (request_headers.query.display_name) { + data += ` for ${request_headers.query.display_name}.` + } else { + data += "." + } data += ` +

Internet names can
+contain letters and
+numbers, but no
+spaces. + +

+
+ + + + + +
+Internet name
+ +
+
+ +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-password.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-password.js new file mode 100644 index 00000000..5b5b0623 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user-password.js @@ -0,0 +1,150 @@ +var minisrv_service_file = true; +var errpage = null; + +const WTVRegister = require("./WTVRegister.js") +const wtvr = new WTVRegister(minisrv_config, SessionStore); + +if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account."); +else if (!request_headers.query.user_name) errpage = doErrorPage(400, "Please enter a username."); +else if (request_headers.query.user_name.length < minisrv_config.config.user_accounts.min_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with " + minisrv_config.config.user_accounts.min_length + " or more characters."); +else if (request_headers.query.user_name.length > minisrv_config.config.user_accounts.max_length) errpage = wtvshared.doErrorPage(400, "Please choose a username with " + minisrv_config.config.user_accounts.max_length + " or less characters."); +else if (!wtvr.checkUsernameSanity(request_headers.query.user_name)) errpage = wtvshared.doErrorPage(400, "The username you have chosen contains invalid characters. Please choose a username with only letters, numbers, _ or -. Also, please be sure your username begins with a letter."); +else if (!wtvr.checkUsernameAvailable(request_headers.query.user_name, ssid_sessions)) errpage = wtvshared.doErrorPage(400, "The username you have selected is already in use. Please select another username."); +else if (ssid_sessions[socket.ssid].getNumberOfUserAccounts() > minisrv_config.config.user_accounts.max_users_per_account) errpage = wtvshared.doErrorPage(400, "You are not authorized to add more than " + minisrv_config.config.user_accounts.max_users_per_account + " account${minisrv_config.config.user_accounts.max_users_per_account > 1 ? 's' : ''}."); + + + +if (errpage) { + headers = errpage[0]; + data = errpage[1]; +} else { + + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html` + + data = ` + + + +Adding a User + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +Optional password + +
+ +
+ + + + + + +
+ + +
+Type an optional
+password from ${minisrv_config.config.passwords.min_length} to +
${minisrv_config.config.passwords.max_length} characters long. +

You'll need to type
+the password
+Whenever you switch to ${request_headers.query.user_name}.
+

Leave the spaces
+blank if you don't
+want a password. + +

+
+ + + + + +
+Password
+ +
+
+
Type again to confirm
+ +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js new file mode 100644 index 00000000..c40f084e --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/add-user.js @@ -0,0 +1,134 @@ +var minisrv_service_file = true; + +if (Object.keys(ssid_sessions[socket.ssid].listPrimaryAccountUsers()).length >= minisrv_config.config.user_accounts.max_users_per_account) { + errpage = wtvshared.doErrorPage(400, "You are not authorized to add more than " + minisrv_config.config.user_accounts.max_users_per_account + " account${minisrv_config.config.user_accounts.max_users_per_account > 1 ? 's' : ''}."); +} +else if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account."); + + +if (errpage) { + headers = errpage[0]; + data = errpage[1]; +} else { + + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html` + + data = ` + + + +Adding person's name + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +User's name + +
+ +
+

+ + + + +
+ + +
+Type the person's
+display name
+here. They are
+included when the
+user sends mail. +

Leave the space
+blank if you don't
+want to type this
+person's name. + +

+
+ + + +
+Display name
+ + +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-password.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-password.js new file mode 100644 index 00000000..1e585a5e --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-password.js @@ -0,0 +1,167 @@ +var minisrv_service_file = true; + +ssid_sessions[socket.ssid].loadSessionData(); + +var user_id = (request_headers.query.user_id) ? request_headers.query.user_id : ssid_sessions[socket.ssid].user_id; + +// security +if (ssid_sessions[socket.ssid].user_id != 0 && ssid_sessions[socket.ssid].user_id != user_id) { + user_id = null; // force unset + var errpage = wtvshared.doErrorPage(400, "You are not authorized to change the selected user's password."); + headers = errpage[0]; + data = errpage[1]; +} + +if (user_id != null) { + var userSession = null; + if (ssid_sessions[socket.ssid].user_id == request_headers.query.user_id) userSession = ssid_sessions[socket.ssid]; + else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + userSession.user_id = user_id; + } + + + if (!userSession.loadSessionData()) { + var errpage = wtvshared.doErrorPage(400, "Invalid user ID."); + headers = errpage[0]; + data = errpage[1]; + } + else { + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html`; + + data = ` + + + +Change ${(user_id == ssid_sessions[socket.ssid].user_id) ? 'your' : 'user'} password + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +Change ${(user_id == ssid_sessions[socket.ssid].user_id) ? 'your' : 'user'} password + +
+ +
+

+ + + + +
+ + +
+Type a password
+from ${minisrv_config.config.passwords.min_length} to ${minisrv_config.config.passwords.max_length}
+characters long. +

This password will be
+required to access
+this account. If you
+don't want this
+account to have a
+password, leave
+these spaces blank. + +

+
+ + + + + +
+Password
+`; + if (request_headers.Referer) data += ` +`; + +data += ` +
+
+
Type again to confirm
+ + +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; + } +} +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-begin.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-begin.js new file mode 100644 index 00000000..9d85f7ae --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-begin.js @@ -0,0 +1,164 @@ +var minisrv_service_file = true; +ssid_sessions[socket.ssid].loadSessionData(); + +var user_id = null; +if (request_headers.query.user_id) { + user_id = request_headers.query.user_id; +} else { + user_id = ssid_sessions[socket.ssid].user_id; +} + +// security +if (ssid_sessions[socket.ssid].user_id != 0 && ssid_sessions[socket.ssid].user_id != request_headers.query.user_id) { + user_id = null; // force unset + var errpage = doErrorPage(400, "You are not authorized to edit the selected user."); + headers = errpage[0]; + data = errpage[1]; +} + +if (user_id != null) { + headers = `200 OK +Connection: Keep-Alive +wtv-mail-count: ${ssid_sessions[socket.ssid].mailstore.countUnreadMessages(0)} +Content-Type: text/html` + var userSession = null; + if (ssid_sessions[socket.ssid].user_id == request_headers.query.user_id) userSession = ssid_sessions[socket.ssid]; + else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + userSession.user_id = user_id; + } + + if (!userSession.loadSessionData()) { + var errpage = doErrorPage(400, "Invalid user ID."); + headers = errpage[0]; + data = errpage[1]; + } else { + + data = ` + + + +Changing ${(user_id == 0) ? 'subscriber' : 'user'} information + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +${(user_id == 0) ? 'Subscriber' : 'User'} information + +
+ +
+

+ + + + +
+ + +
+Choose any item to +change the +information. +

Choose Done when +you're finished. + +

+
+ + + + + + + +
+Username:
+${userSession.getSessionData("subscriber_username")} + +
+
+Display Name:
+ +${userSession.getSessionData("subscriber_name")} + +
+
+Password: +
+ +${(userSession.getUserPasswordEnabled()) ? "Change Password" : "Set Password"} + +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; + } +} +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-name.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-name.js new file mode 100644 index 00000000..2e77f440 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/edit-user-name.js @@ -0,0 +1,151 @@ +var minisrv_service_file = true; + +ssid_sessions[socket.ssid].loadSessionData(); + +var user_id = (request_headers.query.user_id) ? request_headers.query.user_id : ssid_sessions[socket.ssid].user_id; + +// security +if (ssid_sessions[socket.ssid].user_id != 0 && ssid_sessions[socket.ssid].user_id != request_headers.query.user_id) { + user_id = null; // force unset + var errpage = wtvshared.doErrorPage(400, "You are not authorized to change the selected user's password."); + headers = errpage[0]; + data = errpage[1]; +} + +if (user_id != null) { + var userSession = null; + if (ssid_sessions[socket.ssid].user_id == request_headers.query.user_id) userSession = ssid_sessions[socket.ssid]; + else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + userSession.user_id = user_id; + } + + if (!userSession.loadSessionData()) { + var errpage = wtvshared.doErrorPage(400, "Invalid user ID."); + headers = errpage[0]; + data = errpage[1]; + } + else { + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html`; + + data = ` + + + +Changing your name + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +Your name + +
+ +
+

+ + + + +
+ + +
+Change your display
+name here. +

Your name is
+included on your
+mail and news posts.
+
+Leave the field blank
+to set your display name to
+${userSession.getSessionData('subscriber_username')}. + +

+
+ + + +
+Display name
+ + +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + +`; + } +} +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/images/AccountBanner.gif b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/images/AccountBanner.gif new file mode 100644 index 0000000000000000000000000000000000000000..8eb45ba306f23a8aa537f25a02a39affb8684285 GIT binary patch literal 3470 zcmbW%dsx!v9sqDqR0KgN@e*jDW-4mp(j={Mvka{fiV~SAsNpRMtAnN+;*GqNm+(^7 z(6sO}XJ(DeHoT)zqh^cDnwFYfo*lR4vdbP0ww*maXPup%^Lsvj{NC^TeZSxD^ZxN} z-m=M`80!l#1HRA$^Z2L!u%^bllLbAk^c8MyhDGFNa4JT$w~ik zbY}90qtJQ(4TqQaUWV&K`;0}6%tA2^)!_aYMMABf3J{t$FJ?*s98dG8_+ zDE||M!udaNIEVh8n;Y?6OlJCf5sA$AqSKTAM4|BhL?F=L1^CN{dkF$A1#x;PS-3ww zH8CAa4rRQoQFJJEllnQmSgM`ZBZB3M4xK*O5W%{7`;!DMzK&PRh33K~xT z-X_>k&d_2~zf@V?p;EuCYiQ5ri^>d{I>Ujtp+6cKV%nuq46R}WQp0$vx4SiO$Nc?Q zVVL-BHHGev%-|ZsoPwq4mgb8Acr4w<(&GRC>j6M8Cb&c1n+sm<9;NQ6?=M6^Go`jS zCTNAT2#eE;W!5Y3mN?~T-#MITLOa$)$ZDGI+tJM2nD zT79Ojo>J+!3i3z=jl^arp&zug+-hZ?=gv$oC;7E-`il;joW{3ddEZ6*-eAcCtOVOb z(WkAGZP4*|tp}RFdfEylzV6O?5!w-3@c6p@!Dblp%R$VA-{wts#B{T}65{W-T}q$z z%f^zu&Tc*86{umhMqfEDs~DUCsen7ba-Zq%oJ?uSURa1tb?)6g4_iV8_T00E>IE#N&p_4*cFj?~=9aAR@U==|)Af44gI6?R znf0#r)KpUNKWz8xkE#S3CkW0=ddQKhZ3Qh&!cx3x=MV>Kw890D+LyR)a&I3CbwBnz z$fhATdun>3NaI;Zw*A^Jf*Ye>$Z3dP5lVSTLDQC>j_si>XxF^_V$U=;ZaTd&dt1-> z>CZlmbG1c>xW&&f1S-NE?sy=o0na?6#-;g|^BV-N9tF$O+~xD389qY;2n*}b^lKKf z9I@tzdFca)x6HnLmO9c^al6ud&?vY@O3xd1FLj|wjpKqc%RIZ4HxD;~PEw08c1oXb zV^hEf#$$Z*$Em(dF|hNetv%l>>0~ zS;#$VF<_iu*~l%eq86hC{uQGxREu)DiBk7V-1;Qd)KeB!v(MRV@0?F8r>QOS2%0~i za5w{~%3(#lX%Wht%Vvy+SG8yD8{nDm=%um<(#S$QG0>_6zusf0!1Ai!STMeLRR?_; zvI%I~CwUy;P8$z)irbw;LY1SnU2$x{ZJJTJM@ol~zuTVwv(b9^pi!Z93&}bMFP@Nm z8)R~lXPIk00ZfP=36}vKx)tk>Vfb^7_4xIX5l5hX8J(wyo@29(<(EAIt?_ttV*W>* zW=VC^Wp+-U@DxMe`|JmhjCYi1HnTj07*fUCR0YR!wb)^g^WyTEW9TH-l&39h4Vck2Sp}1tUnbBLbPJ-$pnW9)Qn7GC zoNJ|T^D)m==cb?f$kNjy2G-UyitSNsLL3Cv!j(DZt>RrQ4!bP$Il$+l%6?6ZDnRPi z=x|FnmgbHmuFn(Q zTjzm}NrIIr)0;njJ(Wgym7ec2DzH3bK8>*#S>IN0NmsC1)Ec(jt8;%#dupqDn@F7D zu0|swTyhWGnaos8k$0|eGj;NqGWYb&cXBo}7wpFY;?4o%AA|Its6$hHI7 zdMSqd?>2ntw=55qKn%Dc{Tgc-m6X50Mdqhr zXy`6ZsOK9%r*QF6rHG$H9*wPA4Jj~IfQL8S2NVWbOk1>rgUCO#Wcwkrh&7^IrxvC| zR^Te61D3W?EWA|mWYFrIP)2&jkcIoJfFgNm#w&r$vDT?I@~0yi-8YKXkkYVEz{T5< zC}UJqK58>y!m2`B>SQriD~7ejn1$&2R{Yu_-I{WiTkmW$+Yd8SBa;Yc#*f`x-NipE_;jq=E_=&b<0m6jus2Kt zafw9S8M0I*+rrjPWt$>tYc=?qXf_M?^`wl8mK~)4BG7~ExWi+=4hf1I z$g>+(+WQOgUG5*o6MaFZHOisH>`u_4sn_x`K$~Zj_r~~4EDA4}Z7k_=-oZ#}uliYx zW(ap1uhaEfM0fZpXl})jgg*3j?*d=VEPNQE-{Kqr-D6UDk7KTL@n|n~U!P=K$F7H* zTuhe(J^AFPHa>F)63SmZrS!%oSg(|)o({yK{l&g0jbOlzPuQB_xy@#wXB5hal{&HD z@M<&^R$?`9qbbOWek`~3mc&G@>xZ44yN7HWhvLVu7VX|+Tn))6LV-O5`6(=CSA%JY zf~z*UWZVchE=&a7-q^SI6kaLm3 z`R-@AI$krp7MKS9u?)@_{RXB7ZW_PI&8-NZKv84zENnWV7Yp*CGZE_HUA>pKmZ*L( z$4S_MRL_0<9nyc~{EksVwkP39_OR$bDd(K|*`CnmVX%*Yk)zd9m<40=tob##!2 z6O+mTYe_cv76p(?18dF3@o}T)ZbR^kFA;aUPvHV?U%_uvJ(QCA- -Your WebTV account +Your ${minisrv_config.config.service_name} account @@ -51,36 +51,28 @@ Your WebTV account
-Your WebTV account +Your ${minisrv_config.config.service_name} account
-Subscriber info
+Subscriber info

-Change your address, phone number, and password
+Change your display name and/or password

-How you pay
+Additional Users

-Change the way you pay for WebTV service
-
-ISP options
-
-Save money if you dial long-distance to WebTV
+Manage additional user accounts
-Billing statement
-
-For your account
-
Terms of service

Rules and regulations

Privacy policy

-Your personal information
+How we use your personal information
@@ -102,7 +94,7 @@ Your WebTV account -
+
diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/setup.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/setup.js index ffef0692..effeb7a3 100644 --- a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/setup.js +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/setup.js @@ -86,11 +86,13 @@ for ${ssid_sessions[socket.ssid].getSessionData("subscriber_username") || "You"} Mail

`; -// password -if (!minisrv_config.config.hide_incomplete_features) { - data += ` -Password
+ +if (minisrv_config.config.passwords) { + if (minisrv_config.config.passwords.enabled) { + data += ` +Password

`; + } } data += ` @@ -114,10 +116,10 @@ data += ` Keyboard

`; -// extra users -if (!minisrv_config.config.hide_incomplete_features) { + +if (ssid_sessions[socket.ssid].user_id == 0) { data += ` -Extra users
+Account

`; } @@ -130,13 +132,10 @@ data += `
Signature and more
-
`; -// password -if (!minisrv_config.config.hide_incomplete_features) { - data += `Change your password
-
`; -} -data += `Options for your TV
+
+Change your password
+
+Options for your TV

Make text bigger or smaller

@@ -147,14 +146,13 @@ if (!minisrv_config.config.hide_incomplete_features) { data += `Change how you print

`; } -data += `Choose an on-screen keyboard
-
`; -// extra users -if (!minisrv_config.config.hide_incomplete_features) { - data += `Add, change, or remove users
-
`; +data += `Choose an on-screen keyboard
`; +if (ssid_sessions[socket.ssid].user_id == 0) { + data += `
+Add, change, or remove users
`; } - data += ` + +data += `
Connecting to WebTV
diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user-done.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user-done.js new file mode 100644 index 00000000..774cf919 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user-done.js @@ -0,0 +1,63 @@ +var minisrv_service_file = true; +var userSession = null; +var errpage = null; + +if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account."); + +// seperate if statements as to not overwrite the first error if multiple occur + +if (!errpage) { + if (request_headers.query.user_password) { + if (request_headers.query.user_password.length < minisrv_config.config.passwords.min_length) errpage = wtvshared.doErrorPage(400, "Your password must contain at least " + minisrv_config.config.passwords.min_length + " characters."); + } + else { + if (request_headers.query.user_password.length > minisrv_config.config.passwords.max_length) errpage = wtvshared.doErrorPage(400, "Your password must contain no more than than " + minisrv_config.config.passwords.max_length + " characters."); + else if (request_headers.query.user_password !== request_headers.query.user_password2) errpage = wtvshared.doErrorPage(400, "The passwords you entered did not match. Please check them and try again."); + } +} + +if (!errpage) { + if (ssid_sessions[socket.ssid].getNumberOfUserAccounts() > minisrv_config.config.user_accounts.max_users_per_account) errpage = wtvshared.doErrorPage(400, "You are not authorized to add more than " + minisrv_config.config.user_accounts.max_users_per_account + " account${minisrv_config.config.user_accounts.max_users_per_account > 1 ? 's' : ''}."); + else if (!request_headers.query.user_name) errpage = wtvshared.doErrorPage(400, "Please enter a username."); + else if (!request_headers.query.display_name) request_headers.query.display_name = request_headers.query.username; +} + +if (errpage) { + headers = errpage[0]; + data = errpage[1]; +} else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + var freeUserId = ssid_sessions[socket.ssid].findFreeUserSlot(ssid_sessions[socket.ssid]); + if (freeUserId) { + userSession.user_id = freeUserId; + userSession.setSessionData("subscriber_name", request_headers.query.display_name); + userSession.setSessionData("subscriber_username", request_headers.query.user_name); + userSession.setSessionData("registered", true); + mailstore_exists = userSession.mailstore.mailstoreExists(); + if (!mailstore_exists) mailstore_exists = userSession.mailstore.createMailstore(); + if (mailstore_exists) { + if (!userSession.mailstore.mailboxExists(mailbox)) { + // mailbox does not yet exist, create it + var mailbox_exists = userSession.mailstore.createMailbox(0); + if (mailbox_exists) { + // Just created Inbox for the first time, so create the welcome message + userSession.mailstore.createWelcomeMessage(); + } + } + } + if (!userSession.saveSessionData(true)) { + var errpage = wtvshared.doErrorPage(400); + headers = errpage[0]; + data = errpage[1]; + } else { + if (request_headers.query.user_password) + userSession.setUserPassword(request_headers.query.user_password); + + headers = `300 OK +Content-type: text/html +Location: wtv-setup:/accounts`; + } + } +} + +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user.js new file mode 100644 index 00000000..20e5db52 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-add-user.js @@ -0,0 +1,184 @@ +var minisrv_service_file = true; +var errpage = null; + +if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account."); + +// seperate if statements as to not overwrite the first error if multiple occur + +if (!errpage) { + if (request_headers.query.user_password) { + if (request_headers.query.user_password.length < minisrv_config.config.passwords.min_length) errpage = wtvshared.doErrorPage(400, "Your password must contain at least " + minisrv_config.config.passwords.min_length + " characters."); + } + else { + if (request_headers.query.user_password.length > minisrv_config.config.passwords.max_length) errpage = wtvshared.doErrorPage(400, "Your password must contain no more than than " + minisrv_config.config.passwords.max_length + " characters."); + else if (request_headers.query.user_password !== request_headers.query.user_password2) errpage = wtvshared.doErrorPage(400, "The passwords you entered did not match. Please check them and try again."); + } +} + +if (!errpage) { + if (ssid_sessions[socket.ssid].getNumberOfUserAccounts() > minisrv_config.config.user_accounts.max_users_per_account) errpage = wtvshared.doErrorPage(400, "You are not authorized to add more than " + minisrv_config.config.user_accounts.max_users_per_account + " account${minisrv_config.config.user_accounts.max_users_per_account > 1 ? 's' : ''}."); + else if (!request_headers.query.user_name) errpage = wtvshared.doErrorPage(400, "Please enter a username."); +} + +if (errpage) { + headers = errpage[0]; + data = errpage[1]; +} else { + + headers = `200 OK +Connection: Keep-Alive +Content-Type: text/html` + + data = ` + + + +Adding a user + + + + + + +
+ + +
+ + + +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+
+
+ + + + + + + + + +
+ + +Adding a user + +
+ +
+

+ + + + +
+ + + + + + + + + + +
+You are adding + +${request_headers.query.user_name}
+
+to your account. +
+
+Display Name: + +${request_headers.query.display_name || request_headers.query.user_name} + +
+
+
+
+ + + + + + + +
+`; + if ((request_headers.query.user_password) == "") { + data += `No password`; + } else { + data += `Has password`; + } + data += ` + +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ + + +`; +} \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-name.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-name.js new file mode 100644 index 00000000..fa5b4591 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-name.js @@ -0,0 +1,39 @@ +var minisrv_service_file = true; + +ssid_sessions[socket.ssid].loadSessionData(); + +var user_id = (request_headers.query.user_id) ? request_headers.query.user_id : ssid_sessions[socket.ssid].user_id; + +// security +if (ssid_sessions[socket.ssid].user_id != 0 && ssid_sessions[socket.ssid].user_id != request_headers.query.user_id) { + user_id = null; // force unset + var errpage = wtvshared.doErrorPage(400, "You are not authorized to change the selected user's password."); + headers = errpage[0]; + data = errpage[1]; +} + +if (user_id != null) { + var userSession; + if (ssid_sessions[socket.ssid].user_id == request_headers.query.user_id) userSession = ssid_sessions[socket.ssid]; + else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + userSession.user_id = user_id; + } + + if (!userSession.loadSessionData()) { + var errpage = wtvshared.doErrorPage(400, "Invalid user ID."); + headers = errpage[0]; + data = errpage[1]; + } + else { + var user_name = userSession.getSessionData('subscriber_username'); + userSession.setSessionData('subscriber_name', (request_headers.query.display_name) ? request_headers.query.display_name : user_name); + userSession.saveSessionData(); + headers = `300 OK +Content-type: text/html +wtv-expire: wtv-setup:/edit-user-begin?user_id=${user_id} +wtv-expire: wtv-setup:/edit-user-name?user_id=${user_id} +Location: wtv-setup:/edit-user-begin?user_id=${user_id}`; + } +} +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-password.js b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-password.js new file mode 100644 index 00000000..11165f81 --- /dev/null +++ b/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-change-password.js @@ -0,0 +1,75 @@ +var minisrv_service_file = true; +var userSession = null; + +ssid_sessions[socket.ssid].loadSessionData(); + +var user_id = null; +if (request_headers.query.user_id) { + user_id = request_headers.query.user_id; +} else { + var errpage = doErrorPage(400, "User was not specified."); + headers = errpage[0]; + data = errpage[1]; +} + +if (ssid_sessions[socket.ssid].user_id != 0 && ssid_sessions[socket.ssid].user_id != request_headers.query.user_id) { + user_id = null; // force unset + var errpage = doErrorPage(400, "You are not authorized to edit the selected user."); + headers = errpage[0]; + data = errpage[1]; +} + +if (user_id) { + headers = `200 OK +Connection: Keep-Alive +wtv-mail-count: ${ssid_sessions[socket.ssid].mailstore.countUnreadMessages(0)} +Content-Type: text/html` + var userSession = null; + if (ssid_sessions[socket.ssid].user_id == request_headers.query.user_id) userSession = ssid_sessions[socket.ssid]; + else { + userSession = new WTVClientSessionData(minisrv_config, socket.ssid); + userSession.user_id = user_id; + } + + if (!userSession.loadSessionData()) { + var errpage = doErrorPage(400, "Invalid user ID."); + headers = errpage[0]; + data = errpage[1]; + } + else { + if (request_headers.query.password.length == 0 && request_headers.query.verify.length == 0) { + userSession.disableUserPassword(); + headers = `300 OK +Content-type: text/html +wtv-expire: wtv-setup:/setup +`; + if (request_headers.query.return_to) { + headers += `wtv-expire: ${request_headers.query.return_to} +Location: ${request_headers.query.return_to}`; + } + else headers += "Location: " + (ssid_sessions[socket.ssid].user_id === user_id) ? 'wtv-setup:/setup' : 'wtv-setup:/accounts'; + } + else if (request_headers.query.password.length < minisrv_config.config.passwords.min_length) errpage = wtvshared.doErrorPage(400, "Your password must contain at least " + minisrv_config.config.passwords.min_length + " characters."); + else if (request_headers.query.password.length > minisrv_config.config.passwords.max_length) errpage = wtvshared.doErrorPage(400, "Your password must contain no more than than " + minisrv_config.config.passwords.max_length + " characters."); + else if (request_headers.query.password !== request_headers.query.verify) errpage = wtvshared.doErrorPage(400, "The passwords you entered did not match. Please check them and try again."); + else { + if (errpage) { + headers = errpage[0]; + data = errpage[1]; + } else { + userSession.setUserPassword(request_headers.query.password); + headers = `300 OK +Content-type: text/html +wtv-expire: wtv-setup:/setup +`; + if (request_headers.query.return_to) { + headers += `wtv-expire: ${request_headers.query.return_to} +Location: ${request_headers.query.return_to}`; + } + else headers += "Location: "+ (ssid_sessions[socket.ssid].user_id === user_id) ? 'wtv-setup:/setup' : 'wtv-setup:/accounts'; + } + } + } +} + +if (userSession) userSession = null; \ No newline at end of file diff --git a/zefie_wtvp_minisrv/WTVClientSessionData.js b/zefie_wtvp_minisrv/WTVClientSessionData.js index ee0f5ea4..b0b1d087 100644 --- a/zefie_wtvp_minisrv/WTVClientSessionData.js +++ b/zefie_wtvp_minisrv/WTVClientSessionData.js @@ -1,4 +1,5 @@ const { lib } = require('crypto-js'); +const CryptoJS = require('crypto-js'); class WTVClientSessionData { @@ -20,6 +21,7 @@ class WTVClientSessionData { lockdownWhitelist = null; baddisk = false; clientAddress = null; + user_id = 0; constructor(minisrv_config, ssid) { if (!minisrv_config) throw ("minisrv_config required"); @@ -36,22 +38,98 @@ class WTVClientSessionData { this.lockdownWhitelist = [ "wtv-1800:/preregister", "wtv-head-waiter:/login", - "wtv-head-waiter:/relogin", + "wtv-head-waiter:/password", + "wtv-head-waiter:/ValidateLogin", "wtv-head-waiter:/login-stage-two", + "wtv-head-waiter:/relogin", "wtv-head-waiter:/bad-disk", - "wtv-log:/log" + "wtv-head-waiter:/images/PasswordBanner.gif", + "wtv-log:/log", ]; this.lockdownWhitelist.push(minisrv_config.config.unauthorized_url); + this.lockdownWhitelist.push(minisrv_config.config.service_logo); + + this.loginWhitelist = Object.assign([], this.lockdownWhitelist); // clone lockdown whitelist into login whitelist this.mailstore = new WTVMail(minisrv_config, ssid, this); } + + switchUserID(user_id) { + this.user_id = user_id; + var wtvsec_tmp = this.get("wtvsec_login"); + this.loadSessionData(); + this.set("wtvsec_login", wtvsec_tmp); + wtvsec_tmp = null; + } + + findFreeUserSlot() { + if (this.user_id != 0) return false; // subscriber only command + var master_directory = this.getUserStoreDirectory(true); + if (this.fs.existsSync(master_directory)) { + for (var i = 0; i < this.minisrv_config.config.user_accounts.max_users_per_account; i++) { + var test_dir = master_directory + this.path.sep + "user" + i; + if (!this.fs.existsSync(test_dir)) { + return i; + break; + } + } + } + return false; + } + + getDisplayName() { + return (this.user_id == 0) ? this.getSessionData("subscriber_name") : this.getSessionData("display_name"); + } + + getNumberOfUserAccounts() { + if (this.user_id != 0) return false; // subscriber only command + return Object.keys(this.listPrimaryAccountUsers()).length; + } + + listPrimaryAccountUsers() { + if (this.user_id != 0) return false; // subscriber only command + + var master_directory = this.getUserStoreDirectory(true); + var account_data = []; + var self = this; + this.fs.readdirSync(master_directory).forEach(f => { + if (self.fs.lstatSync(master_directory + self.path.sep + f).isDirectory()) { + if (f.substr(0, 4) == "user") { + var user_file = master_directory + self.path.sep + f + self.path.sep + f + ".json"; + if (self.fs.existsSync(user_file)) { + if (f == "user0") account_data['subscriber'] = JSON.parse(this.fs.readFileSync(user_file)); + else account_data[f] = JSON.parse(this.fs.readFileSync(user_file)); + } + } + } + }); + return account_data; + } + + + mkdirRecursive(thedir) { + thedir.split(this.path.sep).reduce( + (directories, directory) => { + directories += directory + this.path.sep; + if (!this.fs.existsSync(directories)) { + this.fs.mkdirSync(directories); + } + return directories; + }, + '', + ); + } + /** * Returns the absolute path to the user's file store, or false if unregistered + * @param subscriber {boolean} Returns the parent subscriber directory instead of the user's directory * @returns {string|boolean} Absolute path to the user's file store, or false if unregistered */ - getUserStoreDirectory() { - if (!this.isRegistered()) return false; - return this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + this.path.sep; + getUserStoreDirectory(subscriber = false) { + //if (!this.isRegistered()) return false; + var userstore = this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + this.path.sep; + if (!subscriber) userstore += "user" + this.user_id + this.path.sep; + return userstore; } /** @@ -249,8 +327,8 @@ class WTVClientSessionData { loadSessionData(raw_data = false) { try { - if (this.fs.lstatSync(this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + ".json")) { - var json_data = this.fs.readFileSync(this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + ".json", 'Utf8') + if (this.fs.lstatSync(this.getUserStoreDirectory() + "user" + this.user_id + ".json")) { + var json_data = this.fs.readFileSync(this.getUserStoreDirectory() + "user" + this.user_id + ".json", 'Utf8') if (raw_data) return json_data; var session_data = JSON.parse(json_data); @@ -264,6 +342,41 @@ class WTVClientSessionData { } } + encodePassword(passwd) { + var encoded_passwd = CryptoJS.SHA512(passwd); + return encoded_passwd.toString(CryptoJS.enc.Base64); + } + + setUserPassword(passwd) { + var encoded_passwd = this.encodePassword(passwd); + this.setSessionData("subscriber_password", encoded_passwd); + this.saveSessionData(); + } + + disableUserPassword() { + this.setSessionData("subscriber_password", null); + this.saveSessionData(); + } + + getUserPasswordEnabled() { + if (!this.minisrv_config.config.passwords.enabled) return false; // master config override + var enabled = this.getSessionData("subscriber_password"); + return (enabled); // true if set, false if null/disabled + } + + validateUserPassword(passwd) { + if (!this.getUserPasswordEnabled()) return true; // no password is set so always validate + + var encoded_passwd = this.encodePassword(passwd); + return (encoded_passwd == this.getSessionData("subscriber_password")); + } + + isUserLoggedIn() { + if (!this.getUserPasswordEnabled()) return true; // no password is set so always validate + var password_valid = this.getSessionData("password_valid"); + return (password_valid); + } + saveSessionData(force_write = false) { if (this.isRegistered()) { // load data from disk and merge new data @@ -281,7 +394,11 @@ class WTVClientSessionData { // only save if file has changed var json_save_data = JSON.stringify(this.session_store); var json_load_data = this.loadSessionData(true); - if (json_save_data != json_load_data) this.fs.writeFileSync(this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + ".json", JSON.stringify(this.session_store), "Utf8"); + var storeDir = this.getUserStoreDirectory(); + if (!this.fs.existsSync(storeDir)) this.mkdirRecursive(storeDir); + var sessionToStore = this.session_store; + if (sessionToStore.password_valid) delete sessionToStore.password_valid; // do not save validity state of password login, resets when session expires + if (json_save_data != json_load_data) this.fs.writeFileSync(storeDir + "user" + this.user_id + ".json", JSON.stringify(sessionToStore), "Utf8"); return true; } catch (e) { console.error(" # Error saving session data for", this.wtvshared.filterSSID(this.ssid), e); @@ -305,14 +422,7 @@ class WTVClientSessionData { } isRegistered() { - var self = this; - var ssid_match = false; - this.fs.readdirSync(this.minisrv_config.config.SessionStore).forEach(file => { - if (!file.match(/.*\.json/ig)) return; - if (ssid_match) return; - if (file.split('.')[0] == self.ssid) ssid_match = true; - }); - return ssid_match; + return (this.getSessionData("registered") && this.fs.existsSync(this.getUserStoreDirectory())); } unregisterBox() { @@ -540,16 +650,25 @@ class WTVClientSessionData { } - isAuthorized(url) { + isAuthorized(url, whitelist = 'lockdown') { // not in lockdown so just return true if (!this.lockdown) return true; // in lockdown, check whitelisted urls var self = this; var authorized = false; - Object.keys(this.lockdownWhitelist).forEach(function (k) { - if (self.lockdownWhitelist[k].substring(0, url.length) == url) authorized = true; - }); + switch (whitelist) { + case "lockdown": + Object.keys(this.lockdownWhitelist).forEach(function (k) { + if (self.lockdownWhitelist[k].substring(0, url.length) == url) authorized = true; + }); + break; + case "login": + Object.keys(this.loginWhitelist).forEach(function (k) { + if (self.loginWhitelist[k].substring(0, url.length) == url) authorized = true; + }); + break; + } return authorized; } diff --git a/zefie_wtvp_minisrv/WTVMail.js b/zefie_wtvp_minisrv/WTVMail.js index 023dac6e..4b54fc10 100644 --- a/zefie_wtvp_minisrv/WTVMail.js +++ b/zefie_wtvp_minisrv/WTVMail.js @@ -134,7 +134,7 @@ class WTVMail { var mailbox_path = this.getMailboxStoreDir(mailboxid); var message_id = this.createMessageID(); - var message_file = messageid + this.msgFileExt; + var message_file = message_id + this.msgFileExt; var message_file_out = mailbox_path + message_file; var message_data = { "from_addr": from_addr, diff --git a/zefie_wtvp_minisrv/WTVRegister.js b/zefie_wtvp_minisrv/WTVRegister.js index 3ad670ef..cf275cfa 100644 --- a/zefie_wtvp_minisrv/WTVRegister.js +++ b/zefie_wtvp_minisrv/WTVRegister.js @@ -28,13 +28,19 @@ class WTVRegister { return (check1 && check2); } - checkUsernameAvailable(username, ssid_sessions) { + checkUsernameAvailable(username, ssid_sessions, directory = null) { var username_match = false; - this.fs.readdirSync(this.session_store_dir).forEach(file => { + var search_dir = this.session_store_dir; + var self = this; + if (directory) search_dir = directory; + this.fs.readdirSync(search_dir).forEach(file => { + if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory()) { + return self.checkUsernameAvailable(username, ssid_sessions, search_dir + self.path.sep + file); + } if (!file.match(/.*\.json/ig)) return; if (username_match) return; try { - var temp_session_data_file = this.fs.readFileSync(this.session_store_dir + this.path.sep + file, 'Utf8'); + var temp_session_data_file = this.fs.readFileSync(search_dir + this.path.sep + file, 'Utf8'); var temp_session_data = JSON.parse(temp_session_data_file); if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) username_match = true; } catch (e) { diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 4c2c59c8..1abe6856 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -395,6 +395,17 @@ async function processURL(socket, request_headers) { } } + if (!ssid_sessions[socket.ssid].isUserLoggedIn() && !ssid_sessions[socket.ssid].isAuthorized(shortURL, 'login')) { + // lockdown mode and URL not authorized + headers = "300 Unauthorized\n"; + headers += "Location: " + minisrv_config.config.unauthorized_url + "\n"; + data = ""; + sendToClient(socket, headers, data); + console.log(" * Rejected login bypass request for " + shortURL + " on socket ID", socket.id); + return; + } + + // Check URL for :/, but not :// (to differentiate wtv urls) if (shortURL.indexOf(':/') >= 0 && shortURL.indexOf('://') == -1) { var ssid = socket.ssid; @@ -671,6 +682,17 @@ async function sendToClient(socket, headers_obj, data) { var wtv_connection_close = (headers_obj["wtv-connection-close"]) ? true : false; if (typeof (headers_obj["wtv-connection-close"]) != 'undefined') delete headers_obj["wtv-connection-close"]; + if (!headers_obj['minisrv-no-mail-count']) { + if (ssid_sessions[socket.ssid]) { + if (ssid_sessions[socket.ssid].mailstore) { + headers_obj['wtv-mail-count'] = ssid_sessions[socket.ssid].mailstore.countUnreadMessages(0); + } + } + } else { + if (headers_obj['wtv-mail-count']) delete headers_obj['wtv-mail-count']; + delete headers_obj['minisrv-no-mail-count']; + } + // add Connection header if missing, default to Keep-Alive if (!headers_obj.Connection) { headers_obj.Connection = "Keep-Alive"; @@ -1507,6 +1529,16 @@ if (minisrv_config.config.error_log_file) { process.stderr.write = writeError } +if (minisrv_config.config.passwords) { + if (minisrv_config.config.passwords.enabled) { + if (!minisrv_config.config.passwords.encryption_key) { + console.log(" * WARNING: passwords.encryption_key not defined, using default. Consider setting a unique key before setting passwords."); + console.log(" * WARNING: Changing the encryption key after users have set passwords will invalidate and lock out all users who have set passwords, without your manual intervention."); + minisrv_config.config.passwords.encryption_key = minisrv_config.config.passwords.default_encryption_key; + } + } +} + process.on('uncaughtException', function (err) { console.error((err && err.stack) ? err.stack : err); }); diff --git a/zefie_wtvp_minisrv/config.json b/zefie_wtvp_minisrv/config.json index dac0a17a..0e1ea780 100644 --- a/zefie_wtvp_minisrv/config.json +++ b/zefie_wtvp_minisrv/config.json @@ -27,7 +27,19 @@ "show_diskmap": false, "unauthorized_url": "wtv-1800:/unauthorized?", "allow_guests": true, - "domain_name": "wtv.zefie.com" + "domain_name": "wtv.zefie.com", + "user_accounts": { + "max_users_per_account": 6, + "min_username_length": 5, + "max_username_length": 18 + }, + "passwords": { + "enabled": true, + "min_length": 5, + "max_length": 32, + "form_size": 16, + "default_encryption_key": "S4WZvVfoQ77fovegdO7olln0P0ZNAMWe" + } }, "services": { "wtv-head-waiter": { diff --git a/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj b/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj index a909d052..11bc65f3 100644 --- a/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj +++ b/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj @@ -88,9 +88,12 @@ + + Code + Code @@ -245,12 +248,19 @@ + + + + + + + Code @@ -277,9 +287,15 @@ + + Code + + Code + + Code