-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
168 lines (158 loc) · 5.28 KB
/
index.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
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
<?php
// These are the delta for height and width since my version of rrd graph
// doesn't have the "final size" option
$dw = 97;
$dh = 79;
$params = array("dur" => "3h",
"width" => 2*(550 - $dw)+$dw,
"height" => 309 - $dh,
);
$graphs = array("Combined Traffic" => "combined",
"Inbound Traffic" => "in",
"Outbound Traffic" => "out",
"Solar Output" => "solar"
);
$paramList = array();
foreach($params as $k => $v)
{
if(array_key_exists($k, $_GET)) {
$params[$k] = $_GET[$k];
}
$paramList[] = "$k=$params[$k]";
}
$paramString = implode("&", $paramList);
$intervals = array("3h", "8h", "12h", "1d", "3d", "1week", "2weeks", "1month");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="icon" href="http://www.toasterwaffles.com/favicon.ico" type="image/x-icon" />
<link rel="icon" href="http://www.toasterwaffles.com/favicon.gif" type="image/gif" />
<title>Traffic stats</title>
<style type="text/css">
body {
background: #232323;
color: white;
font-family: Verdana, sans-serif;
font-size: x-small;
}
div#graph { width: <?php echo $params['width'] + $dw ?>px;
height: <?php echo $params['height'] + $dh ?>px; }
div#container {
width: <?php echo $params['width'] + $dw ?>px;
margin: 0 auto;
}
div.loading { background: url(/spinner.gif) no-repeat center center; }
h2 { text-align: center; }
a:link,a:visited { color: #00cee6; }
li {
display: inline;
list-style-type: none;
padding: 0em .5em;
text-align: center;
}
ul { text-align: center; }
ul li:before { content: "| "; }
ul li:first-child:before { content: ""; }
</style>
<script type="text/javascript" src="/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/jquery.throbber.min.js"></script>
<script type="text/javascript">
var dur = "<?php echo $params['dur'] ?>";
var width = <?php echo $params['width'] ?>;
var graph = "combined";
var height = <?php echo $params['height'] ?>;
function updateHeader() {
$("#header").text('Looking at '+dur+' of data');
}
function updateDur(newDur) {
dur = newDur;
updateHeader();
loader();
$('#graph_message').text('');
}
function updateGraph(newGraph) {
graph = newGraph;
loader();
$('#graph_message').text('');
}
</script>
</head>
<body>
<div id="container">
<h2 id="header"></h2>
<script type="text/javascript">updateHeader()</script>
<div id="nav">
<ul>
<?php
foreach ( $graphs as $desc => $g ) {
?>
<li><a href="#" onClick="updateGraph('<?php echo $g ?>');"><?php echo $desc; ?></a></li>
<?php
}
?>
</ul>
<ul>
<?php
foreach ( $intervals as $int ) {
?>
<li><a href="#" onClick="updateDur('<?php echo $int ?>');"><?php echo $int; ?></a></li>
<?php
}
?>
</ul>
</div>
<div id="graph"></div>
<div id="graph_message"></div>
</div>
<script type="text/javascript">
var timer;
var loader = function() {
timer = clearTimeout(timer);
$('#graph').empty();
$('#graph').addClass('loading');
params = getParams(graph);
var img = new Image();
$(img)
.load(function() {
$(this).hide();
$('#graph').removeClass('loading').append(this);
$(this).fadeIn();
<?php
if (substr_count(getcwd(), "dev") > 0) {
?>
$('#graph_message').text('updated with params = '+params);
<?php
} else {
?>
$('#graph_message').text('updated '+(new Date()).toLocaleString());
<?php
}
?>
})
.error(function() { $('#graph_message').text("Error updating: params = "+params); } )
.attr('src', params);
timer = setTimeout("loader()", 1000*60*5);
};
function getParams(graph) {
d = new Date()
k = d.getTime()
givens = "k="+k+"&dur="+dur+"&width="+width+"&height="+height;
switch(graph)
{
case "combined":
return "./draw-combined.php?"+givens;
break;
case "in":
case "out":
return "./draw-directions.php?dir="+graph+"&"+givens;
break;
default:
return "./draw-"+graph+".php?"+givens;
break;
}
}
loader();
</script>
</body>
</html>