v0.9.16
- numerous bug fixes - improve session retention - use wtv-head-waiter:/relogin for boot url - viewer seems to retain only wtv-* and wtv-head-waiter, so lets try to be closer to protocol and boot with a wtv-head-waiter address instead of wtv-1800 - we still handle via wtv-1800 but we accept wtv-head-waiter:/relogin and send the client on its way to the relogin path - update wtv-home:/home - remove spacing in favor of right alignment - add compression status - guest mode session store update - allow calls to saveSessionData() but do not actually write if user is guest - saveSessionData() returns true even if guest, because false is meant to define an error - You can also use SaveIfRegistered(), this will return false on both saveSessionData() errors AND guest mode; - if you want to block guests, check for isRegistered() and block the request if it is false - otherwise this update will allow all tools (including any logins) to work with guest mode, but the stored SessionData will not be persistently saved, and lost when the cleanup timeout hits (default 3 min), or the server is restarted. - more accurately mimic WTVP by accepting URLs without / - use service-style cookie links on tricks - add catchall system & http pc server - define a catchall name to run globally or per service - catchall must be javascript, but not necessarily a .js file - catchall can request async mode - catchall will catch any non-existing requests under its directory - see wtv-flashrom:/content/content-serve.js as an example, which will catch wtv-flashrom:/content/ URLs. - http pc: sends HTTP/1.0 to PC clients - can be disabled with `pc_server_hidden_service_enabled`: false - can change servicevault path by changing string of pc_server_hidden_service - get.js in default PC service vault to get any WTV Url on the service - flashrom system updates - fix bugs - more WNI-like flow path - make scripts use `service_name` variable so that they should work in a renamed service (eg not wtv-flashrom, untested) - rewrite wtv-disk system - move wtv-update to wtv-disk - allow accessing wtv-disk:/sync?group=&diskmap= - rewrite Download List generation to be more proper - only send files if diskmap has changed - allow force redownload with &force=true
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const { lib } = require('crypto-js');
|
||||
|
||||
class WTVClientSessionData {
|
||||
|
||||
fs = require('fs');
|
||||
@@ -38,7 +40,8 @@ class WTVClientSessionData {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(hide_ssid_in_logs, session_storage_directory) {
|
||||
constructor(ssid, hide_ssid_in_logs, session_storage_directory) {
|
||||
this.ssid = ssid;
|
||||
if (hide_ssid_in_logs) this.hide_ssid_in_logs = hide_ssid_in_logs;
|
||||
if (!session_storage_directory) session_storage_directory = __dirname + "/SessionStore";
|
||||
this.session_storage = session_storage_directory;
|
||||
@@ -91,9 +94,6 @@ class WTVClientSessionData {
|
||||
|
||||
this.session_store.cookies[cookie_index] = Object.assign({}, cookie_data);
|
||||
|
||||
// do not write file if user is not registered
|
||||
if (getSessionData('registered')) this.storeSessionData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,11 +172,13 @@ class WTVClientSessionData {
|
||||
return outstring;
|
||||
}
|
||||
|
||||
loadSessionData() {
|
||||
loadSessionData(raw_data = false) {
|
||||
try {
|
||||
if (this.fs.lstatSync(this.session_storage + this.path.sep + this.ssid + ".json")) {
|
||||
var session_data_file = this.fs.readFileSync(this.session_storage + this.path.sep + this.ssid + ".json", 'Utf8');
|
||||
var session_data = JSON.parse(session_data_file);
|
||||
var json_data = this.fs.readFileSync(this.session_storage + this.path.sep + this.ssid + ".json", 'Utf8')
|
||||
if (raw_data) return json_data;
|
||||
|
||||
var session_data = JSON.parse(json_data);
|
||||
this.session_store = session_data;
|
||||
return true;
|
||||
}
|
||||
@@ -188,14 +190,22 @@ class WTVClientSessionData {
|
||||
}
|
||||
|
||||
saveSessionData() {
|
||||
if (!this.session_store.registered) {
|
||||
if (this.isRegistered()) {
|
||||
// load data from disk and merge new data
|
||||
var temp_store = this.session_store;
|
||||
this.loadSessionData();
|
||||
this.session_store = Object.assign(this.session_store, temp_store);
|
||||
if (this.loadSessionData()) this.session_store = Object.assign(this.session_store, temp_store);
|
||||
else this.session_store = temp_store;
|
||||
temp_store = null;
|
||||
} else {
|
||||
// do not write file if user is not registered, return true because this is not an error
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
var store_data = JSON.stringify(this.session_store);
|
||||
this.fs.writeFileSync(this.session_storage + this.path.sep + this.ssid + ".json", store_data, "Utf8");
|
||||
// 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.session_storage + this.path.sep + this.ssid + ".json", JSON.stringify(this.session_store), "Utf8");
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error(" # Error saving session data for", this.filterSSID(this.ssid), e);
|
||||
@@ -205,7 +215,7 @@ class WTVClientSessionData {
|
||||
|
||||
retrieveSessionData() {
|
||||
// alias
|
||||
this.loadSessionData();
|
||||
return this.loadSessionData();
|
||||
}
|
||||
|
||||
storeSessionData() {
|
||||
@@ -213,16 +223,32 @@ class WTVClientSessionData {
|
||||
return this.saveSessionData();
|
||||
}
|
||||
|
||||
SaveIfRegistered() {
|
||||
if (this.isRegistered()) return this.saveSessionData();
|
||||
return false;
|
||||
}
|
||||
|
||||
isRegistered() {
|
||||
var self = this;
|
||||
var ssid_match = false;
|
||||
this.fs.readdirSync(this.session_storage).forEach(file => {
|
||||
if (!file.match(/.*\.json/ig)) return;
|
||||
if (ssid_match) return;
|
||||
if (file.split('.')[0] == self.ssid) ssid_match = true;
|
||||
});
|
||||
return ssid_match;
|
||||
}
|
||||
|
||||
unregisterBox() {
|
||||
try {
|
||||
if (this.fs.lstatSync(this.session_storage + this.path.sep + this.ssid + ".json")) {
|
||||
return this.fs.unlinkSync(this.session_storage + this.path.sep + this.ssid + ".json");
|
||||
this.fs.unlinkSync(this.session_storage + this.path.sep + this.ssid + ".json");
|
||||
this.session_store = {};
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
// Don't log error 'file not found', it just means the client isn't registered yet
|
||||
if (e.code != "ENOENT") console.error(" # Error deleting session data for", this.filterSSID(this.ssid), e);
|
||||
console.error(" # Error deleting session data for", this.filterSSID(this.ssid), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user