From 0d4e3919001ff84102508c56c119586d143ac3bd Mon Sep 17 00:00:00 2001 From: Cookie Engineer Date: Fri, 15 May 2020 16:36:16 +0200 Subject: [PATCH] :sparkles: ENVIRONMENT refactor --- .gitignore | 3 +- base/.eslintrc.json | 19 +- base/bin/base.mjs | 124 +++++++ base/bin/base.sh | 42 --- bin/eslint.sh | 24 -- bin/generate-service.mjs | 135 -------- bin/generate-service.sh | 14 - browser/.eslintrc.json | 20 +- browser/bin/browser.mjs | 314 ++++++++++++++++++ browser/design/footer/Beacon.mjs | 2 +- browser/design/footer/Context.mjs | 2 +- browser/design/footer/Help.mjs | 2 +- browser/design/footer/Session.mjs | 3 +- browser/design/footer/Site.mjs | 2 +- browser/design/footer/Tabs.mjs | 2 +- browser/design/header/Address.mjs | 2 +- browser/design/header/History.mjs | 2 +- browser/design/header/Mode.mjs | 2 +- browser/design/header/Settings.mjs | 2 +- browser/design/index.css | 1 - browser/design/index.mjs | 181 +++++----- browser/design/main/Webview.mjs | 4 +- browser/index.html | 83 ++++- browser/internal/fix-host/index.css | 4 +- browser/internal/fix-host/index.mjs | 56 ++-- browser/internal/fix-mode/index.css | 4 +- browser/internal/fix-mode/index.mjs | 78 +++-- browser/internal/fix-request/index.css | 4 +- browser/internal/fix-request/index.mjs | 234 +++++++------ .../{common/internal.css => index.css} | 2 +- .../{common/internal.mjs => index.mjs} | 112 ++++--- browser/internal/settings/hosts.mjs | 2 +- browser/internal/settings/index.css | 4 +- browser/internal/settings/index.mjs | 19 +- browser/internal/settings/internet.mjs | 2 +- browser/internal/settings/peers.mjs | 2 +- browser/internal/settings/sites.mjs | 2 +- .../{common/default.css => theme.css} | 2 - browser/internal/welcome/index.css | 4 +- browser/service.js | 6 +- browser/source/Client.mjs | 8 +- browser/source/ENVIRONMENT.mjs | 4 +- covert/.eslintrc.json | 8 +- covert/bin/covert.mjs | 59 ++-- covert/source/Covert.mjs | 4 +- covert/source/ENVIRONMENT.mjs | 12 +- covert/source/Linter.mjs | 10 +- covert/source/Renderer.mjs | 2 +- package.json | 18 +- stealth/.eslintrc.json | 8 +- stealth/bin/stealth.mjs | 177 +++++++++- stealth/bin/stealth.sh | 62 ---- stealth/index.mjs | 1 - stealth/review/Server.mjs | 11 +- stealth/review/Stealth.mjs | 35 +- stealth/review/client/Peer.mjs | 4 +- stealth/review/client/Session.mjs | 10 +- stealth/review/peer/Cache.mjs | 17 +- stealth/source/ENVIRONMENT.mjs | 12 +- stealth/source/Settings.mjs | 16 +- stealth/source/Stealth.mjs | 8 +- stealth/source/other/FILE.mjs | 6 +- stealth/source/server/Peer.mjs | 4 +- 63 files changed, 1203 insertions(+), 815 deletions(-) create mode 100644 base/bin/base.mjs delete mode 100755 base/bin/base.sh delete mode 100755 bin/eslint.sh delete mode 100644 bin/generate-service.mjs delete mode 100755 bin/generate-service.sh create mode 100644 browser/bin/browser.mjs rename browser/internal/{common/internal.css => index.css} (99%) rename browser/internal/{common/internal.mjs => index.mjs} (85%) rename browser/internal/{common/default.css => theme.css} (99%) delete mode 100755 stealth/bin/stealth.sh diff --git a/.gitignore b/.gitignore index a7747886..03be6760 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/build +/node_modules +/package-lock.json diff --git a/base/.eslintrc.json b/base/.eslintrc.json index 881675a9..d6129041 100644 --- a/base/.eslintrc.json +++ b/base/.eslintrc.json @@ -10,8 +10,23 @@ "sourceType": "module" }, "overrides": [{ - "files": [ "extern/base.mjs" ], - "rules": { "no-global-assign": "off", "no-undef": "off" } + "files": [ "*.mjs" ], + "rules": {} + }, { + "files": [ "build/browser.mjs" ], + "rules": { + "no-undef": "off" + } + }, { + "files": [ "build/node.mjs" ], + "globals": { + "global": true, + "window": true + }, + "rules": { + "no-control-regex": "off", + "no-undef": "off" + } }, { "files": [ "source/node/console.mjs" ], "rules": { "no-control-regex": "off" } diff --git a/base/bin/base.mjs b/base/bin/base.mjs new file mode 100644 index 00000000..ba13b3d3 --- /dev/null +++ b/base/bin/base.mjs @@ -0,0 +1,124 @@ + +import fs from 'fs'; +import url from 'url'; +import path from 'path'; +import process from 'process'; + +import { console } from '../../base/index.mjs'; + + + +const FILE = url.fileURLToPath(import.meta.url); +const ROOT = path.dirname(path.resolve(FILE, '../')); + +const read = (path) => { + + let buffer = null; + + try { + buffer = fs.readFileSync(path); + } catch (err) { + buffer = null; + } + + return { + path: path, + buffer: buffer + }; + +}; + +const generate = (path, files) => { + + let errors = 0; + let buffers = []; + + files.forEach((file) => { + + if (file.buffer !== null) { + buffers.push(file.buffer); + } else { + console.warn('> "' + file.path + '" is empty.'); + errors++; + } + + }); + + try { + fs.writeFileSync(path, Buffer.concat(buffers)); + } catch (err) { + errors++; + } + + if (errors === 0) { + + console.info('base: generate("base/' + path.substr(ROOT.length + 1) + '")'); + + return true; + + } else { + + console.error('base: generate("base/' + path.substr(ROOT.length + 1) + '")'); + + return false; + + } + +}; + + + +const BASE_FILES = [ + ROOT + '/source/Array.mjs', + ROOT + '/source/Boolean.mjs', + ROOT + '/source/Date.mjs', + ROOT + '/source/Function.mjs', + ROOT + '/source/Number.mjs', + ROOT + '/source/Object.mjs', + ROOT + '/source/RegExp.mjs', + ROOT + '/source/String.mjs', + ROOT + '/source/Emitter.mjs' +].map((path) => read(path)); + +const BROWSER_FILES = [ + ROOT + '/source/browser/Buffer.mjs', + ROOT + '/source/browser/console.mjs', + ROOT + '/source/MODULE.mjs' +].map((path) => read(path)); + +const NODE_FILES = [ + ROOT + '/source/node/Buffer.mjs', + ROOT + '/source/node/console.mjs', + ROOT + '/source/MODULE.mjs' +].map((path) => read(path)); + + + +export const build = () => { + + let results = [ + generate(ROOT + '/build/browser.mjs', [].concat(BASE_FILES).concat(BROWSER_FILES)), + generate(ROOT + '/build/node.mjs', [].concat(BASE_FILES).concat(NODE_FILES)) + ]; + + if (results.includes(false) === false) { + return true; + } + + + return false; + +}; + + +if (process.argv.includes(FILE) === true) { + + let result = build(); + if (result === true) { + process.exit(0); + } else { + process.exit(1); + } + +} + diff --git a/base/bin/base.sh b/base/bin/base.sh deleted file mode 100755 index 3597d80c..00000000 --- a/base/bin/base.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -base_dir="$(dirname "$(dirname "$(readlink -f "$0")")")"; - - - -cd $base_dir; - -if [ -d "$base_dir/build" ]; then - rm -rf "$base_dir/build"; -fi; - -mkdir "$base_dir/build"; - - -BASE_FILES=( - "$base_dir/source/Array.mjs" - "$base_dir/source/Boolean.mjs" - "$base_dir/source/Date.mjs" - "$base_dir/source/Function.mjs" - "$base_dir/source/Number.mjs" - "$base_dir/source/Object.mjs" - "$base_dir/source/RegExp.mjs" - "$base_dir/source/String.mjs" - "$base_dir/source/Emitter.mjs" -); - -BROWSER_FILES=( - "$base_dir/source/browser/Buffer.mjs" - "$base_dir/source/browser/console.mjs" -); - -NODE_FILES=( - "$base_dir/source/node/Buffer.mjs" - "$base_dir/source/node/console.mjs" -); - -cat "${BASE_FILES[@]}" "${BROWSER_FILES[@]}" "$base_dir/source/MODULE.mjs" > $base_dir/build/browser.mjs; -cat "${BASE_FILES[@]}" "${NODE_FILES[@]}" "$base_dir/source/MODULE.mjs" > $base_dir/build/node.mjs; - -exit 0; - diff --git a/bin/eslint.sh b/bin/eslint.sh deleted file mode 100755 index 5b5e8c52..00000000 --- a/bin/eslint.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env sh - -root_dir="$(dirname "$(dirname "$(readlink -f "$0")")")"; -eslint_bin="$(which eslint)"; - - -if [[ -z "$eslint_bin" ]]; then - echo "Please install eslint first"; - exit 1; -fi; - - -cd "$root_dir/base"; -eslint --ext js,mjs .; - -cd "$root_dir/browser"; -eslint --ext js,mjs .; - -cd "$root_dir/covert"; -eslint --ext js,mjs .; - -cd "$root_dir/stealth"; -eslint --ext js,mjs .; - diff --git a/bin/generate-service.mjs b/bin/generate-service.mjs deleted file mode 100644 index 5cb28bc1..00000000 --- a/bin/generate-service.mjs +++ /dev/null @@ -1,135 +0,0 @@ - -import fs from 'fs'; -import path from 'path'; -import process from 'process'; - -import { console, Buffer, isString } from '../base/index.mjs'; - - - -const BROWSER = process.env.PWD + '/browser'; -const SERVICE = process.env.PWD + '/browser/service.js'; -const IGNORE = [ - BROWSER + '/bin', - BROWSER + '/README.md' -]; - -const read = (path) => { - - let buffer = null; - - try { - buffer = fs.readFileSync(path, 'utf8'); - } catch(err) { - buffer = null; - } - - return buffer; - -}; - -const walk = (path, result) => { - - if (IGNORE.includes(path) === true) { - return result; - } - - if (result === undefined) { - result = []; - } - - let stat = null; - - try { - stat = fs.lstatSync(path); - } catch (err) { - stat = null; - } - - if (stat !== null) { - - if (stat.isDirectory() === true) { - - let nodes = []; - - try { - nodes = fs.readdirSync(path); - } catch (err) { - nodes = []; - } - - if (nodes.length > 0) { - - nodes.forEach((node) => { - walk(path + '/' + node, result); - }); - - } - - } else if (stat.isFile() === true) { - - let name = path.split('/').pop(); - if (name.startsWith('.') === false) { - result.push(path); - } - - } - - } - - return result; - -}; - -const write = (path, buffer) => { - - let result = false; - - try { - fs.writeFileSync(path, buffer, 'utf8'); - result = true; - } catch (err) { - result = false; - } - - return result; - -}; - - - -let original = read(SERVICE); -let files = walk(BROWSER).map((path) => { - return path.substr(BROWSER.length + 1); -}).sort((a, b) => { - if (a < b) return -1; - if (b < a) return 1; - return 0; -}); - - -if (isString(original) === true) { - - let template = original; - let index0 = template.indexOf('const ASSETS = [') + 17; - let index1 = template.indexOf('];', index0); - - if (index0 > 17 && index1 > 18) { - template = template.substr(0, index0) + '\n\t\'' + files.join('\',\n\t\'') + '\'\n' + template.substr(index1); - } - - if (template.length !== original.length) { - - let result = write(SERVICE, template); - if (result === true) { - console.info('Updated the "/browser/service.js" file.'); - } else { - console.error('Could not update "/browser/service.js"!'); - } - - } else { - console.warn('Nothing to do.'); - } - -} - diff --git a/bin/generate-service.sh b/bin/generate-service.sh deleted file mode 100755 index 3ce38fbf..00000000 --- a/bin/generate-service.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -root_dir="$(dirname "$(dirname "$(readlink -f "$0")")")"; -node_bin="$(which node)"; - - -if [[ -z "$node_bin" ]]; then - echo "Please install node.js first"; -fi; - -cd "$root_dir"; - -"$node_bin" --experimental-modules ./bin/generate-service.mjs; - diff --git a/browser/.eslintrc.json b/browser/.eslintrc.json index 3c3b02e0..5719e7e9 100644 --- a/browser/.eslintrc.json +++ b/browser/.eslintrc.json @@ -10,34 +10,32 @@ "sourceType": "module" }, "globals": { - "browser": true, - "Buffer": true, - "BROWSER": true, - "WIDGETS": true + "Buffer": true }, "overrides": [{ + "files": [ "*.mjs" ], + "rules": {} + }, { "files": [ "bin/electron/application.js" ], "env": { "node": true } - }, { - "files": [ "bin/firefox/defaults/preferences/prefs.js" ], - "globals": { - "pref": true - } }, { "files": [ "bin/gjs/application.js" ], "globals": { "imports": true } }, { - "files": [ "browser.mjs", "service.js" ], + "files": [ "service.js" ], "rules": { + "no-control-regex": "off", "no-console": "off" } }, { "files": [ "extern/base.mjs" ], - "rules": { "no-global-assign": "off", "no-undef": "off" } + "rules": { + "no-undef": "off" + } }], "rules": { "no-restricted-globals": [ diff --git a/browser/bin/browser.mjs b/browser/bin/browser.mjs new file mode 100644 index 00000000..9ec41e10 --- /dev/null +++ b/browser/bin/browser.mjs @@ -0,0 +1,314 @@ + +import fs from 'fs'; +import url from 'url'; +import path from 'path'; +import process from 'process'; + +import { build as build_base } from '../../base/bin/base.mjs'; +import { console } from '../../base/index.mjs'; + + + +const FILE = url.fileURLToPath(import.meta.url); +const ROOT = path.dirname(path.resolve(FILE, '../../')); + +const copy = (origin, target) => { + + let stat = null; + let result = false; + + try { + stat = fs.statSync(origin); + } catch (err) { + stat = null; + } + + if (stat !== null) { + + if (stat.isDirectory() === true) { + + let files = []; + + try { + files = fs.readdirSync(origin); + } catch (err) { + files = []; + } + + if (files.length > 0) { + + let results = files.map((file) => { + return copy(origin + '/' + file, target + '/' + file); + }); + + if (results.includes(false) === false) { + result = true; + } else { + result = false; + } + + } else { + result = true; + } + + } else if (stat.isFile() === true) { + + stat = null; + + try { + stat = fs.statSync(path.dirname(target)); + } catch (err) { + stat = null; + } + + if (stat === null || stat.isDirectory() === false) { + + try { + fs.mkdirSync(path.dirname(target), { + recursive: true + }); + } catch (err) { + // Ignore + } + + } + + try { + fs.copyFileSync(origin, target); + result = true; + } catch (err) { + result = false; + } + + } + + } + + if (result === true) { + console.info('browser: copy("' + origin.substr(ROOT.length + 1) + '", "' + target.substr(ROOT.length + 1) + '")'); + } else { + console.error('browser: copy("' + origin.substr(ROOT.length + 1) + '", "' + target.substr(ROOT.length + 1) + '")'); + } + + return result; + +}; + +const read = (path) => { + + let buffer = null; + + try { + buffer = fs.readFileSync(path, 'utf8'); + } catch(err) { + buffer = null; + } + + return buffer; + +}; + +const remove = (path) => { + + let stat = null; + let result = false; + + try { + stat = fs.statSync(path); + } catch (err) { + stat = null; + } + + if (stat !== null) { + + if (stat.isDirectory() === true) { + + try { + fs.rmdirSync(path, { + recursive: true + }); + result = true; + } catch (err) { + result = false; + } + + } else if (stat.isFile() === true) { + + try { + fs.unlinkSync(path); + result = true + } catch (err) { + result = false; + } + + } + + } + + return result; + +}; + +const walk = (path, result) => { + + if ( + path === ROOT + '/browser/bin' + || path === ROOT + '/browser/README.md' + ) { + return result; + } + + + if (result === undefined) { + result = []; + } + + let stat = null; + + try { + stat = fs.lstatSync(path); + } catch (err) { + stat = null; + } + + if (stat !== null) { + + if (stat.isDirectory() === true) { + + let nodes = []; + + try { + nodes = fs.readdirSync(path); + } catch (err) { + nodes = []; + } + + if (nodes.length > 0) { + + nodes.forEach((node) => { + walk(path + '/' + node, result); + }); + + } + + } else if (stat.isFile() === true) { + + let name = path.split('/').pop(); + if (name.startsWith('.') === false) { + result.push(path); + } + + } + + } + + return result; + +}; + +const write = (path, buffer) => { + + let result = false; + + try { + fs.writeFileSync(path, buffer, 'utf8'); + result = true; + } catch (err) { + result = false; + } + + if (result === true) { + console.info('browser: write("' + path.substr(ROOT.length + 1) + '")'); + } else { + console.error('browser: write("' + path.substr(ROOT.length + 1) + '")'); + } + + return result; + +}; + + + +export const clean = () => { + + let results = [ + remove(ROOT + '/browser/extern/base.mjs'), + remove(ROOT + '/browser/source/Browser.mjs'), + remove(ROOT + '/browser/source/Tab.mjs'), + remove(ROOT + '/browser/source/client'), + remove(ROOT + '/browser/source/parser') + ]; + + if (results.includes(false) === false) { + return true; + } + + + return false; + +}; + +export const build = () => { + + let results = [ + build_base(), + copy(ROOT + '/base/build/browser.mjs', ROOT + '/browser/extern/base.mjs'), + copy(ROOT + '/stealth/source/Browser.mjs', ROOT + '/browser/source/Browser.mjs'), + copy(ROOT + '/stealth/source/Tab.mjs', ROOT + '/browser/source/Tab.mjs'), + copy(ROOT + '/stealth/source/client', ROOT + '/browser/source/client'), + copy(ROOT + '/stealth/source/parser', ROOT + '/browser/source/parser') + ]; + + + let service = read(ROOT + '/browser/service.js'); + if (service !== null) { + + let files = walk(ROOT + '/browser').map((path) => { + return path.substr((ROOT + '/browser').length + 1); + }).sort((a, b) => { + if (a < b) return -1; + if (b < a) return 1; + return 0; + }); + + if (files.length > 0) { + + let index0 = service.indexOf('const ASSETS = [') + 17; + let index1 = service.indexOf('];', index0); + + if (index0 > 17 && index1 > 18) { + service = service.substr(0, index0) + '\n\t\'' + files.join('\',\n\t\'') + '\'\n' + service.substr(index1); + } + + results.push(write(ROOT + '/browser/service.js', service)); + + } + + } + + + if (results.includes(false) === false) { + return true; + } + + + return false; + +}; + + +if (process.argv.includes(FILE) === true) { + + let results = [ + clean(), + build() + ]; + + if (results.includes(false) === false) { + process.exit(0); + } else { + process.exit(1); + } + +} + diff --git a/browser/design/footer/Beacon.mjs b/browser/design/footer/Beacon.mjs index c50792e8..19859cfb 100644 --- a/browser/design/footer/Beacon.mjs +++ b/browser/design/footer/Beacon.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; diff --git a/browser/design/footer/Context.mjs b/browser/design/footer/Context.mjs index 07d931c6..0938953a 100644 --- a/browser/design/footer/Context.mjs +++ b/browser/design/footer/Context.mjs @@ -1,6 +1,6 @@ +import { Element } from '../../design/index.mjs'; import { isArray, isFunction, isNumber, isObject, isString } from '../../extern/base.mjs'; -import { Element } from '../Element.mjs'; import { URL } from '../../source/parser/URL.mjs'; diff --git a/browser/design/footer/Help.mjs b/browser/design/footer/Help.mjs index 528dcd39..0e17812e 100644 --- a/browser/design/footer/Help.mjs +++ b/browser/design/footer/Help.mjs @@ -1,6 +1,6 @@ +import { Element } from '../../design/index.mjs'; import { isObject, isString } from '../../extern/base.mjs'; -import { Element } from '../Element.mjs'; diff --git a/browser/design/footer/Session.mjs b/browser/design/footer/Session.mjs index 9390a296..30f133b4 100644 --- a/browser/design/footer/Session.mjs +++ b/browser/design/footer/Session.mjs @@ -1,5 +1,6 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; + const TEMPLATE = ` diff --git a/browser/design/footer/Site.mjs b/browser/design/footer/Site.mjs index 0b3af0d6..e88297db 100644 --- a/browser/design/footer/Site.mjs +++ b/browser/design/footer/Site.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; diff --git a/browser/design/footer/Tabs.mjs b/browser/design/footer/Tabs.mjs index eac7c9f4..0d553354 100644 --- a/browser/design/footer/Tabs.mjs +++ b/browser/design/footer/Tabs.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; import { URL } from '../../source/parser/URL.mjs'; diff --git a/browser/design/header/Address.mjs b/browser/design/header/Address.mjs index 674fbe67..e367b5b0 100644 --- a/browser/design/header/Address.mjs +++ b/browser/design/header/Address.mjs @@ -1,6 +1,6 @@ +import { Element } from '../../design/index.mjs'; import { isString } from '../../extern/base.mjs'; -import { Element } from '../Element.mjs'; import { URL } from '../../source/parser/URL.mjs'; diff --git a/browser/design/header/History.mjs b/browser/design/header/History.mjs index 4e24b02f..a4d75417 100644 --- a/browser/design/header/History.mjs +++ b/browser/design/header/History.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; diff --git a/browser/design/header/Mode.mjs b/browser/design/header/Mode.mjs index 197f3dc0..40906d7b 100644 --- a/browser/design/header/Mode.mjs +++ b/browser/design/header/Mode.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; diff --git a/browser/design/header/Settings.mjs b/browser/design/header/Settings.mjs index 14737e6f..cefb677c 100644 --- a/browser/design/header/Settings.mjs +++ b/browser/design/header/Settings.mjs @@ -1,5 +1,5 @@ -import { Element } from '../Element.mjs'; +import { Element } from '../../design/index.mjs'; diff --git a/browser/design/index.css b/browser/design/index.css index 7706ee2e..51fa2e12 100644 --- a/browser/design/index.css +++ b/browser/design/index.css @@ -1,5 +1,4 @@ -@import url("../internal/common/default.css"); @import url("./other/index.css"); @import url("./header/History.css"); @import url("./header/Address.css"); diff --git a/browser/design/index.mjs b/browser/design/index.mjs index 037bb405..dee98ae6 100644 --- a/browser/design/index.mjs +++ b/browser/design/index.mjs @@ -5,124 +5,95 @@ const header = doc.querySelector('header'); const main = doc.querySelector('main'); const footer = doc.querySelector('footer'); -import { console } from '../extern/base.mjs'; -import { flags, hostname } from '../source/ENVIRONMENT.mjs'; -import { dispatch } from '../internal/common/internal.mjs'; -import { Address } from './header/Address.mjs'; -import { Beacon } from './footer/Beacon.mjs'; -import { Browser } from '../source/Browser.mjs'; -import { Context } from './footer/Context.mjs'; -import { Help } from './footer/Help.mjs'; -import { History } from './header/History.mjs'; -import { Mode } from './header/Mode.mjs'; -import { Session } from './footer/Session.mjs'; -import { Settings } from './header/Settings.mjs'; -import { Site } from './footer/Site.mjs'; -import { Tabs } from './footer/Tabs.mjs'; -import { Webview } from './main/Webview.mjs'; - - - -const BROWSER = global.BROWSER = new Browser({ - host: hostname, - debug: flags.debug -}); - -const WIDGETS = global.WIDGETS = {}; - - -WIDGETS.address = new Address(BROWSER, WIDGETS); -WIDGETS.beacon = new Beacon(BROWSER, WIDGETS); -WIDGETS.context = new Context(BROWSER, WIDGETS); -WIDGETS.help = new Help(BROWSER, WIDGETS); -WIDGETS.history = new History(BROWSER, WIDGETS); -WIDGETS.mode = new Mode(BROWSER, WIDGETS); -WIDGETS.session = new Session(BROWSER, WIDGETS); -WIDGETS.settings = new Settings(BROWSER, WIDGETS); -WIDGETS.site = new Site(BROWSER, WIDGETS); -WIDGETS.tabs = new Tabs(BROWSER, WIDGETS); -WIDGETS.webview = new Webview(BROWSER, WIDGETS); - - -WIDGETS.history.render(header); -WIDGETS.address.render(header); -WIDGETS.mode.render(header); -WIDGETS.settings.render(header); - -WIDGETS.webview.render(main); - -WIDGETS.tabs.render(footer); -WIDGETS.beacon.render(footer); -WIDGETS.site.render(footer); -WIDGETS.session.render(footer); -WIDGETS.context.render(footer); -WIDGETS.help.render(footer); - - -setTimeout(() => { - - dispatch(global, BROWSER); - - - BROWSER.once('connect', () => { - - console.info('Browser: Design connected to ws://' + hostname + ':65432.'); - - [ - // 'stealth:settings' - // 'stealth:fix-host?url=' + encodeURIComponent('https://cookie.engineer/index.html'), - // 'stealth:fix-mode?url=' + encodeURIComponent('https://cookie.engineer/index.html'), - // 'stealth:fix-filter?url=' + encodeURIComponent('https://cookie.engineer/index.html'), - // 'stealth:fix-request?url=' + encodeURIComponent('https://cookie.engineer/index.html') + '&cause=socket-stability&code=403' - 'https://cookie.engineer/index.html' - ].map((url) => { - return BROWSER.open(url); - }).forEach((tab) => { - BROWSER.show(tab); - }); +import { isBrowser } from '../source/Browser.mjs'; +import { Address } from './header/Address.mjs'; +import { Beacon } from './footer/Beacon.mjs'; +import { Context } from './footer/Context.mjs'; +import { Help } from './footer/Help.mjs'; +import { History } from './header/History.mjs'; +import { Mode } from './header/Mode.mjs'; +import { Session } from './footer/Session.mjs'; +import { Settings } from './header/Settings.mjs'; +import { Site } from './footer/Site.mjs'; +import { Tabs } from './footer/Tabs.mjs'; +import { Webview } from './main/Webview.mjs'; - }); - BROWSER.once('disconnect', () => { - console.error('Browser: Design disconnected from ws://' + hostname + ':65432.'); - }); - BROWSER.connect(); +export * from './Element.mjs'; +export const WIDGETS = global.WIDGETS = {}; - if (typeof global.onbeforeunload !== 'undefined') { +export const dispatch = (window, browser) => { - global.onbeforeunload = () => { - BROWSER.disconnect(); - }; + browser = isBrowser(browser) ? browser : null; - } -}, 100); + if (browser !== null) { + Object.keys(WIDGETS).forEach((key) => { -setTimeout(() => { + let widget = WIDGETS[key] || null; + if (widget !== null) { + widget.erase(); + } - // Generate Tab Index for WIDGETS.tabs + WIDGETS[key] = null; - let tabindex = 1; + }); - [ - WIDGETS.history.back, - WIDGETS.history.next, - WIDGETS.history.action, - WIDGETS.history.open, - WIDGETS.address.input, - ...WIDGETS.mode.buttons, - WIDGETS.settings.beacon, - WIDGETS.settings.session, - WIDGETS.settings.site, - WIDGETS.settings.browser - ].filter((v) => v !== null).forEach((element) => { - element.attr('tabindex', tabindex++); - }); + WIDGETS.address = new Address(browser, WIDGETS); + WIDGETS.beacon = new Beacon(browser, WIDGETS); + WIDGETS.context = new Context(browser, WIDGETS); + WIDGETS.help = new Help(browser, WIDGETS); + WIDGETS.history = new History(browser, WIDGETS); + WIDGETS.mode = new Mode(browser, WIDGETS); + WIDGETS.session = new Session(browser, WIDGETS); + WIDGETS.settings = new Settings(browser, WIDGETS); + WIDGETS.site = new Site(browser, WIDGETS); + WIDGETS.tabs = new Tabs(browser, WIDGETS); + WIDGETS.webview = new Webview(browser, WIDGETS); + + + WIDGETS.history.render(header); + WIDGETS.address.render(header); + WIDGETS.mode.render(header); + WIDGETS.settings.render(header); + + WIDGETS.webview.render(main); + + WIDGETS.tabs.render(footer); + WIDGETS.beacon.render(footer); + WIDGETS.site.render(footer); + WIDGETS.session.render(footer); + WIDGETS.context.render(footer); + WIDGETS.help.render(footer); + + + setTimeout(() => { + + let tabindex = 1; + + [ + WIDGETS.history.back, + WIDGETS.history.next, + WIDGETS.history.action, + WIDGETS.history.open, + WIDGETS.address.input, + ...WIDGETS.mode.buttons, + WIDGETS.settings.beacon, + WIDGETS.settings.session, + WIDGETS.settings.site, + WIDGETS.settings.browser + ].filter((v) => v !== null).forEach((element) => { + element.attr('tabindex', tabindex++); + }); + + WIDGETS.tabs.tabindex = tabindex; + + }, 100); - WIDGETS.tabs.tabindex = tabindex; + } -}, 500); +}; diff --git a/browser/design/main/Webview.mjs b/browser/design/main/Webview.mjs index b91b089e..06e0f5fd 100644 --- a/browser/design/main/Webview.mjs +++ b/browser/design/main/Webview.mjs @@ -1,8 +1,8 @@ +import { Element } from '../../design/index.mjs'; import { isBoolean, isString } from '../../extern/base.mjs'; -import { Element } from '../Element.mjs'; +import { dispatch } from '../../internal/index.mjs'; import { URL } from '../../source/parser/URL.mjs'; -import { dispatch } from '../../internal/common/internal.mjs'; diff --git a/browser/index.html b/browser/index.html index 7e9c861c..e8e5b167 100644 --- a/browser/index.html +++ b/browser/index.html @@ -22,38 +22,93 @@ +
- - diff --git a/browser/internal/fix-host/index.css b/browser/internal/fix-host/index.css index f589341b..18ee488c 100644 --- a/browser/internal/fix-host/index.css +++ b/browser/internal/fix-host/index.css @@ -1,5 +1,5 @@ -@import url("../common/default.css"); -@import url("../common/internal.css"); +@import url("../theme.css"); +@import url("../index.css"); @import url("../settings/hosts.css"); diff --git a/browser/internal/fix-host/index.mjs b/browser/internal/fix-host/index.mjs index e0da104d..c7f482d6 100644 --- a/browser/internal/fix-host/index.mjs +++ b/browser/internal/fix-host/index.mjs @@ -1,48 +1,44 @@ -import { init } from '../settings/hosts.mjs'; -import { Element } from '../common/Element.mjs'; -import { flags } from '../../source/ENVIRONMENT.mjs'; +import { init } from '../settings/hosts.mjs'; +import { Element, access } from '../../internal/index.mjs'; +import { ENVIRONMENT } from '../../source/ENVIRONMENT.mjs'; const code = Element.query('code[data-key="domain"]'); -(function(global) { +let browser = access('browser'); +if (browser !== null) { - let browser = global.parent.BROWSER || global.BROWSER || null; - if (browser !== null) { + let domain = null; - let domain = null; - - if (flags.url.domain !== null) { - - if (flags.url.subdomain !== null) { - domain = flags.url.subdomain + '.' + flags.url.domain; - } else { - domain = flags.url.domain; - } + if (ENVIRONMENT.flags.url.domain !== null) { + if (ENVIRONMENT.flags.url.subdomain !== null) { + domain = ENVIRONMENT.flags.url.subdomain + '.' + ENVIRONMENT.flags.url.domain; + } else { + domain = ENVIRONMENT.flags.url.domain; } - let cache = browser.settings.hosts.find((h) => h.domain === domain) || null; - if (cache === null) { - - cache = { - domain: domain, - hosts: [] - }; + } - } + let cache = browser.settings.hosts.find((h) => h.domain === domain) || null; + if (cache === null) { - if (code !== null) { - code.value(domain); - } + cache = { + domain: domain, + hosts: [] + }; - init(browser, { - hosts: [ cache ] - }, [ 'refresh', 'save' ]); + } + if (code !== null) { + code.value(domain); } -})(typeof window !== 'undefined' ? window : this); + init(browser, { + hosts: [ cache ] + }, [ 'refresh', 'save' ]); + +} diff --git a/browser/internal/fix-mode/index.css b/browser/internal/fix-mode/index.css index 7424d11c..d3d02570 100644 --- a/browser/internal/fix-mode/index.css +++ b/browser/internal/fix-mode/index.css @@ -1,6 +1,6 @@ -@import url("../common/default.css"); -@import url("../common/internal.css"); +@import url("../theme.css"); +@import url("../index.css"); @import url("../settings/sites.css"); diff --git a/browser/internal/fix-mode/index.mjs b/browser/internal/fix-mode/index.mjs index a791fe3c..58472317 100644 --- a/browser/internal/fix-mode/index.mjs +++ b/browser/internal/fix-mode/index.mjs @@ -1,60 +1,56 @@ -import { init } from '../settings/sites.mjs'; -import { Element } from '../common/Element.mjs'; -import { flags } from '../../source/ENVIRONMENT.mjs'; -import { URL } from '../../source/parser/URL.mjs'; +import { init } from '../settings/sites.mjs'; +import { Element, access } from '../../internal/index.mjs'; +import { ENVIRONMENT } from '../../source/ENVIRONMENT.mjs'; +import { URL } from '../../source/parser/URL.mjs'; const code = Element.query('article code[data-key="url"]'); const button = Element.query('article button[data-key]'); -(function(global) { +let browser = access('browser'); +if (browser !== null) { - let browser = global.parent.BROWSER || global.BROWSER || null; - if (browser !== null) { + let domain = null; - let domain = null; - - if (flags.url.domain !== null) { - - if (flags.url.subdomain !== null) { - domain = flags.url.subdomain + '.' + flags.url.domain; - } else { - domain = flags.url.domain; - } + if (ENVIRONMENT.flags.url.domain !== null) { + if (ENVIRONMENT.flags.url.subdomain !== null) { + domain = ENVIRONMENT.flags.url.subdomain + '.' + ENVIRONMENT.flags.url.domain; + } else { + domain = ENVIRONMENT.flags.url.domain; } - let cache = browser.settings.modes.find((m) => m.domain === domain) || null; - if (cache === null) { - - cache = { - domain: domain, - mode: { - text: false, - image: false, - audio: false, - video: false, - other: false - } - }; - - } + } - if (code !== null) { - code.value(URL.render(flags.url)); - } + let cache = browser.settings.modes.find((m) => m.domain === domain) || null; + if (cache === null) { + + cache = { + domain: domain, + mode: { + text: false, + image: false, + audio: false, + video: false, + other: false + } + }; - if (button !== null) { - button.attr('data-key', 'mode.' + flags.url.mime.type); - } + } - init(browser, { - modes: [ cache ] - }, [ 'save' ]); + if (code !== null) { + code.value(URL.render(ENVIRONMENT.flags.url)); + } + if (button !== null) { + button.attr('data-key', 'mode.' + ENVIRONMENT.flags.url.mime.type); } -})(typeof window !== 'undefined' ? window : this); + init(browser, { + modes: [ cache ] + }, [ 'save' ]); + +} diff --git a/browser/internal/fix-request/index.css b/browser/internal/fix-request/index.css index a7f32d6a..2217ce9e 100644 --- a/browser/internal/fix-request/index.css +++ b/browser/internal/fix-request/index.css @@ -1,6 +1,6 @@ -@import url("../common/default.css"); -@import url("../common/internal.css"); +@import url("../theme.css"); +@import url("../index.css"); diff --git a/browser/internal/fix-request/index.mjs b/browser/internal/fix-request/index.mjs index 6867ad32..2aa34096 100644 --- a/browser/internal/fix-request/index.mjs +++ b/browser/internal/fix-request/index.mjs @@ -1,8 +1,8 @@ -import { sort } from '../settings/peers.mjs'; -import { Element } from '../common/Element.mjs'; -import { flags } from '../../source/ENVIRONMENT.mjs'; -import { URL } from '../../source/parser/URL.mjs'; +import { sort } from '../settings/peers.mjs'; +import { Element, access } from '../../internal/index.mjs'; +import { ENVIRONMENT } from '../../source/ENVIRONMENT.mjs'; +import { URL } from '../../source/parser/URL.mjs'; @@ -121,170 +121,166 @@ const update = () => { -(function(global) { +let browser = access('browser'); +if (browser !== null) { - let browser = global.parent.BROWSER || global.BROWSER || null; - if (browser !== null) { + let service = browser.client.services.peer || null; + if (service !== null && browser.settings.peers.length > 0) { - let service = browser.client.services.peer || null; - if (service !== null && browser.settings.peers.length > 0) { - - browser.settings.peers.forEach((peer) => { + browser.settings.peers.forEach((peer) => { - service.proxy({ - domain: peer.domain, - headers: { - service: 'cache', - method: 'info' - }, - payload: flags.url - }, (info) => { - - if (info === null) { - info = { - headers: { - size: null, - time: null - }, - payload: { - size: null, - time: null - } - }; - } + service.proxy({ + domain: peer.domain, + headers: { + service: 'cache', + method: 'info' + }, + payload: ENVIRONMENT.flags.url + }, (info) => { - CACHES.push({ - domain: peer.domain, - connection: peer.connection, - cache: info - }); - - update(); + if (info === null) { + info = { + headers: { + size: null, + time: null + }, + payload: { + size: null, + time: null + } + }; + } + CACHES.push({ + domain: peer.domain, + connection: peer.connection, + cache: info }); + update(); + }); - } else { - Element.query('#peers').erase(); - } + }); + } else { + Element.query('#peers').erase(); + } - let url = ELEMENTS.status.url || null; - if (url !== null) { - url.value(URL.render(flags.url)); - } - let cause = ELEMENTS.status.cause || null; - if (cause !== null) { + let url = ELEMENTS.status.url || null; + if (url !== null) { + url.value(URL.render(ENVIRONMENT.flags.url)); + } - if (flags.cause !== null) { + let cause = ELEMENTS.status.cause || null; + if (cause !== null) { - cause.forEach((block) => { + if (ENVIRONMENT.flags.cause !== null) { - let value = block.value(); - if (value !== flags.cause) { - block.erase(); - } + cause.forEach((block) => { - }); + let value = block.value(); + if (value !== ENVIRONMENT.flags.cause) { + block.erase(); + } - } else { - cause.forEach((block) => block.erase()); - } + }); + } else { + cause.forEach((block) => block.erase()); } - listen(browser, (action, data, done) => { + } - let service = browser.client.services.peer || null; - if (service !== null) { + listen(browser, (action, data, done) => { - if (action === 'request') { + let service = browser.client.services.peer || null; + if (service !== null) { - service.proxy({ - domain: data.domain, - headers: { - service: 'session', - method: 'request' - }, - payload: flags.url - }, (response) => { + if (action === 'request') { - if (response !== null) { + service.proxy({ + domain: data.domain, + headers: { + service: 'session', + method: 'request' + }, + payload: ENVIRONMENT.flags.url + }, (response) => { - let service = browser.client.services.cache || null; - if (service !== null) { + if (response !== null) { - service.save({ - domain: flags.url.domain || null, - host: flags.url.host || null, - subdomain: flags.url.subdomain || null, - path: flags.url.path || null, - headers: response.headers || null, - payload: response.payload || null - }, (result) => { - done(result); - }); + let service = browser.client.services.cache || null; + if (service !== null) { - } else { - done(false); - } + service.save({ + domain: ENVIRONMENT.flags.url.domain || null, + host: ENVIRONMENT.flags.url.host || null, + subdomain: ENVIRONMENT.flags.url.subdomain || null, + path: ENVIRONMENT.flags.url.path || null, + headers: response.headers || null, + payload: response.payload || null + }, (result) => { + done(result); + }); } else { done(false); } - }); + } else { + done(false); + } - } else if (action === 'download') { + }); - service.proxy({ - domain: data.domain, - headers: { - service: 'cache', - method: 'read' - }, - payload: flags.url - }, (response) => { + } else if (action === 'download') { - if (response !== null) { + service.proxy({ + domain: data.domain, + headers: { + service: 'cache', + method: 'read' + }, + payload: ENVIRONMENT.flags.url + }, (response) => { - let service = browser.client.services.cache || null; - if (service !== null) { + if (response !== null) { - service.save({ - domain: flags.url.domain || null, - host: flags.url.host || null, - subdomain: flags.url.subdomain || null, - path: flags.url.path || null, - headers: response.headers || null, - payload: response.payload || null - }, (result) => { - done(result); - }); + let service = browser.client.services.cache || null; + if (service !== null) { - } else { - done(false); - } + service.save({ + domain: ENVIRONMENT.flags.url.domain || null, + host: ENVIRONMENT.flags.url.host || null, + subdomain: ENVIRONMENT.flags.url.subdomain || null, + path: ENVIRONMENT.flags.url.path || null, + headers: response.headers || null, + payload: response.payload || null + }, (result) => { + done(result); + }); } else { done(false); } - }); + } else { + done(false); + } - } else { - done(false); - } + }); } else { done(false); } - }); + } else { + done(false); + } - } + }); -})(typeof window !== 'undefined' ? window : this); +} diff --git a/browser/internal/common/internal.css b/browser/internal/index.css similarity index 99% rename from browser/internal/common/internal.css rename to browser/internal/index.css index 04985216..313c85ca 100644 --- a/browser/internal/common/internal.css +++ b/browser/internal/index.css @@ -1,4 +1,4 @@ -@import url('./other/index.css'); +@import url('./common/other/index.css'); ::selection { diff --git a/browser/internal/common/internal.mjs b/browser/internal/index.mjs similarity index 85% rename from browser/internal/common/internal.mjs rename to browser/internal/index.mjs index 1524792b..051779df 100644 --- a/browser/internal/common/internal.mjs +++ b/browser/internal/index.mjs @@ -1,19 +1,27 @@ -import { Element } from './Element.mjs'; -import { isBoolean, isString } from '../../extern/base.mjs'; -import { URL } from '../../source/parser/URL.mjs'; +const global = (typeof window !== 'undefined' ? window : this); +import { isBoolean, isObject, isString } from '../extern/base.mjs'; +import { isBrowser } from '../source/Browser.mjs'; +import { URL } from '../source/parser/URL.mjs'; +import { Element } from './common/Element.mjs'; -const global = (typeof window !== 'undefined' ? window : this); -const WIDGETS = global.WIDGETS || {}; + +const STATE = { + escapes: 0 +}; + + +export * from './common/Element.mjs'; + const oncontext = function(window, browser, element, autofocus) { autofocus = isBoolean(autofocus) ? autofocus : false; - let context = WIDGETS.context || null; + let context = access('widgets.context'); let ref = null; let type = element.type(); @@ -158,7 +166,7 @@ const oncontext = function(window, browser, element, autofocus) { offset_y += header.area().h; } - let tabs = WIDGETS.tabs || null; + let tabs = access('widgets.tabs'); if (tabs !== null && tabs.element.state() === 'active') { offset_x += tabs.element.area().w; } @@ -184,7 +192,7 @@ const oncontext = function(window, browser, element, autofocus) { const uncontext = function() { - let context = WIDGETS.context || null; + let context = access('widgets.context'); if (context !== null) { context.emit('hide'); } @@ -322,23 +330,45 @@ const wait_for = function(window, property, callback) { -export const dispatch = function(window, browser) { +export const access = function(query) { + + query = isString(query) ? query : ''; + - let escapes = 0; - let widgets = window.WIDGETS || null; - if (widgets !== null) { + let tmp = query.split('.'); + if (tmp.length > 0) { - if (Object.keys(WIDGETS).length === 0) { + let pointer = null; + + if (tmp[0] === 'browser') { + pointer = isBrowser(global.parent['BROWSER']) ? global.parent['BROWSER'] : null; + } else if (tmp[0] === 'widgets') { + pointer = isObject(global.parent['WIDGETS']) ? global.parent['WIDGETS'] : null; + } - for (let id in widgets) { - WIDGETS[id] = widgets[id]; + for (let t = 1; t < tmp.length; t++) { + + if (typeof pointer[tmp[t]] !== 'undefined') { + pointer = pointer[tmp[t]]; + } else { + pointer = null; + break; } } + + return pointer; + } + return null; + +}; + +export const dispatch = function(window, browser) { + window.document.onclick = (e) => { uncontext(window, browser, true); @@ -408,13 +438,13 @@ export const dispatch = function(window, browser) { // Show Help on three (tries to) Escape in a row - let help = WIDGETS.help || null; + let help = access('widgets.help'); if (help !== null && help.element.state() === 'active') { if (key === 'enter') { help.emit('hide'); - escapes = 0; + STATE.escapes = 0; e.preventDefault(); e.stopPropagation(); @@ -438,15 +468,15 @@ export const dispatch = function(window, browser) { let focus = window.document.activeElement || null; if (focus === null || focus === window.document.body) { - escapes++; + STATE.escapes++; } else { - escapes = 0; + STATE.escapes = 0; } - if (escapes >= 3) { + if (STATE.escapes >= 3) { help.emit('show'); - escapes = 0; + STATE.escapes = 0; e.preventDefault(); e.stopPropagation(); @@ -462,7 +492,7 @@ export const dispatch = function(window, browser) { // Show Context Menu with tabable (but not focusable) elements // XXX: There's no API to reset the selected tabindex focus - let context = WIDGETS.context || null; + let context = access('widgets.context'); if (context !== null && context.element.state() === 'active') { if (key === 'tab') { @@ -507,17 +537,17 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, true); - let beacon = WIDGETS.beacon || null; + let beacon = access('widgets.beacon'); if (beacon !== null) { beacon.emit('hide'); } - let session = WIDGETS.session || null; + let session = access('widgets.session'); if (session !== null) { session.emit('hide'); } - let site = WIDGETS.site || null; + let site = access('widgets.site'); if (site !== null) { site.emit('hide'); } @@ -530,7 +560,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let history = WIDGETS.history || null; + let history = access('widgets.history'); if (history !== null && history.back.state() !== 'disabled') { history.back.emit('click'); } @@ -543,7 +573,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let history = WIDGETS.history || null; + let history = access('widgets.history'); if (history !== null && history.next.state() !== 'disabled') { history.next.emit('click'); } @@ -556,7 +586,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let history = WIDGETS.history || null; + let history = access('widgets.history'); if (history !== null && history.action.state() !== 'disabled') { history.action.emit('click'); } @@ -569,7 +599,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let history = WIDGETS.history || null; + let history = access('widgets.history'); if (history !== null && history.open.state() !== 'disabled') { history.open.emit('click'); } @@ -582,7 +612,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let address = WIDGETS.address || null; + let address = access('widgets.address'); if (address !== null) { address.input.emit('focus'); } @@ -595,7 +625,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let tabs = WIDGETS.tabs || null; + let tabs = access('widgets.tabs'); if (tabs !== null) { if (tabs.curr !== null) { @@ -614,7 +644,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let tabs = WIDGETS.tabs || null; + let tabs = access('widgets.tabs'); if (tabs !== null) { if (tabs.prev !== null) { @@ -633,7 +663,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let tabs = WIDGETS.tabs || null; + let tabs = access('widgets.tabs'); if (tabs !== null) { if (tabs.next !== null) { @@ -652,9 +682,9 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let mode = WIDGETS.mode || null; + let mode = access('widgets.mode'); if (mode !== null) { - rotate_through_modes(browser, WIDGETS.mode.buttons); + rotate_through_modes(browser, mode.buttons); } e.preventDefault(); @@ -675,13 +705,13 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let settings = WIDGETS.settings || null; + let settings = access('widgets.settings'); if (settings !== null) { rotate_through_settings(browser, [ - WIDGETS.settings.beacon || null, - WIDGETS.settings.session || null, - WIDGETS.settings.site || null + settings.beacon || null, + settings.session || null, + settings.site || null ].filter((b) => b !== null)); } @@ -694,7 +724,7 @@ export const dispatch = function(window, browser) { uncontext(window, browser, false); unfocus(window, browser, false); - let settings = WIDGETS.settings || null; + let settings = access('widgets.settings'); if (settings !== null && settings.browser.state() !== 'disabled') { settings.browser.emit('click'); } @@ -704,7 +734,7 @@ export const dispatch = function(window, browser) { } else if (ctrl === true && key === ' ') { - let context = WIDGETS.context || null; + let context = access('widgets.context'); if (context !== null && context.element.state() === 'active') { uncontext(window, browser, false); diff --git a/browser/internal/settings/hosts.mjs b/browser/internal/settings/hosts.mjs index cc91b33b..6cdcca1e 100644 --- a/browser/internal/settings/hosts.mjs +++ b/browser/internal/settings/hosts.mjs @@ -1,6 +1,6 @@ import { isArray, isObject } from '../../extern/base.mjs'; -import { Element } from '../common/Element.mjs'; +import { Element } from '../../internal/index.mjs'; diff --git a/browser/internal/settings/index.css b/browser/internal/settings/index.css index ee6c20b9..509ef8b6 100644 --- a/browser/internal/settings/index.css +++ b/browser/internal/settings/index.css @@ -1,6 +1,6 @@ -@import url("../common/default.css"); -@import url("../common/internal.css"); +@import url("../theme.css"); +@import url("../index.css"); @import url("./internet.css"); @import url("./hosts.css"); diff --git a/browser/internal/settings/index.mjs b/browser/internal/settings/index.mjs index 1ad63fd1..c2be7cc0 100644 --- a/browser/internal/settings/index.mjs +++ b/browser/internal/settings/index.mjs @@ -1,4 +1,5 @@ +import { access } from '../index.mjs'; import { init as init_internet } from './internet.mjs'; import { init as init_hosts } from './hosts.mjs'; import { init as init_peers } from './peers.mjs'; @@ -6,17 +7,13 @@ import { init as init_sites } from './sites.mjs'; -(function(global) { +let browser = access('browser'); +if (browser !== null) { - let browser = global.parent.BROWSER || global.BROWSER || null; - if (browser !== null) { + init_internet(browser, browser.settings); + init_hosts(browser, browser.settings); + init_peers(browser, browser.settings); + init_sites(browser, browser.settings); - init_internet(browser, browser.settings); - init_hosts(browser, browser.settings); - init_peers(browser, browser.settings); - init_sites(browser, browser.settings); - - } - -})(typeof window !== 'undefined' ? window : this); +} diff --git a/browser/internal/settings/internet.mjs b/browser/internal/settings/internet.mjs index 18213272..a6dd2fea 100644 --- a/browser/internal/settings/internet.mjs +++ b/browser/internal/settings/internet.mjs @@ -1,6 +1,6 @@ import { isObject } from '../../extern/base.mjs'; -import { Element } from '../common/Element.mjs'; +import { Element } from '../../internal/index.mjs'; diff --git a/browser/internal/settings/peers.mjs b/browser/internal/settings/peers.mjs index f2b16a26..e84ac50a 100644 --- a/browser/internal/settings/peers.mjs +++ b/browser/internal/settings/peers.mjs @@ -1,6 +1,6 @@ import { isArray, isObject } from '../../extern/base.mjs'; -import { Element } from '../common/Element.mjs'; +import { Element } from '../../internal/index.mjs'; import { IP } from '../../source/parser/IP.mjs'; import { update as update_hosts } from './hosts.mjs'; diff --git a/browser/internal/settings/sites.mjs b/browser/internal/settings/sites.mjs index 02761a1c..d85b80cd 100644 --- a/browser/internal/settings/sites.mjs +++ b/browser/internal/settings/sites.mjs @@ -1,6 +1,6 @@ import { isArray, isObject } from '../../extern/base.mjs'; -import { Element } from '../common/Element.mjs'; +import { Element } from '../../internal/index.mjs'; diff --git a/browser/internal/common/default.css b/browser/internal/theme.css similarity index 99% rename from browser/internal/common/default.css rename to browser/internal/theme.css index 0a3e1a09..a44cf7d7 100644 --- a/browser/internal/common/default.css +++ b/browser/internal/theme.css @@ -101,8 +101,6 @@ body { --scrollbar-default-color: #ffffff; --scrollbar-default-background: transparent; - background: red; - } } diff --git a/browser/internal/welcome/index.css b/browser/internal/welcome/index.css index 261762ff..c00e585c 100644 --- a/browser/internal/welcome/index.css +++ b/browser/internal/welcome/index.css @@ -1,6 +1,6 @@ -@import url('../common/default.css'); -@import url('../common/internal.css'); +@import url('../theme.css'); +@import url('../index.css'); diff --git a/browser/service.js b/browser/service.js index 1e829be3..c39c42df 100644 --- a/browser/service.js +++ b/browser/service.js @@ -55,9 +55,6 @@ const ASSETS = [ 'index.mjs', 'index.webmanifest', 'internal/common/Element.mjs', - 'internal/common/default.css', - 'internal/common/internal.css', - 'internal/common/internal.mjs', 'internal/common/other/icon.woff', 'internal/common/other/index.css', 'internal/common/other/museo-bold.woff', @@ -72,6 +69,8 @@ const ASSETS = [ 'internal/fix-request.html', 'internal/fix-request/index.css', 'internal/fix-request/index.mjs', + 'internal/index.css', + 'internal/index.mjs', 'internal/settings.html', 'internal/settings/hosts.css', 'internal/settings/hosts.mjs', @@ -83,6 +82,7 @@ const ASSETS = [ 'internal/settings/peers.mjs', 'internal/settings/sites.css', 'internal/settings/sites.mjs', + 'internal/theme.css', 'internal/welcome.html', 'internal/welcome/index.css', 'service.js', diff --git a/browser/source/Client.mjs b/browser/source/Client.mjs index 6479cd4d..ac2f1fbc 100644 --- a/browser/source/Client.mjs +++ b/browser/source/Client.mjs @@ -1,6 +1,6 @@ import { Buffer, Emitter, isFunction, isObject, isString } from '../extern/base.mjs'; -import { hostname } from './ENVIRONMENT.mjs'; +import { ENVIRONMENT } from './ENVIRONMENT.mjs'; import { Cache } from './client/Cache.mjs'; import { Host } from './client/Host.mjs'; import { Mode } from './client/Mode.mjs'; @@ -112,7 +112,7 @@ Client.prototype = Object.assign({}, Emitter.prototype, { if (this.__state.connected === false) { - let host = isString(this._settings.host) ? this._settings.host : hostname; + let host = isString(this._settings.host) ? this._settings.host : ENVIRONMENT.hostname; let ref = URL.parse('ws://' + host + ':65432'); let hosts = ref.hosts.sort((a, b) => { @@ -135,12 +135,12 @@ Client.prototype = Object.assign({}, Emitter.prototype, { }); - if (ref.domain === hostname || hosts.length > 0) { + if (ref.domain === ENVIRONMENT.hostname || hosts.length > 0) { let server = ref.domain; // Ensure same websocket remote address as the iframe requests - if (ref.domain !== hostname && hosts.length > 0) { + if (ref.domain !== ENVIRONMENT.hostname && hosts.length > 0) { let check = hosts.find((ip) => ip.scope === 'private') || null; if (check === null) { diff --git a/browser/source/ENVIRONMENT.mjs b/browser/source/ENVIRONMENT.mjs index 4cd7e3e3..e7eb04ea 100644 --- a/browser/source/ENVIRONMENT.mjs +++ b/browser/source/ENVIRONMENT.mjs @@ -3,7 +3,7 @@ import { URL } from './parser/URL.mjs'; -export const flags = ((global) => { +const flags = ((global) => { let flags = { cause: null, @@ -56,7 +56,7 @@ export const flags = ((global) => { })(typeof window !== 'undefined' ? window : this); -export const hostname = ((global) => { +const hostname = ((global) => { let host = 'localhost'; diff --git a/covert/.eslintrc.json b/covert/.eslintrc.json index 47a46241..2e3a1cf1 100644 --- a/covert/.eslintrc.json +++ b/covert/.eslintrc.json @@ -10,8 +10,14 @@ "sourceType": "module" }, "overrides": [{ + "files": [ "*.mjs" ], + "rules": {} + }, { "files": [ "extern/base.mjs" ], - "rules": { "no-global-assign": "off", "no-undef": "off" } + "rules": { + "no-control-regex": "off", + "no-undef": "off" + } }], "rules": { "no-restricted-globals": [ diff --git a/covert/bin/covert.mjs b/covert/bin/covert.mjs index aaf602d1..ca42d207 100644 --- a/covert/bin/covert.mjs +++ b/covert/bin/covert.mjs @@ -1,16 +1,17 @@ import process from 'process'; -import { console } from '../extern/base.mjs'; -import { Covert } from '../source/Covert.mjs'; -import { Linter } from '../source/Linter.mjs'; -import { action, flags, patterns } from '../source/ENVIRONMENT.mjs'; +import { console } from '../extern/base.mjs'; +import { Covert } from '../source/Covert.mjs'; +import { Linter } from '../source/Linter.mjs'; +import { ENVIRONMENT } from '../source/ENVIRONMENT.mjs'; import BASE from '../../base/review/index.mjs'; import COVERT from '../../covert/review/index.mjs'; import STEALTH from '../../stealth/review/index.mjs'; + const REVIEWS = [ ...BASE.reviews, ...COVERT.reviews, @@ -76,13 +77,13 @@ const show_help = () => { -if (action === 'check') { +if (ENVIRONMENT.action === 'check') { let linter = new Linter({ - action: action || null, - debug: flags.debug || false, - internet: flags.internet || null, - patterns: patterns || [], + action: ENVIRONMENT.action || null, + debug: ENVIRONMENT.flags.debug || false, + internet: ENVIRONMENT.flags.internet || null, + patterns: ENVIRONMENT.patterns || [], reviews: REVIEWS, sources: SOURCES }); @@ -91,26 +92,26 @@ if (action === 'check') { process.exit(linter.destroy() || 0); }); - if (patterns.length > 0 && linter.reviews.length === 0) { + if (ENVIRONMENT.patterns.length > 0 && linter.reviews.length === 0) { - console.warn('Linter: No Review(s) matching the patterns "' + patterns.join('" or "') + '" found.'); + console.warn('Linter: No Review(s) matching the patterns "' + ENVIRONMENT.patterns.join('" or "') + '" found.'); process.exit(2); } else { linter.connect(); } -} else if (action === 'watch') { +} else if (ENVIRONMENT.action === 'watch') { let covert = new Covert({ - action: action || null, - debug: flags.debug || false, - internet: flags.internet || null, - network: flags.network || null, - patterns: patterns || [], + action: ENVIRONMENT.action || null, + debug: ENVIRONMENT.flags.debug || false, + internet: ENVIRONMENT.flags.internet || null, + network: ENVIRONMENT.flags.network || null, + patterns: ENVIRONMENT.patterns || [], reviews: REVIEWS, sources: SOURCES, - timeout: flags.timeout || null + timeout: ENVIRONMENT.flags.timeout || null }); process.on('SIGINT', () => { @@ -157,35 +158,35 @@ if (action === 'check') { }); - if (patterns.length > 0 && covert.reviews.length === 0) { + if (ENVIRONMENT.patterns.length > 0 && covert.reviews.length === 0) { - console.warn('Covert: No Review(s) matching the patterns "' + patterns.join('" or "') + '" found.'); + console.warn('Covert: No Review(s) matching the patterns "' + ENVIRONMENT.patterns.join('" or "') + '" found.'); process.exit(2); } else { covert.connect(); } -} else if (action === 'scan' || action === 'time') { +} else if (ENVIRONMENT.action === 'scan' || ENVIRONMENT.action === 'time') { let covert = new Covert({ - action: action || null, - debug: flags.debug || false, - internet: flags.internet || null, - network: flags.network || null, - patterns: patterns || [], + action: ENVIRONMENT.action || null, + debug: ENVIRONMENT.flags.debug || false, + internet: ENVIRONMENT.flags.internet || null, + network: ENVIRONMENT.flags.network || null, + patterns: ENVIRONMENT.patterns || [], reviews: REVIEWS, sources: SOURCES, - timeout: flags.timeout || null + timeout: ENVIRONMENT.flags.timeout || null }); covert.on('disconnect', () => { process.exit(covert.destroy() || 0); }); - if (patterns.length > 0 && covert.reviews.length === 0) { + if (ENVIRONMENT.patterns.length > 0 && covert.reviews.length === 0) { - console.warn('Covert: No Review(s) matching the patterns "' + patterns.join('" or "') + '" found.'); + console.warn('Covert: No Review(s) matching the patterns "' + ENVIRONMENT.patterns.join('" or "') + '" found.'); process.exit(2); } else { diff --git a/covert/source/Covert.mjs b/covert/source/Covert.mjs index addb9981..fbc0884c 100644 --- a/covert/source/Covert.mjs +++ b/covert/source/Covert.mjs @@ -2,7 +2,7 @@ import process from 'process'; import { console, Emitter, isBoolean, isNumber, isString } from '../extern/base.mjs'; -import { root } from './ENVIRONMENT.mjs'; +import { ENVIRONMENT } from './ENVIRONMENT.mjs'; import { Filesystem } from './Filesystem.mjs'; import { Network } from './Network.mjs'; import { Renderer } from './Renderer.mjs'; @@ -600,7 +600,7 @@ const Covert = function(settings) { internet: true, patterns: [], reviews: [], - root: root, + root: ENVIRONMENT.root, timeout: null }, settings)); diff --git a/covert/source/ENVIRONMENT.mjs b/covert/source/ENVIRONMENT.mjs index 787ce2ed..4eab8423 100644 --- a/covert/source/ENVIRONMENT.mjs +++ b/covert/source/ENVIRONMENT.mjs @@ -5,7 +5,7 @@ import process from 'process'; -export const action = (() => { +const action = (() => { let value = Array.from(process.argv).slice(2).filter((v) => v.startsWith('--') === false).shift() || ''; @@ -23,7 +23,7 @@ export const action = (() => { })(); -export const flags = (() => { +const flags = (() => { let flags = { debug: false, @@ -68,7 +68,7 @@ export const flags = (() => { })(); -export const patterns = (() => { +const patterns = (() => { let patterns = []; @@ -80,7 +80,7 @@ export const patterns = (() => { })(); -export const root = (() => { +const root = (() => { let pwd = process.env.PWD || null; if (pwd !== null) { @@ -100,7 +100,7 @@ export const root = (() => { })(); -export const temp = (() => { +const temp = (() => { let user = process.env.SUDO_USER || process.env.USER; let folder = '/tmp/covert-' + user; @@ -150,7 +150,7 @@ const randomize = (length) => { }; -export const mktemp = (prefix, seed) => { +const mktemp = (prefix, seed) => { prefix = typeof prefix === 'string' ? prefix : randomize(4); seed = typeof seed === 'number' ? Math.round(seed / 2) * 2 : null; diff --git a/covert/source/Linter.mjs b/covert/source/Linter.mjs index 80b485fd..49b01239 100644 --- a/covert/source/Linter.mjs +++ b/covert/source/Linter.mjs @@ -3,7 +3,7 @@ import util from 'util'; import process from 'process'; import { console, Emitter, isArray, isBoolean, isFunction, isObject, isString } from '../extern/base.mjs'; -import { root } from './ENVIRONMENT.mjs'; +import { ENVIRONMENT } from './ENVIRONMENT.mjs'; import { Filesystem } from './Filesystem.mjs'; import { Renderer } from './Renderer.mjs'; import { Review, isReview } from './Review.mjs'; @@ -38,9 +38,9 @@ const init = function(settings) { projects.forEach((project) => { - let implementations = this.filesystem.scan(root + '/' + project + '/source', true).map((path) => { + let implementations = this.filesystem.scan(ENVIRONMENT.root + '/' + project + '/source', true).map((path) => { - let raw = path.substr(root.length + 1); + let raw = path.substr(ENVIRONMENT.root.length + 1); if (raw.endsWith('.mjs')) { let tmp = raw.substr(0, raw.length - 4).split('/'); @@ -237,7 +237,7 @@ const update_review = async function(review) { let path = tmp.join('/'); - let module = await import(root + '/' + path).then((obj) => { + let module = await import(ENVIRONMENT.root + '/' + path).then((obj) => { return obj; }).catch((err) => { // Do nothing @@ -430,7 +430,7 @@ const Linter = function(settings) { patterns: [], reviews: [], sources: {}, - root: root + root: ENVIRONMENT.root }, settings)); diff --git a/covert/source/Renderer.mjs b/covert/source/Renderer.mjs index 5f23eaca..dd39812f 100644 --- a/covert/source/Renderer.mjs +++ b/covert/source/Renderer.mjs @@ -429,7 +429,7 @@ const render_summary = function(review, is_current) { test.results.stack.forEach((entry, e) => { - if (entry.diff !== null) { + if (entry !== null && entry.diff !== null) { console.log(''); diff --git a/package.json b/package.json index 101af5ea..806a5f90 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,28 @@ { "name": "stealth", - "version": "2020-X0", + "description": "Stealth 2020-X0", + "private": true, + "version": "2020.0.0", "module": "./stealth/index.mjs", "scripts": { - "start": "bash ./stealth/bin/stealth.sh", + + "lint": "npx eslint ./base ./browser ./covert ./stealth", + "postinstall": "node ./base/bin/base.mjs", + "test": "node ./covert/bin/covert.mjs scan", + + "base": "node ./base/bin/base.mjs", "browser": "bash ./browser/bin/browser.sh", - "stealth": "bash ./stealth/bin/stealth.sh" + "covert": "node ./covert/bin/covert.mjs", + "stealth": "node ./stealth/bin/stealth.mjs" + }, "exports": { ".": "./stealth/index.mjs", "./base": "./base/index.mjs", "./covert": "./covert/index.mjs", "./stealth": "./stealth/index.mjs" + }, + "devDependencies": { + "eslint": "^7.0.0" } } diff --git a/stealth/.eslintrc.json b/stealth/.eslintrc.json index bbf7c410..3a0799d8 100644 --- a/stealth/.eslintrc.json +++ b/stealth/.eslintrc.json @@ -10,8 +10,14 @@ "sourceType": "module" }, "overrides": [{ + "files": [ "*.mjs" ], + "rules": {} + }, { "files": [ "extern/base.mjs" ], - "rules": { "no-global-assign": "off", "no-undef": "off" } + "rules": { + "no-control-regex": "off", + "no-undef": "off" + } }], "rules": { "no-restricted-globals": [ diff --git a/stealth/bin/stealth.mjs b/stealth/bin/stealth.mjs index 4ef0937f..3f994e31 100644 --- a/stealth/bin/stealth.mjs +++ b/stealth/bin/stealth.mjs @@ -1,26 +1,173 @@ +import fs from 'fs'; +import url from 'url'; +import path from 'path'; import process from 'process'; -import { console } from '../extern/base.mjs'; -import { Stealth } from '../source/Stealth.mjs'; -import { flags } from '../source/ENVIRONMENT.mjs'; +import { console } from '../../base/index.mjs'; +import { build as build_browser, clean as clean_browser } from '../../browser/bin/browser.mjs'; +import { Stealth } from '../source/Stealth.mjs'; +import { ENVIRONMENT } from '../source/ENVIRONMENT.mjs'; -console.log(''); -console.info('Stealth'); -console.log(''); +const FILE = url.fileURLToPath(import.meta.url); +const ROOT = path.dirname(path.resolve(FILE, '../../')); -let stealth = new Stealth({ - debug: flags.debug, - host: flags.host, - profile: flags.profile -}); +const copy = (origin, target) => { -stealth.on('disconnect', (result) => { - process.exit(result === true ? 0 : 1); -}); + let stat = null; + let result = false; -stealth.connect(); + try { + stat = fs.statSync(origin); + } catch (err) { + stat = null; + } + + if (stat !== null) { + + if (stat.isFile() === true) { + + stat = null; + + try { + stat = fs.statSync(path.dirname(target)); + } catch (err) { + stat = null; + } + + if (stat === null || stat.isDirectory() === false) { + + try { + fs.mkdirSync(path.dirname(target), { + recursive: true + }); + } catch (err) { + // Ignore + } + + } + + try { + fs.copyFileSync(origin, target); + result = true; + } catch (err) { + result = false; + } + + } + + } + + if (result === true) { + console.info('stealth: copy("' + origin.substr(ROOT.length + 1) + '", "' + target.substr(ROOT.length + 1) + '")'); + } else { + console.error('stealth: copy("' + origin.substr(ROOT.length + 1) + '", "' + target.substr(ROOT.length + 1) + '")'); + } + + return result; + +}; + +const remove = (path) => { + + let stat = null; + let result = false; + + try { + stat = fs.statSync(path); + } catch (err) { + stat = null; + } + + if (stat !== null) { + + if (stat.isFile() === true) { + + try { + fs.unlinkSync(path); + result = true + } catch (err) { + result = false; + } + + } + + } + + return result; + +}; + + + +export const clean = () => { + + let results = [ + clean_browser(), + remove(ROOT + '/stealth/extern/base.mjs') + ]; + + if (results.includes(false) === false) { + return true; + } + + + return false; + +}; + +export const build = () => { + + let results = [ + build_browser(), + copy(ROOT + '/base/build/node.mjs', ROOT + '/stealth/extern/base.mjs') + ]; + + if (results.includes(false) === false) { + return true; + } + + + return false; + +}; + + +if (process.argv.includes(FILE) === true) { + + let results = [ + clean(), + build() + ]; + + if (results.includes(false) === false) { + + console.clear(); + + console.log(''); + console.info('Stealth'); + console.log(''); + + let stealth = new Stealth({ + debug: ENVIRONMENT.flags.debug, + host: ENVIRONMENT.flags.host, + profile: ENVIRONMENT.flags.profile + }); + + stealth.on('disconnect', (result) => { + process.exit(result === true ? 0 : 1); + }); + + stealth.connect(); + + } else { + + process.exit(1); + + } + +} diff --git a/stealth/bin/stealth.sh b/stealth/bin/stealth.sh deleted file mode 100755 index a2fd594b..00000000 --- a/stealth/bin/stealth.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash - -root_dir="$(dirname "$(dirname "$(dirname "$(readlink -f "$0")")")")"; -node_bin="$(which node)"; - - - -if [[ -z "$node_bin" ]]; then - echo "Please install node.js first"; - exit 1; -fi; - - - -build_browser() { - - cd "$root_dir"; - - bash "./base/bin/base.sh"; - - if [[ ! -d "./browser/extern" ]]; then - mkdir "./browser/extern"; - fi; - - rm "./browser/extern/base.mjs" 2> /dev/null; - rm "./browser/source/Browser.mjs" 2> /dev/null; - rm "./browser/source/Tab.mjs" 2> /dev/null; - rm -rf "./browser/source/client" 2> /dev/null; - rm -rf "./browser/source/parser" 2> /dev/null; - - cp "./base/build/browser.mjs" "./browser/extern/base.mjs"; - cp "./stealth/source/Browser.mjs" "./browser/source/Browser.mjs"; - cp "./stealth/source/Tab.mjs" "./browser/source/Tab.mjs"; - cp -R "./stealth/source/client" "./browser/source/client"; - cp -R "./stealth/source/parser" "./browser/source/parser"; - -} - -build_stealth() { - - cd "$root_dir"; - - bash "./base/bin/base.sh"; - - if [[ ! -d "./stealth/extern" ]]; then - mkdir "./stealth/extern"; - fi; - - rm "./stealth/extern/base.mjs" 2> /dev/null; - cp "./base/build/node.mjs" "./stealth/extern/base.mjs"; - -} - - - -cd "$root_dir"; - -build_browser; -build_stealth; - -exec "$node_bin" --tls-cipher-list="ECDHE-RSA-AES128-GCM-SHA256" --no-warnings --experimental-modules ./stealth/bin/stealth.mjs "$@"; - diff --git a/stealth/index.mjs b/stealth/index.mjs index 974e8560..cf806767 100644 --- a/stealth/index.mjs +++ b/stealth/index.mjs @@ -1,7 +1,6 @@ export * from './source/Browser.mjs'; export * from './source/Client.mjs'; -export * from './source/Emitter.mjs'; export * from './source/ENVIRONMENT.mjs'; export * from './source/Request.mjs'; export * from './source/Server.mjs'; diff --git a/stealth/review/Server.mjs b/stealth/review/Server.mjs index 05d4c398..b71f7514 100644 --- a/stealth/review/Server.mjs +++ b/stealth/review/Server.mjs @@ -1,7 +1,8 @@ -import { after, before, describe, finish, mktemp, root } from '../../covert/index.mjs'; -import { Server, isServer } from '../../stealth/source/Server.mjs'; -import { Stealth } from '../../stealth/source/Stealth.mjs'; +import { after, before, describe, finish } from '../../covert/index.mjs'; +import { ENVIRONMENT as SANDBOX } from '../../covert/index.mjs'; +import { Server, isServer } from '../../stealth/source/Server.mjs'; +import { Stealth } from '../../stealth/source/Stealth.mjs'; @@ -9,8 +10,8 @@ export const connect = before('Server.prototype.connect()', function(assert) { this.server = null; this.stealth = new Stealth({ - profile: mktemp('stealth/Server', 8), - root: root + profile: SANDBOX.mktemp('stealth/Server', 8), + root: SANDBOX.root }); this.stealth.once('connect', () => { diff --git a/stealth/review/Stealth.mjs b/stealth/review/Stealth.mjs index 989b4226..4d040df1 100644 --- a/stealth/review/Stealth.mjs +++ b/stealth/review/Stealth.mjs @@ -1,10 +1,11 @@ -import { after, before, describe, finish, mktemp, root } from '../../covert/index.mjs'; -import { Service } from '../../covert/EXAMPLE.mjs'; -import { hostname } from '../../stealth/source/ENVIRONMENT.mjs'; -import { Stealth, isStealth } from '../../stealth/source/Stealth.mjs'; -import { isRequest } from '../../stealth/source/Request.mjs'; -import { Session, isSession } from '../../stealth/source/Session.mjs'; +import { after, before, describe, finish } from '../../covert/index.mjs'; +import { ENVIRONMENT as SANDBOX } from '../../covert/index.mjs'; +import { Service } from '../../covert/EXAMPLE.mjs'; +import { ENVIRONMENT } from '../../stealth/source/ENVIRONMENT.mjs'; +import { Stealth, isStealth } from '../../stealth/source/Stealth.mjs'; +import { isRequest } from '../../stealth/source/Request.mjs'; +import { Session, isSession } from '../../stealth/source/Session.mjs'; @@ -12,13 +13,13 @@ export const connect = before('Stealth.prototype.connect()', function(assert) { this.server = null; this.stealth = new Stealth({ - profile: mktemp('stealth/Stealth', 8), - root: root + profile: SANDBOX.mktemp('stealth/Stealth', 8), + root: SANDBOX.root }); - assert(this.stealth._settings.debug, false); - assert(this.stealth._settings.host, null); - assert(this.stealth._settings.root, root); + assert(this.stealth._settings.debug, false); + assert(this.stealth._settings.host, null); + assert(this.stealth._settings.root, SANDBOX.root); this.stealth.once('connect', () => { @@ -39,10 +40,10 @@ describe('new Stealth()', function(assert) { host: '127.0.0.3' }); - assert(stealth._settings.debug, false); - assert(stealth._settings.host, '127.0.0.3'); - assert(stealth._settings.profile, null); - assert(stealth._settings.root, root); + assert(stealth._settings.debug, false); + assert(stealth._settings.host, '127.0.0.3'); + assert(stealth._settings.profile, null); + assert(stealth._settings.root, SANDBOX.root); assert(Stealth.isStealth(stealth), true); assert(isStealth(stealth), true); @@ -118,8 +119,8 @@ describe('Stealth.prototype.track()', function(assert) { assert(session2, session3); assert(session1.domain.endsWith('.tholian.network'), true); - assert(session2.domain, hostname); - assert(session3.domain, hostname); + assert(session2.domain, ENVIRONMENT.hostname); + assert(session3.domain, ENVIRONMENT.hostname); }); diff --git a/stealth/review/client/Peer.mjs b/stealth/review/client/Peer.mjs index 2af92718..6e457a22 100644 --- a/stealth/review/client/Peer.mjs +++ b/stealth/review/client/Peer.mjs @@ -1,7 +1,7 @@ import { isFunction } from '../../../base/index.mjs'; import { after, before, describe, finish } from '../../../covert/index.mjs'; -import { hostname } from '../../../stealth/source/ENVIRONMENT.mjs'; +import { ENVIRONMENT } from '../../../stealth/source/ENVIRONMENT.mjs'; import { Peer } from '../../../stealth/source/client/Peer.mjs'; import { connect as connect_stealth, disconnect as disconnect_stealth } from '../Stealth.mjs'; import { connect as connect_client, disconnect as disconnect_client } from '../Client.mjs'; @@ -41,7 +41,7 @@ describe('Peer.prototype.info()', function(assert) { }, (response) => { assert(response !== null); - assert(response.domain, hostname); + assert(response.domain, ENVIRONMENT.hostname); assert(response.connection, 'mobile'); }); diff --git a/stealth/review/client/Session.mjs b/stealth/review/client/Session.mjs index 9a8501b9..e1964b7b 100644 --- a/stealth/review/client/Session.mjs +++ b/stealth/review/client/Session.mjs @@ -3,7 +3,7 @@ import { isArray, isBuffer, isFunction, isObject } from '.. import { after, before, describe, finish } from '../../../covert/index.mjs'; import { Session } from '../../../stealth/source/client/Session.mjs'; import { URL } from '../../../stealth/source/parser/URL.mjs'; -import { hostname } from '../../../stealth/source/ENVIRONMENT.mjs'; +import { ENVIRONMENT } from '../../../stealth/source/ENVIRONMENT.mjs'; import { connect as connect_stealth, disconnect as disconnect_stealth } from '../Stealth.mjs'; import { connect as connect_client, disconnect as disconnect_client } from '../Client.mjs'; @@ -85,7 +85,7 @@ describe('Session.prototype.query()/all', function(assert) { type: 'Session', data: { agent: null, - domain: hostname, + domain: ENVIRONMENT.hostname, tabs: [], warning: 0 } @@ -101,7 +101,7 @@ describe('Session.prototype.query()/domain/success', function(assert) { assert(isFunction(this.client.services.session.query), true); this.client.services.session.query({ - domain: hostname + domain: ENVIRONMENT.hostname }, (response) => { assert(isArray(response), true); @@ -111,7 +111,7 @@ describe('Session.prototype.query()/domain/success', function(assert) { type: 'Session', data: { agent: null, - domain: hostname, + domain: ENVIRONMENT.hostname, tabs: [], warning: 0 } @@ -151,7 +151,7 @@ describe('Session.prototype.read()', function(assert) { assert(response.type, 'Session'); assert(response.data, { agent: null, - domain: hostname, + domain: ENVIRONMENT.hostname, tabs: [], warning: 0 }); diff --git a/stealth/review/peer/Cache.mjs b/stealth/review/peer/Cache.mjs index 5efdd207..389f8f55 100644 --- a/stealth/review/peer/Cache.mjs +++ b/stealth/review/peer/Cache.mjs @@ -1,8 +1,9 @@ -import { isFunction } from '../../../base/index.mjs'; -import { after, before, describe, finish, mktemp, root } from '../../../covert/index.mjs'; -import { Client } from '../../../stealth/source/Client.mjs'; -import { Stealth } from '../../../stealth/source/Stealth.mjs'; +import { isFunction } from '../../../base/index.mjs'; +import { after, before, describe, finish } from '../../../covert/index.mjs'; +import { ENVIRONMENT as SANDBOX } from '../../../covert/index.mjs'; +import { Client } from '../../../stealth/source/Client.mjs'; +import { Stealth } from '../../../stealth/source/Stealth.mjs'; @@ -14,15 +15,15 @@ before('peers[].connect', function(assert) { let client1 = new Client(); let stealth1 = new Stealth({ host: '127.0.0.1', - profile: mktemp('stealth/peer/Cache'), - root: root + profile: SANDBOX.mktemp('stealth/peer/Cache'), + root: SANDBOX.root }); let client2 = new Client(); let stealth2 = new Stealth({ host: '127.0.0.2', - profile: mktemp('stealth/peer/Cache'), - root: root + profile: SANDBOX.mktemp('stealth/peer/Cache'), + root: SANDBOX.root }); diff --git a/stealth/source/ENVIRONMENT.mjs b/stealth/source/ENVIRONMENT.mjs index dc8b8232..a445df24 100644 --- a/stealth/source/ENVIRONMENT.mjs +++ b/stealth/source/ENVIRONMENT.mjs @@ -5,7 +5,7 @@ import process from 'process'; -export const flags = (() => { +const flags = (() => { let flags = { debug: false, @@ -40,9 +40,9 @@ export const flags = (() => { })(); -export const hostname = os.hostname(); +const hostname = os.hostname(); -export const hosts = (() => { +const hosts = (() => { let hosts = null; let platform = os.platform(); @@ -60,7 +60,7 @@ export const hosts = (() => { })(); -export const profile = (() => { +const profile = (() => { let folder = '/tmp/stealth'; let user = process.env.SUDO_USER || process.env.USER; @@ -89,7 +89,7 @@ export const profile = (() => { })(); -export const root = (() => { +const root = (() => { let pwd = process.env.PWD || null; if (pwd !== null) { @@ -109,7 +109,7 @@ export const root = (() => { })(); -export const temp = (() => { +const temp = (() => { let user = process.env.SUDO_USER || process.env.USER; let folder = '/tmp/stealth-' + user; diff --git a/stealth/source/Settings.mjs b/stealth/source/Settings.mjs index 3213bb2c..3b352f4f 100644 --- a/stealth/source/Settings.mjs +++ b/stealth/source/Settings.mjs @@ -3,7 +3,7 @@ import fs from 'fs'; import path from 'path'; import { console, isArray, isBoolean, isFunction, isObject, isString } from '../extern/base.mjs'; -import { hosts as default_hosts, profile as default_profile, temp } from './ENVIRONMENT.mjs'; +import { ENVIRONMENT } from './ENVIRONMENT.mjs'; import { Session } from './Session.mjs'; import { HOSTS } from './parser/HOSTS.mjs'; @@ -29,12 +29,12 @@ const init = function(callback) { let result = false; - if (default_hosts !== null) { + if (ENVIRONMENT.hosts !== null) { let stat = null; try { - stat = fs.lstatSync(path.resolve(default_hosts)); + stat = fs.lstatSync(path.resolve(ENVIRONMENT.hosts)); } catch (err) { stat = null; } @@ -44,7 +44,7 @@ const init = function(callback) { let tmp = null; try { - tmp = fs.readFileSync(path.resolve(default_hosts), 'utf8'); + tmp = fs.readFileSync(path.resolve(ENVIRONMENT.hosts), 'utf8'); } catch (err) { tmp = null; } @@ -458,7 +458,7 @@ const setup = function(profile, callback) { const Settings = function(stealth, profile, vendor) { - profile = isString(profile) ? profile : default_profile; + profile = isString(profile) ? profile : ENVIRONMENT.profile; vendor = isString(vendor) ? vendor : null; @@ -481,7 +481,7 @@ const Settings = function(stealth, profile, vendor) { init.call(this, (result) => { if (result === true) { - console.info('Settings: Native Hosts imported from "' + default_hosts + '".'); + console.info('Settings: Native Hosts imported from "' + ENVIRONMENT.hosts + '".'); console.log('> ' + this.hosts.length + ' Host' + (this.hosts.length === 1 ? '' : 's') + '.'); } @@ -523,7 +523,7 @@ const Settings = function(stealth, profile, vendor) { } else { - this.profile = temp; + this.profile = ENVIRONMENT.temp; read.call(this, this.profile, true, (result) => { @@ -631,7 +631,7 @@ Settings.prototype = { data.peers.push(peer); }); - if (this.profile !== default_profile) { + if (this.profile !== ENVIRONMENT.profile) { data.profile = this.profile; } diff --git a/stealth/source/Stealth.mjs b/stealth/source/Stealth.mjs index 85fd3c6e..9b7c5872 100644 --- a/stealth/source/Stealth.mjs +++ b/stealth/source/Stealth.mjs @@ -2,7 +2,7 @@ import process from 'process'; import { console, Emitter, isObject, isString } from '../extern/base.mjs'; -import { hostname, root } from './ENVIRONMENT.mjs'; +import { ENVIRONMENT } from './ENVIRONMENT.mjs'; import { Request } from './Request.mjs'; import { Server } from './Server.mjs'; import { Session } from './Session.mjs'; @@ -92,7 +92,7 @@ const Stealth = function(settings) { debug: false, host: null, profile: null, - root: root + root: ENVIRONMENT.root }, settings)); @@ -444,9 +444,9 @@ Stealth.prototype = Object.assign({}, Emitter.prototype, { let sdomain = ip.ip || null; if (sdomain === '::1') { - headers['domain'] = sdomain = hostname; + headers['domain'] = sdomain = ENVIRONMENT.hostname; } else if (sdomain === '127.0.0.1') { - headers['domain'] = sdomain = hostname; + headers['domain'] = sdomain = ENVIRONMENT.hostname; } else if (host !== null) { headers['domain'] = sdomain = host.domain; } diff --git a/stealth/source/other/FILE.mjs b/stealth/source/other/FILE.mjs index d6a506c7..2f1b1a16 100644 --- a/stealth/source/other/FILE.mjs +++ b/stealth/source/other/FILE.mjs @@ -3,7 +3,7 @@ import fs from 'fs'; import path from 'path'; import { Buffer, isFunction, isObject } from '../../extern/base.mjs'; -import { root } from '../ENVIRONMENT.mjs'; +import { ENVIRONMENT } from '../ENVIRONMENT.mjs'; @@ -22,7 +22,7 @@ const FILE = { if (callback !== null) { - fs.readFile(path.resolve(root + url), (err, buffer) => { + fs.readFile(path.resolve(ENVIRONMENT.root + url), (err, buffer) => { if (!err) { @@ -46,7 +46,7 @@ const FILE = { let buffer = null; try { - buffer = fs.readFileSync(path.resolve(root + url)); + buffer = fs.readFileSync(path.resolve(ENVIRONMENT.root + url)); } catch (err) { buffer = null; } diff --git a/stealth/source/server/Peer.mjs b/stealth/source/server/Peer.mjs index 25ea99ad..ba152771 100644 --- a/stealth/source/server/Peer.mjs +++ b/stealth/source/server/Peer.mjs @@ -1,6 +1,6 @@ import { Emitter, isFunction, isObject, isString } from '../../extern/base.mjs'; -import { hostname } from '../ENVIRONMENT.mjs'; +import { ENVIRONMENT } from '../ENVIRONMENT.mjs'; import { IP } from '../parser/IP.mjs'; import { Client, isClient } from '../Client.mjs'; @@ -206,7 +206,7 @@ Peer.prototype = Object.assign({}, Emitter.prototype, { event: 'info' }, payload: { - domain: hostname, + domain: ENVIRONMENT.hostname, connection: settings.internet.connection } });