-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlive.php
95 lines (87 loc) · 3.14 KB
/
live.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
include 'config.php';
include 'common.php';
logexists();
if (isset($_GET['ajax'])) {
session_start();
$handle = fopen($logpath, 'r'); //open log
if (isset($_SESSION['offset'])) { //this part is executed from 2nd cycle
$rawdata = stream_get_contents($handle, -1, $_SESSION['offset']); //open stream
if ($rawdata !== "") { //only if last cycle got something, process new data, otherwise skip to next cycle
$_SESSION['offset'] += strlen($rawdata); //update offset
$rows=explode("\n", $rawdata, -1); //if more rows are received in the same cycle, divide it. -1 is necessary because last element would be empty
foreach($rows as $row) {
color($row);
echo $rowc;
} //close foreach
} //close if ($rawdata !== "")
} else { //only at the beginning, print last rows
$log=file($logpath);
$rows=count($log)-1 -$startrows;
$counter=1;
while ($counter<=$startrows) {
$row=$log[$rows+$counter];
color($row);
echo $rowc;
$counter++;
} //close while
fseek($handle, 0, SEEK_END); //put the handle at the end of log
$_SESSION['offset'] = ftell($handle);
} //close else of if (isset($_SESSION['offset']))
exit();
} //close if (isset($_GET['ajax']))
function color($row) {
global $rowc;
global $refresh;
global $logpath;
global $timestampcolor;
global $APRSIScolor;
global $RFcolor;
global $TXcolor;
global $RXcolor;
global $pathcolor;
$timestamp=substr($row, 0, 24); //take only the part of the line, where date and time is
$int=substr($row,24,10); //cut interface
$txrx=substr($row,34,2);// cut rx-tx indicator
$body=explode(":",substr($row,36),2);
$path=$body[0];
$comment=$body[1];
$timestampc="<span style='color:".$timestampcolor."'>".$timestamp."</span>";
if (strpos($int,"APRSIS")!==false) {
$intc="<span style='color:".$APRSIScolor."'>".$int.str_repeat(" ",3)."</span>";
}
else {
$intc="<span style='color:".$RFcolor."'>".$int.str_repeat(" ",10 - strlen($int))."</span>";
}
if (strpos($txrx,"T")!==false) {
$txrx="<span style='color:".$TXcolor."'>TX"." </span>";
}
else {
$txrx="<span style='color:".$RXcolor."'>RX"."  </span>";
}
$path="<span style='color:".$pathcolor."'>".$path."</span>";
if ((strpos($int,$_SESSION['if'])!==false) or (strpos($int,"APRSIS")!==false)) {
$rowc=$timestampc." ".$intc." ".$txrx." ".$path.":".$comment."<br>";
}
else {
$rowc=""; //don't print traffic from other radio interfaces than the selected
}
} //close function
?>
<!doctype html> <html lang="en"> <head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://creativecouple.github.io/jquery-timing/jquery-timing.min.js"></script>
<script>
$(function() {
$.repeat(<?php echo $refresh ?>, function() {
$.get('live.php?ajax', function(rawdata) {
$('#tail').append(rawdata);
});
});
});
</script> </head> <body>
<div id="tail"><i>Real time traffic monitor - Starting up...</i><br><br>
<b>TIMESTAMP<?php echo str_repeat(" ",17) ?>INTERF <?php echo str_repeat(" ",3) ?>R/T<?php echo str_repeat(" ",2)?>PATH:BODY</b>
<br></div> </body>
</html>