diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/MakeChatPage.js b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/MakeChatPage.js
index b75a4c37..22725453 100644
--- a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/MakeChatPage.js
+++ b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/MakeChatPage.js
@@ -1,13 +1,6 @@
-headers = `200 OK`;
-
-
-if (request_headers.query.nick) headers += `
-wtv-irc-nick: ${request_headers.query.nick}
-wtv-user-nick: ${request_headers.query.nick}`
-;
-
-headers += `
-Content-Type: text/html`;
+headers = "200 OK";
+if (request_headers.query.nick) headers += "\n" + ssid_sessions[socket.ssid].setIRCNick(request_headers.query.nick);
+headers += "\nContent-Type: text/html";
if (request_headers.query.host && request_headers.query.port && request_headers.query.channel) {
data = `
@@ -46,16 +39,6 @@ ${request_headers.query.channel}
-|
- |
|
@@ -120,12 +103,9 @@ ${request_headers.query.channel}
|
|
- |
+ |
- Go to
-
-
- |
+ Home
| |
diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.html b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.html
deleted file mode 100644
index 2f14e323..00000000
--- a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.html
+++ /dev/null
@@ -1,123 +0,0 @@
-
-
-
-Chat Home
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- |
-
- | | |
-
-
-
- | |
-
-
-
-
-
-
-
-
-
- |
- |
-
-
-|
-
- |
-
-
-
-
-
-
-|
-
- |
-
-
-|
- |
- |
-
-Chat Home
-
-
- |
- | |
- |
- |
-
-
-
-
-|
- |
-yo yo yo yo
-
-enter your nick...
-
- |
- |
-|
-
- |
- |
-
-
-|
- |
-|
- |
-
-
-|
- | | | |
-
-
-
diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js
new file mode 100644
index 00000000..72891537
--- /dev/null
+++ b/zefie_wtvp_minisrv/ServiceVault/wtv-chat/home.js
@@ -0,0 +1,144 @@
+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);
+headers += "\nContent-Type: text/html";
+
+var irc_nick = ssid_sessions[socket.ssid].get("wtv-irc-nick");
+
+data = `
+
+
+Chat Home (Testing)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+ | | |
+
+
+ |
+ |
+|
+ |
+
+ |
+ | |
+ |
+|
+ |
+
+ |
+ | |
+ |
+|
+ |
+ |
+
+ | |
+
+
+
+
+
+
+
+
+ |
+ |
+
+
+|
+
+ |
+
+
+
+
+`;
\ 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 5f4e23a1..0272707d 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
@@ -47,8 +47,8 @@ Content-type: text/html`;
}
else {
var namerand = Math.floor(Math.random() * 100000);
- var nickname = (minisrv_config.config.service_name + '_' + namerand).substring(0, 16);
- var userid = '1'+ Math.floor(Math.random() * 1000000000000000000);
+ var nickname = (minisrv_config.config.service_name + '_' + namerand)
+ var userid = '1' + Math.floor(Math.random() * 1000000000000000000);
var offline_user_list = CryptoJS.enc.Latin1.parse("\n\t\n").toString(CryptoJS.enc.Base64);
data = '';
headers = `200 OK
@@ -77,9 +77,8 @@ wtv-noback-all: wtv-
wtv-service: reset
`+ getServiceString('all') + `
wtv-boot-url: wtv-1800:/preregister?relogin=true
-wtv-user-name: ${nickname}
wtv-human-name: ${nickname}
-wtv-irc-nick: ${nickname}
+${ssid_sessions[socket.ssid].setIRCNick(nickname)}
wtv-home-url: wtv-home:/home?
wtv-domain: wtv.zefie.com
wtv-inactive-timeout: 0
diff --git a/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js b/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js
index 0b59c112..46edaa79 100644
--- a/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js
+++ b/zefie_wtvp_minisrv/ServiceVault/wtv-home/home.js
@@ -11,7 +11,7 @@ if (ssid_sessions[socket.ssid].get('box-does-psuedo-encryption')) {
}
-data =`
+data = `
Home for minisrv
@@ -29,12 +29,25 @@ function go() {
`
+`;
}
data += "\n";
diff --git a/zefie_wtvp_minisrv/WTVClientCapabilities.js b/zefie_wtvp_minisrv/WTVClientCapabilities.js
index 587586cb..8cd474da 100644
--- a/zefie_wtvp_minisrv/WTVClientCapabilities.js
+++ b/zefie_wtvp_minisrv/WTVClientCapabilities.js
@@ -118,9 +118,8 @@ class WTVClientCapabilities {
// convert wtv_capability_flags to binary string, reverse the string, and split into array containing each character;
var bitfield = hex2bin(wtv_capability_flags).reverse().split("");
- // only add to the capabilities array if the result is true
var add = function (flag_name, flag) {
- if (flag) capabilities[flag_name] = flag;
+ capabilities[flag_name] = flag;
}
// process bitfield and set capabilities
diff --git a/zefie_wtvp_minisrv/WTVClientSessionData.js b/zefie_wtvp_minisrv/WTVClientSessionData.js
index 7bec66c7..ba7b5dbf 100644
--- a/zefie_wtvp_minisrv/WTVClientSessionData.js
+++ b/zefie_wtvp_minisrv/WTVClientSessionData.js
@@ -9,11 +9,48 @@ class WTVClientSessionData {
\***********************************/
data_store = null;
+ capabilities = null;
constructor() {
this.data_store = new Array();
}
+ hasCap(cap) {
+ if (this.capabilities) {
+ return this.capabilities[cap] || false;
+ }
+ return false;
+ }
+
+ getMaxUsernameLength() {
+ if (parseInt(this.data_store['wtv-system-version'] < 4000)) {
+ // older builds may crash with nicknames longer than 16 chars.
+ // actual build where support started is yet unknown
+ return 16;
+ } else {
+ // newer builds supported up to 32 chars, I think
+ return 32;
+ }
+ }
+
+ setIRCNick(nick) {
+ // strip out unsupported chars
+ nick = nick.replace(/[^a-zA-Z0-9\-\_\`\^]/g, "");
+
+ // limit nick length based on build support
+ nick = nick.substring(0, this.getMaxUsernameLength());
+
+ // returns headers to send to client, while storing the new data in our session data.
+ this.data_store['wtv-user-name'] = nick;
+ this.data_store['wtv-irc-nick'] = nick;
+ return "wtv-irc-nick: " + nick + "\nwtv-user-nick: " + nick;
+ }
+
+ isMiniBrowser() {
+ if (this.data_store['wtv-need-upgrade'] || this.data_store['wtv-used-8675309']) return true;
+ return false;
+ }
+
get(key = null) {
if (typeof (this.data_store) === 'undefined') return null;
else if (key === null) return this.data_store;
diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js
index f0e09753..734a1e4f 100644
--- a/zefie_wtvp_minisrv/app.js
+++ b/zefie_wtvp_minisrv/app.js
@@ -9,6 +9,7 @@ const net = require('net');
const CryptoJS = require('crypto-js');
const mime = require('mime-types');
const { crc16 } = require('easy-crc');
+const process = require('process');
var WTVSec = require('./WTVSec.js');
var WTVClientCapabilities = require('./WTVClientCapabilities.js');
var WTVClientSessionData = require('./WTVClientSessionData.js');
@@ -71,6 +72,7 @@ function doErrorPage(code, data = null) {
headers += "Content-Type: text/html\r\n";
break;
}
+ console.error("doErrorPage Called:", code, data);
return new Array(headers, data);
}
@@ -166,11 +168,11 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
var errpage = doErrorPage(400);
headers = errpage[0];
data = errpage[1] + "
The interpreter said:
" + e.toString() + " ";
- console.log(" * Scripting error:",e);
+ console.error(" * Scripting error:",e);
}
if (!request_is_async) {
if (!service_vault_found) {
- console.log(" * Could not find a Service Vault for " + service_name + ":/" + service_path.replace(service_name + path.sep, ""));
+ console.error(" * Could not find a Service Vault for " + service_name + ":/" + service_path.replace(service_name + path.sep, ""));
var errpage = doErrorPage(404);
headers = errpage[0];
data = errpage[1];
@@ -179,8 +181,8 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
var errpage = doErrorPage(400);
headers = errpage[0];
data = errpage[1];
- console.log(" * Scripting or Data error: Headers were not defined. (headers,data) as follows:")
- console.log(socket.id, headers, data)
+ console.error(" * Scripting or Data error: Headers were not defined. (headers,data) as follows:")
+ console.error(socket.id, headers, data)
}
if (data === null) {
data = '';
@@ -215,6 +217,7 @@ function filterSSID(obj) {
function makeSafePath(base, target) {
target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, "");
+ if (path.sep != "/") target = target.replace(/\//g, path.sep);
var targetPath = path.posix.normalize(target)
return base + path.sep + targetPath;
}
@@ -729,7 +732,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
if (!ssid_sessions[socket.ssid]) {
ssid_sessions[socket.ssid] = new WTVClientSessionData();
}
- if (!ssid_sessions[socket.ssid].data_store.capabilities) ssid_sessions[socket.ssid].data_store.capabilities = new WTVClientCapabilities(headers["wtv-capability-flags"]);
+ if (!ssid_sessions[socket.ssid].capabilities) ssid_sessions[socket.ssid].capabilities = new WTVClientCapabilities(headers["wtv-capability-flags"]);
}
@@ -1058,7 +1061,7 @@ async function cleanupSocket(socket) {
}
socket.end();
} catch (e) {
- console.log(" # Could not clean up socket data for socket ID", socket.id, e);
+ console.error(" # Could not clean up socket data for socket ID", socket.id, e);
}
}
@@ -1068,7 +1071,7 @@ async function handleSocket(socket) {
socket.id = parseInt(crc16('CCITT-FALSE', Buffer.from(String(socket.remoteAddress) + String(socket.remotePort), "utf8")).toString(16), 16);
socket_sessions[socket.id] = [];
socket.setEncoding('hex'); //set data encoding (Text: 'ascii', 'utf8' ~ Binary: 'hex', 'base64' (do not trust 'binary' encoding))
- socket.setTimeout(600000);
+ socket.setTimeout(10800000); // 3 hours
socket.on('data', function (data_hex) {
if (!socket_sessions[socket.id].secure && !socket_sessions[socket.id].expecting_post_data) {
// buffer unencrypted data until we see the classic double-newline, or get blank
@@ -1120,7 +1123,7 @@ function integrateConfig(main, user) {
return main;
}
-function returnAbsolsutePath(check_path) {
+function returnAbsolutePath(check_path) {
if (check_path.substring(0, 1) != path.sep && check_path.substring(1, 1) != ":") {
// non-absolute path, so use current directory as base
check_path = (__dirname + path.sep + check_path);
@@ -1170,7 +1173,7 @@ try {
try {
var minisrv_user_config = JSON.parse(fs.readFileSync(__dirname + "/user_config.json"));
} catch (e) {
- console.log("ERROR: Could not read user_config.json", e);
+ console.error("ERROR: Could not read user_config.json", e);
var throw_me = true;
}
// file exists and we read and parsed it, but the variable is undefined
@@ -1178,11 +1181,11 @@ try {
try {
minisrv_config = integrateConfig(minisrv_config, minisrv_user_config)
} catch (e) {
- console.log("ERROR: Could not read user_config.json", e);
+ console.error("ERROR: Could not read user_config.json", e);
}
}
} catch (e) {
- if (zdebug) console.log(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
+ if (zdebug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
}
if (throw_me) {
@@ -1191,7 +1194,7 @@ if (throw_me) {
if (minisrv_config.config.ServiceVaults) {
Object.keys(minisrv_config.config.ServiceVaults).forEach(function (k) {
- var service_vault = returnAbsolsutePath(minisrv_config.config.ServiceVaults[k]);
+ var service_vault = returnAbsolutePath(minisrv_config.config.ServiceVaults[k]);
service_vaults.push(service_vault);
console.log(" * Configured Service Vault at", service_vault, "with priority",(parseInt(k)+1));
})
@@ -1231,6 +1234,19 @@ if (minisrv_config.config.service_logo.indexOf(':') == -1) minisrv_config.config
if (minisrv_config.config.service_splash_logo.indexOf(':') == -1) minisrv_config.config.service_splash_logo = "wtv-star:/ROMCache/" + minisrv_config.config.service_splash_logo;
minisrv_config.version = require('./package.json').version;
+if (minisrv_config.config.error_log_file) {
+ var error_log_stream = fs.createWriteStream(returnAbsolutePath(minisrv_config.config.error_log_file), { flags: 'a' });
+ var process_stderr = process.stderr.write;
+ var writeError = function() {
+ process_stderr.apply(process.stderr, arguments);
+ if (error_log_stream) error_log_stream.write.apply(error_log_stream, arguments);
+ }
+ process.stderr.write = writeError
+}
+
+process.on('uncaughtException', function (err) {
+ console.error((err && err.stack) ? err.stack : err);
+});
// defaults
var zdebug = false;
@@ -1289,6 +1305,8 @@ bind_ports.forEach(function (v) {
});
initstring = initstring.substring(0, initstring.length - 2);
+
+
console.log(" * Started server on ports " + initstring + "...")
var listening_ip_string = (minisrv_config.config.bind_ip != "0.0.0.0") ? "IP: " + minisrv_config.config.bind_ip : "all interfaces";
console.log(" * Listening on", listening_ip_string,"~","Service IP:", service_ip);
diff --git a/zefie_wtvp_minisrv/config.json b/zefie_wtvp_minisrv/config.json
index 71468cfc..898e651a 100644
--- a/zefie_wtvp_minisrv/config.json
+++ b/zefie_wtvp_minisrv/config.json
@@ -10,7 +10,8 @@
"service_splash_logo": "splash_logo_msn.gif",
"hide_ssid_in_logs": true,
"post_percentages": [ 0, 25, 50, 100],
- "verbosity": 2
+ "verbosity": 2,
+ "error_log_file": "errors.log"
},
"services": {
"wtv-1800": {
diff --git a/zefie_wtvp_minisrv/package.json b/zefie_wtvp_minisrv/package.json
index 5286c4aa..1f2fd2a6 100644
--- a/zefie_wtvp_minisrv/package.json
+++ b/zefie_wtvp_minisrv/package.json
@@ -1,6 +1,6 @@
{
"name": "zefie_wtvp_minisrv",
- "version": "0.9.6",
+ "version": "0.9.7",
"description": "WebTV Service (WTVP) Emulation Server",
"main": "app.js",
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv",
diff --git a/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj b/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj
index 2c248647..96f24d9f 100644
--- a/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj
+++ b/zefie_wtvp_minisrv/zefie_wtvp_minisrv.njsproj
@@ -32,6 +32,11 @@
+
+
+
+
+
Code
@@ -219,6 +224,7 @@
+
| | | | | | |