From 51f2fd5ad79abc0694ecc78f91c33521a83c2b6d Mon Sep 17 00:00:00 2001 From: zefie Date: Tue, 12 Aug 2025 14:14:11 -0400 Subject: [PATCH] remove PB pages when removing/unregistering user --- zefie_wtvp_minisrv/.gitignore | 1 + zefie_wtvp_minisrv/app.js | 4 +- zefie_wtvp_minisrv/client_sim.js | 18 ++--- .../ServiceVault/wtv-author/edit-block.js | 2 +- .../ServiceVault/wtv-setup/accounts.js | 2 +- .../includes/classes/WTVAuthor.js | 66 +++++++++++++------ .../includes/classes/WTVClientSessionData.js | 10 ++- .../includes/classes/WTVDisk.js | 1 + .../includes/classes/WTVMinifyingProxy.js | 16 ++--- 9 files changed, 74 insertions(+), 46 deletions(-) diff --git a/zefie_wtvp_minisrv/.gitignore b/zefie_wtvp_minisrv/.gitignore index d4ae3fd9..219e2f47 100644 --- a/zefie_wtvp_minisrv/.gitignore +++ b/zefie_wtvp_minisrv/.gitignore @@ -5,6 +5,7 @@ # ServiceLogPost Posted Logs ServiceLogPost/*_* +client_sim_tests # Large files not pertaining to the service code UserServiceVault/*-* diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index f7d7c46c..246ff6af 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -1238,8 +1238,8 @@ function handleProxy(socket, request_type, request_headers, res, data) { console.warn(` * HTML transformation failed: ${err.message}`); } } - - if (request_type != "http" && request_type != "https") { + + if (request_type !== "http" && request_type !== "https") { // replace http and https links on non http/https protocol (for proto:// for example) const data_t = Buffer.concat(data).toString().replaceAll("http://", request_type + "://").replaceAll("https://", request_type + "://"); data = [Buffer.from(data_t)] diff --git a/zefie_wtvp_minisrv/client_sim.js b/zefie_wtvp_minisrv/client_sim.js index e5e25e8b..f5df6da1 100644 --- a/zefie_wtvp_minisrv/client_sim.js +++ b/zefie_wtvp_minisrv/client_sim.js @@ -1164,7 +1164,7 @@ class WebTVClientSimulator { } // Handle user-id header - indicates successful authentication - if (headers['user-id']) { + if (headers['user-id'] || (headers['wtv-visit'] && headers['wtv-visit'].startsWith('wtv-register:/splash'))) { this.debugLog(`*** Authentication successful! user-id detected: ${headers['user-id']} ***`); this.userIdDetected = true; @@ -1566,7 +1566,7 @@ class WebTVClientSimulator { let fileContent = fileResult.body; const contentType = fileResult.headers ? fileResult.headers['content-type'] : ''; const normalizedContentType = contentType.split(';')[0].trim().toLowerCase(); - var isgzip = false; + let isgzip = false; if (normalizedContentType === 'application/gzip' && !this.keepgz) { this.debugLog(`Decompressing gzip file for ${fileUrl}...`); @@ -1581,8 +1581,8 @@ class WebTVClientSimulator { fileContent = fileResult.body; } } - - var filePath = this.getServicePath(fileUrl, fileResult.headers || {}); + + let filePath = this.getServicePath(fileUrl, fileResult.headers || {}); if (isgzip) filePath = filePath.slice(0, -3); zip.addFile(filePath, fileContent); downloadedFiles.add(fileUrl); @@ -1800,9 +1800,9 @@ class WebTVClientSimulator { // Images and media /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, - /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, - /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, - /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, + /]+bgsound\s*=\s*["']([^"']+)["'][^>]*>/gi, + /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, + /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, // Scripts and stylesheets /]+src\s*=\s*["']([^"']+)["'][^>]*>/gi, @@ -2366,12 +2366,12 @@ class WebTVClientSimulator { this.debugLog('Parsing VLN-stage-two HTML for form and hidden fields...'); // Find the form action URL - var formMatch = htmlString.match(/]+action=["']([^"']+)["'][^>]*>/i); + let formMatch = htmlString.match(/]+action=["']([^"']+)["'][^>]*>/i); if (!formMatch) { // Match
// Handles quoted and unquoted action values // Improved regex: match action attribute, quoted or unquoted, non-greedy - var formMatch = htmlString.match(/]*\saction\s*=\s*(?:"([^"]*?)"|'([^']*?)'|([^\s"'<>]+))/i); + formMatch = htmlString.match(/]*\saction\s*=\s*(?:"([^"]*?)"|'([^']*?)'|([^\s"'<>]+))/i); if (!formMatch) { console.error('No form with action found in VLN-stage-two HTML'); this.cleanup(); diff --git a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js index 7b657256..c99df53e 100644 --- a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js +++ b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-author/edit-block.js @@ -10,7 +10,7 @@ var photo; var thumbnail; if (pagedata.blocks[oldBlockNum].photo) { - photo = wtvshared.atob(pagedata.blocks[oldBlockNum].photo) + photo = wtvshared.btoa(pagedata.blocks[oldBlockNum].photo) thumbnail = photo.replace('clipart/', 'clipart/icons/'); } diff --git a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/accounts.js b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/accounts.js index 535728b9..e9bd3933 100644 --- a/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/accounts.js +++ b/zefie_wtvp_minisrv/includes/ServiceVault/wtv-setup/accounts.js @@ -2,7 +2,7 @@ const minisrv_service_file = true; session_data.loadSessionData(); if (session_data.user_id != 0) { - const errpage = doErrorPage(400, "You are not authorized to edit the primary account."); + const errpage = wtvshared.doErrorPage(400, "You are not authorized to edit the primary account."); headers = errpage[0]; data = errpage[1]; } else { diff --git a/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js b/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js index 36902053..02e08846 100644 --- a/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js +++ b/zefie_wtvp_minisrv/includes/classes/WTVAuthor.js @@ -729,19 +729,22 @@ html += `">next page var pagestorepath = this.pagestore_dir; var self = this; self.pageArr = []; - var files = this.fs.readdirSync(pagestorepath) - this.debug("listPages","files",files) + if (self.fs.existsSync(pagestorepath)) { + var files = this.fs.readdirSync(pagestorepath) + this.debug("listPages","files",files) files.map(function (v) { - // 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; - if (self.fs.existsSync(pagepath)) page_data_raw = self.fs.readFileSync(pagepath); - if (page_data_raw) { - var page_data = JSON.parse(page_data_raw); - self.pageArr.push(page_data); - } - + 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; + if (self.fs.existsSync(pagepath)) page_data_raw = self.fs.readFileSync(pagepath); + if (page_data_raw) { + var page_data = JSON.parse(page_data_raw); + self.pageArr.push(page_data); + } + } }) + } return self.pageArr; } @@ -819,9 +822,14 @@ html += `">next page var publishname = pagedata.publishname; if (this.fs.existsSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname)) { try { - this.fs.rmdirSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname, { recursive: true }) + this.fs.rmSync(destDir + this.wtvclient.session_store.subscriber_username + '/' + publishname, { recursive: true }) pagedata.published = false; this.editPage(pagedata, pagenum, false); + const pages = this.listPages() + const publishedPagesCount = pages.filter(page => page.published).length; + if (publishedPagesCount === 0) { + this.fs.rmSync(destDir + this.wtvclient.session_store.subscriber_username, { recursive: true }); + } this.generatePageList() return true; } catch { } @@ -881,8 +889,8 @@ html += `">next page generatePageList() { // this one's pretty ok i think, but it should have screenshots of each page - var pagelist = this.listPages() - var html = ` + const pagelist = this.listPages() + let html = `