Security fixes: - Add HTTP method validation to delete_comment.php (block CSRF via GET) - Remove $_GET fallback in comment deletion (was CSRF bypass vector) - Guard session_start() with session_status() check across API files - Escape json_encode() data attributes with htmlspecialchars in views - Escape inline APP_TIMEZONE config values in DashboardView/TicketView - Validate timezone param against DateTimeZone::listIdentifiers() in index.php - Remove Database::escape() (was using real_escape_string, not safe) - Fix AttachmentModel hardcoded connection; inject via constructor Backend fixes: - Fix CommentModel bind_param type for ticket_id (s→i) - Fix buildCommentThread orphan parent guard - Fix StatsModel JOIN→LEFT JOIN so unassigned tickets aren't excluded - Add ticket ID validation in BulkOperationsModel before implode() - Add duplicate key retry in TicketModel::createTicket() for race conditions - Wrap SavedFiltersModel default filter changes in transactions - Add null result guards in WorkflowModel query methods Frontend JS: - Rewrite toast.js as lt.toast shim (base.js dependency) - Delegate escapeHtml() to lt.escHtml() - Rewrite keyboard-shortcuts.js using lt.keys.on() - Migrate settings.js to lt.api.* and lt.modal.open/close() - Migrate advanced-search.js to lt.api.* and lt.modal.open/close() - Migrate dashboard.js fetch calls to lt.api.*; update all dynamic modals (bulk ops, quick actions, confirm/input) to lt-modal structure - Migrate ticket.js fetchMentionUsers to lt.api.get() - Remove console.log/error/warn calls from JS files Views: - Add /web_template/base.css and base.js to all 10 view files - Call lt.keys.initDefaults() in DashboardView, TicketView, admin views - Migrate all modal HTML from settings-modal/settings-content to lt-modal-overlay/lt-modal/lt-modal-header/lt-modal-body/lt-modal-footer - Replace style="display:none" with aria-hidden="true" on all modals - Replace modal open/close style.display with lt.modal.open/close() - Update modal buttons to lt-btn lt-btn-primary/lt-btn-ghost classes - Remove manual ESC keydown handlers (replaced by lt.keys.initDefaults) - Fix unescaped timezone values in TicketView inline script Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
160 lines
9.4 KiB
PHP
160 lines
9.4 KiB
PHP
<?php
|
|
// Admin view for browsing audit logs
|
|
// Receives $auditLogs, $totalPages, $page, $filters from controller
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Audit Log - Admin</title>
|
|
<link rel="icon" type="image/png" href="<?php echo $GLOBALS['config']['ASSETS_URL']; ?>/images/favicon.png">
|
|
<link rel="stylesheet" href="/web_template/base.css">
|
|
<link rel="stylesheet" href="<?php echo $GLOBALS['config']['ASSETS_URL']; ?>/css/dashboard.css">
|
|
<link rel="stylesheet" href="<?php echo $GLOBALS['config']['ASSETS_URL']; ?>/css/ticket.css">
|
|
<script src="/web_template/base.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="user-header">
|
|
<div class="user-header-left">
|
|
<a href="/" class="back-link">← Dashboard</a>
|
|
<span style="margin-left: 1rem; color: var(--terminal-amber);">Admin: Audit Log</span>
|
|
</div>
|
|
<div class="user-header-right">
|
|
<?php if (isset($GLOBALS['currentUser'])): ?>
|
|
<span class="user-name"><?php echo htmlspecialchars($GLOBALS['currentUser']['display_name'] ?? $GLOBALS['currentUser']['username']); ?></span>
|
|
<span class="admin-badge">Admin</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ascii-frame-outer" style="max-width: 1400px; margin: 2rem auto;">
|
|
<span class="bottom-left-corner">╚</span>
|
|
<span class="bottom-right-corner">╝</span>
|
|
|
|
<div class="ascii-section-header">Audit Log Browser</div>
|
|
<div class="ascii-content">
|
|
<div class="ascii-frame-inner">
|
|
<!-- Filters -->
|
|
<form method="GET" style="display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;">
|
|
<div>
|
|
<label style="display: block; font-size: 0.8rem; color: var(--terminal-amber);">Action Type</label>
|
|
<select name="action_type" class="setting-select">
|
|
<option value="">All Actions</option>
|
|
<option value="create" <?php echo ($filters['action_type'] ?? '') === 'create' ? 'selected' : ''; ?>>Create</option>
|
|
<option value="update" <?php echo ($filters['action_type'] ?? '') === 'update' ? 'selected' : ''; ?>>Update</option>
|
|
<option value="delete" <?php echo ($filters['action_type'] ?? '') === 'delete' ? 'selected' : ''; ?>>Delete</option>
|
|
<option value="comment" <?php echo ($filters['action_type'] ?? '') === 'comment' ? 'selected' : ''; ?>>Comment</option>
|
|
<option value="assign" <?php echo ($filters['action_type'] ?? '') === 'assign' ? 'selected' : ''; ?>>Assign</option>
|
|
<option value="status_change" <?php echo ($filters['action_type'] ?? '') === 'status_change' ? 'selected' : ''; ?>>Status Change</option>
|
|
<option value="login" <?php echo ($filters['action_type'] ?? '') === 'login' ? 'selected' : ''; ?>>Login</option>
|
|
<option value="security" <?php echo ($filters['action_type'] ?? '') === 'security' ? 'selected' : ''; ?>>Security</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label style="display: block; font-size: 0.8rem; color: var(--terminal-amber);">User</label>
|
|
<select name="user_id" class="setting-select">
|
|
<option value="">All Users</option>
|
|
<?php if (isset($users)): foreach ($users as $user): ?>
|
|
<option value="<?php echo $user['user_id']; ?>" <?php echo ($filters['user_id'] ?? '') == $user['user_id'] ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($user['display_name'] ?? $user['username']); ?>
|
|
</option>
|
|
<?php endforeach; endif; ?>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label style="display: block; font-size: 0.8rem; color: var(--terminal-amber);">Date From</label>
|
|
<input type="date" name="date_from" value="<?php echo htmlspecialchars($filters['date_from'] ?? ''); ?>" class="setting-select">
|
|
</div>
|
|
<div>
|
|
<label style="display: block; font-size: 0.8rem; color: var(--terminal-amber);">Date To</label>
|
|
<input type="date" name="date_to" value="<?php echo htmlspecialchars($filters['date_to'] ?? ''); ?>" class="setting-select">
|
|
</div>
|
|
<div style="display: flex; align-items: flex-end;">
|
|
<button type="submit" class="btn">Filter</button>
|
|
<a href="?" class="btn btn-secondary" style="margin-left: 0.5rem;">Reset</a>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Log Table -->
|
|
<table style="width: 100%; font-size: 0.9rem;">
|
|
<thead>
|
|
<tr>
|
|
<th>Timestamp</th>
|
|
<th>User</th>
|
|
<th>Action</th>
|
|
<th>Entity</th>
|
|
<th>Entity ID</th>
|
|
<th>Details</th>
|
|
<th>IP Address</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($auditLogs)): ?>
|
|
<tr>
|
|
<td colspan="7" style="text-align: center; padding: 2rem; color: var(--terminal-green-dim);">
|
|
No audit log entries found.
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($auditLogs as $log): ?>
|
|
<tr>
|
|
<td style="white-space: nowrap;"><?php echo date('Y-m-d H:i:s', strtotime($log['created_at'])); ?></td>
|
|
<td><?php echo htmlspecialchars($log['display_name'] ?? $log['username'] ?? 'System'); ?></td>
|
|
<td>
|
|
<span style="color: var(--terminal-amber);"><?php echo htmlspecialchars($log['action_type']); ?></span>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($log['entity_type'] ?? '-'); ?></td>
|
|
<td>
|
|
<?php if ($log['entity_type'] === 'ticket' && $log['entity_id']): ?>
|
|
<a href="/ticket/<?php echo htmlspecialchars($log['entity_id']); ?>" style="color: var(--terminal-green);">
|
|
<?php echo htmlspecialchars($log['entity_id']); ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<?php echo htmlspecialchars($log['entity_id'] ?? '-'); ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td style="max-width: 300px; overflow: hidden; text-overflow: ellipsis;">
|
|
<?php
|
|
if ($log['details']) {
|
|
$details = is_string($log['details']) ? json_decode($log['details'], true) : $log['details'];
|
|
if (is_array($details)) {
|
|
echo '<code style="font-size: 0.8rem;">' . htmlspecialchars(json_encode($details)) . '</code>';
|
|
} else {
|
|
echo htmlspecialchars($log['details']);
|
|
}
|
|
} else {
|
|
echo '-';
|
|
}
|
|
?>
|
|
</td>
|
|
<td style="white-space: nowrap; font-size: 0.85rem;"><?php echo htmlspecialchars($log['ip_address'] ?? '-'); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<!-- Pagination -->
|
|
<?php if ($totalPages > 1): ?>
|
|
<div class="pagination" style="margin-top: 1rem; text-align: center;">
|
|
<?php
|
|
$params = $_GET;
|
|
for ($i = 1; $i <= min($totalPages, 10); $i++) {
|
|
$params['page'] = $i;
|
|
$activeClass = ($i == $page) ? 'active' : '';
|
|
$url = '?' . http_build_query($params);
|
|
echo "<a href='$url' class='btn btn-small $activeClass'>$i</a> ";
|
|
}
|
|
if ($totalPages > 10) {
|
|
echo "...";
|
|
}
|
|
?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|