This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
615 lines (525 loc) · 19.1 KB
/
index.html
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!--
/*
* @author Flip
* @package ffMap
* @version 1.3.4
* @licenses CC-BY-SA Creative Commons Namensnennung - Weitergabe unter gleichen Bedingungen 4.0 International Lizenz. https://creativecommons.org/licenses/by-sa/4.0/
*/
-->
<html lang="de">
<head>
<meta charset="utf-8">
<title> Freifunk Map</title>
<link rel="stylesheet" href="style.css">
<!-- jQuerry -->
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<!-- jQuerry UI -->
<link rel="stylesheet" href="jquery-ui-1.11.2.custom/jquery-ui.min.css">
<script src="jquery-ui-1.11.2.custom/jquery-ui.min.js"></script>
<!-- jleaflet -->
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"></script>
<link rel="stylesheet" href="Leaflet.markercluster/dist/MarkerCluster.css" />
<script src="Leaflet.markercluster/dist/leaflet.markercluster-src.js"></script>
<!-- Leaflet Control OSM Geocoder -->
<link rel="stylesheet" href="css/l.geosearch.css" />
<script src="js/l.control.geosearch.js"></script>
<script src="js/l.geosearch.provider.openstreetmap.js"></script>
<!-- DataTables -->
<link rel="stylesheet" type="text/css" href="DataTables/media/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="DataTables/media/js/jquery.dataTables.min.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#mapView">Map</a></li>
<li><a href="#nodeList">Node List</a></li>
<li><a href="stats.html">Statistik</a></li>
<li id="tabInfo"> </li>
</ul>
<div style="display:none; position: absolute; top: 50%; left: 50%; margin-top: -50px; margin-left: -50px; z-index:999;" id="dvloader"><img src="images/loading.gif" /></div>
<div id="mapView">
<nav class='menu-ui'>
<a href='#' id='online' class='active'>Online Nodes</a>
<a href='#' id='offline'>Offline Nodes</a>
<a href='#' id='mesh'>Mesh</a>
<a href='#' id='segmente'>Segmente</a>
</nav>
</div>
<div id="nodeList">
<p id="nodescount"> </p>
<p id="nodesloc"> </p>
<p id="nodesclients"> </p>
<table id="nodes" class="display" width="100%" cellspacing="0">
<thead>
<th class="hidden">Id</th><th> </th><th>Node</th><th>Clients</th><th>Model</th><th>location</th><th>update</th><th>Version</th><th>Gateway</th>
</thead>
</table>
</div>
</div>
<div class="modal fade modal-geo" tabindex="-1" role="dialog" aria-labelledby="Geo Koordinaten">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="input-group">
<span class="input-group-addon">Breitengrad: </span>
<input id="modal_latitude" type="text" class="form-control" readonly>
</div>
<div class="input-group">
<span class="input-group-addon">Längengrad:</span>
<input id="modal_longitude" type="text" class="form-control" readonly>
</div>
<div class="input-group">
<span class="input-group-addon">Lat,Long: </span>
<input id="modal_latlong" type="text" class="form-control" readonly>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
function getAbsolutePath() {
var loc = window.location;
var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}
//get URL parameter (php $_GET Äquivalent)
function getParam(variable){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
function getColor(val, bad, good) {
var colors = ['#D50000', '#D5A200', '#CCD500', '#00D500'];
var index = Math.floor( colors.length * (val - bad)/(good - bad) );
index = Math.max(0, Math.min(colors.length-1, index));
return colors[index];
}
$(document).ready(function(){
$( "#tabs" ).tabs({ heightStyle: "content" });
$( "#tabs" ).tabs(
{
beforeLoad: function( event, ui )
{
ui.jqXHR.error(function() {
ui.panel.html("Couldn't load this tab. We'll try to fix this as soon as possible.");
});
}
});
var nodesMeshLocation = new Array();
var doublelocation = new Array();
var markers = new L.MarkerClusterGroup({
disableClusteringAtZoom: 18,
iconCreateFunction: function(cluster) {
var childCount = cluster.getChildCount();
var c = ' onlinemarker-cluster-';
if (childCount < 2) {
c += 'small';
} else if (childCount < 20) {
c += 'medium';
} else {
c += 'large';
}
return new L.DivIcon({ html: '<div><span><b>' + childCount + '</b></span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
}
});
var markersOffline = new L.MarkerClusterGroup({
iconCreateFunction: function(cluster) {
var childCount = cluster.getChildCount();
return new L.DivIcon({ html: '<div><span><b>' + childCount + '</b></span></div>', className: 'marker-cluster offlinemarker-cluster', iconSize: new L.Point(40, 40) });
}
});
var mashLayer = L.layerGroup();
var segmentLayer = L.layerGroup();
var osmtile = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {id: 'MapID', attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'});
//init map
var longitude = getParam('longitude');
var latitude = getParam('latitude');
var zoom = getParam('zoom');
var nodeIdvalue = getParam('node');
if(longitude == false){longitude = '48.7986';}
if(latitude == false){latitude = '9.2048';}
if(zoom == false){zoom = '11';}
//init map
var map = L.map('mapView', {
center: [longitude, latitude],
zoom: zoom,
layers: [osmtile]
});
map.addLayer(markers);
//add scale to map
L.control.scale().addTo(map);
//add GeoSearch to map
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.OpenStreetMap()
}).addTo(map);
// show / hide layers
map.getContainer().querySelector('#online').onclick = function() {
if (this.className === 'active') {
map.removeLayer(markers);
this.className = '';
} else {
map.addLayer(markers);
this.className = 'active';
}
return false;
};
map.getContainer().querySelector('#offline').onclick = function() {
if (this.className === 'active') {
map.removeLayer(markersOffline);
this.className = '';
} else {
map.addLayer(markersOffline);
this.className = 'active';
}
return false;
};
map.getContainer().querySelector('#mesh').onclick = function() {
if (this.className === 'active') {
map.removeLayer(mashLayer);
this.className = '';
} else {
if(mashLayer.getLayers().length == 0)
{
$("#dvloader").show();
try
{
$.ajax({
url: "./json/batman-vis.json?nocache=" + (new Date()).getTime(),
dataType: "text"
}).done(function(data) {
//workaroud because json file is not valid, only each line it self is valid...
data = "[" + data.replace(/}/g, "},");
data = data.substring(0, data.lastIndexOf(",")) + "]";
var nodesMesh = new Array();
$.each( jQuery.parseJSON(data), function(key, val)
{
if(val.router != undefined && val.neighbor != undefined)
{
var source = nodesMeshLocation[val.router];
var destination = nodesMeshLocation[val.neighbor];
if(source != undefined && destination != undefined)
{
var index = -1;
$.each(nodesMesh, function(i, item){
if(item[0] == destination && item[1] == source)
{
index = i;
}
});
if(index < 0)
{
//add new mesh connection to array
nodesMesh.push([source, destination, val.label]);
}
else
{
//edit mesh connection and add quality
nodesMesh[index].push(val.label);
}
}
}
});
var mostbad = 30;
var best = 1;
$.each(nodesMesh, function(i, item)
{
var node1 = item[0];
var node2 = item[1];
var quality = item[2];
if(item[3] != undefined && item[2] < item[3])
{
var quality = item[3];
}
var color = getColor(quality, mostbad, best);
//var opacity = 0.25 + (1/mostbad)*(mostbad+1-quality);
var polyline = L.polyline([
node1[0],
node2[0]
], {color: color, /*opacity: opacity*/});
if(item[3] != undefined)
{
polyline.bindPopup("<b>" + node1[1] + " -> " + node2[1] + " : " + item[2] + "</b><br><b>" + node2[1] + " -> " + node1[1] + " : " + item[3] + "</b>");
}
else
{
polyline.bindPopup("<b>" + node1[1] + " -> " + node2[1] + " : " + item[2] + "</b><br>");
}
polyline.on('mouseover', polyline.openPopup.bind(polyline));
mashLayer.addLayer(polyline);
});
});
$("#dvloader").hide();
}
catch (err)
{
console.log(err);
$("#dvloader").hide();
}
}
map.addLayer(mashLayer);
this.className = 'active';
}
return false;
};
map.getContainer().querySelector('#segmente').onclick = function() {
if (this.className === 'active') {
map.removeLayer(segmentLayer);
this.className = '';
} else {
if(segmentLayer.getLayers().length == 0)
{
$("#dvloader").show();
try
{
$.ajax({
url: "./json/result.json?nocache=" + (new Date()).getTime(),
dataType: "text"
}).done(function(data) {
var collection = jQuery.parseJSON(data);
$.each( collection, function(seg, geodata)
{
var color = "";
for(var i = 0; i < 3; i++) {
var sub = Math.floor(Math.random() * 256).toString(16);
color += (sub.length == 1 ? "0" + sub : sub);
}
$.each( geodata, function(keygeo, valgeo)
{
var seg = L.geoJson(valgeo, {
style: function () {
return {weight: 0, opacity: 1, color: '#'+color}
}
});
segmentLayer.addLayer(seg);
});
});
});
$("#dvloader").hide();
}
catch (err)
{
console.log(err);
$("#dvloader").hide();
}
}
map.addLayer(segmentLayer);
this.className = 'active';
}
return false;
};
var nodescount = 0;
var nodesonlinecount = 0;
var nodesloc = 0;
var nodesclients = 0;
try
{
$("#dvloader").show();
$.getJSON("./json/alfred-json-map.json?nocache=" + (new Date()).getTime(),
function(data)
{
var ffMarkerOnline = L.divIcon({className: 'marker-cluster onlinemarker-cluster-small leaflet-zoom-animated leaflet-clickable ffMarkerStyle', iconSize: [40, 40], html: '<div></div>'});
var ffMarkerOffline = L.divIcon({className: 'marker-cluster offlinemarker-cluster leaflet-zoom-animated leaflet-clickable ffMarkerStyle', iconSize: [40, 40], html: '<div></div>'});
$.each( data, function( key, val )
{
//url for this node
var link = null;
if(val.location != undefined && val.location.latitude != undefined && val.location.longitude != undefined) {
var ffMarkerStyle = ffMarkerOnline;
if (val['status'] != undefined && val['status'] == "offline") {
ffMarkerStyle = ffMarkerOffline;
}
link = '?longitude=' + val.location.latitude + '&latitude=' + val.location.longitude + '&zoom=18';
var marker1 = L.marker([val.location.latitude, val.location.longitude], {icon: ffMarkerStyle});
marker1.bindPopup("<b>" + val.hostname + "</b><br>" + val['clients']['total'] + " Clients");
marker1.on('mouseover', marker1.openPopup.bind(marker1));
if(val['status'] != undefined && val['status'] == "offline")
{
markersOffline.addLayer(marker1);
}
else
{
//is already a marker on this position -> update Popup
var total = val['clients']['total'];
$.each(doublelocation, function(i, item){
if(marker1.getLatLng().equals(item.marker.getLatLng()))
{
//renew marker
item.clients += val['clients']['total'];
var popup = item.marker.getPopup();
popup.setContent("<b> [Total Clients:" + item.clients + "]</b><br><br>" + popup.getContent().replace(/<b> \[Total Clients:.*?\]<\/b><br><br>/, "") + "<br><b>" + val.hostname + "</b><br>" + val['clients']['total'] + " Clients");
popup.update();
popupCurrent = marker1.getPopup();
popupCurrent.setContent(popup.getContent());
popupCurrent.update();
}
});
doublelocation.push({
marker: marker1,
clients: total
});
markers.addLayer(marker1);
}
if(nodeIdvalue != undefined && nodeIdvalue == key.replace(/:/g, ''))
{
map.setZoomAround(new L.LatLng(val.location.latitude, val.location.longitude), 18,true);
}
//fill nodesMeshLocation for drawing later mesh
if(val['network'] != undefined && val['network']['mesh_interfaces'] != undefined)
{
$.each(val['network']['mesh_interfaces'], function(i, mesh_interface){
nodesMeshLocation[mesh_interface] = [[val.location.latitude, val.location.longitude], val.hostname];
});
}
if(val['network'] != undefined && val['network']['mesh'] != undefined)
{
$.each(val['network']['mesh'], function(i, mesh_interface){
if (mesh_interface['interfaces'] != undefined && val.location.latitude != undefined && val.location.longitude != undefined) {
if (mesh_interface['interfaces']['other'] != undefined) {
nodesMeshLocation[mesh_interface['interfaces']['other']] = [[val.location.latitude, val.location.longitude], val.hostname];
}
if (mesh_interface['interfaces']['wireless'] != undefined) {
nodesMeshLocation[mesh_interface['interfaces']['wireless']] = [[val.location.latitude, val.location.longitude], val.hostname];
}
}
});
}
}
var gw = val['gateway'];
switch(gw)
{
case '02:00:0a:38:00:01': gw = 'GW01';
break;
case '02:00:0a:38:00:02': gw = 'GW02';
break;
case '02:00:0a:38:00:03': gw = 'GW03';
break;
case '02:00:0a:38:00:04': gw = 'GW04';
break;
case '02:00:0a:38:00:05': gw = 'GW05';
break;
case '02:00:0a:38:00:06': gw = 'GW06';
break;
case '02:00:0a:38:00:07': gw = 'GW07';
break;
case '02:00:0a:38:00:08': gw = 'GW08';
break;
case '02:00:0a:38:00:09': gw = 'GW09';
break;
case '02:00:0a:38:00:10': gw = 'GW10';
break;
default:
var regex = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/;
if (regex.exec(gw)) {
var mac = gw.split(":");
if (mac[5] != "00") {
gw = 'GW' + mac[4] + "-" + mac[5] + " (Segment: " + mac[3] + ")"
} else {
gw = 'GW' + mac[4] + " (Segment: " + mac[3] + ")";
}
}
}
var statuspage = ' (<a href="http://ffs-'+key.replace(/:/g, '')+'.nodes.freifunk-stuttgart.de">Statusseite</a>)'
//Add node to Node-List
$("#nodes").DataTable().row.add( {
"id": nodescount,
"Status": val['status'] != undefined && val['status'] == "offline" ? '<span class="ui-icon ui-icon-close"></span>' : '',
"Node": link == null ? val['hostname'] + statuspage : '<a href="' + link + '" >' + val['hostname'] + '</a>' + statuspage,
"Clients": val['clients']['total'],
"Model": val['hardware']['model'],
"location": val['location'] == undefined ? 'no' : 'yes',
"update": val['software']['autoupdater']['branch'] + " (" + val['software']['autoupdater']['enabled'] + ")",
"Version": val['software']['firmware']['base'],
"Gateway": gw,
} );
//fill counters
if(val['status'] == undefined || val['status'] == "online")
{
nodesonlinecount++;
}
nodescount++;
val['location'] == undefined ? null : nodesloc++;
nodesclients += val['clients']['total'];
});
$("#nodescount").html("Nodes total: " + nodescount);
$("#nodesloc").html("Nodes with location: " + nodesloc);
$("#nodesclients").html("Clients: " + nodesclients);
$("#tabInfo").html("Online Nodes: " + nodesonlinecount + " | Clients: " + nodesclients);
var order = $("#nodes").DataTable().order();
if(order[0][0] == 0) {order[0][0] = 3; order[0][1] = 'desc';}
$("#nodes").DataTable().order( [ order[0][0], order[0][1] ] ).draw();
});
$("#dvloader").hide();
}
catch (err)
{
console.log(err);
$("#dvloader").hide();
}
// Managed Click for Location Info (get Koordinaten für neue Freifunk Nodes)
var logo= L.control({
position : 'topleft'
});
logo.onAdd = function(map) {
this._div = L.DomUtil.create('div', 'myControl');
var img_log = '<div id="locationInfo"><img src=\"images/locationbar.png\"></img></div>';
this._div.innerHTML = img_log;
return this._div;
};
logo.addTo(map);
$("#locationInfo").on("click", function() {
$('.leaflet-container').css('cursor','crosshair');
map.addOneTimeEventListener("click", function (e) {
function clickhandler(e) {
$("#modal_latitude").val(e.latlng.lat);
$("#modal_longitude").val(e.latlng.lng);
$("#modal_latlong").val(e.latlng.lat + "," + e.latlng.lng);
$(".modal-geo").modal('show');
map.off("click", clickhandler);
$('.leaflet-container').css('cursor','');
};
var clickevent = map.on('click', clickhandler);
});
});
//init NodeList
$('#nodes').DataTable({
paging: false,
stateSave: true,
columns: [
{ data: "id", visible: false, },
{ data: "Status" },
{ data: "Node" },
{ data: "Clients" },
{ data: "Model" },
{ data: "location" },
{ data: "update" },
{ data: "Version" },
{ data: "Gateway" }
],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
if ( aData['Status'] != "" )
{
$('td', nRow).css('background-color', "rgba(0, 158, 224, 0.1)");
}
}
});
//call this for specific tab
var tabIndex = getParam('tab');
if(tabIndex !== false) {
$( "#tabs" ).tabs({ active: tabIndex });
}
});
</script>