Compare commits
2
Commits
65c776d1a2
...
50872d8951
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50872d8951 | ||
|
|
68458be71f |
Generated
+1030
-1175
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -30,8 +30,8 @@
|
|||||||
"@tailwindcss/vite": "^4.1.16",
|
"@tailwindcss/vite": "^4.1.16",
|
||||||
"@types/node": "^24",
|
"@types/node": "^24",
|
||||||
"@vitest/browser": "^3.2.4",
|
"@vitest/browser": "^3.2.4",
|
||||||
"drizzle-kit": "^0.31.8",
|
"drizzle-kit": "^0.18.1",
|
||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.2",
|
||||||
"eslint": "^9.36.0",
|
"eslint": "^9.36.0",
|
||||||
"eslint-config-prettier": "^10.1.8",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-svelte": "^3.12.4",
|
"eslint-plugin-svelte": "^3.12.4",
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { customType } from 'drizzle-orm/mysql-core';
|
||||||
|
|
||||||
|
export const mediumblob = customType<{
|
||||||
|
data: Buffer;
|
||||||
|
driverData: Buffer;
|
||||||
|
}>({
|
||||||
|
dataType() {
|
||||||
|
return 'MEDIUMBLOB';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const longblob = customType<{
|
||||||
|
data: Buffer;
|
||||||
|
driverData: Buffer;
|
||||||
|
}>({
|
||||||
|
dataType() {
|
||||||
|
return 'LONGBLOB';
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,4 +1,16 @@
|
|||||||
import { mysqlTable, serial, int, text, tinyint } from 'drizzle-orm/mysql-core';
|
import {
|
||||||
|
boolean,
|
||||||
|
char,
|
||||||
|
int,
|
||||||
|
longtext,
|
||||||
|
mysqlTable,
|
||||||
|
serial,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
tinyint,
|
||||||
|
varchar
|
||||||
|
} from 'drizzle-orm/mysql-core';
|
||||||
|
import { longblob, mediumblob } from './custom-types';
|
||||||
|
|
||||||
export const task = mysqlTable('task', {
|
export const task = mysqlTable('task', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
@@ -6,10 +18,65 @@ export const task = mysqlTable('task', {
|
|||||||
priority: int('priority').notNull().default(1)
|
priority: int('priority').notNull().default(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const settings = mysqlTable('settings', {
|
export const config = mysqlTable('config', {
|
||||||
var: text('var').notNull().unique(),
|
key: varchar('key', { length: 64 }).primaryKey(),
|
||||||
state: tinyint('state')
|
value: longtext('value').notNull()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Setting = typeof settings.$inferSelect;
|
export const projects = mysqlTable('projects', {
|
||||||
|
id: tinyint('id').notNull().primaryKey().autoincrement(),
|
||||||
|
name: text('name').notNull(),
|
||||||
|
data: longtext('data', {}).notNull(),
|
||||||
|
enabled: tinyint('enabled').notNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const locales = mysqlTable('locales', {
|
||||||
|
code: char('code').notNull().unique(),
|
||||||
|
name: char('name').notNull(),
|
||||||
|
dictionary: longtext().notNull(),
|
||||||
|
flag: longtext('').notNull(),
|
||||||
|
enabled: tinyint('enabled').notNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const groups = mysqlTable('groups', {
|
||||||
|
gid: int('gid').primaryKey().autoincrement(),
|
||||||
|
name: varchar('name', { length: 32 }).notNull().unique()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const users = mysqlTable('users', {
|
||||||
|
uid: int('uid').primaryKey().autoincrement(),
|
||||||
|
username: varchar('username', { length: 32 }).notNull().unique(),
|
||||||
|
password: varchar('password', { length: 128 }).notNull(),
|
||||||
|
home: int('home').notNull(),
|
||||||
|
gid: int('gid')
|
||||||
|
.notNull()
|
||||||
|
.references(() => groups.gid),
|
||||||
|
accessible: boolean('accessible').notNull(),
|
||||||
|
face: mediumblob('face')
|
||||||
|
});
|
||||||
|
|
||||||
|
export const filesystem = mysqlTable(
|
||||||
|
'filesystem',
|
||||||
|
{
|
||||||
|
id: int('id').primaryKey().default(1),
|
||||||
|
data: longtext('data').notNull(),
|
||||||
|
checksum: varchar('checksum', { length: 32 }).notNull(),
|
||||||
|
updatedAt: timestamp('updated_at').defaultNow().onUpdateNow()
|
||||||
|
} /* ,
|
||||||
|
{
|
||||||
|
// Ensures only one row can exist
|
||||||
|
singleRow: check('single_row_check', `id = 1`)
|
||||||
|
} */
|
||||||
|
);
|
||||||
|
|
||||||
|
export const fileContents = mysqlTable('file_contents', {
|
||||||
|
guid: varchar('guid', { length: 36 }).primaryKey(),
|
||||||
|
data: longblob('data').notNull(),
|
||||||
|
mimeType: varchar('mime_type', { length: 127 }).default('text/plain')
|
||||||
|
});
|
||||||
|
|
||||||
|
export const allowList = mysqlTable('allow_list', {
|
||||||
|
ip: int('ip').notNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type Config = typeof config.$inferSelect;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { Bash } from './bash';
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
import type { TreeNode } from './fs';
|
import type { TreeNode } from './fs';
|
||||||
import { Posix } from './posix';
|
|
||||||
|
|
||||||
export enum SortNodeBy {
|
export enum SortNodeBy {
|
||||||
NAME = 'name',
|
NAME = 'name',
|
||||||
@@ -15,11 +14,12 @@ export enum SortNodeBy {
|
|||||||
|
|
||||||
export class Sort {
|
export class Sort {
|
||||||
public static nodeArraySort(
|
public static nodeArraySort(
|
||||||
this: Bash,
|
|
||||||
nodes: TreeNode[] | number[],
|
nodes: TreeNode[] | number[],
|
||||||
reverse: boolean = false,
|
reverse: boolean = false,
|
||||||
sortBy: SortNodeBy = SortNodeBy.NAME
|
sortBy: SortNodeBy = SortNodeBy.NAME
|
||||||
): TreeNode[] {
|
): TreeNode[] {
|
||||||
|
const Fs = FileSystem.instance;
|
||||||
|
|
||||||
if (nodes.length === 0) {
|
if (nodes.length === 0) {
|
||||||
console.warn('Tried to sort an empty node array!');
|
console.warn('Tried to sort an empty node array!');
|
||||||
return [];
|
return [];
|
||||||
@@ -28,7 +28,7 @@ export class Sort {
|
|||||||
|
|
||||||
if (typeof nodes[0] === 'number') {
|
if (typeof nodes[0] === 'number') {
|
||||||
for (const inode of nodes as number[]) {
|
for (const inode of nodes as number[]) {
|
||||||
const node = this.getFs().getNodeByINode(inode);
|
const node = Fs.getNodeByInode(inode);
|
||||||
parsedNodes.push(node);
|
parsedNodes.push(node);
|
||||||
}
|
}
|
||||||
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
Sort.nodeQSort(parsedNodes, reverse, sortBy, 0, parsedNodes.length - 1);
|
||||||
|
|||||||
@@ -1,30 +1,46 @@
|
|||||||
import type { User } from '../shell/shell';
|
import type { User } from '../shell/shell';
|
||||||
import { MD5 } from '../util/hash';
|
|
||||||
|
|
||||||
export class FileSystem {
|
export class FileSystem {
|
||||||
static #instance: FileSystem;
|
static #instance: FileSystem;
|
||||||
private _fs: Map<number, TreeNode>;
|
private _fs: Map<number, TreeNode>;
|
||||||
private _root: number;
|
private _root: number;
|
||||||
|
|
||||||
private constructor() {
|
private constructor(fs: Map<number, TreeNode>) {
|
||||||
|
this._fs = fs;
|
||||||
this._root = this._fs.values().next().value!.inode;
|
this._root = this._fs.values().next().value!.inode;
|
||||||
|
|
||||||
if (!this._root) throw new Error('First entry in the filesystem map empty!');
|
if (!this._root) throw new Error('First entry in the filesystem map empty!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Init() {
|
public static async Init(fsJson: JSON) {
|
||||||
const fsJson: JSON = await this._fetchFileSystem('/temp/path');
|
//const fsChecksum = MD5.hash(JSON.stringify(fsJson));
|
||||||
const checksum: any = MD5.hash(JSON.stringify(fsJson));
|
|
||||||
|
/*
|
||||||
|
const cache: string | null = localStorage.getItem('fs-json');
|
||||||
|
if (cache) {
|
||||||
|
const fsCacheChecksum = MD5.hash(cache);
|
||||||
|
|
||||||
|
console.log(fsChecksum);
|
||||||
|
console.log(fsCacheChecksum);
|
||||||
|
|
||||||
|
if (fsChecksum !== fsCacheChecksum) {
|
||||||
|
//calculate version control difference to preserve user made changes (do a merge)
|
||||||
|
}
|
||||||
|
fsJson = JSON.parse(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async _fetchFileSystem(path: string): Promise<JSON> {
|
localStorage.setItem('fs-json', JSON.stringify(fsJson));
|
||||||
const response = await fetch(path);
|
*/
|
||||||
if (!response.ok) throw new Error('Failed to fetch the file system json');
|
|
||||||
|
|
||||||
return await response.json();
|
const fs: Map<number, TreeNode> = this._jsonToNodeTable(fsJson);
|
||||||
|
|
||||||
|
// This produces a different checksum!
|
||||||
|
// Find a way to produce the same hash from Map and a fetched json file or cached stringified json
|
||||||
|
|
||||||
|
FileSystem.#instance = new FileSystem(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchFsSignature(path: string): Promise<any> {
|
/* private async _fetchFsSignature(path: string): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(path);
|
const response = await fetch(path);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -36,12 +52,12 @@ export class FileSystem {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch the file system signature', error);
|
console.error('Failed to fetch the file system signature', error);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
private async fetchFsJson(sig: string): Promise<JSON> {
|
/* private static async fetchFsJson(): Promise<JSON> {
|
||||||
const signature: string | null = localStorage.getItem('signature');
|
const checksum: string | null = localStorage.getItem('fs-checksum');
|
||||||
|
|
||||||
if (signature !== sig || signature === null || localStorage.getItem('fs') === null) {
|
if (checksum !== sig || signature === null || localStorage.getItem('fs') === null) {
|
||||||
const fs: JSON = await this._fetchFileSystem('/src/lib/assets/fs/fs.json');
|
const fs: JSON = await this._fetchFileSystem('/src/lib/assets/fs/fs.json');
|
||||||
localStorage.setItem('signature', sig);
|
localStorage.setItem('signature', sig);
|
||||||
localStorage.setItem('fs', JSON.stringify(fs));
|
localStorage.setItem('fs', JSON.stringify(fs));
|
||||||
@@ -57,9 +73,9 @@ export class FileSystem {
|
|||||||
|
|
||||||
return JSON.parse(fs);
|
return JSON.parse(fs);
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
private _jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
private static _jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
||||||
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
||||||
const entryList = Object.entries(data);
|
const entryList = Object.entries(data);
|
||||||
|
|
||||||
@@ -288,10 +304,10 @@ export class FileSystem {
|
|||||||
|
|
||||||
public static get instance(): FileSystem {
|
public static get instance(): FileSystem {
|
||||||
if (!FileSystem.#instance) {
|
if (!FileSystem.#instance) {
|
||||||
FileSystem.#instance = new FileSystem();
|
throw new Error(`FileSystem was not initialized properly!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileSystem.instance;
|
return FileSystem.#instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export abstract class Command {
|
|||||||
public abstract readonly _help: string; //TODO: Dont know where to pull the help text from yet
|
public abstract readonly _help: string; //TODO: Dont know where to pull the help text from yet
|
||||||
public abstract result: CommandResult;
|
public abstract result: CommandResult;
|
||||||
|
|
||||||
public abstract Main(this: Shell, flags: CommandFlag[], args: string[]): void;
|
public abstract Main(flags: CommandFlag[], args: string[]): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandFlag = {
|
export type CommandFlag = {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import type { Stack } from '$lib/stores/stack';
|
import type { Stack } from '$lib/stores/stack';
|
||||||
import { FileSystem } from '../filesystem/filesystem';
|
import type { Command } from './command';
|
||||||
|
import type { Process } from './process';
|
||||||
|
|
||||||
export class Shell {
|
export class Shell {
|
||||||
private readonly _fs: FileSystem;
|
|
||||||
|
|
||||||
private _passwd: User[];
|
private _passwd: User[];
|
||||||
private _group: Group[];
|
private _group: Group[];
|
||||||
|
|
||||||
@@ -14,9 +13,15 @@ export class Shell {
|
|||||||
private user: User;
|
private user: User;
|
||||||
private _process?: Process;
|
private _process?: Process;
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
this._fs = new FileSystem();
|
|
||||||
}
|
public static Initialize(
|
||||||
|
username: string,
|
||||||
|
password: string,
|
||||||
|
commands: Map<string, Command>,
|
||||||
|
passwd: Map<number, User>,
|
||||||
|
group: Map<number, Group>
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ExitCode {
|
export enum ExitCode {
|
||||||
|
|||||||
+129
-6
@@ -1,11 +1,110 @@
|
|||||||
export class MD5 {
|
export class MD5 {
|
||||||
private static encoder: TextEncoder = new TextEncoder();
|
private static encoder: TextEncoder = new TextEncoder();
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
private static K: number[] = [
|
||||||
|
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||||
|
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||||
|
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||||
|
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||||
|
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||||
|
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||||
|
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||||
|
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||||
|
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||||
|
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||||
|
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||||
|
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||||
|
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||||
|
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||||
|
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||||
|
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
|
||||||
|
];
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
private static S: number[] = [
|
||||||
|
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||||
|
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
||||||
|
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
||||||
|
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
|
||||||
|
];
|
||||||
|
|
||||||
public static hash(input: string) {
|
public static hash(input: string) {
|
||||||
const uIntArr: Uint8Array<ArrayBuffer> = this.encoder.encode(input);
|
const inputArr: Uint8Array<ArrayBuffer> = this.encoder.encode(input);
|
||||||
|
const padded = MD5.pad(inputArr);
|
||||||
|
|
||||||
|
let A = 0x67452301;
|
||||||
|
let B = 0xefcdab89;
|
||||||
|
let C = 0x98badcfe;
|
||||||
|
let D = 0x10325476;
|
||||||
|
|
||||||
|
function processBlock(M: number[]) {
|
||||||
|
function F(b: number, c: number, d: number): number {
|
||||||
|
return (b & c) | (~b & d);
|
||||||
|
}
|
||||||
|
function H(b: number, c: number, d: number): number {
|
||||||
|
return b ^ c ^ d;
|
||||||
|
}
|
||||||
|
function I(b: number, c: number, d: number): number {
|
||||||
|
return c ^ (b | ~d);
|
||||||
|
}
|
||||||
|
function G(b: number, c: number, d: number): number {
|
||||||
|
return (b & d) | (c & ~d);
|
||||||
}
|
}
|
||||||
|
|
||||||
private pad(input: Uint8Array) {
|
let AA = A,
|
||||||
|
BB = B,
|
||||||
|
CC = C,
|
||||||
|
DD = D;
|
||||||
|
|
||||||
|
for (let i = 0; i < 64; i++) {
|
||||||
|
let f: number, g: number;
|
||||||
|
|
||||||
|
if (i < 16) {
|
||||||
|
f = F(B, C, D);
|
||||||
|
g = i;
|
||||||
|
} else if (i < 32) {
|
||||||
|
f = G(B, C, D);
|
||||||
|
g = (5 * i + 1) % 16;
|
||||||
|
} else if (i < 48) {
|
||||||
|
f = H(B, C, D);
|
||||||
|
g = (3 * i + 5) % 16;
|
||||||
|
} else {
|
||||||
|
f = I(B, C, D);
|
||||||
|
g = (7 * i) % 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sum = MD5.add32(A, MD5.add32(f, MD5.add32(M[g], MD5.K[i])));
|
||||||
|
const temp = MD5.add32(B, MD5.leftRotate(sum, MD5.S[i]));
|
||||||
|
|
||||||
|
A = D;
|
||||||
|
D = C;
|
||||||
|
C = B;
|
||||||
|
B = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
A = MD5.add32(A, AA);
|
||||||
|
B = MD5.add32(B, BB);
|
||||||
|
C = MD5.add32(C, CC);
|
||||||
|
D = MD5.add32(D, DD);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < padded.length; i += 64) {
|
||||||
|
const M = MD5.sliceToWords(padded.slice(i, i + 64));
|
||||||
|
processBlock(M); // modifies A, B, C, D directly
|
||||||
|
}
|
||||||
|
|
||||||
|
const hashBytes = new Uint8Array([
|
||||||
|
...MD5.wordToBytesLE(A),
|
||||||
|
...MD5.wordToBytesLE(B),
|
||||||
|
...MD5.wordToBytesLE(C),
|
||||||
|
...MD5.wordToBytesLE(D)
|
||||||
|
]);
|
||||||
|
|
||||||
|
return MD5.toHexString(hashBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static pad(input: Uint8Array): Uint8Array {
|
||||||
const inputBitLength: number = input.length * 8;
|
const inputBitLength: number = input.length * 8;
|
||||||
|
|
||||||
const out: Uint8Array = new Uint8Array([...input, 0x80]);
|
const out: Uint8Array = new Uint8Array([...input, 0x80]);
|
||||||
@@ -27,21 +126,21 @@ export class MD5 {
|
|||||||
(high >> 24) & 0xff
|
(high >> 24) & 0xff
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return new Int8Array([...out, ...zeroArray, ...lengthBytes]);
|
return new Uint8Array([...out, ...zeroArray, ...lengthBytes]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private sliceToBlocks(input: Uint8Array): number[][] {
|
private static sliceToBlocks(input: Uint8Array): number[][] {
|
||||||
const blocks: number[][] = [];
|
const blocks: number[][] = [];
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i += 64) {
|
for (let i = 0; i < input.length; i += 64) {
|
||||||
const block = input.slice(i, i + 64);
|
const block = input.slice(i, i + 64);
|
||||||
blocks.push(this.sliceToWords(block));
|
blocks.push(MD5.sliceToWords(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sliceToWords(block: Uint8Array): number[] {
|
private static sliceToWords(block: Uint8Array): number[] {
|
||||||
const words: number[] = new Array<number>(16);
|
const words: number[] = new Array<number>(16);
|
||||||
|
|
||||||
for (let i = 0; i < 16; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
@@ -57,4 +156,28 @@ export class MD5 {
|
|||||||
|
|
||||||
return words;
|
return words;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static leftRotate(x: number, n: number): number {
|
||||||
|
x = x >>> 0;
|
||||||
|
return ((x << n) | (x >>> (32 - n))) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static add32(a: number, b: number): number {
|
||||||
|
return ((a >>> 0) + (b >>> 0)) >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static wordToBytesLE(word: number): Uint8Array {
|
||||||
|
return new Uint8Array([
|
||||||
|
word & 0xff,
|
||||||
|
(word >>> 8) & 0xff,
|
||||||
|
(word >>> 16) & 0xff,
|
||||||
|
(word >>> 24) & 0xff
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static toHexString(bytes: Uint8Array): string {
|
||||||
|
return Array.from(bytes)
|
||||||
|
.map((b) => b.toString(16).padStart(2, '0'))
|
||||||
|
.join('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Type } from '$lib/termos/filesystem/filesystem';
|
||||||
|
import { File, Folder } from '@lucide/svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
nodeName,
|
||||||
|
nodeType,
|
||||||
|
isProject = true
|
||||||
|
}: { nodeName: string; nodeType: Type; isProject: boolean } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class=" flex flex-row items-center rounded-md bg-bg-lighter-dark p-2">
|
||||||
|
{#if nodeType == Type.Directory}
|
||||||
|
<Folder class="text-primary-dark" strokeWidth={1} />
|
||||||
|
{:else}
|
||||||
|
<File strokeWidth={1} />
|
||||||
|
{/if}
|
||||||
|
<h4 class={isProject ? 'text-primary-dark' : 'text-text-dark'}>{nodeName}</h4>
|
||||||
|
</div>
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ChevronRight, Power, SquarePen } from '@lucide/svelte';
|
|
||||||
|
|
||||||
let { projectName, checked = true }: { projectName: string; checked: boolean } = $props();
|
let { projectName, checked = true }: { projectName: string; checked: boolean } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class=" flex items-center text-text-dark saturate-50 has-checked:saturate-100 light:text-text-light"
|
class=" flex items-center text-text-dark saturate-50 has-checked:saturate-100 light:text-text-light"
|
||||||
>
|
>
|
||||||
<div class=" flex w-full flex-col justify-center gap-1 rounded-lg bg-bg-mid-dark">
|
<div class=" flex w-48 flex-col justify-center gap-1 rounded-lg bg-bg-mid-dark">
|
||||||
<h5 class=" m-4 font-primary text-xl font-bold">{projectName}</h5>
|
<h5 class=" m-4 font-primary text-xl font-bold">{projectName}</h5>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<label
|
<label
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../app.css';
|
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
import { onMount, type Snippet } from 'svelte';
|
|
||||||
import { theme } from '$lib/stores/theme';
|
import { theme } from '$lib/stores/theme';
|
||||||
import Loading from '../modules/Loading.svelte';
|
import { onMount, type Snippet } from 'svelte';
|
||||||
import Shimeji from '../modules/Shimeji.svelte';
|
import '../app.css';
|
||||||
|
//import Loading from '../modules/Loading.svelte';
|
||||||
|
//import Shimeji from '../modules/Shimeji.svelte';
|
||||||
|
|
||||||
let { children }: { children: Snippet } = $props();
|
let { children }: { children: Snippet } = $props();
|
||||||
|
|
||||||
@@ -44,7 +44,6 @@
|
|||||||
class:dark={$theme === 'dark'}
|
class:dark={$theme === 'dark'}
|
||||||
class:light={$theme === 'light'}
|
class:light={$theme === 'light'}
|
||||||
>
|
>
|
||||||
<Shimeji />
|
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { filesystem } from '$lib/server/db/schema';
|
||||||
|
import { MD5 } from '$lib/termos/util/hash';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function GET({ request }): Promise<Response> {
|
||||||
|
const row = await db
|
||||||
|
.select({
|
||||||
|
data: filesystem.data,
|
||||||
|
checksum: filesystem.checksum
|
||||||
|
})
|
||||||
|
.from(filesystem)
|
||||||
|
.where(eq(filesystem.id, 1))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!row.length) {
|
||||||
|
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data, checksum } = row[0];
|
||||||
|
const clientETag = request.headers.get('if-none-match');
|
||||||
|
|
||||||
|
if (clientETag === `"${checksum}"`) {
|
||||||
|
return new Response(null, {
|
||||||
|
status: 304,
|
||||||
|
headers: { ETag: `"${checksum}"` }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(data, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
ETag: `"${checksum}"`,
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST({ request }) {
|
||||||
|
const newData = await request.text();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(newData);
|
||||||
|
//TODO: Schema validation
|
||||||
|
} catch {
|
||||||
|
//TODO: Change that to a proper http headers error
|
||||||
|
return new Response(null, {
|
||||||
|
status: 400
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const checksum: string = MD5.hash(newData);
|
||||||
|
|
||||||
|
await db.update(filesystem).set({ data: newData, checksum }).where(eq(filesystem.id, 1));
|
||||||
|
|
||||||
|
return new Response(JSON.stringify({ success: true }), { status: 200 });
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { users } from '$lib/server/db/schema';
|
||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export async function GET({ request }): Promise<Response> {
|
||||||
|
const rows = await db
|
||||||
|
.select({
|
||||||
|
uid: users.uid,
|
||||||
|
username: users.username,
|
||||||
|
password: users.password,
|
||||||
|
home: users.home,
|
||||||
|
gid: users.gid,
|
||||||
|
accessible: users.accessible
|
||||||
|
})
|
||||||
|
.from(users);
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: {}[] = rows.map((u) => ({
|
||||||
|
...u,
|
||||||
|
avatarUrl: `/api/users/${u.uid}/avatar`
|
||||||
|
}));
|
||||||
|
|
||||||
|
return json(result);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { users } from '$lib/server/db/schema';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function GET({ params, request }): Promise<Response> {
|
||||||
|
const row = await db
|
||||||
|
.select({
|
||||||
|
uid: users.uid,
|
||||||
|
username: users.username,
|
||||||
|
password: users.password,
|
||||||
|
home: users.home,
|
||||||
|
gid: users.gid,
|
||||||
|
accessible: users.accessible
|
||||||
|
})
|
||||||
|
.from(users)
|
||||||
|
.where(eq(users.uid, Number(params.uid)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!row.length) {
|
||||||
|
return new Response(`User not found`, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = row[0];
|
||||||
|
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
...user,
|
||||||
|
avatarUrl: `/api/users/${user.uid}/avatar`
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { users } from '$lib/server/db/schema';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function PUT({ params, request }) {
|
||||||
|
const uid = Number(params.uid);
|
||||||
|
const arrayBuffer = await request.arrayBuffer();
|
||||||
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
await db.update(users).set({ face: buffer }).where(eq(users.uid, uid));
|
||||||
|
return new Response(null, { status: 204 });
|
||||||
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../../app.css';
|
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
import { getContext, setContext, type Snippet } from 'svelte';
|
import { BookA, ChartLine, ChartNoAxesColumn, FolderArchive, Plus } from '@lucide/svelte';
|
||||||
import { BookA, ChartLine, ChartNoAxesColumn, Construction, FolderArchive, Plus } from '@lucide/svelte';
|
import { type Snippet } from 'svelte';
|
||||||
|
import '../../app.css';
|
||||||
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
||||||
let { children, data}: { children: Snippet, data: any } = $props();
|
let { children, data }: { children: Snippet; data: any } = $props();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -36,7 +35,7 @@
|
|||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex w-full grow">
|
<div class=" w-full">
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { locales } from '$lib/server/db/schema';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async () => {
|
||||||
|
return {
|
||||||
|
locales: await db
|
||||||
|
.select({
|
||||||
|
code: locales.code,
|
||||||
|
name: locales.name,
|
||||||
|
dictionary: locales.dictionary,
|
||||||
|
flag: locales.flag,
|
||||||
|
enabled: locales.enabled
|
||||||
|
})
|
||||||
|
.from(locales)
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,19 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import LangModule from '../../../modules/panel/LangModule.svelte';
|
import LangModule from '../../../modules/panel/LangModule.svelte';
|
||||||
import plFlag from '$lib/assets/plFlag.svg';
|
|
||||||
import enFlag from '$lib/assets/enFlag.svg';
|
let { data }: { data: any } = $props();
|
||||||
import deFlag from '$lib/assets/deFlag.svg';
|
|
||||||
import frFlag from '$lib/assets/frFlag.svg';
|
|
||||||
import jaFlag from '$lib/assets/jaFlag.svg';
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<form name="langs" class="m-10 flex flex-col gap-4">
|
<form name="locales" class="m-10 flex flex-col gap-4">
|
||||||
<LangModule checked langName="Polish" icon={plFlag} />
|
{#each data.locales as locale}
|
||||||
|
<LangModule checked={locale.enabled} langName={locale.name} icon={locale.flag} />
|
||||||
|
{/each}
|
||||||
|
<!-- <LangModule checked langName="Polish" icon={plFlag} />
|
||||||
<LangModule checked langName="English" icon={enFlag} />
|
<LangModule checked langName="English" icon={enFlag} />
|
||||||
<LangModule checked langName="German" icon={deFlag} />
|
<LangModule checked langName="German" icon={deFlag} />
|
||||||
<LangModule langName="Japanese" icon={jaFlag} />
|
<LangModule langName="Japanese" icon={jaFlag} />
|
||||||
<LangModule langName="French" icon={frFlag} />
|
<LangModule langName="French" icon={frFlag} /> -->
|
||||||
</form>
|
</form>
|
||||||
<div></div>
|
<div>
|
||||||
|
<form>
|
||||||
|
<input type="file" />
|
||||||
|
<input type="image" alt="NaN" />
|
||||||
|
<input type="text" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,34 @@
|
|||||||
import { db } from "$lib/server/db";
|
import fsData from '$lib/assets/fs/fs.json';
|
||||||
import { settings } from "$lib/server/db/schema";
|
import { db } from '$lib/server/db';
|
||||||
import { eq } from "drizzle-orm";
|
import { projects, settings } from '$lib/server/db/schema';
|
||||||
import type { PageServerLoad } from "./$types";
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
|
import { Sort, SortNodeBy } from '$lib/termos/util/sort';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
export const load: PageServerLoad = async () => {
|
||||||
|
FileSystem.Init(fsData as any);
|
||||||
|
|
||||||
|
const fs = FileSystem.instance;
|
||||||
|
|
||||||
|
const node = fs.getNodeByInode(13); //Gordonox home dir
|
||||||
|
let nodes = node.children.map((child) => fs.getNodeByInode(child));
|
||||||
|
nodes = Sort.nodeArraySort(nodes, false, SortNodeBy.NAME);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
settings: await db.select({setting: settings.state}).from(settings).where(eq(settings.var, 'maintenance')).limit(1)
|
settings: await db
|
||||||
|
.select({ setting: settings.state })
|
||||||
|
.from(settings)
|
||||||
|
.where(eq(settings.var, 'maintenance'))
|
||||||
|
.limit(1),
|
||||||
|
projects: await db
|
||||||
|
.select({
|
||||||
|
id: projects.id,
|
||||||
|
name: projects.name,
|
||||||
|
data: projects.data,
|
||||||
|
enabled: projects.enabled
|
||||||
|
})
|
||||||
|
.from(projects),
|
||||||
|
nodes: nodes
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Construction } from '@lucide/svelte';
|
import { Construction, Eye, EyeOff } from '@lucide/svelte';
|
||||||
|
import NodeModule from '../../../modules/panel/NodeModule.svelte';
|
||||||
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
||||||
import { setMaintenanceState } from '../settings.remote';
|
import { setMaintenanceState } from '../settings.remote';
|
||||||
|
|
||||||
let { data }: { data: any } = $props();
|
let { data }: { data: any } = $props();
|
||||||
|
|
||||||
let maintenance = $state(Boolean(data.settings[0].setting));
|
let maintenance = $state(Boolean(data.settings[0].setting));
|
||||||
console.log(maintenance);
|
let showHidden = $state(false);
|
||||||
|
|
||||||
|
console.log(data.projects[0].name);
|
||||||
|
|
||||||
function handleToggle() {
|
function handleToggle() {
|
||||||
console.log(maintenance);
|
console.log(maintenance);
|
||||||
@@ -15,19 +18,58 @@
|
|||||||
let result = setMaintenanceState(Number(maintenance) as 1 | 0);
|
let result = setMaintenanceState(Number(maintenance) as 1 | 0);
|
||||||
console.log(result);
|
console.log(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleHidden() {
|
||||||
|
showHidden = !showHidden;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class=" m-10">
|
<div
|
||||||
<ProjectModule projectName="ProjectName" checked={false} />
|
class=" grid-cols-[1.5fr, 1fr] grid w-full"
|
||||||
</div>
|
style="grid-template-areas:
|
||||||
|
'a b'; "
|
||||||
|
>
|
||||||
|
<div class=" m-10">
|
||||||
|
{#each data.projects as project}
|
||||||
|
<ProjectModule projectName={project.name} checked={project.enabled} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="m-8 flex w-xl flex-col justify-self-end">
|
||||||
|
<div>
|
||||||
|
<button title="ButtonShowHidden" onclick={toggleHidden}>
|
||||||
|
{#if !showHidden}
|
||||||
|
<EyeOff stroke-width={1} class="text-text-muted-dark" />
|
||||||
|
{:else}
|
||||||
|
<Eye stroke-width={1} />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class=" flex flex-col gap-1">
|
||||||
|
{#each data.nodes as node}
|
||||||
|
{#if showHidden}
|
||||||
|
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||||
|
{/if}
|
||||||
|
{#if !node.name.startsWith('.') && !showHidden}
|
||||||
|
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class=" mt-4">
|
<div class=" mt-4">
|
||||||
<Construction strokeWidth={1} />
|
<Construction strokeWidth={1} />
|
||||||
<label
|
<label
|
||||||
for='maintenence'
|
for="maintenence"
|
||||||
class="relative m-2 ml-auto block h-5 w-10 cursor-pointer rounded-full bg-bg-lighter-dark shadow-subtle"
|
class="relative m-2 ml-auto block h-5 w-10 cursor-pointer rounded-full bg-bg-lighter-dark shadow-subtle"
|
||||||
>
|
>
|
||||||
<input type="checkbox" checked={maintenance} onclick={async () => await setMaintenanceState(Number(!maintenance))} id='maintenence' class=" peer sr-only" />
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={maintenance}
|
||||||
|
onclick={async () => await setMaintenanceState(Number(!maintenance))}
|
||||||
|
id="maintenence"
|
||||||
|
class=" peer sr-only"
|
||||||
|
/>
|
||||||
<span
|
<span
|
||||||
class=" absolute top-0.5 left-0.5 h-4/5 w-2/5 rounded-full bg-bg-dark peer-checked:left-5.5 peer-checked:bg-primary-dark"
|
class=" absolute top-0.5 left-0.5 h-4/5 w-2/5 rounded-full bg-bg-dark peer-checked:left-5.5 peer-checked:bg-primary-dark"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { query } from "$app/server";
|
import { query } from '$app/server';
|
||||||
import { db } from "$lib/server/db";
|
import { db } from '$lib/server/db';
|
||||||
import { settings } from "$lib/server/db/schema";
|
import { settings } from '$lib/server/db/schema';
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from 'drizzle-orm';
|
||||||
import z from "zod";
|
import z from 'zod';
|
||||||
|
|
||||||
export const setMaintenanceState = query(z.number(), async (state) => {
|
export const setMaintenanceState = query(z.number(), async (state) => {
|
||||||
await db.update(settings)
|
await db.update(settings).set({ state }).where(eq(settings.var, 'maintenance'));
|
||||||
.set({ state })
|
|
||||||
.where(eq(settings.var, 'maintenance'));
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { MD5 } from '$lib/termos/util/hash';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
console.log(MD5.hash(''));
|
||||||
|
console.log(MD5.hash('a'));
|
||||||
|
console.log(MD5.hash('abc'));
|
||||||
|
|
||||||
|
onMount(() => {});
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user