File: index.php

package info (click to toggle)
bandwidthd 2.0.1%2Bcvs20090917-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,568 kB
  • sloc: sh: 2,958; ansic: 2,743; php: 1,263; yacc: 216; makefile: 158; lex: 36; sql: 27
file content (304 lines) | stat: -rw-r--r-- 10,781 bytes parent folder | download | duplicates (9)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?
include("include.php");

if (isset($_GET['group_id']))
	$group_id = $_GET['group_id'];

$db = ConnectDb();
?>

<!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" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<style type="text/css">
v\:* {
  behavior:url(#default#VML);
  }
</style>
<title>DerbyTech Wireless Network</title>
<script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAANV8M8s128eP55wUqCqvWyBQVMYhLIeywhJ0puM4BK8Tp-d4myhTvfxey30oeLPqs-t72AGpR7hBa9w" type="text/javascript"></script>
<link href="bandwidthd.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
//<![CDATA[

var request;  	// XML Request
var map; 		// Our google map

function drawCircle(map,lng,lat,radius) 
	{
	var color = '#0000ff';    // color blue
	var width = 1;             // width pixels
	var d2r = Math.PI/180;   // degrees to radians
	var r2d = 180/Math.PI;   // radians to degrees
	var Clat = (radius/3963)*r2d;   //  using 3963 as earth's radius
	
	var Clng = Clat/Math.cos(lat*d2r);
   	var Cpoints = [];
   	for (var i=0; i < 65; i++) 
		{
		var theta = Math.PI * (i/32);
      	Cx = lng + (Clng * Math.cos(theta));
      	Cy = lat + (Clat * Math.sin(theta));
      	Cpoints.push(new GPoint(Cx,Cy));
   		};
   	map.addOverlay(new GPolyline(Cpoints,color,width));
	}

function drawSlice(map,lng,lat,orientation,degrees,radius) 
	{
	if (degrees == 360)
		{
		drawCircle(map,lng,lat,radius);
		return;
		}

	var color = '#0000ff';    // color blue
	var width = 1;             // width pixels

	var d2r = Math.PI/180;   // degrees to radians
	var r2d = 180/Math.PI;   // radians to degrees

	var Clat = (radius/3963)*r2d;   //  using 3963 as earth's radius	
	var Clng = Clat/Math.cos(lat*d2r);

	var start = (90-orientation-degrees/2)*d2r;
	var end = (90-orientation+degrees/2)*d2r;

   	var Cpoints = [];
	Cpoints.push(new GPoint(lng,lat));

	theta = 1/64;
	for (var deg=start; deg < end; deg += theta)
		{
		Cx = lng + (Clng * Math.cos(deg));
		Cy = lat + (Clat * Math.sin(deg));
		Cpoints.push(new GPoint(Cx,Cy));
		}

	deg = end;
	Cx = lng + (Clng * Math.cos(deg));
    Cy = lat + (Clat * Math.sin(deg));
    Cpoints.push(new GPoint(Cx,Cy));

	Cpoints.push(new GPoint(lng,lat));

   	map.addOverlay(new GPolyline(Cpoints,color,width));
	}

// Creates a marker whith tower info
function createTower(point, text, icon) 
	{
 	var marker = new GMarker(point, icon);

  	// Show this marker's index in the info window when it is clicked
  	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });

  	return marker;
	}

var polylines = new Array();

<?
if (isset($group_id))
	$xml_url = "xml.php?group_id=$group_id";
else
	$xml_url = "xml.php";
?>

function LoadLines()
	{
    request = GXmlHttp.create();
    request.open("GET", "<?=$xml_url?>", true);
    request.onreadystatechange = ProcessXml;
    request.send(null);
	}

