4
0

node.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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, "Firmware", showFirmware(d))
  123. attributeEntry(attributes, "Uptime", showUptime(d))
  124. attributeEntry(attributes, "Teil des Netzes", showFirstseen(d))
  125. attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
  126. attributeEntry(attributes, "IP Adressen", showIPs(d))
  127. attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
  128. attributeEntry(attributes, "Clients", showClients(d))
  129. el.appendChild(attributes)
  130. if (d.neighbours.length > 0) {
  131. var h3 = document.createElement("h3")
  132. h3.textContent = "Nachbarknoten (" + d.neighbours.length + ")"
  133. el.appendChild(h3)
  134. var table = document.createElement("table")
  135. var thead = document.createElement("thead")
  136. var tr = document.createElement("tr")
  137. var th1 = document.createElement("th")
  138. th1.textContent = "Knoten"
  139. th1.classList.add("sort-default")
  140. tr.appendChild(th1)
  141. var th2 = document.createElement("th")
  142. th2.textContent = "TQ"
  143. tr.appendChild(th2)
  144. var th3 = document.createElement("th")
  145. th3.textContent = "Entfernung"
  146. tr.appendChild(th3)
  147. thead.appendChild(tr)
  148. table.appendChild(thead)
  149. var tbody = document.createElement("tbody")
  150. d.neighbours.forEach( function (d) {
  151. var tr = document.createElement("tr")
  152. var td1 = document.createElement("td")
  153. var a1 = document.createElement("a")
  154. a1.classList.add("hostname")
  155. a1.textContent = d.node.nodeinfo.hostname
  156. a1.href = "#"
  157. a1.onclick = router.node(d.node)
  158. td1.appendChild(a1)
  159. if (d.link.vpn)
  160. td1.appendChild(document.createTextNode(" (VPN)"))
  161. if (has_location(d.node)) {
  162. var span = document.createElement("span")
  163. span.classList.add("icon")
  164. span.classList.add("ion-location")
  165. td1.appendChild(span)
  166. }
  167. tr.appendChild(td1)
  168. var td2 = document.createElement("td")
  169. var a2 = document.createElement("a")
  170. a2.href = "#"
  171. a2.textContent = showTq(d.link)
  172. a2.onclick = router.link(d.link)
  173. td2.appendChild(a2)
  174. tr.appendChild(td2)
  175. var td3 = document.createElement("td")
  176. var a3 = document.createElement("a")
  177. a3.href = "#"
  178. a3.textContent = showDistance(d.link)
  179. a3.onclick = router.link(d.link)
  180. td3.appendChild(a3)
  181. td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
  182. tr.appendChild(td3)
  183. tbody.appendChild(tr)
  184. })
  185. table.appendChild(tbody)
  186. new Tablesort(table)
  187. el.appendChild(table)
  188. }
  189. }
  190. })