-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadmin_audit_logs.templ
More file actions
377 lines (370 loc) · 14.2 KB
/
Copy pathadmin_audit_logs.templ
File metadata and controls
377 lines (370 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package templates
import (
"fmt"
"net/url"
"github.com/go-authgate/authgate/internal/models"
)
templ AdminAuditLogs(props AuditLogsPageProps) {
@Layout("Audit Logs", LayoutAdminNavbar, &props.NavbarProps) {
<div class="main-content">
<div class="card">
@Breadcrumb([]BreadcrumbItem{
{Label: "Admin", Href: "/admin/clients"},
{Label: "Audit Logs", Href: ""},
})
<!-- Page Header -->
<div class="audit-logs-header">
<h1 class="audit-logs-title">
<span class="audit-logs-title-icon">
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
</span>
<span>Audit Logs</span>
</h1>
if props.TotalItems > 0 {
<div class="audit-logs-count">
<span>Total Events:</span>
<span class="audit-logs-count-number">{ fmt.Sprintf("%d", props.TotalItems) }</span>
</div>
}
</div>
<!-- Filters -->
@SfToolbar() {
<form method="GET" action="/admin/audit">
<div class="sf-search-row">
<div class="sf-search-field">
<span class="search-icon">
@SearchIcon()
</span>
<input
type="text"
name="search"
class="search-input"
placeholder="Search action, resource, username, full name..."
value={ props.Search }
data-debounce-search
/>
</div>
<select name="page_size" class="page-size-select" onchange="this.form.submit()">
<option value="20" selected?={ props.PageSize == 20 }>20 items</option>
<option value="50" selected?={ props.PageSize == 50 }>50 items</option>
<option value="100" selected?={ props.PageSize == 100 }>100 items</option>
</select>
<button type="submit" class="search-btn">Apply Filters</button>
<a href="/admin/audit" class="clear-btn">Clear</a>
<div class="sf-extra-buttons">
<a href={ templ.URL("/admin/audit/export?" + props.QueryString) } class="audit-btn audit-btn-export">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
<span>Export CSV</span>
</a>
</div>
</div>
<!-- Advanced Filters Toggle -->
<div class="audit-filters-toggle-row">
<button
type="button"
id="toggle-filters-btn"
class="audit-filters-toggle-btn"
onclick="toggleFilters()"
aria-expanded="true"
aria-controls="audit-advanced-filters"
>
<span class="toggle-filters-text">Hide Filters</span>
<svg class="toggle-filters-icon" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transition:transform var(--transition-fast);transform:rotate(180deg);">
<path d="M4 6l4 4 4-4"></path>
</svg>
</button>
</div>
<!-- Advanced Filters -->
<div class="audit-advanced-filters" id="audit-advanced-filters">
<div class="audit-filter-group">
<label class="search-label">Event Type</label>
<select name="event_type" class="audit-filter-select">
<option value="">All Events</option>
<option value="AUTHENTICATION_SUCCESS" selected?={ props.EventType == "AUTHENTICATION_SUCCESS" }>Auth Success</option>
<option value="AUTHENTICATION_FAILURE" selected?={ props.EventType == "AUTHENTICATION_FAILURE" }>Auth Failure</option>
<option value="OAUTH_AUTHENTICATION" selected?={ props.EventType == "OAUTH_AUTHENTICATION" }>OAuth Auth</option>
<option value="LOGOUT" selected?={ props.EventType == "LOGOUT" }>Logout</option>
<option value="ACCESS_TOKEN_ISSUED" selected?={ props.EventType == "ACCESS_TOKEN_ISSUED" }>Token Issued</option>
<option value="TOKEN_REFRESHED" selected?={ props.EventType == "TOKEN_REFRESHED" }>Token Refreshed</option>
<option value="TOKEN_REVOKED" selected?={ props.EventType == "TOKEN_REVOKED" }>Token Revoked</option>
<option value="TOKEN_DISABLED" selected?={ props.EventType == "TOKEN_DISABLED" }>Token Disabled</option>
<option value="TOKEN_ENABLED" selected?={ props.EventType == "TOKEN_ENABLED" }>Token Enabled</option>
<option value="DEVICE_CODE_GENERATED" selected?={ props.EventType == "DEVICE_CODE_GENERATED" }>Device Code Generated</option>
<option value="DEVICE_CODE_AUTHORIZED" selected?={ props.EventType == "DEVICE_CODE_AUTHORIZED" }>Device Code Authorized</option>
<option value="CLIENT_CREATED" selected?={ props.EventType == "CLIENT_CREATED" }>Client Created</option>
<option value="CLIENT_UPDATED" selected?={ props.EventType == "CLIENT_UPDATED" }>Client Updated</option>
<option value="CLIENT_DELETED" selected?={ props.EventType == "CLIENT_DELETED" }>Client Deleted</option>
<option value="CLIENT_SECRET_REGENERATED" selected?={ props.EventType == "CLIENT_SECRET_REGENERATED" }>Secret Regenerated</option>
<option value="RATE_LIMIT_EXCEEDED" selected?={ props.EventType == "RATE_LIMIT_EXCEEDED" }>Rate Limit Exceeded</option>
</select>
</div>
<div class="audit-filter-group">
<label class="search-label">Severity</label>
<select name="severity" class="audit-filter-select">
<option value="">All</option>
<option value="INFO" selected?={ props.Severity == "INFO" }>Info</option>
<option value="WARNING" selected?={ props.Severity == "WARNING" }>Warning</option>
<option value="ERROR" selected?={ props.Severity == "ERROR" }>Error</option>
<option value="CRITICAL" selected?={ props.Severity == "CRITICAL" }>Critical</option>
</select>
</div>
<div class="audit-filter-group">
<label class="search-label">Status</label>
<select name="success" class="audit-filter-select">
<option value="">All</option>
<option value="true" selected?={ props.Success == "true" }>Success</option>
<option value="false" selected?={ props.Success == "false" }>Failed</option>
</select>
</div>
<div class="audit-filter-group">
<label class="search-label">Actor IP</label>
<input type="text" name="actor_ip" class="audit-filter-input" placeholder="e.g., 192.168.1.1" value={ props.ActorIP }/>
</div>
</div>
</form>
}
<!-- Table -->
if len(props.Logs) > 0 {
<div class="audit-table-wrapper">
<table class="audit-logs-table">
<thead>
<tr>
<th>Time</th>
<th>Event Type</th>
<th>Severity</th>
<th>Actor</th>
<th>Action</th>
<th>Resource</th>
<th>IP Address</th>
<th style="text-align: center;">Status</th>
</tr>
</thead>
<tbody>
for _, log := range props.Logs {
@AuditLogRow(log)
}
</tbody>
</table>
</div>
<!-- Pagination -->
if props.TotalPages > 0 {
@AuditLogsPagination(props)
}
} else {
<!-- Empty State -->
<div class="empty-state">
if props.Search != "" {
@EmptyStateSearch()
} else {
@EmptyStateAudit()
}
<h3 class="empty-title">
if props.Search != "" {
No audit logs found
} else {
No Audit Logs Yet
}
</h3>
<p class="empty-text">
if props.Search != "" {
Try adjusting your search terms or filters to find what you're looking for.
} else {
Audit logs will appear here as actions are performed in the system. Activities like authentication, token operations, and admin actions are logged automatically.
}
</p>
</div>
}
</div>
</div>
}
}
// humanReadableEventType converts raw event type constants to friendly labels.
func humanReadableEventType(eventType models.EventType) string {
switch eventType {
case models.EventAuthenticationSuccess:
return "Login Success"
case models.EventAuthenticationFailure:
return "Login Failure"
case models.EventOAuthAuthentication:
return "OAuth Login"
case models.EventLogout:
return "Logout"
case models.EventAccessTokenIssued:
return "Token Issued"
case models.EventRefreshTokenIssued:
return "Refresh Token Issued"
case models.EventIDTokenIssued:
return "ID Token Issued"
case models.EventTokenRefreshed:
return "Token Refreshed"
case models.EventTokenRevoked:
return "Token Revoked"
case models.EventTokenDisabled:
return "Token Disabled"
case models.EventTokenEnabled:
return "Token Enabled"
case models.EventTokenIntrospected:
return "Token Introspected"
case models.EventDeviceCodeGenerated:
return "Device Code Created"
case models.EventDeviceCodeAuthorized:
return "Device Authorized"
case models.EventAuthorizationCodeGenerated:
return "Auth Code Generated"
case models.EventAuthorizationCodeExchanged:
return "Auth Code Exchanged"
case models.EventAuthorizationCodeDenied:
return "Auth Code Denied"
case models.EventClientCreated:
return "Client Created"
case models.EventClientUpdated:
return "Client Updated"
case models.EventClientDeleted:
return "Client Deleted"
case models.EventClientSecretRegenerated:
return "Secret Regenerated"
case models.EventClientRegistered:
return "Client Registered"
case models.EventClientApproved:
return "Client Approved"
case models.EventClientRejected:
return "Client Rejected"
case models.EventClientCredentialsTokenIssued:
return "Client Credentials Issued"
case models.EventRateLimitExceeded:
return "Rate Limited"
case models.EventSuspiciousActivity:
return "Suspicious Activity"
case models.EventUserAuthorizationGranted:
return "Access Granted"
case models.EventUserAuthorizationRevoked:
return "Access Revoked"
case models.EventClientTokensRevokedAll:
return "All Tokens Revoked"
case models.EventTypeAuditLogView:
return "Audit Log Viewed"
case models.EventTypeAuditLogExported:
return "Audit Log Exported"
default:
return string(eventType)
}
}
templ AuditLogRow(log *models.AuditLog) {
<tr>
<td class="audit-timestamp-cell" data-label="Time">
<div class="audit-timestamp-date">{ log.EventTime.Format("2006-01-02") }</div>
<div class="audit-timestamp-time">{ log.EventTime.Format("15:04:05") }</div>
<div class="audit-timestamp-relative" data-timestamp={ log.EventTime.Format("2006-01-02T15:04:05Z07:00") }></div>
</td>
<td data-label="Event Type">
<span class="audit-event-type" title={ log.EventType }>{ humanReadableEventType(log.EventType) }</span>
</td>
<td data-label="Severity">
if log.Severity == "INFO" {
<span class="audit-severity-badge severity-info">{ log.Severity }</span>
} else if log.Severity == "WARNING" {
<span class="audit-severity-badge severity-warning">{ log.Severity }</span>
} else if log.Severity == "ERROR" {
<span class="audit-severity-badge severity-error">{ log.Severity }</span>
} else if log.Severity == "CRITICAL" {
<span class="audit-severity-badge severity-critical">{ log.Severity }</span>
}
</td>
<td data-label="Actor">
if log.ActorUsername != "" {
<span class="audit-actor">{ UserDisplay(log.ActorUsername, log.ActorFullName) }</span>
} else {
<span class="audit-actor-system">System</span>
}
</td>
<td data-label="Action">
<div class="audit-action">{ log.Action }</div>
if log.ErrorMessage != "" {
<div class="audit-error-message">
{ log.ErrorMessage }
</div>
}
</td>
<td class="audit-resource" data-label="Resource">
if log.ResourceName != "" {
{ log.ResourceName }
} else if log.ResourceID != "" {
{ log.ResourceID }
} else {
<span class="audit-resource-empty">—</span>
}
</td>
<td data-label="IP Address">
<span class="audit-ip">{ log.ActorIP }</span>
</td>
<td style="text-align: center;" data-label="Status">
if log.Success {
<span class="audit-status-badge status-success">✓</span>
} else {
<span class="audit-status-badge status-failed">✗</span>
}
</td>
</tr>
}
func buildAuditPaginationURL(page, pageSize int, search, eventType, severity, success, actorIP string) string {
u := fmt.Sprintf("/admin/audit?page=%d&page_size=%d", page, pageSize)
if search != "" {
u += "&search=" + url.QueryEscape(search)
}
if eventType != "" {
u += "&event_type=" + url.QueryEscape(eventType)
}
if severity != "" {
u += "&severity=" + url.QueryEscape(severity)
}
if success != "" {
u += "&success=" + url.QueryEscape(success)
}
if actorIP != "" {
u += "&actor_ip=" + url.QueryEscape(actorIP)
}
return u
}
templ AuditLogsPagination(props AuditLogsPageProps) {
<div class="pagination-container">
<div class="pagination-info">
<span>Showing page</span>
<span class="pagination-info-total">{ fmt.Sprintf("%d", props.Page) }</span>
<span>of</span>
<span class="pagination-info-total">{ fmt.Sprintf("%d", props.TotalPages) }</span>
</div>
<div class="pagination-controls">
if props.Page > 1 {
<a
href={ templ.URL(buildAuditPaginationURL(props.PrevPage, props.PageSize, props.Search, props.EventType, props.Severity, props.Success, props.ActorIP)) }
class="pagination-button"
>
<span class="pagination-button-icon">←</span>
<span>Previous</span>
</a>
} else {
<button class="pagination-button" disabled>
<span class="pagination-button-icon">←</span>
<span>Previous</span>
</button>
}
<span class="pagination-current">
Page { fmt.Sprintf("%d", props.Page) } of { fmt.Sprintf("%d", props.TotalPages) }
</span>
if props.Page < props.TotalPages {
<a
href={ templ.URL(buildAuditPaginationURL(props.NextPage, props.PageSize, props.Search, props.EventType, props.Severity, props.Success, props.ActorIP)) }
class="pagination-button"
>
<span>Next</span>
<span class="pagination-button-icon">→</span>
</a>
} else {
<button class="pagination-button" disabled>
<span>Next</span>
<span class="pagination-button-icon">→</span>
</button>
}
</div>
</div>
}