function ProcessXml() 
		{
	  	if (request.readyState == 4) 
			{
			if (request.status == 200) 
				{
				while(polylines.length > 0)
					{
					polyline = polylines.pop();
					map.removeOverlay(polyline);
					delete polyline;
					}

	 		   	//var xmlDoc = request.responseXML;
    			//var links = xmlDoc.documentElement.getElementsByTagName("link");
				var links = request.responseXML.getElementsByTagName("link");
    			for (var i = 0; i < links.length; i++) 
					{
					a_lng = parseFloat(links[i].getAttribute("a_lng"));
					a_lat = parseFloat(links[i].getAttribute("a_lat"));
					b_lng = parseFloat(links[i].getAttribute("b_lng"));
					b_lat = parseFloat(links[i].getAttribute("b_lat"));
					color = links[i].getAttribute("color");				
					var polyline = new GPolyline([new GPoint(a_lng, a_lat), new GPoint(b_lng, b_lat)], color, 5);
					map.addOverlay(polyline);
					polylines.push(polyline);
    				}
				}
			else
				alert("There was a problem retrieving the XML data:\n" + request.statusText);

			window.setTimeout('LoadLines()', 120000);
  			}
		}

function OnLoad() 
	{
	if (parseInt(navigator.appVersion)>3) 
		{
	 	if (navigator.appName=="Netscape") 
			{
			document.getElementById("map").style.height = (window.innerHeight-75)+"px";
	 		}
 		if (navigator.appName.indexOf("Microsoft")!=-1) 
			{
			document.getElementById("map").style.height = (document.body.document.documentElement.clientHeight-90)+"px";
			}
		}
	
	//if (!GBrowserIsCompatible()) 
	//	return;
	//var pntDerbyTech = new GPoint(-90.44474244117737, 41.5146750885744);
	//var pntDerbyTech = new GPoint(-90.44466733932495, 41.51341380076779);

	// Build Icon
	var icon_base = new GIcon();
	icon_base.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon_base.iconSize = new GSize(12, 20);
	icon_base.shadowSize = new GSize(22, 20);
	icon_base.iconAnchor = new GPoint(6, 20);
	icon_base.infoWindowAnchor = new GPoint(5, 1);

	icon_green = new GIcon(icon_base);
	icon_green.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";

	icon_blue = new GIcon(icon_base);
	icon_blue.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";

	icon_red = new GIcon(icon_base);
	icon_red.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	
	// Display Map

	map = new GMap(document.getElementById("map"));
	//map.setMapType(G_SATELLITE_TYPE)
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.centerAndZoom(new GPoint(<?=ZOOM_LONG?>, <?=ZOOM_LAT?>), <?=ZOOM_LEVEL?>);

	LoadLines();

// Displays Towers
<?
$sql = "SELECT locations.*, groups.color from locations, groups where locations.group_id = groups.group_id";
if (isset($group_id))
	$sql .= " and locations.group_id = $group_id";

$locations = pg_query($sql);

while ($r = @pg_fetch_array($locations))
    {
	$Statistics = "window.open(\'location_statistics.php?location_id=".$r['id']."\',\'statistics\',\'scrollbars=yes,height=\'+screen.height+\',width=550,resizable=yes,top=0 \')"; 
	$html = $r['name']."<BR><a href=# onclick=\"$Statistics\">Statistics</a><BR>Management<BR>";

	$sensors = pg_query("select distinct on (sensor_name) sensor_name, management_url from sensors where location = ".$r['id'].";");
	while ($sensor = @pg_fetch_array($sensors))
		{
		//$html .= "<a href=".$sensor['management_url'].">X</a> - <a href=# onclick=\"window.open(\'".$sensor['management_url']."\')\">".$sensor['sensor_name']."</a><BR>";
		$html .= "<a target=".$sensor['management_url']." href=".$sensor['management_url'].">".$sensor['sensor_name']."</a><BR>";
		}
	$html .= "</TABLE>";
	echo("map.addOverlay(createTower(new GPoint(".$r['longitude'].", ".$r['latitude']."), '$html', icon_".$r['color']."));\n");
    }

// Display Coverage Slices
$sql = "SELECT longitude, latitude, direction, angle, radius from slices, sensors, locations where slices.sensor_id = sensors.sensor_id and sensors.location = locations.id";
if (isset($group_id))
    $sql .= " and locations.group_id = $group_id";

$res = pg_query($sql);

while ($r = @pg_fetch_array($res))
    {
	echo("drawSlice(map, ".$r['longitude'].", ".$r['latitude'].", ".$r['direction'].", ".$r['angle'].", ".$r['radius'].");\n");	
	}

// Implement Search
if (isset($_GET['search']))
	{
	//$locations = pg_query("SELECT id, name, longitude, latitude, count(sensors.sensor_name) from sensors, locations where sensors.location = locations.id and sensor_name ~* '".$_GET['search']."' group by id, name, longitude, latitude order by count desc limit 1;");
	// Very wierd query... Pulls all towers that have sensors who's name matches the query and pulls towers who's name matches the query and artificially ranks the towers very high, right now limit 1 but in future can be used to create a weighted list of matches
	$locations = pg_query("SELECT id, name, longitude, latitude, count(sensors.sensor_name) from sensors, locations where locations.id = sensors.location and sensor_name ~* '".$_GET['search']."' or name ~* '".$_GET['search']."' group by id, name, longitude, latitude order by count desc limit 1;");
	while ($r = @pg_fetch_array($locations))
	    {
		$Statistics = "window.open(\'location_statistics.php?location_id=".$r['id']."\',\'statistics\',\'scrollbars=yes,height=900,width=550\')"; 
		$html = $r['name']."<BR><a href=# onclick=\"$Statistics\">Statistics</a><BR>Management<BR>";

		$sensors = pg_query("select distinct on (sensor_name) sensor_name, management_url from sensors where location = ".$r['id'].";");
		while ($sensor = @pg_fetch_array($sensors))
			{
			$html .= "<a href=# onclick=\"window.open(\'".$sensor['management_url']."\')\">".$sensor['sensor_name']."</a><BR>";
			}
		echo("map.centerAndZoom(new GPoint(".$r['longitude'].", ".$r['latitude']."), 7);\n");
		echo("var marker;\n");
		echo("marker = createTower(new GPoint(".$r['longitude'].", ".$r['latitude']."), '$html', icon_green);\n");
		echo("map.addOverlay(marker);\n");
		echo("marker.openInfoWindowHtml('$html');\n");
   	 	}	
	}
	
?>
	}



                          
