This commit is contained in:
David Schroeder
2026-07-26 10:33:50 -05:00
parent 60a739a1aa
commit 0ed0fb5817
8 changed files with 35 additions and 63 deletions
+6 -24
View File
@@ -207,7 +207,7 @@ func (s *Server) listAuditEventTypes(r *http.Request) ([]string, error) {
func auditQuery(filters auditFilters, limit int) (string, []any) {
query := `SELECT ae.event_type, COALESCE(a.customer_label, ''), ae.actor,
ae.hostname, ae.package_slug, ae.source_ip, ae.lan_ip,
ae.hostname, ae.package_slug, ae.source_ip,
ae.details, ae.created_at
FROM audit_events ae
LEFT JOIN authorizations a ON a.id = ae.authorization_id
@@ -244,8 +244,8 @@ func auditQuery(filters auditFilters, limit int) (string, []any) {
arguments = append(arguments, filter.value)
}
if filters.SourceIP != "" {
query += " AND (LOCATE(?, ae.source_ip) > 0 OR LOCATE(?, ae.lan_ip) > 0)"
arguments = append(arguments, filters.SourceIP, filters.SourceIP)
query += " AND LOCATE(?, ae.source_ip) > 0"
arguments = append(arguments, filters.SourceIP)
}
query += " ORDER BY ae.created_at DESC LIMIT ?"
arguments = append(arguments, limit)
@@ -274,7 +274,6 @@ func (s *Server) listAuditEvents(r *http.Request, filters auditFilters, limit in
&record.Hostname,
&record.PackageSlug,
&record.SourceIP,
&record.LANIP,
&record.Details,
&record.CreatedAt,
); err != nil {
@@ -623,23 +622,6 @@ func (s *Server) audit(
packageSlug string,
sourceIP string,
details string,
) error {
return s.auditWithNetwork(
ctx, eventType, user, authorizationID, hostname, packageSlug,
sourceIP, "", details,
)
}
func (s *Server) auditWithNetwork(
ctx context.Context,
eventType string,
user string,
authorizationID *uint64,
hostname string,
packageSlug string,
sourceIP string,
lanIP string,
details string,
) error {
var authID any
if authorizationID != nil {
@@ -649,9 +631,9 @@ func (s *Server) auditWithNetwork(
ctx,
`INSERT INTO audit_events
(event_type, actor, authorization_id, hostname, package_slug,
source_ip, lan_ip, details)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
eventType, user, authID, hostname, packageSlug, sourceIP, lanIP, details,
source_ip, details)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
eventType, user, authID, hostname, packageSlug, sourceIP, details,
)
return err
}