Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat: admin audit log — merged PR #118

Mauricede859318faca
diff --cc client/package-lock.json
index 9a806710e,9a806710e..5dc9bc02e
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@@ -1,12 -1,12 +1,12 @@@
{
"name": "trek-client",
-- "version": "2.6.2",
++ "version": "2.7.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "trek-client",
-- "version": "2.6.2",
++ "version": "2.7.0",
"dependencies": {
"@react-pdf/renderer": "^4.3.2",
"axios": "^1.6.7",
diff --cc server/src/db/migrations.ts
index 3f468d7b0,7d59ef58b..963cff2c3
--- a/server/src/db/migrations.ts
+++ b/server/src/db/migrations.ts
@@@ -322,63 -322,19 +322,78 @@@ function runMigrations(db: Database.Dat
)`);
},
() => {
+ // Add day_plan_position to reservations for persistent transport ordering in day timeline
+ try { db.exec('ALTER TABLE reservations ADD COLUMN day_plan_position REAL DEFAULT NULL'); } catch {}
+ },
+ () => {
+ // Add paid_by_user_id to budget_items for expense tracking / settlement
+ try { db.exec('ALTER TABLE budget_items ADD COLUMN paid_by_user_id INTEGER REFERENCES users(id)'); } catch {}
+ },
+ () => {
+ // Add target_date to bucket_list for optional visit planning
+ try { db.exec('ALTER TABLE bucket_list ADD COLUMN target_date TEXT DEFAULT NULL'); } catch {}
+ },
+ () => {
+ // Notification preferences per user
+ db.exec(`CREATE TABLE IF NOT EXISTS notification_preferences (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ notify_trip_invite INTEGER DEFAULT 1,
+ notify_booking_change INTEGER DEFAULT 1,
+ notify_trip_reminder INTEGER DEFAULT 1,
+ notify_vacay_invite INTEGER DEFAULT 1,
+ notify_photos_shared INTEGER DEFAULT 1,
+ notify_collab_message INTEGER DEFAULT 1,
+ notify_packing_tagged INTEGER DEFAULT 1,
+ notify_webhook INTEGER DEFAULT 0,
+ UNIQUE(user_id)
+ )`);
+ },
+ () => {
+ // Add missing notification preference columns for existing tables
+ try { db.exec('ALTER TABLE notification_preferences ADD COLUMN notify_vacay_invite INTEGER DEFAULT 1'); } catch {}
+ try { db.exec('ALTER TABLE notification_preferences ADD COLUMN notify_photos_shared INTEGER DEFAULT 1'); } catch {}
+ try { db.exec('ALTER TABLE notification_preferences ADD COLUMN notify_collab_message INTEGER DEFAULT 1'); } catch {}
+ try { db.exec('ALTER TABLE notification_preferences ADD COLUMN notify_packing_tagged INTEGER DEFAULT 1'); } catch {}
+ },
+ () => {
+ // Public share links for read-only trip access
+ db.exec(`CREATE TABLE IF NOT EXISTS share_tokens (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ token TEXT NOT NULL UNIQUE,
+ created_by INTEGER NOT NULL REFERENCES users(id),
+ share_map INTEGER DEFAULT 1,
+ share_bookings INTEGER DEFAULT 1,
+ share_packing INTEGER DEFAULT 0,
+ share_budget INTEGER DEFAULT 0,
+ share_collab INTEGER DEFAULT 0,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ )`);
+ },
+ () => {
+ // Add permission columns to share_tokens
+ try { db.exec('ALTER TABLE share_tokens ADD COLUMN share_map INTEGER DEFAULT 1'); } catch {}
+ try { db.exec('ALTER TABLE share_tokens ADD COLUMN share_bookings INTEGER DEFAULT 1'); } catch {}
+ try { db.exec('ALTER TABLE share_tokens ADD COLUMN share_packing INTEGER DEFAULT 0'); } catch {}
+ try { db.exec('ALTER TABLE share_tokens ADD COLUMN share_budget INTEGER DEFAULT 0'); } catch {}
+ try { db.exec('ALTER TABLE share_tokens ADD COLUMN share_collab INTEGER DEFAULT 0'); } catch {}
+ },
++ () => {
++ // Audit log
+ db.exec(`
+ CREATE TABLE IF NOT EXISTS audit_log (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ user_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
+ action TEXT NOT NULL,
+ resource TEXT,
+ details TEXT,
+ ip TEXT
+ );
+ CREATE INDEX IF NOT EXISTS idx_audit_log_created ON audit_log(created_at DESC);
+ `);
+ },
];
if (currentVersion < migrations.length) {
diff --cc server/src/index.ts
index 4906f4478,666feb033..a485c139a
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@@ -79,9 -80,36 +80,37 @@@ if (shouldForceHttps)
app.use(express.json({ limit: '100kb' }));
app.use(express.urlencoded({ extended: true }));
+ if (DEBUG) {
+ app.use((req: Request, res: Response, next: NextFunction) => {
+ const startedAt = Date.now();
+ const requestId = Math.random().toString(36).slice(2, 10);
+ const redact = (value: unknown): unknown => {
+ if (!value || typeof value !== 'object') return value;
+ if (Array.isArray(value)) return value.map(redact);
+ const hidden = new Set(['password', 'token', 'jwt', 'authorization', 'cookie', 'client_secret', 'mfa_token', 'code']);
+ const out: Record<string, unknown> = {};
+ for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
+ out[k] = hidden.has(k.toLowerCase()) ? '[REDACTED]' : redact(v);
+ }
+ return out;
+ };
+
+ const safeQuery = redact(req.query);
+ const safeBody = redact(req.body);
+ console.log(`[DEBUG][REQ ${requestId}] ${req.method} ${req.originalUrl} ip=${req.ip} query=${JSON.stringify(safeQuery)} body=${JSON.stringify(safeBody)}`);
+
+ res.on('finish', () => {
+ const elapsedMs = Date.now() - startedAt;
+ console.log(`[DEBUG][RES ${requestId}] ${req.method} ${req.originalUrl} status=${res.statusCode} elapsed_ms=${elapsedMs}`);
+ });
+
+ next();
+ });
+ }
+
// Avatars are public (shown on login, sharing screens)
app.use('/uploads/avatars', express.static(path.join(__dirname, '../uploads/avatars')));
+app.use('/uploads/covers', express.static(path.join(__dirname, '../uploads/covers')));
// All other uploads require authentication
app.get('/uploads/:type/:filename', (req: Request, res: Response) => {
diff --cc server/src/routes/auth.ts
index 23807c847,f752269a4..5229b08e3
--- a/server/src/routes/auth.ts
+++ b/server/src/routes/auth.ts
@@@ -522,27 -512,22 +523,36 @@@ router.get('/app-settings', authenticat
const user = db.prepare('SELECT role FROM users WHERE id = ?').get(authReq.user.id) as { role: string } | undefined;
if (user?.role !== 'admin') return res.status(403).json({ error: 'Admin access required' });
- const { allow_registration, allowed_file_types } = req.body;
- if (allow_registration !== undefined) {
- db.prepare("INSERT OR REPLACE INTO app_settings (key, value) VALUES ('allow_registration', ?)").run(String(allow_registration));
+ const result: Record<string, string> = {};
+ for (const key of ADMIN_SETTINGS_KEYS) {
+ const row = db.prepare("SELECT value FROM app_settings WHERE key = ?").get(key) as { value: string } | undefined;
+ if (row) result[key] = key === 'smtp_pass' ? '••••••••' : row.value;
}
- if (allowed_file_types !== undefined) {
- db.prepare("INSERT OR REPLACE INTO app_settings (key, value) VALUES ('allowed_file_types', ?)").run(String(allowed_file_types));
+ res.json(result);
+});
+
+router.put('/app-settings', authenticate, (req: Request, res: Response) => {
+ const authReq = req as AuthRequest;
+ const user = db.prepare('SELECT role FROM users WHERE id = ?').get(authReq.user.id) as { role: string } | undefined;
+ if (user?.role !== 'admin') return res.status(403).json({ error: 'Admin access required' });
+
+ for (const key of ADMIN_SETTINGS_KEYS) {
+ if (req.body[key] !== undefined) {
+ const val = String(req.body[key]);
+ // Don't save masked password
+ if (key === 'smtp_pass' && val === '••••••••') continue;
+ db.prepare("INSERT OR REPLACE INTO app_settings (key, value) VALUES (?, ?)").run(key, val);
+ }
}
+ writeAudit({
+ userId: authReq.user.id,
+ action: 'settings.app_update',
+ ip: getClientIp(req),
+ details: {
+ allow_registration: allow_registration !== undefined ? Boolean(allow_registration) : undefined,
+ allowed_file_types_changed: allowed_file_types !== undefined,
+ },
+ });
res.json({ success: true });
});