-
Notifications
You must be signed in to change notification settings - Fork 2
/
alfred.html
199 lines (171 loc) · 5.9 KB
/
alfred.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
<!DOCTYPE html>
<html>
<head>
<title>Freifunk Ruhrgebiet - Alfred Status</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/list.css" />
<script type="text/javascript" src="lib/frameworks/jquery-1.11.0.min.js"></script>
<script>
var arr = [];
$(function() {
$.getJSON( 'alfred_merged.json', function(data) {
$.each( data, function( key,val ) {
try {
if (typeof val['statistics'] != "undefined")
stats = val['statistics']
else
stats = val
arr.push({
hostname: val['hostname'],
address: val.network.addresses ? val.network.addresses.filter(function (a) { return /^2a02:/.test(a); })[0] : null,
uptime: parseFloat(stats['uptime']),
tx: parseFloat(stats['traffic']['tx']['bytes']),
rx: parseFloat(stats['traffic']['rx']['bytes']),
firmware: val['software']['firmware']['release'],
model: val['hardware']['model'],
autoupdate: (val.software.autoupdater.enabled?val.software.autoupdater.branch:''),
loadavg: parseFloat(stats['loadavg'] != null?stats['loadavg']:0),
mem: parseFloat(stats['memory'] != null?stats['memory']['free']:1.0) / parseFloat(stats['memory'] != null?stats['memory']['total']:0)
});
} catch (e) {alert(e.message)};
});
$('#headings th').click(function() {
var id = $(this).attr('id');
var asc = (!$(this).attr('asc')); // switch the order, true if not set
// set asc="asc" when sorted in ascending order
$('#headings th').each(function() {
$(this).removeAttr('asc');
});
if (asc) $(this).attr('asc', 'asc');
sortResults(id, asc);
});
sortResults('hostname', true);
});
});
function order(c) {
if (/^\d$/.test(c))
return 0;
else if (/^[a-z]$/i.test(c))
return c.charCodeAt(0);
else if (c === '~')
return -1;
else if (c)
return c.charCodeAt(0) + 256;
else
return 0;
}
// Based on dpkg code
function vercomp(a, b) {
var apos = 0, bpos = 0;
while (apos < a.length || bpos < b.length) {
var first_diff = 0;
while ((apos < a.length && !/^\d$/.test(a[apos])) || (bpos < b.length && !/^\d$/.test(b[bpos]))) {
var ac = order(a[apos]);
var bc = order(b[bpos]);
if (ac !== bc)
return ac - bc;
apos++;
bpos++;
}
while (a[apos] === '0')
apos++;
while (b[bpos] === '0')
bpos++;
while (/^\d$/.test(a[apos]) && /^\d$/.test(b[bpos])) {
if (first_diff === 0)
first_diff = a.charCodeAt(apos) - b.charCodeAt(bpos);
apos++;
bpos++;
}
if (/^\d$/.test(a[apos]))
return 1;
if (/^\d$/.test(b[bpos]))
return -1;
if (first_diff !== 0)
return first_diff;
}
return 0;
}
function compare(a, b) {
try {
a = a.toUpperCase();
b = b.toUpperCase();
} catch (e) {}
if (a == b) return 0;
else if (a > b) return 1;
else return -1;
}
function sortResults(prop, asc) {
for (var i = 0; i < arr.length; i++) {
arr[i].pos = i;
}
arr = arr.sort(function(a, b) {
var ret;
if (prop === 'firmware' || prop === 'model')
ret = vercomp(a[prop], b[prop]);
else if (prop === 'loadavg')
ret = a[prop] >= b[prop]?1:-1;
else
ret = compare(a[prop], b[prop]);
if (ret == 0) ret = compare(a.pos, b.pos);
if (asc) return ret;
else return -ret;
});
showResults();
}
function showResults () {
var node = $('#results');
for (var e in arr) {
node.append(
$('<tr>').append(
$('<td>').append(
$('<a target="_blank">')
.attr('href', 'http://[' + arr[e].address + ']/')
.text(arr[e].hostname)
),
$('<td>').text(Math.floor(arr[e].uptime/3600) + 'h'),
$('<td>').text(Math.floor(arr[e].tx/1048576)),
$('<td>').text(Math.floor(arr[e].rx/1048576)),
$('<td>').text(arr[e].firmware),
$('<td>').text(arr[e].model),
$('<td>').text(arr[e].autoupdate),
$('<td>').text(arr[e].loadavg),
$('<td>').text((arr[e].mem*100).toFixed(2))
)
);
}
}
</script>
</head>
<body>
<header>
<h1><a href="/" id="sitelink">freifunk-ruhrgebiet.de</a></h1>
<ul>
<li><a href="../graph.html">Graph</a></li>
<li><a href="../geomap.html">Karte</a></li>
<li><a href="../list.html">Liste</a></li>
<li><a href="alfred.html">Alfred</a></li>
</ul>
</header>
<div class="container">
<h1>Alfred</h1>
<table id="list" class="tablesorter tablesorter-default">
<thead id="headings">
<tr class="tablesorter-headerRow">
<th id="hostname">hostname</th>
<th id="uptime">uptime</th>
<th id="tx">tx (mb)</th>
<th id="rx">rx (mb)</th>
<th id="firmware">firmware</th>
<th id="model">model</th>
<th id="autoupdate">autoupdate</th>
<th id="loadavg">loadavg</th>
<th id="mem">mem free</th>
</tr>
</thead>
<tbody id="results">
<!-- this will be auto-populated -->
</tbody>
</table>
</body>
</html>