diff --git a/zefie_wtvp_minisrv/includes/ServiceDeps/wtv-author/page_list.njk b/zefie_wtvp_minisrv/includes/ServiceDeps/wtv-author/page_list.njk new file mode 100644 index 00000000..d81265c3 --- /dev/null +++ b/zefie_wtvp_minisrv/includes/ServiceDeps/wtv-author/page_list.njk @@ -0,0 +1,49 @@ +{# Page list template for published pages #} + + + +{{ subscriber_name }} + + + + + + + +
+
+
+Pages of {{ subscriber_name }} +
+
+{% for page in published_pages %} +
+ + + + +
+{{ page.title }} + +
+{{ page.description }} +
+
+
+{% endfor %} +
+ + diff --git a/zefie_wtvp_minisrv/includes/classes/HTTPX.js b/zefie_wtvp_minisrv/includes/classes/HTTPX.js index 99a8d630..73717077 100644 --- a/zefie_wtvp_minisrv/includes/classes/HTTPX.js +++ b/zefie_wtvp_minisrv/includes/classes/HTTPX.js @@ -12,7 +12,7 @@ exports.createServer = (opts, handler) => { socket.pause(); // Determine if this is an HTTP(s) request - let byte = buffer[0]; + const byte = buffer[0]; let protocol; if (byte === 22) { @@ -21,7 +21,7 @@ exports.createServer = (opts, handler) => { protocol = 'http'; } - let proxy = server[protocol]; + const proxy = server[protocol]; if (proxy) { // Push the buffer back onto the front of the data stream socket.unshift(buffer); diff --git a/zefie_wtvp_minisrv/includes/classes/LZSS.js b/zefie_wtvp_minisrv/includes/classes/LZSS.js index 0ec8e079..105d7229 100644 --- a/zefie_wtvp_minisrv/includes/classes/LZSS.js +++ b/zefie_wtvp_minisrv/includes/classes/LZSS.js @@ -34,7 +34,7 @@ class LZSS { } insertNode(i) { - let keyi = this.ring_buffer[i]; + const keyi = this.ring_buffer[i]; let keyii = this.ring_buffer[i + 1] ^ this.ring_buffer[i + 2]; keyii = ((keyii ^ (keyii >> 4)) & 0x0F) << 8; @@ -129,7 +129,7 @@ class LZSS { this.parent[this.rchild[i]] = ii; } this.parent[ii] = this.parent[i]; - let parent_link = this.parent[i]; + const parent_link = this.parent[i]; if (this.rchild[parent_link] !== i) { this.lchild[parent_link] = ii; } else { diff --git a/zefie_wtvp_minisrv/includes/classes/Prototypes.js b/zefie_wtvp_minisrv/includes/classes/Prototypes.js index 7a2ab26d..1a119bd1 100644 --- a/zefie_wtvp_minisrv/includes/classes/Prototypes.js +++ b/zefie_wtvp_minisrv/includes/classes/Prototypes.js @@ -4,8 +4,8 @@ const prototypes = { return this.split("").reverse().join(""); }, toHexString: function () { - var result = ''; - for (var i = 0; i < this.length; i++) { + let result = ''; + for (let i = 0; i < this.length; i++) { result += this.charCodeAt(i).toString(16); } return result; @@ -13,7 +13,7 @@ const prototypes = { }, Array: { replace: function(sub, newSub) { - splits = this.split(sub, 2); + const splits = this.split(sub, 2); return Array.concat(splits[0], newSub, splits[1]) }, moveKey: function (from, to) { diff --git a/zefie_wtvp_minisrv/includes/classes/WTVAdmin.js b/zefie_wtvp_minisrv/includes/classes/WTVAdmin.js index e64d3055..3369ec17 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVAdmin.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVAdmin.js @@ -28,8 +28,8 @@ class WTVAdmin { */ constructor(minisrv_config, wtvclient, service_name) { this.minisrv_config = minisrv_config; - var { WTVShared } = require("./WTVShared.js"); - var WTVRegister = require("./WTVRegister.js"); + const { WTVShared } = require("./WTVShared.js"); + const WTVRegister = require("./WTVRegister.js"); this.wtvclient = wtvclient; this.wtvshared = new WTVShared(minisrv_config); this.wtvr = new WTVRegister(minisrv_config); @@ -54,13 +54,14 @@ class WTVAdmin { if (ssid == admin_ssid) { return this.REASON_NOSELF; } else { - var fake_config = this.wtvshared.getUserConfig(); + const fake_config = this.wtvshared.getUserConfig(); if (!fake_config.config) fake_config.config = {}; if (!fake_config.config.ssid_block_list) fake_config.config.ssid_block_list = []; - var entry_exists = false; - var self = this; + let entry_exists = false; + const self = this; Object.keys(fake_config.config.ssid_block_list).forEach(function (k) { if (fake_config.config.ssid_block_list[k] == ssid) { + entry_exists = true; return self.REASON_EXISTS; } }); @@ -78,8 +79,8 @@ class WTVAdmin { * @returns {number} The result of the unban operation */ unbanSSID(ssid) { - var config_changed = false; - var fake_config = this.wtvshared.getUserConfig(); + let config_changed = false; + const fake_config = this.wtvshared.getUserConfig(); if (!fake_config.config) fake_config.config = {}; if (!fake_config.config.ssid_block_list) fake_config.config.ssid_block_list = []; if (typeof ssid === 'string') { @@ -100,8 +101,8 @@ class WTVAdmin { }); } if (config_changed) { - wtvshared.writeToUserConfig(fake_config); - minisrv_config = reloadConfig(); + this.wtvshared.writeToUserConfig(fake_config); + //this.minisrv_config = reloadConfig(); return this.SUCCESS } else { return this.REASON_NONEXIST; @@ -114,7 +115,7 @@ class WTVAdmin { * @returns {string} The reason for rejecting the connection */ rejectConnection(reason_is_ssid) { - var rejectReason; + let rejectReason; if (this.pcservices) { rejectReason = this.clientAddress + " is not in the whitelist for PC Services Admin."; console.log(" * Request from IP (" + this.clientAddress + ") for PC Services Admin, but that IP is not authorized."); @@ -158,12 +159,12 @@ class WTVAdmin { * @returns {Array} An array of arrays, each containing the SSID and its associated account information */ listRegisteredSSIDs() { - var search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts"); - var self = this; - var out = []; + const search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts"); + const self = this; + const out = []; this.fs.readdirSync(search_dir).forEach(file => { if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory()) { - var user = self.getAccountInfoBySSID(file); + const user = self.getAccountInfoBySSID(file); out.push([file, user]); } }); @@ -176,19 +177,19 @@ class WTVAdmin { * @return {boolean} True if authorized, false otherwise */ isAuthorized(justchecking = false) { - var allowed_ssid = false; - var allowed_ip = false; - var use_ssid = (this.wtvclient.ssid && !this.pcservices) ? true : false + let allowed_ssid = false; + let allowed_ip = false; + const use_ssid = (this.wtvclient.ssid && !this.pcservices) ? true : false if (use_ssid) { if (this.minisrv_config.services[this.service_name].authorized_ssids) { - var self = this; + const self = this; Object.keys(self.minisrv_config.services[this.service_name].authorized_ssids).forEach(function (k) { if (typeof self.minisrv_config.services[self.service_name].authorized_ssids[k] == "string") { - var ssid = self.minisrv_config.services[self.service_name].authorized_ssids[k] + const ssid = self.minisrv_config.services[self.service_name].authorized_ssids[k] if (ssid == self.wtvclient.ssid) allowed_ssid = true; allowed_ip = true; // no ip block defined } else { - var ssid = k; + const ssid = k; if (ssid == self.wtvclient.ssid) { allowed_ssid = true; Object.keys(self.minisrv_config.services[self.service_name].authorized_ssids[k]).forEach(function (j) { @@ -209,7 +210,7 @@ class WTVAdmin { } if (this.minisrv_config.config.pc_admin.ip_whitelist) { - var self = this; + const self = this; Object.keys(this.minisrv_config.config.pc_admin.ip_whitelist).forEach(function (k) { if (allowed_ip) return; allowed_ip = self.wtvshared.isInSubnet(self.clientAddress, self.minisrv_config.config.pc_admin.ip_whitelist[k]); @@ -232,9 +233,9 @@ class WTVAdmin { * @returns {Object|null} An object containing account information if the username is found, null otherwise */ getAccountInfo(username, directory = null) { - var search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts"); - var account_data = null; - var self = this; + let search_dir = this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts"); + let account_data = null; + const 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() && account_data === null) { @@ -243,8 +244,8 @@ class WTVAdmin { if (account_data !== null) return; if (!file.match(/.*\.json/ig)) return; try { - var temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8'); - var temp_session_data = JSON.parse(temp_session_data_file); + const temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8'); + const temp_session_data = JSON.parse(temp_session_data_file); if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) { account_data = [temp_session_data, (search_dir + self.path.sep + file).replace(this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore + this.path.sep + "accounts"), "").split(this.path.sep)[1]]; @@ -255,11 +256,11 @@ class WTVAdmin { }); if (account_data !== null) { if (account_data.ssid) return account_data; - var account_info = {}; + const account_info = {}; account_info.ssid = account_data[1]; account_info.username = account_data[0].subscriber_username; account_info.user_id = account_data[0].subscriber_userid; - var userSession = new this.WTVClientSessionData(this.minisrv_config, account_info.ssid); + const userSession = new this.WTVClientSessionData(this.minisrv_config, account_info.ssid); userSession.user_id = 0; account_info.account_users = userSession.listPrimaryAccountUsers(); return account_info; @@ -273,8 +274,8 @@ class WTVAdmin { * @returns {Object|boolean} An object containing account information if the SSID is registered, false otherwise */ getAccountInfoBySSID(ssid) { - var account_info = {}; - var userSession = new this.WTVClientSessionData(this.minisrv_config, ssid); + const account_info = {}; + const userSession = new this.WTVClientSessionData(this.minisrv_config, ssid); userSession.user_id = 0; if (userSession.isRegistered(false)) { account_info.ssid = ssid; @@ -301,7 +302,7 @@ class WTVAdmin { * @returns {WTVClientSessionData} The session data object for the account */ getAccountBySSID(ssid) { - var userSession = new this.WTVClientSessionData(this.minisrv_config, ssid); + const userSession = new this.WTVClientSessionData(this.minisrv_config, ssid); userSession.user_id = 0; return userSession; } @@ -312,8 +313,8 @@ class WTVAdmin { * @returns {boolean} True if the SSID is banned, false otherwise */ isBanned(ssid) { - var self = this; - var isBanned = false; + const self = this; + let isBanned = false; if (this.minisrv_config.config.ssid_block_list) { Object.keys(this.minisrv_config.config.ssid_block_list).forEach(function (k) { if (self.minisrv_config.config.ssid_block_list[k] == ssid) { diff --git a/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js b/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js index 1efa66f2..9b27b0c4 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js @@ -60,9 +60,9 @@ class WTVAuthor { pagestoreExists() { if (this.pagestore_dir === null) { // set pagestore directory local var so we don't call the function every time - var userstore_dir = this.wtvclient.getUserStoreDirectory(); + const userstore_dir = this.wtvclient.getUserStoreDirectory(); // PageStore - var store_dir = "PageStore" + this.path.sep; + const store_dir = "PageStore" + this.path.sep; this.pagestore_dir = userstore_dir + store_dir; } return this.fs.existsSync(this.pagestore_dir); @@ -79,66 +79,68 @@ class WTVAuthor { } createPage(style) { - this.pagestoreExists() - var pagestorepath = this.pagestore_dir; - // All this shit is to work around the part where I don't use UUIDs to store pages, which is bad - var pages = this.fs.readdirSync(pagestorepath) - if (pages.length == 0) { - pagenum = 0; - } else { - var pagelen = pages.length; - if (pagelen < 0) pagelen = 0; - this.debug("createPage","pages",pages) - var pagenums = []; - for(let i = 0; i < pagelen; i++) { - var toarr = pages[i].slice(0, pages[i].indexOf('.')); - pagenums.push(parseInt(toarr)); - } - pagenums = pagenums.sort() - this.debug("createPage", "pagenums", pagenums) - var pagenum = parseInt(pagenums[pagelen - 1]); - this.debug("createPage", "pagenum", pagenum) - this.debug("createPage", "pagelen", pagelen) + this.pagestoreExists() + let pagenum = 0; + let pagefile = null; + const pagestorepath = this.pagestore_dir; + // All this shit is to work around the part where I don't use UUIDs to store pages, which is bad + const pages = this.fs.readdirSync(pagestorepath) + if (pages.length === 0) { + pagenum = 0; + } else { + let pagelen = pages.length; + if (pagelen < 0) pagelen = 0; + this.debug("createPage","pages",pages) + let pagenums = []; + for(let i = 0; i < pagelen; i++) { + const toarr = pages[i].slice(0, pages[i].indexOf('.')); + pagenums.push(parseInt(toarr)); } - if (pages.length == 0) { - pagenum = 0 - var pagefile = pagenum + this.pageFileExt; - } else { - var pagefile = (pagenum + 1) + this.pageFileExt; - } - var pagefileout = this.pagestore_dir + pagefile; - // JSON data structure - var pagedata = { - "style": style, - "title": "(Untitled)", - "description": "(no description)", - "pagebreaks": [], - "showtitle": true, - "inlist": true, - "published": false, - "publishdate": null, - "publishname": null, - "blocks": [] - } - if (this.fs.existsSync(pagefileout)) { - console.error(" * ERROR: Page already exists (should never happen). Page lost."); - return false; - } + pagenums = pagenums.sort() + this.debug("createPage", "pagenums", pagenums) + const pagenum = parseInt(pagenums[pagelen - 1]); + this.debug("createPage", "pagenum", pagenum) + this.debug("createPage", "pagelen", pagelen) + } + if (pages.length == 0) { + pagenum = 0 + pagefile = pagenum + this.pageFileExt; + } else { + pagefile = (pagenum + 1) + this.pageFileExt; + } + const pagefileout = this.pagestore_dir + pagefile; + // JSON data structure + const pagedata = { + "style": style, + "title": "(Untitled)", + "description": "(no description)", + "pagebreaks": [], + "showtitle": true, + "inlist": true, + "published": false, + "publishdate": null, + "publishname": null, + "blocks": [] + } + if (this.fs.existsSync(pagefileout)) { + console.error(" * ERROR: Page already exists (should never happen). Page lost."); + return false; + } - // Encode page data into JSON - var returnval = pages.length - var result = this.fs.writeFileSync(pagefileout, JSON.stringify(pagedata)); - if (returnval != 0) { - var npages = this.fs.readdirSync(pagestorepath) - var returnval = npages.length - 1; - } + // Encode page data into JSON + let returnval = pages.length + this.fs.writeFileSync(pagefileout, JSON.stringify(pagedata)); + if (returnval != 0) { + const npages = this.fs.readdirSync(pagestorepath) + returnval = npages.length - 1; + } return returnval; } loadPage(pagenum) { this.pagestoreExists() - var page_file = this.listPages(); - var page_data_raw = page_file[pagenum]; + const page_file = this.listPages(); + const page_data_raw = page_file[pagenum]; if (page_data_raw) { return page_data_raw; @@ -149,13 +151,13 @@ class WTVAuthor { setStyle(style, title, desc, state, docName) { // There's probably a better way to do this involving external files for each style, but no this.debug("setStyle", "this.wtvshared.makeSafeStringPath(style) (before load)", this.wtvshared.makeSafeStringPath(style)); - var template_data_file = this.wtvshared.getTemplate("wtv-author", "styles/" + this.wtvshared.makeSafeStringPath(style) + ".js", true); + const template_data_file = this.wtvshared.getTemplate("wtv-author", "styles/" + this.wtvshared.makeSafeStringPath(style) + ".js", true); if (template_data_file) { this.debug("setStyle", "template_data_file", template_data_file); const PBTemplate = require(template_data_file); - var pbtemplate = new PBTemplate(this, title, desc, state, docName); - var template_data = pbtemplate.get(); - var self = this; + const pbtemplate = new PBTemplate(this, title, desc, state, docName); + const template_data = pbtemplate.get(); + const self = this; Object.keys(template_data).forEach((k) => { self[k] = template_data[k]; }) @@ -291,8 +293,8 @@ class WTVAuthor { } generatePage(state, pagenum, page) { - var pagedata = this.loadPage(pagenum); - var title + const pagedata = this.loadPage(pagenum); + let title; // Should probably have a better way to know if the page has no title if (pagedata.title == "(Untitled)" && state == "editing") title = "Choose this to add a title to your document" @@ -300,7 +302,7 @@ class WTVAuthor { title = pagedata.title // Set the page style with too many paramaters this.setStyle(pagedata.style, title, pagedata.description, state, pagenum); - var html = this.header + let html = this.header if (page == 1) { if (pagedata.showtitle == true){ html += this.titheader @@ -310,12 +312,10 @@ class WTVAuthor { // This generates blocks on separate pages in the most neat and optimized way possible (i think, i hate past jar) if (page != 1) { for (let i = pagedata.pagebreaks[page - 2]; i < (pagedata.pagebreaks[page - 1] || pagedata.blocks.length); i++) { - var type = pagedata.blocks[i].type html += this.generateBlock(i, pagenum, state) } } else if (pagedata.pagebreaks.length != 0){ for (let i = 0; i < pagedata.pagebreaks[0]; i++) { - var type = pagedata.blocks[i].type html += this.generateBlock(i, pagenum, state) if (this.afterblock1 && i == 0) { html += this.afterblock1 @@ -323,7 +323,6 @@ class WTVAuthor { } } else { for (let i = 0; i < pagedata.blocks.length; i++) { - var type = pagedata.blocks[i].type html += this.generateBlock(i, pagenum, state) if (this.afterblock1 && i == 0) { html += this.afterblock1 @@ -334,18 +333,18 @@ class WTVAuthor { // Add the footer if we're not in edit mode html += this.getPaginationFooter(state, pagedata, page, pagenum) html += this.footerend - return html; + return html; } editPage(pagedata, pagenum, callPublish = true) { // just stolen from favorites lmao - var pageout = new Object(); - var pagepath = this.pagestore_dir; + const pageout = new Object(); + const pagepath = this.pagestore_dir; Object.assign(pageout, pagedata); - var pagestorepath = this.pagestore_dir; - var pages = this.fs.readdirSync(pagestorepath) - var page = pages[pagenum] - var result = this.fs.writeFileSync(pagepath + page, JSON.stringify(pageout)); + const pagestorepath = this.pagestore_dir; + const pages = this.fs.readdirSync(pagestorepath) + const page = pages[pagenum] + const result = this.fs.writeFileSync(pagepath + page, JSON.stringify(pageout)); if (pagedata.published == true && callPublish) { this.publishPage(pagenum, pagedata.inlist, false) } @@ -353,44 +352,39 @@ class WTVAuthor { } editMetadata(title, description, showtitle, pagenum) { - var pagedata = this.loadPage(pagenum); + const pagedata = this.loadPage(pagenum); if (!pagedata) return false; - - if (showtitle == "true") - var showtitle2 = false - else - var showtitle2 = true - pagedata.title = title - pagedata.description = description - pagedata.showtitle = showtitle2 + pagedata.title = title; + pagedata.description = description; + pagedata.showtitle = !showtitle; this.editPage(pagedata, pagenum); return true; } listPages() { // i don't remember why, but i'm pretty sure this function sucks - var pagestore = this.pagestoreExists(); + const pagestore = this.pagestoreExists(); if (!pagestore) this.createPagestore(); - var userstore_dir = this.wtvclient.getUserStoreDirectory(); + const userstore_dir = this.wtvclient.getUserStoreDirectory(); // PageStore - var store_dir = "PageStore" + this.path.sep; + const store_dir = "PageStore" + this.path.sep; this.pagestore_dir = userstore_dir + store_dir; - var pagestorepath = this.pagestore_dir; - var self = this; + const pagestorepath = this.pagestore_dir; + const self = this; self.pageArr = []; if (self.fs.existsSync(pagestorepath)) { - var files = this.fs.readdirSync(pagestorepath) + const files = this.fs.readdirSync(pagestorepath) this.debug("listPages","files",files) files.map(function (v) { if (v.endsWith(self.pageFileExt)) { // oh yeah it's because any non-JSON file in pagestore will throw an error and break everything - var page_data_raw = null; - var pagepath = pagestorepath + self.path.sep + v; + let page_data_raw = null; + const pagepath = pagestorepath + self.path.sep + v; if (self.fs.existsSync(pagepath)) page_data_raw = self.fs.readFileSync(pagepath); if (page_data_raw) { - var page_data = JSON.parse(page_data_raw); + const page_data = JSON.parse(page_data_raw); self.pageArr.push(page_data); } } @@ -400,12 +394,12 @@ class WTVAuthor { } deleteBlock(pagenum, position) { - var pagedata = this.loadPage(pagenum); + const pagedata = this.loadPage(pagenum); if (!pagedata) return false; - - var block = pagedata.blocks[position] - var blocks = pagedata.blocks + const block = pagedata.blocks[position]; + + const blocks = pagedata.blocks; blocks.splice(position, 1); this.editPage(pagedata, pagenum); if (block.type == "break") @@ -418,7 +412,7 @@ class WTVAuthor { return this.minisrv_config.services['wtv-author'].public_domain; } else { if (this.minisrv_config.services['wtv-author'].publish_mode == "service") { - var target_service = this.minisrv_config.services[this.minisrv_config.services['wtv-author'].publish_dest]; + const target_service = this.minisrv_config.services[this.minisrv_config.services['wtv-author'].publish_dest]; if (target_service) { return target_service.host + ":" + target_service.port; } @@ -437,9 +431,9 @@ class WTVAuthor { } getPublishDir() { - var destDir = false; + let destDir = false; if (this.minisrv_config.services['wtv-author'].publish_mode == "service") { - var target_service = this.minisrv_config.services[this.minisrv_config.services['wtv-author'].publish_dest]; + const target_service = this.minisrv_config.services[this.minisrv_config.services['wtv-author'].publish_dest]; if (target_service) { if (!target_service.pc_services) { console.error("Invalid service configuration: publish_dest is not a pc service."); @@ -451,7 +445,7 @@ class WTVAuthor { if (target_service.service_vaults) { destDir = target_service.service_vaults[0] + this.path.sep + target_service.servicevault_dir + this.path.sep; } else { - destDir = minisrv_config.config.ServiceVaults[0] + this.path.sep + target_service.servicevault_dir + this.path.sep; + destDir = this.minisrv_config.config.ServiceVaults[0] + this.path.sep + target_service.servicevault_dir + this.path.sep; } } } else if (this.minisrv_config.services['wtv-author'].publish_mode == "directory") { @@ -465,12 +459,12 @@ class WTVAuthor { unpublishPage(pagenum) { - var pagedata = this.loadPage(pagenum) - var destDir = this.getPublishDir(); + const pagedata = this.loadPage(pagenum) + const destDir = this.getPublishDir(); if (pagedata.published != true) { return "This page is not published." } - var publishname = pagedata.publishname; + const publishname = pagedata.publishname; if (this.fs.existsSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname)) { try { this.fs.rmSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname, { recursive: true }) @@ -491,9 +485,9 @@ class WTVAuthor { publishPage(pagenum, listpublicly) { // this was done in a rush and probably also sucks // remember to increment the "hours wasted here" comment at the top of the file - var pagedata = this.loadPage(pagenum) - var destDir = this.getPublishDir(); - var publishname = null; + const pagedata = this.loadPage(pagenum) + const destDir = this.getPublishDir(); + let publishname, fileout; if (pagedata.published != true) { publishname = pagedata.title.slice(0, 50).replaceAll(" ", "").replace(/[^A-Za-z0-9]/g, "-"); @@ -510,11 +504,11 @@ class WTVAuthor { this.fs.mkdirSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname + "/clipart/styleMedia/", { recursive: true }) this.fs.mkdirSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname + "/media/", { recursive: true }) for (let i = 1; i < pagedata.pagebreaks.length + 2; i++) { - var pagehtml = this.generatePage("publishing", pagenum, i) + const pagehtml = this.generatePage("publishing", pagenum, i) if (i == 1) - var fileout = "index.html" + fileout = "index.html" else - var fileout = "page" + i + ".html" + fileout = "page" + i + ".html" this.fs.writeFile(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname + '/' + fileout, pagehtml, err => { if (err) { console.error(err); @@ -528,7 +522,7 @@ class WTVAuthor { if (err) throw err; }); } - var strftime = require('strftime'); + const strftime = require('strftime'); pagedata.publishdate = strftime("%a, %b %d, %Y, %I:%M%P", new Date(new Date().toUTCString())) pagedata.published = true; pagedata.inlist = listpublicly; @@ -540,66 +534,24 @@ class WTVAuthor { generatePageList() { // this one's pretty ok i think, but it should have screenshots of each page - const pagelist = this.listPages() - let html = ` - - -${this.wtvclient.session_store.subscriber_name} - - - - - - - -
-
-
-Pages of ${this.wtvclient.session_store.subscriber_name} -
-
`; - loop: - for (let i = 0; i < pagelist.length; i++) { - if (pagelist[i].published == true && pagelist[i].inlist == true) { - html += `
- - - - -
-${pagelist[i].title} - -
-${pagelist[i].description} -
-
-
` - } else { - continue loop; - } - } - html += `
- -` + const pagelist = this.listPages(); + + // Filter published pages that should be listed + const publishedPages = pagelist.filter(page => page.published === true && page.inlist === true); + + const templatePath = this.wtvshared.getServiceDep('wtv-author/page_list.njk', true); + this.nunjucks.configure({ autoescape: false }); + + const html = this.nunjucks.render(templatePath, { + subscriber_name: this.wtvclient.session_store.subscriber_name, + published_pages: publishedPages + }); this.fs.writeFile(this.getPublishDir() + this.wtvclient.session_store.subscriber_username + '/index.html', html, err => { - if (err) { - console.error(err); - } - // file written successfully + if (err) { + console.error(err); + } + // file written successfully }); } @@ -628,7 +580,7 @@ vspace=0 for (let i = 0; i < pagelist.length; i++) { this.deletePage(i); } - const userstore_dir = otherUser.getUserStoreDirectory(); + const userstore_dir = this.wtvclient.getUserStoreDirectory(); const store_dir = "PageStore" + this.path.sep; this.pagestore_dir = userstore_dir + store_dir; this.wtvclient.switchUserID(0, false, false, false); @@ -663,7 +615,7 @@ vspace=0 pagedata.blocks[oldposition].style = style if (oldposition != position) - moveArrayKey(pagedata.blocks,oldposition,position); + this.wtvshared.moveObjectKey(pagedata.blocks,oldposition,position); this.editPage(pagedata, pagenum); return true; @@ -710,7 +662,7 @@ vspace=0 blocks[oldposition].caption = caption if (oldposition != position) { - moveArrayKey(blocks, oldposition,position); + this.wtvshared.moveObjectKey(blocks, oldposition,position); } this.editPage(pagedata, pagenum); @@ -746,7 +698,7 @@ vspace=0 pagedata.blocks[oldposition].dividerAfter = dividerAfter if (oldposition != position) - moveArrayKey(pagedata.blocks, oldposition,position); + this.wtvshared.moveObjectKey(pagedata.blocks, oldposition,position); this.editPage(pagedata, pagenum); return true; @@ -777,7 +729,7 @@ vspace=0 pagedata.blocks[oldposition].items = items if (oldposition != position) - moveArrayKey(pagedata.blocks,oldposition,position); + this.wtvshared.moveObjectKey(pagedata.blocks,oldposition,position); this.editPage(pagedata, pagenum); return true; @@ -842,7 +794,7 @@ vspace=0 pagedata.blocks[oldposition].items = items if (oldposition != position) - moveArrayKey(pagedata.blocks,oldposition,position); + this.wtvshared.moveObjectKey(pagedata.blocks,oldposition,position); this.editPage(pagedata, pagenum); return true; @@ -868,7 +820,7 @@ vspace=0 if (!pagedata) return false; if (oldposition != position) - moveArrayKey(pagedata.blocks,oldposition,position); + this.wtvshared.moveObjectKey(pagedata.blocks,oldposition,position); this.editPage(pagedata, pagenum); this.generateBreakList(pagenum); diff --git a/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js b/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js index 5159db66..969fd905 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVBGMusic.js @@ -1246,18 +1246,18 @@ class WTVBGMusic { constructor(minisrv_config, session_data) { if (!minisrv_config) throw ("minisrv_config required"); if (!session_data) throw ("WTVClientSessionData required"); - var WTVShared = require("./WTVShared.js")['WTVShared']; + const WTVShared = require("./WTVShared.js")['WTVShared']; this.minisrv_config = minisrv_config; this.session_data = session_data; this.wtvshared = new WTVShared(minisrv_config); } getMusicObj(force_default = false) { - var music_obj = this.session_data.getSessionData("wtv-bgmusic"); + let music_obj = this.session_data.getSessionData("wtv-bgmusic"); if (music_obj === null) music_obj = {}; // check if we need to set defaults - var setDefaults = force_default; + let setDefaults = force_default; if (!music_obj.enableCategories) setDefaults = true; else if (music_obj.enableCategories.length == 0) setDefaults = true; if (!music_obj.enableSongs) setDefaults = true; @@ -1317,12 +1317,13 @@ class WTVBGMusic { } getSong(songid) { + let musiclist; if (this.session_data.hasCap("client-can-do-rmf")) { // use rmf list - var musiclist = this.musiclist_rmf; + musiclist = this.musiclist_rmf; } else { // use classic list - var musiclist = this.musiclist_classic; + musiclist = this.musiclist_classic; } if (musiclist[songid]) return musiclist[songid]; return null; @@ -1341,14 +1342,15 @@ class WTVBGMusic { getCategorySongList(category) { + let musiclist; if (this.session_data.hasCap("client-can-do-rmf")) { // use rmf list - var musiclist = this.musiclist_rmf; + musiclist = this.musiclist_rmf; } else { // use classic list - var musiclist = this.musiclist_classic; + musiclist = this.musiclist_classic; } - var songList = []; + const songList = []; Object.keys(musiclist).forEach(function (k) { musiclist[k].id = k; if (String(category).length === 1) { @@ -1363,10 +1365,10 @@ class WTVBGMusic { } getCategoryList() { - var enabledCategories = []; - var self = this; + const enabledCategories = []; + const self = this; Object.keys(self.categories).forEach(function (k) { - var songList = self.getCategorySongList(parseInt(k) + 1); + const songList = self.getCategorySongList(parseInt(k) + 1); if (songList.length > 0) enabledCategories.push({ "id": parseInt(k) + 1, "name": self.categories[k] }); @@ -1380,8 +1382,8 @@ class WTVBGMusic { } isCategoryEnabled(category) { - var music_obj = this.getMusicObj(); - var enabled = false; + const music_obj = this.getMusicObj(); + let enabled = false; music_obj.enableCategories.forEach(function (v) { if (parseInt(v) == parseInt(category)) { enabled = true; @@ -1391,13 +1393,13 @@ class WTVBGMusic { } isSongEnabled(song, checkCat = false) { - var music_obj = this.getMusicObj(); - var enabled = false; + const music_obj = this.getMusicObj(); + let enabled = false; music_obj.enableSongs.forEach(function (v) { if (parseInt(v) == parseInt(song)) { if (checkCat) { - songCategory = getSongCategory(song); - if (isCategoryEnabled(songCategory)) { + const songCategory = this.getSongCategory(song); + if (this.isCategoryEnabled(songCategory)) { enabled = true; } } else { diff --git a/zefie_wtvp_minisrv/includes/classes/WTVClientCapabilities.js b/zefie_wtvp_minisrv/includes/classes/WTVClientCapabilities.js index 89d4988f..5db1ad1e 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVClientCapabilities.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVClientCapabilities.js @@ -20,7 +20,7 @@ class WTVClientCapabilities { // (this script does not do that, also note that LC2 MiniBrowser does not support client:relog) // None of this is 100% for certain yet (except the bitfield stuff), do not trust as verbatim, more testing needed - var capabilities_table = [ + const capabilities_table = [ ["client-can-do-muzac", "Can Do Muzac"], ["client-can-do-chat", "Can Chat"], ["client-can-do-openISP", "Can do OpenISP"], @@ -97,7 +97,7 @@ class WTVClientCapabilities { let remainingSize = hex.length; for (let p = 0; p < hex.length / 8; p++) { //In case remaining hex length (or initial) is not multiple of 8 - let blockSize = remainingSize < 8 ? remainingSize : 8; + const blockSize = remainingSize < 8 ? remainingSize : 8; binary += parseInt(hex.slice(p * 8, p * 8 + blockSize), 16).toString(2); diff --git a/zefie_wtvp_minisrv/includes/classes/WTVClientSessionData.js b/zefie_wtvp_minisrv/includes/classes/WTVClientSessionData.js index 24aaf6f4..e94ed14c 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVClientSessionData.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVClientSessionData.js @@ -158,7 +158,7 @@ class WTVClientSessionData { findFreeUserSlot() { if (this.user_id != 0) return false; // subscriber only command - let master_directory = this.getUserStoreDirectory(true); + const master_directory = this.getUserStoreDirectory(true); if (this.fs.existsSync(master_directory)) { for (let i = 0; i < this.minisrv_config.config.user_accounts.max_users_per_account; i++) { const test_dir = master_directory + this.path.sep + "user" + i; @@ -184,7 +184,7 @@ class WTVClientSessionData { if (this.user_id != 0) return false; // subscriber only command const master_directory = this.getUserStoreDirectory(true); - let account_data = []; + const account_data = []; const self = this; this.fs.readdirSync(master_directory).forEach(f => { if (self.fs.lstatSync(master_directory + self.path.sep + f).isDirectory()) { @@ -339,7 +339,7 @@ class WTVClientSessionData { if (!file_exists || (file_exists && overwrite)) result = this.fs.writeFileSync(store_full_path, data); if (result !== false && last_modified) { const file_timestamp = new Date(last_modified * 1000); - fs.utimesSync(store_full_path, Date.now(), file_timestamp) + this.fs.utimesSync(store_full_path, Date.now(), file_timestamp) } } catch (e) { console.error(" # User File Store failed", e); @@ -408,7 +408,7 @@ class WTVClientSessionData { this.createScrapbook(); } let total_size = 0; - let files = this.fs.readdirSync(this.scrapbook_dir); + const files = this.fs.readdirSync(this.scrapbook_dir); files.forEach(file => { if (!file.endsWith('.meta')) { const file_path = this.scrapbook_dir + file; @@ -498,7 +498,7 @@ class WTVClientSessionData { * @returns {Buffer|false} Buffer data, or false if could not open file */ getUserStoreFileByURL(url) { - let path_split = url.split('/'); + const path_split = url.split('/'); path_split.shift(); path_split.shift(); const store_dir_path = path_split.join('/').replace('/', this.path.sep); @@ -931,21 +931,7 @@ class WTVClientSessionData { checkSecurity() { const self = this; - const rejectReason = null; - const ip2long = function (ip) { - let components; - - if (components = ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) { - let iplong = 0; - let power = 1; - for (let i = 4; i >= 1; i -= 1) { - iplong += power * parseInt(components[i]); - power *= 256; - } - return iplong; - } - else return -1; - }; + let rejectReason = null; const rejectSSIDConnection = function (blacklist) { if (blacklist) { @@ -981,7 +967,7 @@ class WTVClientSessionData { } else { rejectSSIDConnection(blacklist); } - if (ssid_access_list_ip_override && self.minisrv_config.config.debug_flags.debug) console.log(" * Request from disallowed SSID", wtvshared.filterSSID(ssid), "was allowed due to IP address whitelist"); + if (ssid_access_list_ip_override && self.minisrv_config.config.debug_flags.debug) console.log(" * Request from disallowed SSID", this.wtvshared.filterSSID(ssid), "was allowed due to IP address whitelist"); } // process whitelist first diff --git a/zefie_wtvp_minisrv/includes/classes/WTVFTP.js b/zefie_wtvp_minisrv/includes/classes/WTVFTP.js index baf2bfa9..a13642ed 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVFTP.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVFTP.js @@ -27,7 +27,7 @@ class WTVFTP { let user = null; let pass = null; - let host = parsed.hostname; + const host = parsed.hostname; if (parsed.auth) { const [username, password] = parsed.auth.split(':'); @@ -56,7 +56,7 @@ class WTVFTP { ftpClient.on('ready', () => { if (filename) { - var totalsize = 0; + let totalsize = 0; ftpClient.cwd(dir, (err) => { if (err) { this.sendToClient(socket, { 'Status': '500 Failed to change directory', 'Content-Type': 'text/plain' }, 'Failed to change directory'); @@ -134,7 +134,7 @@ class WTVFTP { } formatDirectoryListing(list) { - let html = ` + const html = ` FTP Directory Listing