v0.9.19
- numerous bug fixes - add `npm start` support - minibrowser theme thanks to @GraspYonOx - remove TOS coz no one cares anyway
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* Shared functions across all classes and apps
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,9 @@ class WTVShared {
|
||||
minisrv_config = [];
|
||||
|
||||
constructor(minisrv_config) {
|
||||
this.minisrv_config = minisrv_config;
|
||||
if (minisrv_config == null) this.minisrv_config = this.readMiniSrvConfig();
|
||||
else this.minisrv_config = minisrv_config;
|
||||
|
||||
if (!String.prototype.reverse) {
|
||||
String.prototype.reverse = function () {
|
||||
var splitString = this.split("");
|
||||
@@ -20,6 +22,79 @@ class WTVShared {
|
||||
}
|
||||
}
|
||||
|
||||
returnAbsolutePath(check_path) {
|
||||
if (check_path.substring(0, 1) != this.path.sep && check_path.substring(1, 1) != ":") {
|
||||
// non-absolute path, so use current directory as base
|
||||
check_path = (__dirname + this.path.sep + check_path);
|
||||
} else {
|
||||
// already absolute path
|
||||
}
|
||||
return check_path;
|
||||
}
|
||||
|
||||
isMiniBrowser(ssid_session) {
|
||||
return (ssid_session.get("wtv-need-upgrade") || ssid_session.get("wtv-used-8675309"));
|
||||
}
|
||||
|
||||
isOldBuild(ssid_session) {
|
||||
if (this.isMiniBrowser(ssid_session) || parseInt(ssid_session.get("wtv-system-version")) < 3500) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
readMiniSrvConfig(user_config = true, notices = true) {
|
||||
if (notices) console.log(" *** Reading global configuration...");
|
||||
try {
|
||||
var minisrv_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "config.json"));
|
||||
} catch (e) {
|
||||
throw ("ERROR: Could not read config.json", e);
|
||||
}
|
||||
|
||||
var integrateConfig = function(main, user) {
|
||||
Object.keys(user).forEach(function (k) {
|
||||
if (typeof (user[k]) == 'object' && user[k] != null) {
|
||||
// new entry
|
||||
if (!main[k]) main[k] = new Array();
|
||||
// go down the rabbit hole
|
||||
main[k] = integrateConfig(main[k], user[k]);
|
||||
} else {
|
||||
// update main config
|
||||
main[k] = user[k];
|
||||
}
|
||||
});
|
||||
return main;
|
||||
}
|
||||
|
||||
if (user_config) {
|
||||
try {
|
||||
if (this.fs.lstatSync(__dirname + "/user_config.json")) {
|
||||
if (notices) console.log(" *** Reading user configuration...");
|
||||
try {
|
||||
var minisrv_user_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "user_config.json"));
|
||||
} catch (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
|
||||
// Likely a syntax parser error that did not trip the exception check above
|
||||
try {
|
||||
minisrv_config = integrateConfig(minisrv_config, minisrv_user_config)
|
||||
} catch (e) {
|
||||
console.error("ERROR: Could not read user_config.json", e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (minisrv_config.config.debug_flags.debug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
return minisrv_config;
|
||||
}
|
||||
|
||||
getMiniSrvConfig() {
|
||||
return this.minisrv_config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Last-Modified date in Unix Timestamp format
|
||||
* @param {string} file Path to a file
|
||||
@@ -91,7 +166,7 @@ class WTVShared {
|
||||
} else {
|
||||
// already absolute path
|
||||
}
|
||||
return path;
|
||||
return this.fixPathSlashes(path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,13 +184,10 @@ class WTVShared {
|
||||
* @param {string} path
|
||||
* @return {string} path without gz, or unmodified path if it isnt a gz
|
||||
*/
|
||||
stripGzipFromPath(path) {
|
||||
var path_split = path.split('.');
|
||||
if (path_split[path_split.length - 1].toLowerCase() == "gz") {
|
||||
path_split.pop();
|
||||
path = path_split.join(".");
|
||||
}
|
||||
return path;
|
||||
getFilePath(path) {
|
||||
var path_split = path.split('/');
|
||||
path_split.pop();
|
||||
return path_split.join('/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,11 +206,25 @@ class WTVShared {
|
||||
*/
|
||||
makeSafePath(base, target) {
|
||||
target.replace(/[\|\&\;\$\%\@\"\<\>\+\,\\]/g, "");
|
||||
if (this.path.sep != "/") target = target.replace(/\//g, this.path.sep);
|
||||
var targetPath = this.path.posix.normalize(target)
|
||||
return base + this.path.sep + targetPath;
|
||||
return this.fixPathSlashes(base + this.path.sep + targetPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Corrects any / or \ differences, if any for file paths
|
||||
* @param {string} path
|
||||
* @returns {string} corrected path
|
||||
*/
|
||||
fixPathSlashes(path) {
|
||||
// fix slashes
|
||||
if (this.path.sep == '/' && path.indexOf("\\") != -1) path = path.replace(/\\/g, this.path.sep);
|
||||
else if (this.path.sep == "\\" && path.indexOf("/") != -1) path = path.replace(/\//g, this.path.sep);
|
||||
|
||||
// remove double slashes
|
||||
while (path.indexOf(this.path.sep + this.path.sep) != -1) path = path.replace(this.path.sep + this.path.sep, this.path.sep);
|
||||
|
||||
return path;
|
||||
}
|
||||
/**
|
||||
* Makes sure an SSID is clean, and doesn't contain any exploitable characters
|
||||
* @param {string} ssid
|
||||
|
||||
Reference in New Issue
Block a user