Self-contained HTTP/HTTPS/TCP/UDP reverse proxy manager written in Go, with SQLite storage, a Bootstrap 5 admin UI (Go templates, no JS framework), and a REST API under /api/v1. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QTXFrNP1imCW7jtfL5SZrw
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/owen/vibeproxy/internal/models"
|
|
)
|
|
|
|
func InsertAuditLog(db *sql.DB, actor, action, target, details string) error {
|
|
_, err := db.Exec(`INSERT INTO audit_logs (actor, action, target, details) VALUES (?, ?, ?, ?)`, actor, action, target, details)
|
|
return err
|
|
}
|
|
|
|
func ListAuditLogs(db *sql.DB, limit, offset int) ([]models.AuditLog, int, error) {
|
|
var total int
|
|
if err := db.QueryRow(`SELECT COUNT(*) FROM audit_logs`).Scan(&total); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if limit <= 0 || limit > 500 {
|
|
limit = 50
|
|
}
|
|
rows, err := db.Query(`SELECT id, timestamp, actor, action, target, details FROM audit_logs ORDER BY id DESC LIMIT ? OFFSET ?`, limit, offset)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
defer rows.Close()
|
|
var out []models.AuditLog
|
|
for rows.Next() {
|
|
var a models.AuditLog
|
|
var ts string
|
|
if err := rows.Scan(&a.ID, &ts, &a.Actor, &a.Action, &a.Target, &a.Details); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
a.Timestamp = parseTime(ts)
|
|
out = append(out, a)
|
|
}
|
|
return out, total, rows.Err()
|
|
}
|