4
0

node.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. }
  60. }
  61. function showIPs(d) {
  62. var ips = dictGet(d.nodeinfo, ["network", "addresses"])
  63. if (ips === null)
  64. return undefined
  65. ips.sort()
  66. return function (el) {
  67. ips.forEach( function (ip, i) {
  68. var link = !ip.startsWith("fe80:")
  69. if (i > 0)
  70. el.appendChild(document.createElement("br"))
  71. if (link) {
  72. var a = document.createElement("a")
  73. a.href = "http://[" + ip + "]/"
  74. a.textContent = ip
  75. el.appendChild(a)
  76. } else
  77. el.appendChild(document.createTextNode(ip))
  78. })
  79. }
  80. }
  81. function showBar(className, v) {
  82. var span = document.createElement("span")
  83. span.classList.add("bar")
  84. span.classList.add(className)
  85. var bar = document.createElement("span")
  86. bar.style.width = (v * 100) + "%"
  87. span.appendChild(bar)
  88. var label = document.createElement("label")
  89. label.textContent = (Math.round(v * 100)) + " %"
  90. span.appendChild(label)
  91. return span
  92. }
  93. function showRAM(d) {
  94. if (!("memory_usage" in d.statistics))
  95. return undefined
  96. return function (el) {
  97. el.appendChild(showBar("memory-usage", d.statistics.memory_usage))
  98. }
  99. }
  100. function showAutoupdate(d) {
  101. var au = dictGet(d.nodeinfo, ["software", "autoupdater"])
  102. if (!au)
  103. return undefined
  104. return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert"
  105. }
  106. return function(config, el, router, d) {
  107. var h2 = document.createElement("h2")
  108. h2.textContent = d.nodeinfo.hostname
  109. var span = document.createElement("span")
  110. span.classList.add(d.flags.online ? "online" : "offline")
  111. span.textContent = " (" + (d.flags.online ? "online" : "offline, " + d.lastseen.fromNow(true)) + ")"
  112. h2.appendChild(span)
  113. el.appendChild(h2)
  114. var attributes = document.createElement("table")
  115. attributes.classList.add("attributes")
  116. attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null)
  117. attributeEntry(attributes, "Koordinaten", showGeoURI(d))
  118. if (config.showContact)
  119. attributeEntry(attributes, "Kontakt", dictGet(d.nodeinfo, ["owner", "contact"]))
  120. attributeEntry(attributes, "Hardware", dictGet(d.nodeinfo, ["hardware", "model"]))
  121. attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"]))
  122. attributeEntry(attributes, "Node ID", dictGet(d.nodeinfo, ["node_id"]))
  123. attributeEntry(attributes, "Firmware", showFirmware(d))
  124. attributeEntry(attributes, "Uptime", showUptime(d))
  125. attributeEntry(attributes, "Teil des Netzes", showFirstseen(d))
  126. attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
  127. attributeEntry(attributes, "IP Adressen", showIPs(d))
  128. attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
  129. attributeEntry(attributes, "Clients", showClients(d))
  130. el.appendChild(attributes)
  131. if (d.neighbours.length > 0) {
  132. var h3 = document.createElement("h3")
  133. h3.textContent = "Nachbarknoten (" + d.neighbours.length + ")"
  134. el.appendChild(h3)
  135. var table = document.createElement("table")
  136. var thead = document.createElement("thead")
  137. var tr = document.createElement("tr")
  138. var th1 = document.createElement("th")
  139. th1.textContent = "Knoten"
  140. th1.classList.add("sort-default")
  141. tr.appendChild(th1)
  142. var th2 = document.createElement("th")
  143. th2.textContent = "TQ"
  144. tr.appendChild(th2)
  145. var th3 = document.createElement("th")
  146. th3.textContent = "Entfernung"
  147. tr.appendChild(th3)
  148. thead.appendChild(tr)
  149. table.appendChild(thead)
  150. var tbody = document.createElement("tbody")
  151. d.neighbours.forEach( function (d) {
  152. var tr = document.createElement("tr")
  153. var td1 = document.createElement("td")
  154. var a1 = document.createElement("a")
  155. a1.classList.add("hostname")
  156. a1.textContent = d.node.nodeinfo.hostname
  157. a1.href = "#"
  158. a1.onclick = router.node(d.node)
  159. td1.appendChild(a1)
  160. if (d.link.vpn)
  161. td1.appendChild(document.createTextNode(" (VPN)"))
  162. if (has_location(d.node)) {
  163. var span = document.createElement("span")
  164. span.classList.add("icon")
  165. span.classList.add("ion-location")
  166. td1.appendChild(span)
  167. }
  168. tr.appendChild(td1)
  169. var td2 = document.createElement("td")
  170. var a2 = document.createElement("a")
  171. a2.href = "#"
  172. a2.textContent = showTq(d.link)
  173. a2.onclick = router.link(d.link)
  174. td2.appendChild(a2)
  175. tr.appendChild(td2)
  176. var td3 = document.createElement("td")
  177. var a3 = document.createElement("a")
  178. a3.href = "#"
  179. a3.textContent = showDistance(d.link)
  180. a3.onclick = router.link(d.link)
  181. td3.appendChild(a3)
  182. td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
  183. tr.appendChild(td3)
  184. tbody.appendChild(tr)
  185. })
  186. table.appendChild(tbody)
  187. new Tablesort(table)
  188. el.appendChild(table)
  189. }
  190. }
  191. })