node.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. define(["moment", "numeral", "tablesort", "tablesort.numeric"],
  2. function (moment, numeral, Tablesort) {
  3. function showGeoURI(d) {
  4. function showLatitude(d) {
  5. var suffix = Math.sign(d) > -1 ? "' N" : "' S"
  6. d = Math.abs(d)
  7. var a = Math.floor(d)
  8. var min = (d * 60) % 60
  9. a = (a < 10 ? "0" : "") + a
  10. return a + "° " + numeral(min).format("0.000") + suffix
  11. }
  12. function showLongitude(d) {
  13. var suffix = Math.sign(d) > -1 ? "' E" : "' W"
  14. d = Math.abs(d)
  15. var a = Math.floor(d)
  16. var min = (d * 60) % 60
  17. a = (a < 100 ? "0" + (a < 10 ? "0" : "") : "") + a
  18. return a + "° " + numeral(min).format("0.000") + suffix
  19. }
  20. if (!has_location(d))
  21. return undefined
  22. return function (el) {
  23. var latitude = d.nodeinfo.location.latitude
  24. var longitude = d.nodeinfo.location.longitude
  25. var a = document.createElement("a")
  26. a.textContent = showLatitude(latitude) + " " +
  27. showLongitude(longitude)
  28. a.href = "geo:" + latitude + "," + longitude
  29. el.appendChild(a)
  30. }
  31. }
  32. function showFirmware(d) {
  33. var release = dictGet(d.nodeinfo, ["software", "firmware", "release"])
  34. var base = dictGet(d.nodeinfo, ["software", "firmware", "base"])
  35. if (release === null || base === null)
  36. return undefined
  37. return release + " / " + base
  38. }
  39. function showUptime(d) {
  40. if (!("uptime" in d.statistics))
  41. return undefined
  42. return moment.duration(d.statistics.uptime, "seconds").humanize()
  43. }
  44. function showFirstseen(d) {
  45. if (!("firstseen" in d))
  46. return undefined
  47. return d.firstseen.fromNow(true)
  48. }
  49. function showClients(d) {
  50. if (!d.flags.online)
  51. return undefined
  52. return function (el) {
  53. el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"))
  54. el.appendChild(document.createElement("br"))
  55. var span = document.createElement("span")
  56. span.classList.add("clients")
  57. span.textContent = " ".repeat(d.statistics.clients)
  58. el.appendChild(span)
  59. el.appendChild(document.createElement("br"))
  60. var image = document.createElement("img")
  61. image.setAttribute("src", "nodestats/" + d.nodeinfo.node_id + ".png")
  62. image.setAttribute("width", "100%")
  63. var link = document.createElement("a")
  64. link.appendChild(image)
  65. link.title = "nodegraph"
  66. link.href = "nodestats/" + d.nodeinfo.node_id + ".png"
  67. link.target = "_blank"
  68. el.appendChild(link)
  69. }
  70. }
  71. function showIPs(d) {
  72. var ips = dictGet(d.nodeinfo, ["network", "addresses"])
  73. if (ips === null)
  74. return undefined
  75. ips.sort()
  76. return function (el) {
  77. ips.forEach( function (ip, i) {
  78. var link = !ip.startsWith("fe80:")
  79. if (i > 0)
  80. el.appendChild(document.createElement("br"))
  81. if (link) {
  82. var a = document.createElement("a")
  83. a.href = "http://[" + ip + "]/"
  84. a.textContent = ip
  85. el.appendChild(a)
  86. } else
  87. el.appendChild(document.createTextNode(ip))
  88. })
  89. }
  90. }
  91. function showBar(className, v) {
  92. var span = document.createElement("span")
  93. span.classList.add("bar")
  94. span.classList.add(className)
  95. var bar = document.createElement("span")
  96. bar.style.width = (v * 100) + "%"
  97. span.appendChild(bar)
  98. var label = document.createElement("label")
  99. label.textContent = (Math.round(v * 100)) + " %"
  100. span.appendChild(label)
  101. return span
  102. }
  103. function showRAM(d) {
  104. if (!("memory_usage" in d.statistics))
  105. return undefined
  106. return function (el) {
  107. el.appendChild(showBar("memory-usage", d.statistics.memory_usage))
  108. }
  109. }
  110. function showAutoupdate(d) {
  111. var au = dictGet(d.nodeinfo, ["software", "autoupdater"])
  112. if (!au)
  113. return undefined
  114. return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert"
  115. }
  116. return function(config, el, router, d) {
  117. var h2 = document.createElement("h2")
  118. h2.textContent = d.nodeinfo.hostname
  119. var span = document.createElement("span")
  120. span.classList.add(d.flags.online ? "online" : "offline")
  121. span.textContent = " (" + (d.flags.online ? "online" : "offline, " + d.lastseen.fromNow(true)) + ")"
  122. h2.appendChild(span)
  123. el.appendChild(h2)
  124. var attributes = document.createElement("table")
  125. attributes.classList.add("attributes")
  126. attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null)
  127. attributeEntry(attributes, "Koordinaten", showGeoURI(d))
  128. if (config.showContact)
  129. attributeEntry(attributes, "Kontakt", dictGet(d.nodeinfo, ["owner", "contact"]))
  130. attributeEntry(attributes, "Hardware", dictGet(d.nodeinfo, ["hardware", "model"]))
  131. if (config.showPrimaryMac)
  132. attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"]))
  133. if (config.showNodeId)
  134. attributeEntry(attributes, "Node ID", dictGet(d.nodeinfo, ["node_id"]))
  135. attributeEntry(attributes, "Firmware", showFirmware(d))
  136. attributeEntry(attributes, "Uptime", showUptime(d))
  137. if (config.showFirstseen)
  138. attributeEntry(attributes, "Teil des Netzes", showFirstseen(d))
  139. if (config.showRam)
  140. attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
  141. attributeEntry(attributes, "IP Adressen", showIPs(d))
  142. attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
  143. attributeEntry(attributes, "Clients", showClients(d))
  144. el.appendChild(attributes)
  145. if (d.neighbours.length > 0) {
  146. var h3 = document.createElement("h3")
  147. h3.textContent = "Nachbarknoten (" + d.neighbours.length + ")"
  148. el.appendChild(h3)
  149. var table = document.createElement("table")
  150. var thead = document.createElement("thead")
  151. var tr = document.createElement("tr")
  152. var th1 = document.createElement("th")
  153. th1.textContent = "Knoten"
  154. th1.classList.add("sort-default")
  155. tr.appendChild(th1)
  156. var th2 = document.createElement("th")
  157. th2.textContent = "TQ"
  158. tr.appendChild(th2)
  159. var th3 = document.createElement("th")
  160. th3.textContent = "Entfernung"
  161. tr.appendChild(th3)
  162. thead.appendChild(tr)
  163. table.appendChild(thead)
  164. var tbody = document.createElement("tbody")
  165. d.neighbours.forEach( function (d) {
  166. if (!d.link.vpn) {
  167. var tr = document.createElement("tr")
  168. var td1 = document.createElement("td")
  169. var a1 = document.createElement("a")
  170. a1.classList.add("hostname")
  171. a1.textContent = d.node.nodeinfo.hostname
  172. a1.href = "#"
  173. a1.onclick = router.node(d.node)
  174. td1.appendChild(a1)
  175. if (d.link.vpn)
  176. td1.appendChild(document.createTextNode(" (VPN)"))
  177. if (has_location(d.node)) {
  178. var span = document.createElement("span")
  179. span.classList.add("icon")
  180. span.classList.add("ion-location")
  181. td1.appendChild(span)
  182. }
  183. tr.appendChild(td1)
  184. var td2 = document.createElement("td")
  185. var a2 = document.createElement("a")
  186. a2.href = "#"
  187. a2.textContent = showTq(d.link)
  188. a2.onclick = router.link(d.link)
  189. td2.appendChild(a2)
  190. tr.appendChild(td2)
  191. var td3 = document.createElement("td")
  192. var a3 = document.createElement("a")
  193. a3.href = "#"
  194. a3.textContent = showDistance(d.link)
  195. a3.onclick = router.link(d.link)
  196. td3.appendChild(a3)
  197. td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
  198. tr.appendChild(td3)
  199. tbody.appendChild(tr)
  200. }
  201. })
  202. table.appendChild(tbody)
  203. new Tablesort(table)
  204. el.appendChild(table)
  205. }
  206. }
  207. })