diff --git a/package-lock.json b/package-lock.json index 888acbf..c338929 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1195,9 +1195,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "2.50.2", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.50.2.tgz", - "integrity": "sha512-875hTUkEbz+MyJIxWbQjfMaekqdmEKUUfR7JyKcpfMRZqcGyrO9Gd+iS1D/Dx8LpE5FEtutWGOtlAh4ReSAiOA==", + "version": "2.53.2", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.53.2.tgz", + "integrity": "sha512-M+MqAvFve12T1HWws/2npP/s3hFtyjw3GB/OXW/8a1jZBk48qnvPJrtgE+VOMc3RnjUMxc4mv/vQ73nvj2uNMg==", "dev": true, "license": "MIT", "peer": true, @@ -1207,12 +1207,11 @@ "@types/cookie": "^0.6.0", "acorn": "^8.14.1", "cookie": "^0.6.0", - "devalue": "^5.6.2", + "devalue": "^5.6.3", "esm-env": "^1.2.2", "kleur": "^4.1.5", "magic-string": "^0.30.5", "mrmime": "^2.0.0", - "sade": "^1.8.1", "set-cookie-parser": "^3.0.0", "sirv": "^3.0.0" }, @@ -1224,10 +1223,10 @@ }, "peerDependencies": { "@opentelemetry/api": "^1.0.0", - "@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0", + "@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0 || ^7.0.0", "svelte": "^4.0.0 || ^5.0.0-next.0", "typescript": "^5.3.3", - "vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0" + "vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0 || ^8.0.0" }, "peerDependenciesMeta": { "@opentelemetry/api": { @@ -1641,6 +1640,12 @@ "undici-types": "~6.21.0" } }, + "node_modules/@types/trusted-types": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", + "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.46.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.46.2.tgz", @@ -1832,24 +1837,37 @@ "typescript": ">=4.8.4 <6.0.0" } }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.8.tgz", + "integrity": "sha512-reYkDYtj/b19TeqbNZCV4q9t+Yxylf/rYBsLb42SXJatTv4/ylq5lEiAmhA/IToxO7NI2UzNMghHoHuaqDkAjw==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -2076,9 +2094,9 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", + "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "license": "MIT", "dependencies": { @@ -2405,10 +2423,9 @@ } }, "node_modules/devalue": { - "version": "5.6.2", - "resolved": "https://registry.npmjs.org/devalue/-/devalue-5.6.2.tgz", - "integrity": "sha512-nPRkjWzzDQlsejL1WVifk5rvcFi/y1onBRxjaFMjZeR9mFpqu2gmAZ9xUB9/IEanEP/vBtGeGganC/GO1fmufg==", - "dev": true, + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/devalue/-/devalue-5.6.3.tgz", + "integrity": "sha512-nc7XjUU/2Lb+SvEFVGcWLiKkzfw8+qHI7zn8WYXKkLMgfGSHbgCEaR6bJpev8Cm6Rmrb19Gfd/tZvGqx9is3wg==", "license": "MIT" }, "node_modules/dom-accessibility-api": { @@ -2673,9 +2690,9 @@ } }, "node_modules/esrap": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/esrap/-/esrap-2.1.2.tgz", - "integrity": "sha512-DgvlIQeowRNyvLPWW4PT7Gu13WznY288Du086E751mwwbsgr29ytBiYeLzAGIo0qk3Ujob0SDk8TiSaM5WQzNg==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/esrap/-/esrap-2.2.3.tgz", + "integrity": "sha512-8fOS+GIGCQZl/ZIlhl59htOlms6U8NvX6ZYgYHpRU/b6tVSh3uHkOHZikl3D4cMbYM0JlpBe+p/BkZEi8J9XIQ==", "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.4.15" @@ -3484,9 +3501,9 @@ } }, "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "license": "ISC", "dependencies": { @@ -4282,9 +4299,9 @@ } }, "node_modules/svelte": { - "version": "5.43.2", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.43.2.tgz", - "integrity": "sha512-ro1umEzX8rT5JpCmlf0PPv7ncD8MdVob9e18bhwqTKNoLjS8kDvhVpaoYVPc+qMwDAOfcwJtyY7ZFSDbOaNPgA==", + "version": "5.53.5", + "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.53.5.tgz", + "integrity": "sha512-YkqERnF05g8KLdDZwZrF8/i1eSbj6Eoat8Jjr2IfruZz9StLuBqo8sfCSzjosNKd+ZrQ8DkKZDjpO5y3ht1Pow==", "license": "MIT", "peer": true, "dependencies": { @@ -4292,12 +4309,14 @@ "@jridgewell/sourcemap-codec": "^1.5.0", "@sveltejs/acorn-typescript": "^1.0.5", "@types/estree": "^1.0.5", + "@types/trusted-types": "^2.0.7", "acorn": "^8.12.1", - "aria-query": "^5.3.1", + "aria-query": "5.3.1", "axobject-query": "^4.1.0", "clsx": "^2.1.1", + "devalue": "^5.6.3", "esm-env": "^1.2.1", - "esrap": "^2.1.0", + "esrap": "^2.2.2", "is-reference": "^3.0.3", "locate-character": "^3.0.0", "magic-string": "^0.30.11", @@ -4362,9 +4381,9 @@ } }, "node_modules/svelte/node_modules/aria-query": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.2.tgz", - "integrity": "sha512-COROpnaoap1E2F000S62r6A60uHZnmlvomhfyT2DlTcrY1OrBKn2UhH7qn5wTC9zMvD0AY7csdPSNwKP+7WiQw==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.1.tgz", + "integrity": "sha512-Z/ZeOgVl7bcSYZ/u/rh0fOpvEpq//LZmdbkXyc7syVzjPAhfOa9ebsdTSjEBDU4vs5nC98Kfduj1uFo0qyET3g==", "license": "Apache-2.0", "engines": { "node": ">= 0.4" diff --git a/src/lib/assets/fs/fs.json b/src/lib/assets/fs/fs.json index 95ed8b6..ce03c3d 100755 --- a/src/lib/assets/fs/fs.json +++ b/src/lib/assets/fs/fs.json @@ -433,7 +433,7 @@ }, "13": { "Inode": 13, - "Name": "kamil", + "Name": "gornodox", "Type": 16384, "Size": 4096, "Children": [ diff --git a/src/lib/assets/login-avatar.png b/src/lib/assets/login-avatar.png new file mode 100755 index 0000000..1618fd4 Binary files /dev/null and b/src/lib/assets/login-avatar.png differ diff --git a/src/lib/stores/bash/bash.ts b/src/lib/stores/bash/bash.ts index bfb8e29..f2147ff 100755 --- a/src/lib/stores/bash/bash.ts +++ b/src/lib/stores/bash/bash.ts @@ -8,9 +8,8 @@ import { GROUP, type Group } from './etc/groupData'; export type BashInitArgs = { io?: Terminal; - instanceId: number; + fs: Map; user: {username: string, password: string}; - fs?: VirtualFS; }; export type Result = { @@ -20,7 +19,6 @@ export type Result = { }; export class Bash { - private readonly _instanceId: number; private vfs: VirtualFS; private _passwd: User[]; private _userInstances: Stack; @@ -30,7 +28,6 @@ export class Bash { private readonly _commands: Record; constructor(args: BashInitArgs) { - this._instanceId = args.instanceId this._commands = COMMANDS; this._passwd = PASSWD; this._group = GROUP; @@ -46,7 +43,7 @@ export class Bash { this.user = this._userInstances.peek()! - this.vfs = this._terminal.fileSystem; + this.vfs = new VirtualFS({ fs: args.fs, user: this.user}); } private _initNewUserSession(user: User): User { @@ -63,7 +60,7 @@ export class Bash { output: output, cmd: cmd }; - console.log(data); + console.log(this.vfs.formatPath(this.vfs.getPathByInode(inode)), "TEST TEST !@#"); this._terminal.PrintOutput(data); } diff --git a/src/lib/stores/bash/commands/clear.ts b/src/lib/stores/bash/commands/clear.ts index 4ac234d..542c2be 100644 --- a/src/lib/stores/bash/commands/clear.ts +++ b/src/lib/stores/bash/commands/clear.ts @@ -1,5 +1,6 @@ -import { ExitCode, type Bash } from "../bash"; -import type { CommandArgs, ICommand, Result } from "../static"; +import { type Bash, type Result } from "../bash"; +import type { CommandArgs, ICommand } from "../commandRegistry"; +import { ExitCode } from "../metadata"; export const cmd_clear = function(this: Bash, args: CommandArgs): Result { let result: Result = { exitCode: ExitCode.ERROR, path: this.getCwd() }; diff --git a/src/lib/stores/bash/etc/userData.ts b/src/lib/stores/bash/etc/userData.ts index 9cc3dc3..c254eaa 100644 --- a/src/lib/stores/bash/etc/userData.ts +++ b/src/lib/stores/bash/etc/userData.ts @@ -35,11 +35,11 @@ export const PASSWD: User[] = [ history: [] }, { - username: 'kamil', + username: 'gornodox', passwd: '000', uid: 1002, gid: 1000, - home: '/home/kamil', + home: '/home/gornodox', history: [] } ]; \ No newline at end of file diff --git a/src/lib/stores/bash/fs.ts b/src/lib/stores/bash/fs.ts index 5c777ea..ed45c57 100755 --- a/src/lib/stores/bash/fs.ts +++ b/src/lib/stores/bash/fs.ts @@ -1,4 +1,5 @@ import type { Bash } from "./bash"; +import type { User } from "./etc/userData"; import type { Permission, TimeStamps } from "./metadata"; export enum Type { @@ -14,8 +15,8 @@ export type NodePerms = { }; export type FsInitArgs = { - fs: any; - bash: Bash; + fs: Map; + user: User; }; export type TreeNode = { @@ -38,7 +39,7 @@ export type TreeNode = { export class VirtualFS { private FsTable: Map; private rootINode: number; - private _Bash: Bash; + private user: User; home: number; cwd: number; @@ -46,11 +47,12 @@ export class VirtualFS { constructor(args: FsInitArgs) { this.FsTable = args.fs; + this.user = args.user; this.rootINode = 1; - this._Bash = args.bash; - this.home = this._pathStringToINode(args.bash.getUser().home); - this.cwd = args.bash.getUser().cwd ? args.bash.getUser().cwd! : this.home; - this.pwd = args.bash.getUser().pwd ? args.bash.getUser().pwd! : this.cwd; + + this.home = this._pathStringToINode(args.user.home); + this.cwd = args.user.cwd ? args.user.cwd! : this.home; + this.pwd = args.user.pwd ? args.user.pwd! : this.cwd; console.log(this.home); console.log(this.cwd); @@ -59,10 +61,12 @@ export class VirtualFS { private _iNodeToPathString(inode: number): string { const currentNode = this.FsTable.get(inode); + if (!currentNode) throw new Error('could not find the node in the fs table - inodetopathstring'); - if (!currentNode.parent) { + if (!currentNode.parent || + currentNode.inode === this.rootINode) { return '/'; } diff --git a/src/lib/stores/terminal/init.svelte.ts b/src/lib/stores/terminal/init.svelte.ts index aadf032..1ab61e5 100755 --- a/src/lib/stores/terminal/init.svelte.ts +++ b/src/lib/stores/terminal/init.svelte.ts @@ -1,6 +1,6 @@ import type { User } from '../bash/etc/userData'; import type { TreeNode } from '../bash/fs'; -import { type ILocale } from './localeRegistry'; +//import { type ILocale } from './localeRegistry'; import { Terminal, type PageCallbacks, type TermInitArgs } from './terminal'; let initializing = $state(true); @@ -117,17 +117,16 @@ export async function initTerminal( const sig = await fetchFsSignature('/src/lib/assets/fs/signature'); const fsJson = await fetchFsJson(sig); const fs: Map = jsonToNodeTable(fsJson); - const locale: ILocale = { + /* const locale: ILocale = { id: localeId, keys: fetchLocale(localeId) - }; + }; */ const args: TermInitArgs = { - fs, - locale, + //locale, bash: { - user, - instanceId: 0 + fs, + user } }; diff --git a/src/lib/stores/terminal/localeRegistry.ts b/src/lib/stores/terminal/localeRegistry.ts index f974ecd..099644b 100644 --- a/src/lib/stores/terminal/localeRegistry.ts +++ b/src/lib/stores/terminal/localeRegistry.ts @@ -1,13 +1,18 @@ -export interface ILocale { +/* export interface ILocale { id: string; keys?: {}; + SetKeys: () => void; } -const en: ILocale = { +const en_US: ILocale = { id: 'en_US', - keys: {} + keys: {}, + + SetKeys(): () { + + } } export const LOCALES = { - en -} as const satisfies Record; \ No newline at end of file + en_US +} as const satisfies Record; */ \ No newline at end of file diff --git a/src/lib/stores/terminal/terminal.ts b/src/lib/stores/terminal/terminal.ts index 71bc3d4..ab6ef3b 100755 --- a/src/lib/stores/terminal/terminal.ts +++ b/src/lib/stores/terminal/terminal.ts @@ -3,14 +3,13 @@ import type { CommandArgs } from '../bash/commandRegistry'; import type { User } from '../bash/etc/userData'; import { VirtualFS, type TreeNode } from '../bash/fs'; import type { ExitCode } from '../bash/metadata'; -import type { ILocale } from './localeRegistry'; +//import type { ILocale } from './localeRegistry'; export type TerminalMode = {}; export type TermInitArgs = { - fs: Map; bash: BashInitArgs; - locale: ILocale + //locale: ILocale }; export type ParsedInput = { @@ -32,27 +31,15 @@ export type PageCallbacks = { }; export class Terminal { - private _bashInstanceId: number; - private _bashInstances: Bash[]; + private _bash: Bash; private _callbacks: Partial = {}; - public fileSystem: VirtualFS; - public locale: ILocale; + //public locale: ILocale; constructor(args: TermInitArgs) { args.bash.io = this; - this._bashInstanceId = 0; - this._bashInstances = []; + this._bash = new Bash(args.bash); - this._initializeBashInstance(args.bash); - - this.fileSystem = new VirtualFS({ fs: args.fs, bash: this._bashInstances[this._bashInstanceId] }); - this.locale = args.locale; - - } - - private _initializeBashInstance(init: BashInitArgs) { - const instance: Bash = new Bash(init); - this._bashInstances.push(instance); + //this.locale = args.locale; } @@ -114,10 +101,10 @@ export class Terminal { } executeCommand(input: string): void { - this._bashInstances[this._bashInstanceId].updateHistory(input); + this._bash.updateHistory(input); const parsed: ParsedInput = this._parseInput(input); console.log(parsed, 'executeCommand output'); - this._bashInstances[this._bashInstanceId].executeCommand(parsed.command, parsed.args); + this._bash.executeCommand(parsed.command, parsed.args); } registerCallbacks(callbacks: PageCallbacks): void { @@ -129,7 +116,7 @@ export class Terminal { } getUser(): User { - return this._bashInstances[this._bashInstanceId].getUser(); + return this._bash.getUser(); } getTerminalWidth(): number { @@ -147,9 +134,9 @@ export class Terminal { } getCwd(): string { - const fs: VirtualFS = this._bashInstances[this._bashInstanceId].getFs(); - console.log(fs.getPathByInode(this._bashInstances[this._bashInstanceId].getCwd())); - return fs.formatPath(fs.getPathByInode(this._bashInstances[this._bashInstanceId].getCwd())); + const fs: VirtualFS = this._bash.getFs(); + console.log(fs.getPathByInode(this._bash.getCwd())); + return fs.formatPath(fs.getPathByInode(this._bash.getCwd())); } PrintOutput(data: PrintData) { diff --git a/src/modules/Login.svelte b/src/modules/Login.svelte new file mode 100644 index 0000000..1f5aad2 --- /dev/null +++ b/src/modules/Login.svelte @@ -0,0 +1,69 @@ + + +
+ +
+ gornodox +
+
{formElem.classList.remove('invalid')}} use:enhance={({ formData }) => + { + init(formData); + } + } method="POST" action="?/login" class:invalid={form?.error} name="login-form" autocomplete="off" class="mt-6 flex flex-row gap-1"> +
+ + +
+ +
+
+ + + diff --git a/src/modules/Settings.svelte b/src/modules/Settings.svelte index 4d94e92..d3db66a 100755 --- a/src/modules/Settings.svelte +++ b/src/modules/Settings.svelte @@ -27,7 +27,7 @@
diff --git a/src/modules/Terminal.svelte b/src/modules/Terminal.svelte index f297269..7d12858 100755 --- a/src/modules/Terminal.svelte +++ b/src/modules/Terminal.svelte @@ -10,6 +10,17 @@ const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d); + export async function init(password: string) { + try { + terminal = await initTerminal({ username: 'gornodox', password}, callbackInit, 'en_US'); + updateTerminal(); + } catch (error) { + console.error('onMount trycatch failed', error); + } + + runTerminal(); + } + function updateTerminal() { username = terminal!.getUser().username; cwd = terminal!.getCwd(); @@ -66,6 +77,10 @@ elem.scrollTop = elem.scrollHeight; } + function runTerminal() { + document.getElementById('terminal-window')?.classList.remove('hidden'); + } + //Callback initializer const callbackInit = { print: (data: any) => { @@ -78,35 +93,17 @@ getFontSize: getFontSize }; - //Test user with basic data so the bash can run - let testUser: User = { - username: 'kamil', - passwd: '123', - uid: 0, - gid: 0, - home: '/home/kamil', - history: [] - }; - //Empty terminal variable where the terminal class instance will be stored let terminal: Terminal; - let username: string = $state(testUser.username); - let cwd: string = $state(testUser.home); + let username: string = $state(''); + let cwd: string = $state(''); let inputValue = $state(''); - onMount(async () => { - try { - terminal = await initTerminal({ username: 'root', password: '123'}, callbackInit, 'en_US'); - updateTerminal(); - } catch (error) { - console.error('onMount trycatch failed', error); - } - });