//]]></script>

</head>
<body onload="OnLoad()">
<FORM name=search method=get action=<?=$_SERVER['PHP_SELF']?>>

<?
$locations = pg_query("SELECT count(name) as num from locations");
$r = @pg_fetch_array($locations);
echo("Monitoring: ".$r['num']." Towers");

$locations = pg_query("SELECT count(sensor_name) as num from (select distinct sensor_name from sensors) as sens;");
$r = @pg_fetch_array($locations);
echo(" ".$r['num']." Routers");

$locations = pg_query("SELECT count(interface) as num from sensors;");
$r = @pg_fetch_array($locations);
echo(" ".$r['num']." Interfaces");

$locations = pg_query("SELECT count(id1) as num from links;");
$r = @pg_fetch_array($locations);
echo(" ".$r['num']." Links");

?><BR>
<a href=# onclick="document.search.submit()" class=text-button>Search</a> &nbsp <INPUT name=search size=50 value="<?=$_GET['search']?>"><br>
<a href=# onclick="window.open('sensors.php', 'sensors')" class=text-button>Usage Reports</a>
<a href=# onclick="window.open('failures.php', 'failures')" class=text-button>Failure Report</a>
<a href=# onclick="window.open('uptime.php', 'uptime')" class=text-button>Uptime Report</a>
<a href=# onclick="window.open('manage/manage.php', 'manage')" class=text-button>Management</a>
<a href=<?=$_SERVER['PHP_SELF']?> class=text-button>All Towers</a>
<?
$locations = pg_query("SELECT * from groups");
                                                                                                                                               
while ($r = @pg_fetch_array($locations))
    {
	echo("<a href=".$_SERVER['PHP_SELF']."?group_id=".$r['group_id']." class=text-button color=".$r['color'].">".$r['name']."</a> ");
	}
?>


<center><div id="map" style="width: 100%; height: 100px"></div>
</body>
</html>