node.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. define(function () {
  2. return function(config, el, router, d) {
  3. var h2 = document.createElement("h2")
  4. h2.textContent = d.nodeinfo.hostname
  5. var span = document.createElement("span")
  6. span.classList.add(d.flags.online ? "online" : "offline")
  7. span.textContent = " (" + (d.flags.online ? "online" : "offline, " + d.lastseen.fromNow(true)) + ")"
  8. h2.appendChild(span)
  9. el.appendChild(h2)
  10. var attributes = document.createElement("table")
  11. attributes.classList.add("attributes")
  12. attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null)
  13. attributeEntry(attributes, "In der Karte", has_location(d) ? "ja" : "nein")
  14. if (config.showContact)
  15. attributeEntry(attributes, "Kontakt", dictGet(d.nodeinfo, ["owner", "contact"]))
  16. attributeEntry(attributes, "Hardware", dictGet(d.nodeinfo, ["hardware", "model"]))
  17. attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"]))
  18. attributeEntry(attributes, "Firmware", showFirmware(d))
  19. attributeEntry(attributes, "Uptime", showUptime(d))
  20. attributeEntry(attributes, "Teil des Netzes", showFirstseen(d))
  21. attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
  22. attributeEntry(attributes, "IP Adressen", showIPs(d))
  23. attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
  24. attributeEntry(attributes, "Clients", showClients(d))
  25. el.appendChild(attributes)
  26. if (d.neighbours.length > 0) {
  27. var h3 = document.createElement("h3")
  28. h3.textContent = "Nachbarknoten (" + d.neighbours.length + ")"
  29. el.appendChild(h3)
  30. var table = document.createElement("table")
  31. var thead = document.createElement("thead")
  32. var tr = document.createElement("tr")
  33. var th1 = document.createElement("th")
  34. th1.textContent = "Knoten"
  35. th1.classList.add("sort-default")
  36. tr.appendChild(th1)
  37. var th2 = document.createElement("th")
  38. th2.textContent = "TQ"
  39. tr.appendChild(th2)
  40. var th3 = document.createElement("th")
  41. th3.textContent = "Entfernung"
  42. tr.appendChild(th3)
  43. thead.appendChild(tr)
  44. table.appendChild(thead)
  45. var tbody = document.createElement("tbody")
  46. d.neighbours.forEach( function (d) {
  47. var tr = document.createElement("tr")
  48. var td1 = document.createElement("td")
  49. var a1 = document.createElement("a")
  50. a1.classList.add("hostname")
  51. a1.textContent = d.node.nodeinfo.hostname
  52. a1.href = "#"
  53. a1.onclick = router.node(d.node)
  54. td1.appendChild(a1)
  55. if (d.link.vpn)
  56. td1.appendChild(document.createTextNode(" (VPN)"))
  57. if (has_location(d.node)) {
  58. var span = document.createElement("span")
  59. span.classList.add("icon")
  60. span.classList.add("ion-location")
  61. td1.appendChild(span)
  62. }
  63. tr.appendChild(td1)
  64. var td2 = document.createElement("td")
  65. var a2 = document.createElement("a")
  66. a2.href = "#"
  67. a2.textContent = showTq(d.link)
  68. a2.onclick = router.link(d.link)
  69. td2.appendChild(a2)
  70. tr.appendChild(td2)
  71. var td3 = document.createElement("td")
  72. var a3 = document.createElement("a")
  73. a3.href = "#"
  74. a3.textContent = showDistance(d.link)
  75. a3.onclick = router.link(d.link)
  76. td3.appendChild(a3)
  77. td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
  78. tr.appendChild(td3)
  79. tbody.appendChild(tr)
  80. })
  81. table.appendChild(tbody)
  82. new Tablesort(table)
  83. el.appendChild(table)
  84. }
  85. function showFirmware(d) {
  86. var release = dictGet(d.nodeinfo, ["software", "firmware", "release"])
  87. var base = dictGet(d.nodeinfo, ["software", "firmware", "base"])
  88. if (release === null || base === null)
  89. return
  90. return release + " / " + base
  91. }
  92. function showUptime(d) {
  93. if (!("uptime" in d.statistics))
  94. return
  95. return moment.duration(d.statistics.uptime, "seconds").humanize()
  96. }
  97. function showFirstseen(d) {
  98. if (!("firstseen" in d))
  99. return
  100. return d.firstseen.fromNow(true)
  101. }
  102. function showClients(d) {
  103. if (!d.flags.online)
  104. return
  105. return function (el) {
  106. el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"))
  107. el.appendChild(document.createElement("br"))
  108. var span = document.createElement("span")
  109. span.classList.add("clients")
  110. span.textContent = " ".repeat(d.statistics.clients)
  111. el.appendChild(span)
  112. }
  113. }
  114. function showIPs(d) {
  115. var ips = dictGet(d.nodeinfo, ["network", "addresses"])
  116. if (ips === null)
  117. return
  118. ips.sort()
  119. return function (el) {
  120. ips.forEach( function (ip, i) {
  121. var link = !ip.startsWith("fe80:")
  122. if (i > 0)
  123. el.appendChild(document.createElement("br"))
  124. if (link) {
  125. var a = document.createElement("a")
  126. a.href = "http://[" + ip + "]/"
  127. a.textContent = ip
  128. el.appendChild(a)
  129. } else
  130. el.appendChild(document.createTextNode(ip))
  131. })
  132. }
  133. }
  134. function showRAM(d) {
  135. if (!("memory_usage" in d.statistics))
  136. return
  137. return function (el) {
  138. el.appendChild(showBar("memory-usage", d.statistics.memory_usage))
  139. }
  140. }
  141. function showBar(className, v) {
  142. var span = document.createElement("span")
  143. span.classList.add("bar")
  144. span.classList.add(className)
  145. var bar = document.createElement("span")
  146. bar.style.width = (v * 100) + "%"
  147. span.appendChild(bar)
  148. var label = document.createElement("label")
  149. label.textContent = (Math.round(v * 100)) + " %"
  150. span.appendChild(label)
  151. return span
  152. }
  153. function showAutoupdate(d) {
  154. var au = dictGet(d.nodeinfo, ["software", "autoupdater"])
  155. if (!au)
  156. return
  157. return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert"
  158. }
  159. }
  160. })