-
Notifications
You must be signed in to change notification settings - Fork 12
/
dotbottom.html
191 lines (176 loc) · 6.11 KB
/
dotbottom.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
haasdebug=0
strengthmap=new Map()
txt2 = txt2.slice(0, -1)
txt2=txt2.replaceAll('",' , '":')
txt2=txt2.replaceAll('\x0a','|')
txt2='{ "vis2" : [ ' +txt2+ ' ] }'
if (haasdebug) console.log(txt2)
var obj2 = JSON.parse(txt2)
if (haasdebug) console.log("Num nodes reporting: "+ obj2.vis2.length )
for (x in obj2.vis2) {
for (y in obj2.vis2[x]) {
if (haasdebug) console.log("Node mac: "+ y)
strengthmap.set(y.toUpperCase(),new Map())
res=obj2.vis2[x][y].slice(0, -1).split("|")
if (haasdebug) console.log("Node connections: "+ res )
for (i in res){
if (res[i]!=undefined){
rese=res[i].split(" = ")
if (haasdebug) console.log("rese[0]: "+rese[0])
if (haasdebug) console.log("rese[1]: "+rese[1])
if (rese[1]==undefined) continue
rese1split=rese[1].split(": ")
if (rese1split==undefined) continue
chan=rese1split[2]
if (haasdebug) console.log("chan: "+chan)
if (haasdebug) console.log("rese[2]: "+rese[2])
ress = rese[2].split(" ")
for (r=0; r<ress.length; r+=3){
if (haasdebug) console.log("Endpoint mac / strength dBm: "+ress[r+0]+" / "+ress[r+1])
strengthmap.get(y.toUpperCase()).set(ress[r+0].toUpperCase(), {strength: ress[r+1], chan: chan})
}
}
}
}
}
var obj3 = txt3.split("||")
if (haasdebug) console.log("obj3 length is: "+obj3.length)
macmap={}
for (o in obj3){
l=obj3[o].split(" ")
if (l.length>1) {
if (haasdebug) console.log("l is: "+l[0]+" / "+l[1])
sip=l[1]
if (sip.indexOf("-192.168.")>-1){
sip = sip.slice(sip.indexOf("-192.168.")+1);
}
macmap[l[0].toUpperCase()]={ip:sip}
}
}
var obj4 = txt4.split("||")
if (haasdebug) console.log("obj4 length is: "+obj4.length)
dhcpmap={}
for (o2 in obj4){
l2=obj4[o2].split(" ")
if (l2.length>3) {
if (haasdebug) console.log("l2 is: "+l2[1]+" / "+l2[2]+" / "+l2[3])
dhcpmap[l2[1].toUpperCase()]={ip:l2[2],host:l2[3]}
}
}
var obj = JSON.parse(txt);
nodemap={}
for (r = 0; r < obj.vis.length; r++) {
var name = obj.vis[r].primary.toUpperCase()
var macnode = name
if (haasdebug) console.log("macnode: "+macnode)
if (macmap[macnode]!=undefined){
name = macmap[macnode].ip
}
var rnode = nodemap[name]
if (rnode==undefined){
rnode = graph.newNode({label: name});
nodemap[name]=rnode
}
rnode.data.color= '#000000'
rnode.data.font= '16px Verdana, sans-serif'
rnode.data.ondoubleclick= function() { console.log("Hello "+rnode.data.label+" !"); }
for (n = 0; n < obj.vis[r].neighbors.length; n++) {
var name2 = obj.vis[r].neighbors[n].neighbor.toUpperCase()
var macnode2 = name2
if (haasdebug) console.log("macnode2: "+macnode2)
if (macmap[macnode2]!=undefined){
name2 = macmap[macnode2].ip
}
var nnode = nodemap[name2]
if (nnode==undefined){
nnode = graph.newNode({label: name2, color: '#00F000', font: '16px Verdana, sans-serif'});
nodemap[name2]=nnode
}
var ename = "LAN"
var eweight = 3.0
var nc='#005050' //LAN color
var dbm=0
//if (obj.vis[r].neighbors[n].metric!=undefined){
// ename = obj.vis[r].neighbors[n].metric
// eweight = eweight/(1.0 + 300.*(parseFloat(ename)-1.0))
// ename = (30.0*eweight).toFixed(0)
//}
for (let [key, value] of strengthmap) {
keyn=key
if (macmap[key]!=undefined){
keyn=macmap[key].ip
}
if (keyn==name){ // this should be the ip of the first node
if (haasdebug) console.log("key is : "+keyn)
if (vv=value.get(macnode2)){ // look for the mac of the second node
if (ename != "LAN"){
if (haasdebug) console.log("Already had wifi info for link from "+macnode+"/"+name+" to "+macnode2+"/"+name2)
}
ch = vv.chan.split(" (")[0]
if (Number(ch)<20) nc='#001010' //2G
else nc='#009090' //5G
ename = "Ch"+ch+", "+vv.strength+"dBm"
dbm = Number(vv.strength)
eweight = Math.max(0.4*(10.0+(dbm/10.0)),0.1)
if (haasdebug) console.log("node pair ename :"+ename)
//break; //found it
}
}
}
if (dbm>-85){ // don't draw really weak links
var nedge = graph.newEdge(nnode, rnode, {label: ename, color: nc, directional: 1, weight: eweight.toString(), font: '10px Verdana, sans-serif'});
}
}
for (c = 0; c < obj.vis[r].clients.length; c++) {
var name3 = obj.vis[r].clients[c].toUpperCase()
macclient = name3
if (haasdebug) console.log("macclient: "+macclient)
if (macmap[macclient]!=undefined){
name3 = macmap[macclient].ip
if (name == name3){
if (haasdebug) console.log(name3+" is already a node")
continue;
}
}
if (dhcpmap[macclient]!=undefined){
name3 = dhcpmap[macclient].ip
if (dhcpmap[macclient].host!="*") name3+="\n"+dhcpmap[macclient].host
}
var cnode = nodemap[name3]
if (cnode==undefined){
var cnode = graph.newNode({label: name3.replace(" ","\n"), color: '#0000F0', font: '12px Verdana, sans-serif'});
nodemap[name3]=cnode
}
var ename = "LAN"
var eweight = 2.0
var nc='#200000' //LAN color
for (let [key, value] of strengthmap) {
if (haasdebug) console.log("key : "+key)
if (vv=value.get(macclient)){
if (ename != "LAN"){
if (haasdebug) console.log("Already had wifi info for client link from "+macnode+"/"+name+" to "+macclient+"/"+name3)
}
ch = vv.chan.split(" (")[0]
if (Number(ch)<20) nc='#800000' //2G
else nc='#E00000' //5G
ename = "Ch"+ch+", "+vv.strength+"dBm"
dbm = Number(vv.strength)
eweight = Math.max(0.3*(10.0+(dbm/10.0)),0.1)
if (haasdebug) console.log(ename)
//break; //found it
}
}
var nedge = graph.newEdge(cnode, rnode, {label: ename, color: nc, directional: 0, weight: eweight.toString(), font: '10px Verdana, sans-serif'});
}
}
jQuery(function(){
var springy = window.springy = jQuery('#springydemo').springy({
graph: graph,
nodeSelected: function(node){
console.log('Node selected: ' + JSON.stringify(node.data));
}
});
});
</script>
</body>
</html>