-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-viewer.php
More file actions
214 lines (197 loc) Β· 7.53 KB
/
Copy pathlog-viewer.php
File metadata and controls
214 lines (197 loc) Β· 7.53 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
<?php
require_once 'includes/config.php';
require_once 'includes/auth-functions.php';
require_once 'includes/functions.php';
// Start session and check admin authentication
session_start();
require_authentication();
$current_user = get_current_user();
if ($current_user['role'] !== 'admin') {
redirect_to('dashboard.php');
}
// Get log files
$log_files = array(
'access.log' => 'Access Log',
'error.log' => 'Error Log',
'security.log' => 'Security Log',
'admin.log' => 'Admin Actions',
'file-operations.log' => 'File Operations'
);
$selected_log = isset($_GET['log']) ? $_GET['log'] : 'access.log';
$lines_to_show = isset($_GET['lines']) ? (int)$_GET['lines'] : 50;
// Read log file
$log_content = array();
if (isset($log_files[$selected_log])) {
$log_path = STORAGE_DIR . '/logs/' . $selected_log;
if (file_exists($log_path)) {
$all_lines = file($log_path, FILE_IGNORE_NEW_LINES);
$log_content = array_slice(array_reverse($all_lines), 0, $lines_to_show);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log Viewer - FileServer Admin</title>
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="assets/css/admin.css">
<style>
.log-viewer {
background: #1e1e1e;
color: #d4d4d4;
font-family: 'Courier New', monospace;
font-size: 12px;
padding: 20px;
border-radius: 5px;
max-height: 600px;
overflow-y: auto;
white-space: pre-wrap;
margin: 20px 0;
}
.log-controls {
margin: 20px 0;
display: flex;
gap: 15px;
align-items: center;
flex-wrap: wrap;
}
.log-line {
margin: 2px 0;
padding: 2px 0;
}
.log-line.error { color: #ff6b6b; }
.log-line.security { color: #ffd93d; }
.log-line.admin { color: #6bcf7f; }
.log-line.info { color: #74c0fc; }
.log-stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-card {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
text-align: center;
}
</style>
</head>
<body>
<?php include 'templates/header.html'; ?>
<?php include 'templates/navigation.html'; ?>
<div class="container">
<div class="admin-header">
<h1>π Log Viewer</h1>
<p>Monitor system activity and events</p>
</div>
<div class="log-controls">
<label for="log-select">Log File:</label>
<select id="log-select" onchange="changeLog()">
<?php foreach ($log_files as $file => $label): ?>
<option value="<?php echo $file; ?>" <?php echo $selected_log === $file ? 'selected' : ''; ?>>
<?php echo $label; ?>
</option>
<?php endforeach; ?>
</select>
<label for="lines-select">Lines:</label>
<select id="lines-select" onchange="changeLines()">
<option value="25" <?php echo $lines_to_show === 25 ? 'selected' : ''; ?>>25</option>
<option value="50" <?php echo $lines_to_show === 50 ? 'selected' : ''; ?>>50</option>
<option value="100" <?php echo $lines_to_show === 100 ? 'selected' : ''; ?>>100</option>
<option value="200" <?php echo $lines_to_show === 200 ? 'selected' : ''; ?>>200</option>
</select>
<button onclick="refreshLogs()" class="btn btn-primary">π Refresh</button>
<button onclick="clearLog()" class="btn btn-warning">ποΈ Clear Log</button>
</div>
<div class="log-stats">
<div class="stat-card">
<h3>π Log File</h3>
<div class="stat-number"><?php echo $log_files[$selected_log]; ?></div>
</div>
<div class="stat-card">
<h3>π Total Lines</h3>
<div class="stat-number"><?php echo count($log_content); ?></div>
</div>
<div class="stat-card">
<h3>π File Size</h3>
<div class="stat-number">
<?php
$log_path = STORAGE_DIR . '/logs/' . $selected_log;
echo file_exists($log_path) ? format_file_size(filesize($log_path)) : '0 B';
?>
</div>
</div>
<div class="stat-card">
<h3>π Last Modified</h3>
<div class="stat-number">
<?php
$log_path = STORAGE_DIR . '/logs/' . $selected_log;
echo file_exists($log_path) ? date('M j, Y g:i A', filemtime($log_path)) : 'N/A';
?>
</div>
</div>
</div>
<div class="log-viewer" id="log-content">
<?php if (empty($log_content)): ?>
<div style="text-align: center; color: #999; padding: 40px;">
π No log entries found or log file is empty
</div>
<?php else: ?>
<?php foreach ($log_content as $line): ?>
<?php
$class = 'info';
if (strpos($line, '[ERROR]') !== false) $class = 'error';
elseif (strpos($line, '[SECURITY]') !== false) $class = 'security';
elseif (strpos($line, '[ADMIN]') !== false) $class = 'admin';
?>
<div class="log-line <?php echo $class; ?>"><?php echo htmlspecialchars($line); ?></div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php include 'templates/footer.html'; ?>
<script>
function changeLog() {
const log = document.getElementById('log-select').value;
const lines = document.getElementById('lines-select').value;
window.location.href = `log-viewer.php?log=${log}&lines=${lines}`;
}
function changeLines() {
const log = document.getElementById('log-select').value;
const lines = document.getElementById('lines-select').value;
window.location.href = `log-viewer.php?log=${log}&lines=${lines}`;
}
function refreshLogs() {
location.reload();
}
function clearLog() {
const log = document.getElementById('log-select').value;
if (confirm(`Are you sure you want to clear the ${log} file? This action cannot be undone.`)) {
fetch('api/admin.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'clear_log',
log_file: log
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert('Error clearing log: ' + data.message);
}
});
}
}
// Auto-refresh every 30 seconds
setInterval(refreshLogs, 30000);
</script>
</body>
</html>