-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemit-logs.php
77 lines (74 loc) · 1.49 KB
/
emit-logs.php
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
<div class="log">
<?php
$page = $_GET['page'];
printLogFileLines( "logs.php", $page );
?>
<table>
<thead>
<tr>
<th>Time</th>
<th>Device</th>
<th>Event</th>
</tr>
</thead>
<tbody>
<?php
if( $page ) {
foreach( $oldLogFilesPrintf as $candidate ) {
$candidateFile = sprintf( $candidate, $page );
if( substr( $candidateFile, -3 ) === ".gz" ) {
$logFh = @gzopen( $candidateFile, "r" );
} else {
$logFh = @fopen( $candidateFile, "r" );
}
if( $logFh ) {
break;
}
}
} else {
$logFh = @fopen( $logFile, "r" );
}
if( $logFh ) {
while( $line = fgets( $logFh )) {
if( ( $matches = parseLogLine( $line ))) {
?>
<tr>
<td><?= sprintf( "%02d-%02d-%02d %02d:%02d:%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6] ) ?></td>
<td><?php
foreach( $devices as $deviceName => $devicePin ) {
if( $devicePin[0] == $matches[7] ) {
print($deviceName);
}
}
?></td>
<td>
<?php
if( $matches[8] == 1 ) {
print( 'On' );
} else if( $matches[8] == 0 ) {
print( 'Off' );
} else {
print( $matches[8] );
}
?>
</td>
</tr>
<?php
}
}
fclose( $logFh );
}
if( !isset( $matches ) || !$matches ) {
?>
<tr>
<td colspan="3">No events logged so far.</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
require( 'emit-current-time.php' );
?>
</div>