luci-app-cjdns: import package from SeattleMeshnet/meshbox
[feed/routing.git] / luci-app-cjdns / luasrc / view / cjdns / status.htm
1 <script type="text/javascript">//<![CDATA[
2
3 var peersURI = '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "peers")%>';
4 var updatePeers = function(x, peers) {
5 var table = document.getElementById('cjdns-peerings');
6 while (table.rows.length > 1) {
7 table.deleteRow(1);
8 }
9
10 if ((peers) && ((peers.err) || (typeof peers.length === 'undefined'))) {
11 var errpeer = (peers.err)
12 ? 'Socket Error: unable to connect to Admin API'
13 : 'No active peers';
14 var row = table.insertRow(-1);
15 row.className = 'cbi-section-table-row';
16 var cell = row.insertCell(-1);
17 cell.colSpan = 7;
18 cell.textContent = errpeer;
19 return;
20 };
21
22 peers.forEach(function(peer, i) {
23 if (peer.user == null) {
24 var user = '';
25 } else if (peer.user == 'Local Peers') {
26 var user = 'beacon';
27 } else {
28 var user = peer.user;
29 }
30
31 if (peer.isIncoming === 0) {
32 var interface = 'outgoing';
33 } else {
34 var interface = 'incoming';
35 }
36
37 var status = interface + ', ' + peer.state.toLowerCase();
38
39 if (peer.version === 0) {
40 var version = '-';
41 } else {
42 var version = 'v' + peer.version;
43 }
44
45 var rxtx = lbbytes(peer.bytesIn) + ' / ' + lbbytes(peer.bytesOut);
46
47 var row = table.insertRow(-1);
48 row.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
49 row.insertCell(-1).textContent = user;
50 row.insertCell(-1).textContent = peer.ipv6;
51 row.insertCell(-1).textContent = status;
52 row.insertCell(-1).textContent = version;
53 row.insertCell(-1).textContent = rxtx;
54 var latencyCell = row.insertCell(-1);
55 latencyCell.textContent = 'waiting';
56
57 var pingURI = '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "ping")%>';
58 var timeout = 2000;
59 XHR.get(pingURI, { label: peer.switchLabel, timeout: timeout }, function(x, pong) {
60 var pongrsp = ((pong.err == "ai:recv > timeout") || (pong == "undefined") || (pong.ms >= timeout))
61 ? '> ' + timeout + ' ms'
62 : pong.ms + ' ms';
63 latencyCell.textContent = pongrsp;
64 })
65 });
66
67 };
68
69 XHR.get(peersURI, null, updatePeers);
70 XHR.poll(5, peersURI, null, updatePeers);
71
72 //]]></script>
73
74 <script type="text/javascript">
75 <%# Author: [GitHub/75lb] -%>
76 //<![CDATA[
77 function lbbytes (bytes){
78
79 var kilobyte = 1024,
80 megabyte = kilobyte * 1024,
81 gigabyte = megabyte * 1024,
82 terabyte = gigabyte * 1024;
83
84 if ((bytes >= 0) && (bytes < kilobyte)) {
85 return bytes + " B";
86 } else if ((bytes >= kilobyte) && (bytes < megabyte)) {
87 return (bytes / kilobyte).toFixed(2) + " KB";
88 } else if ((bytes >= megabyte) && (bytes < gigabyte)) {
89 return (bytes / megabyte).toFixed(2) + " MB";
90 } else if ((bytes >= gigabyte) && (bytes < terabyte)) {
91 return (bytes / gigabyte).toFixed(2) + " GB";
92 } else if (bytes >= terabyte) {
93 return (bytes / terabyte).toFixed(2) + " TB";
94 } else {
95 return bytes + " B";
96 }
97 };
98 //]]>
99 </script>
100
101 <fieldset class="cbi-section">
102 <legend>Active cjdns peers</legend>
103 <table class="cbi-section-table" id="cjdns-peerings">
104 <tr class="cbi-section-table-titles">
105 <th class="cbi-section-table-cell">User/Name</th>
106 <th class="cbi-section-table-cell">IPv6</th>
107 <th class="cbi-section-table-cell">Status</th>
108 <th class="cbi-section-table-cell">Version</th>
109 <th class="cbi-section-table-cell">Rx / Tx</th>
110 <th class="cbi-section-table-cell">Latency</th>
111 </tr>
112 <tr class="cbi-section-table-row">
113 <td colspan="7">Querying Admin API</td>
114 </tr>
115 </table>
116 </fieldset>