diff --git a/config.js b/config.js index c91b6b1..bcd0056 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,7 @@ export default { port: 8080, mode: 'dev', - minify: false, - assetScrambling: false -} \ No newline at end of file + minify: true, + assetScrambling: true, + allowDangerousTemplateInsert: false +}; \ No newline at end of file diff --git a/package.json b/package.json index 4f9b31f..6f0569f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "type": "module", "scripts": { - "start": "npm i && node server" + "start": "node server", + "prod": "node server prod", + "dev": "node server dev" }, "author": "Polaris Developments", "license": "GNU-3.0-or-later", diff --git a/server/index.js b/server/index.js index 949923a..a097973 100644 --- a/server/index.js +++ b/server/index.js @@ -14,7 +14,8 @@ import fs from 'node:fs'; const app = express(); const server = http.createServer(); const bareServer = createBareServer('/bare/'); -const port = process.env.PORT || process.argv[2] || 8080; +const mode = (process.argv[2] === 'prod' || process.argv[2] === 'dev' ? process.argv[2] : (process.argv[3] === 'prod' || process.argv[3] === 'dev' ? process.argv[3] : (config.mode === 'prod' || config.mode === 'dev' ? config.mode : 'prod'))); +const port = (process.argv[2] !== 'prod' && process.argv[2] !== 'dev' && Boolean(Number(process.argv[2]))) ? process.argv[2] : (Boolean(Number(process.argv[3])) ? process.argv[3] : (Boolean(Number(config.port)) ? config.port : (mode === 'prod' ? 80 : 8080 ) )); const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); app.get('/cdn/*', cors({ @@ -97,4 +98,4 @@ server.on('upgrade', (req, socket, head) => { else socket.end(); }); -server.listen(port, () => console.log(`Polaris started! http://localhost:${port}`)); \ No newline at end of file +server.listen(port, () => console.log(`Polaris listening\n\nPort: ${server.address().port}\nMode: ${mode}\nNode.js: ${process.version}\n`)); \ No newline at end of file diff --git a/server/utils/rewriter.js b/server/utils/rewriter.js index fddb274..24acf77 100644 --- a/server/utils/rewriter.js +++ b/server/utils/rewriter.js @@ -10,6 +10,7 @@ import path from 'node:path'; import url from 'node:url'; import fs from 'node:fs'; +const mode = (process.argv[2] === 'prod' || process.argv[2] === 'dev' ? process.argv[2] : (process.argv[3] === 'prod' || process.argv[3] === 'dev' ? process.argv[3] : (config.mode === 'prod' || config.mode === 'dev' ? config.mode : 'prod'))); const __dirname = url.fileURLToPath(new URL('../', import.meta.url)); const html = (data) => { @@ -21,11 +22,21 @@ const html = (data) => { if (data.split('\n')[0].trim().endsWith('-->')) return data.split('\n')[0].trim().replace('-->', ''); else return undefined; }) - .filter(data => fs.existsSync(path.join(__dirname, '../templates', data + '.html'))) + .map(data => { + if (data) { + if (data.startsWith('{{') && data.split(':')[data.split(':').length - 2].endsWith('}}')) { + if (config.allowDangerousTemplateInsert) { + if (Boolean(eval(String(data.split(':')[data.split(':').length - 2]).slice(2, -2)))) return data; + else return undefined; + } else return undefined; + } else return data; + } else return undefined; + }) + .filter(data => fs.existsSync(path.join(__dirname, '../templates', (data ? (data.startsWith('{{') && data.split(':')[data.split(':').length - 2].endsWith('}}') ? data.split(':')[data.split(':').length - 1] : data) : undefined) + '.html'))) .map(data => { return { name: data, - file: fs.readFileSync(path.join(__dirname, '../templates', data + '.html')) + file: fs.readFileSync(path.join(__dirname, '../templates', (data ? (data.startsWith('{{') && data.split(':')[data.split(':').length - 2].endsWith('}}') ? data.split(':')[data.split(':').length - 1] : data) : undefined) + '.html')) }; }); diff --git a/static/assets/js/apps.js b/static/assets/js/apps.js index 554a4f8..6b1146e 100644 --- a/static/assets/js/apps.js +++ b/static/assets/js/apps.js @@ -1,5 +1,5 @@ import PolarisError from '/assets/js/error.js'; -import { workerLoaded, loadWorker } from '/assets/js/wpm.js'; +import { loadWorker } from '/assets/js/wpm.js'; const tiltEffectSettings = { max: 8, @@ -18,7 +18,7 @@ const load = () => { document.querySelector('.apps').appendChild(el); el.addEventListener('click', async () => { - if (!workerLoaded) await loadWorker(); + await loadWorker('uv'); localStorage.setItem('frameData', JSON.stringify({ type: 'app', app diff --git a/static/assets/js/games.js b/static/assets/js/games.js index e751d32..f93ada8 100644 --- a/static/assets/js/games.js +++ b/static/assets/js/games.js @@ -1,5 +1,5 @@ import PolarisError from '/assets/js/error.js'; -import { workerLoaded, loadWorker } from '/assets/js/wpm.js'; +import { loadWorker } from '/assets/js/wpm.js'; const tiltEffectSettings = { max: 8, @@ -53,17 +53,16 @@ function renderGames(gamesToRender) { popularGamesContainer.appendChild(popularEl); popularEl.addEventListener('click', async () => { - if (!workerLoaded) await loadWorker(); - const frameData = { - type: 'game', - game - }; + await loadWorker('uv'); if (game.openinnewtab === 'yes') { - window.open(game.source, '_blank'); + window.open(game.source); console.log('Open game in new tab:', frameData); } else { - localStorage.setItem('frameData', JSON.stringify(frameData)); + localStorage.setItem('frameData', JSON.stringify({ + type: 'game', + game + })); location.href = '/view'; } }); diff --git a/static/assets/js/main.js b/static/assets/js/main.js index a8f02c5..47ee81e 100644 --- a/static/assets/js/main.js +++ b/static/assets/js/main.js @@ -64,21 +64,6 @@ if (location.pathname === '/') { description.classList = 'small'; document.querySelector('#changelog').appendChild(description); })); - - var items = ['the start', 'What are you doing here?', '"School"', 'I dont get paid enough', 'What Up Son?', 'help', 'i like bagle', '3.14159265359', 'Who thought this was a good idea?', 'Stage 4', 'i have a concerning lump on my back', 'Bean was here', 'Your Mother', 'Pacer Test', 'Why did he leave', 'by the way...', 'Kilroy was here', 'Kilroy is here', 'look behind you', 'West Virginia', 'theres a reason', 'Country road', 'Thats a wrap', 'Pretty', 'No', 'Yes', 'leave me', 'What square?', 'uhhh', 'Plutocracy', 'Practically Free*', 'capitalize this', 'Place Holder', 'Try me', 'fine', 'Why are we doing this again?', 'half eaten saltine crackers are underated', 'Javascript > Java', 'L + Ratio', 'Cope', 'I Love Refrigerators', 'That Happened.', 'Pedicure', '(insert message here)', 'terminal', 'πŸ’€πŸ’€πŸ’€', 'finnish', 'who writes these?', 'reference', 'I am going to peel the skin off your face (:', 'bye', 'no', 'the fact is', 'run', 'uh what', 'hello world', 'Positively awful', 'tax fraud', 'comatose state', 'Not me', 'my second job is a discord mod', 'kids bop', 'Is it just me or', 'Hello people', '74% Incomplete', 'wake up', 'Monster Energy', 'ew', 'The amount of pain I am in right now is unimaginable', 'chicken', 'men', 'What?', 'Your opinion is invalid', 'gay pride', 'Im going', '4skin', '/0', 'Who said that?', 'No Fair.', 'Famous... Enough', 'Parent Approved!', 'Teacher Approved!', 'Treason', 'Just do it already!', 'You\'re Fired', 'Not worth it', 'was there a reason?', 'the egg came first', 'patriotism', 'Family Friendly', 'Do you ever feel like a plastic bag Drifting through the windWanting to start again? Do you ever feel, feel so paper thin Like a house of cards One blow from caving in?', 'Why?', 'discord is in the first o', 'Shane Dawson likes cats', 'who stole this', 'unblock linux', 'darn you', 'gushers', 'yummy', 'charles loves you', 'mekhi loves anime', 'pls dont type smurf :)']; - - function getRandomFact() { - var randomIndex = Math.floor(Math.random() * items.length); - return items[randomIndex]; - } - - // When the page loads, set the innerHTML of elements with class 'blue' to a random item - window.addEventListener('load', function () { - var blue = document.getElementsByClassName('blue'); - for (var i = 0; i < blue.length; i++) { - blue[i].innerHTML = getRandomFact(); - } - }); } if (window.scrollY !== 0) document.querySelector('.navbar').classList.add('scrolling'); diff --git a/static/assets/js/search.js b/static/assets/js/search.js index adece4f..6ecb3ae 100644 --- a/static/assets/js/search.js +++ b/static/assets/js/search.js @@ -1,4 +1,5 @@ -import { workerLoaded, loadWorker } from '/assets/js/wpm.js'; +import PolarisError from '/assets/js/error.js'; +import { loadWorker } from '/assets/js/wpm.js'; const load = () => { const xor = { @@ -19,16 +20,14 @@ const load = () => { e.preventDefault(); if (typeof navigator.serviceWorker === 'undefined') new PolarisError('Failed to load Proxy'); - if (!workerLoaded) await loadWorker(); + await loadWorker('uv'); const url = /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/.test(query.value) ? ((!query.value.startsWith('http://') && !query.value.startsWith('https://')) ? 'https://' + query.value : query.value) : 'https://www.google.com/search?q=' + encodeURIComponent(query.value); - const frameData = { + localStorage.setItem('frameData', JSON.stringify({ type: 'proxy', source: `/uv/service/${xor.encode(url)}` - }; - - localStorage.setItem('frameData', JSON.stringify(frameData)); + })); location.href = '/view'; }); } diff --git a/static/assets/js/settings.js b/static/assets/js/settings.js index 6f70961..a5f4a67 100644 --- a/static/assets/js/settings.js +++ b/static/assets/js/settings.js @@ -1,5 +1,5 @@ -import Theme from '/assets/js/themes.js'; import PolarisError from '/assets/js/error.js'; +import Theme from '/assets/js/themes.js'; const isScrollable = (element) => element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight; diff --git a/static/assets/js/themes.js b/static/assets/js/themes.js index 2910f33..632f517 100644 --- a/static/assets/js/themes.js +++ b/static/assets/js/themes.js @@ -1,111 +1,86 @@ const set = (name, value) => { - if (!localStorage.getItem('settings')) { - localStorage.setItem('settings', JSON.stringify({})); - } else { - try { - JSON.parse(localStorage.getItem('settings')); - } catch (e) { - localStorage.setItem('settings', JSON.stringify({})); - } + if (!localStorage.getItem('settings')) { + localStorage.setItem('settings', JSON.stringify({})); + } else { + try { + JSON.parse(localStorage.getItem('settings')); + } catch (e) { + localStorage.setItem('settings', JSON.stringify({})); } + } - const settings = JSON.parse(localStorage.getItem('settings')); - settings[name] = value; - localStorage.setItem('settings', JSON.stringify(settings)); + const settings = JSON.parse(localStorage.getItem('settings')); + settings[name] = value; + localStorage.setItem('settings', JSON.stringify(settings)); }; const get = (name) => { - if (!localStorage.getItem('settings')) { - localStorage.setItem('settings', JSON.stringify({})); - } else { - try { - JSON.parse(localStorage.getItem('settings')); - } catch (e) { - localStorage.setItem('settings', JSON.stringify({})); - } + if (!localStorage.getItem('settings')) { + localStorage.setItem('settings', JSON.stringify({})); + } else { + try { + JSON.parse(localStorage.getItem('settings')); + } catch (e) { + localStorage.setItem('settings', JSON.stringify({})); } + } - const settings = JSON.parse(localStorage.getItem('settings')); - return settings[name]; + const settings = JSON.parse(localStorage.getItem('settings')); + return settings[name]; } class Theme { - constructor() { - this.theme = get('theme'); + constructor() { + this.theme = get('theme'); - if (this.theme) { - this.set(this.theme); - } else { - this.set('system default'); - } + if (this.theme) { + this.set(this.theme); + } else { + this.set('system default'); } + } - set = (theme, save) => { - document.body.setAttribute('data-theme', theme); + set = (theme, save) => { + document.body.setAttribute('data-theme', theme); - if (save !== false) { - set('theme', theme); - } - } + if (save !== false) set('theme', theme); + } } -// Define a variable to track whether the audio has been played -let audioPlayed = false; -// Function to play the audio and display the image +/*let audioPlayed = false; +let smurfString = ''; + function playSmurfAudio() { if (!audioPlayed) { const audio = new Audio('/assets/misc/smurf.mp3'); audio.play(); audioPlayed = true; - // Display the image const imageElement = document.createElement('img'); imageElement.src = '/assets/img/smurf.jpg'; document.body.appendChild(imageElement); - // Delay theme change by 7 seconds setTimeout(() => { - let themeToggleInterval = setInterval(() => { - // Toggle between light and dark themes - if (document.body.getAttribute('data-theme') === 'flamingo') { - document.body.setAttribute('data-theme', 'light'); - } else { - document.body.setAttribute('data-theme', 'flamingo'); - } - }, 300); - - // Stop changing the theme when the audio ends audio.onended = () => { - clearInterval(themeToggleInterval); document.body.setAttribute('data-theme', 'dark'); - // Remove the image when the audio ends document.body.removeChild(imageElement); + + audioPlayed = false; }; }, 7000); } } -// Event listener to check for the word "smurf" -document.addEventListener('keydown', (event) => { +window.addEventListener('keydown', (event) => { if (event.key === 's' || event.key === 'm' || event.key === 'u' || event.key === 'r' || event.key === 'f') { - // Add the pressed key to a string and check if it matches "smurf" - if (event.key === 's') { - smurfString = 's'; - } else { - smurfString += event.key; - } + if (event.key === 's') smurfString = 's'; + else smurfString += event.key; if (smurfString === 'smurf') { playSmurfAudio(); + smurfString = ''; } - } else { - smurfString = ''; // Reset the string if a different key is pressed - } -}); - -// Variable to store the string as it's being typed -let smurfString = ''; - - + } else smurfString = ''; +});*/ export default new Theme(); \ No newline at end of file diff --git a/static/assets/js/wpm.js b/static/assets/js/wpm.js index 190d239..40a5277 100644 --- a/static/assets/js/wpm.js +++ b/static/assets/js/wpm.js @@ -1,25 +1,7 @@ -let workerLoaded = false; -let chosenProxy = 'uv'; // dynamic is broken so dont change this - -let loadWorker = async (worker) => { - let allWorkers = await navigator.serviceWorker.getRegistrations(); - allWorkers.forEach(worker => { - if (!worker.active?.scriptURL?.includes(chosenProxy)) worker.unregister(); - }); - - await navigator.serviceWorker.register(`/${worker || chosenProxy}/sw.js`, { - scope: `/uv/service/`, - }); -}; - -(async () => { - await loadWorker(); - workerLoaded = true; -})(); - -window.loadWorker = loadWorker; +const loadWorker = async (proxy) => await navigator.serviceWorker.register(`/${proxy}/sw.js`, { + scope: `/${proxy}/service/`, +}); export { - workerLoaded, loadWorker }; diff --git a/static/index.html b/static/index.html index 3fcb19a..316af95 100644 --- a/static/index.html +++ b/static/index.html @@ -44,6 +44,7 @@ + \ No newline at end of file diff --git a/static/TOS.html b/static/tos.html similarity index 99% rename from static/TOS.html rename to static/tos.html index e8ed1c1..f094ad9 100644 --- a/static/TOS.html +++ b/static/tos.html @@ -222,8 +222,8 @@
22. ELECTRONIC COMMUNICATIONS, TRANSACTIONS, AND SIGNATURES
-
+