update
This commit is contained in:
@@ -207,7 +207,8 @@ 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.details, ae.created_at
|
||||
ae.hostname, ae.package_slug, ae.source_ip, ae.lan_ip,
|
||||
ae.details, ae.created_at
|
||||
FROM audit_events ae
|
||||
LEFT JOIN authorizations a ON a.id = ae.authorization_id
|
||||
WHERE 1 = 1`
|
||||
@@ -233,7 +234,6 @@ func auditQuery(filters auditFilters, limit int) (string, []any) {
|
||||
{"ae.actor", filters.User},
|
||||
{"ae.hostname", filters.Hostname},
|
||||
{"ae.package_slug", filters.PackageSlug},
|
||||
{"ae.source_ip", filters.SourceIP},
|
||||
{"ae.details", filters.Details},
|
||||
}
|
||||
for _, filter := range containsFilters {
|
||||
@@ -243,6 +243,10 @@ func auditQuery(filters auditFilters, limit int) (string, []any) {
|
||||
query += " AND LOCATE(?, " + filter.column + ") > 0"
|
||||
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 += " ORDER BY ae.created_at DESC LIMIT ?"
|
||||
arguments = append(arguments, limit)
|
||||
return query, arguments
|
||||
@@ -270,6 +274,7 @@ 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 {
|
||||
@@ -618,6 +623,23 @@ 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 {
|
||||
@@ -626,9 +648,10 @@ func (s *Server) audit(
|
||||
_, err := s.db.ExecContext(
|
||||
ctx,
|
||||
`INSERT INTO audit_events
|
||||
(event_type, actor, authorization_id, hostname, package_slug, source_ip, details)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
eventType, user, authID, hostname, packageSlug, sourceIP, details,
|
||||
(event_type, actor, authorization_id, hostname, package_slug,
|
||||
source_ip, lan_ip, details)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
eventType, user, authID, hostname, packageSlug, sourceIP, lanIP, details,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user