node.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, "Clients", showClients(d))
  24. el.appendChild(attributes)
  25. if (d.neighbours.length > 0) {
  26. var h3 = document.createElement("h3")
  27. h3.textContent = "Nachbarknoten (" + d.neighbours.length + ")"
  28. el.appendChild(h3)
  29. var table = document.createElement("table")
  30. var thead = document.createElement("thead")
  31. var tr = document.createElement("tr")
  32. var th1 = document.createElement("th")
  33. th1.textContent = "Knoten"
  34. th1.classList.add("sort-default")
  35. tr.appendChild(th1)
  36. var th2 = document.createElement("th")
  37. th2.textContent = "TQ"
  38. tr.appendChild(th2)
  39. var th3 = document.createElement("th")
  40. th3.textContent = "Entfernung"
  41. tr.appendChild(th3)
  42. thead.appendChild(tr)
  43. table.appendChild(thead)
  44. var tbody = document.createElement("tbody")
  45. d.neighbours.forEach( function (d) {
  46. var tr = document.createElement("tr")
  47. var td1 = document.createElement("td")
  48. var a1 = document.createElement("a")
  49. a1.classList.add("hostname")
  50. a1.textContent = d.node.nodeinfo.hostname
  51. a1.href = "#"
  52. a1.onclick = router.node(d.node)
  53. td1.appendChild(a1)
  54. if (d.link.vpn)
  55. td1.appendChild(document.createTextNode(" (VPN)"))
  56. if (has_location(d.node)) {
  57. var span = document.createElement("span")
  58. span.classList.add("icon")
  59. span.classList.add("ion-location")
  60. td1.appendChild(span)
  61. }
  62. tr.appendChild(td1)
  63. var td2 = document.createElement("td")
  64. var a2 = document.createElement("a")
  65. a2.href = "#"
  66. a2.textContent = showTq(d.link)
  67. a2.onclick = router.link(d.link)
  68. td2.appendChild(a2)
  69. tr.appendChild(td2)
  70. var td3 = document.createElement("td")
  71. var a3 = document.createElement("a")
  72. a3.href = "#"
  73. a3.textContent = showDistance(d.link)
  74. a3.onclick = router.link(d.link)
  75. td3.appendChild(a3)
  76. td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
  77. tr.appendChild(td3)
  78. tbody.appendChild(tr)
  79. })
  80. table.appendChild(tbody)
  81. new Tablesort(table)
  82. el.appendChild(table)
  83. }
  84. function showFirmware(d) {
  85. var release = dictGet(d.nodeinfo, ["software", "firmware", "release"])
  86. var base = dictGet(d.nodeinfo, ["software", "firmware", "base"])
  87. if (release === null || base === null)
  88. return
  89. return release + " / " + base
  90. }
  91. function showUptime(d) {
  92. if (!("uptime" in d.statistics))
  93. return
  94. return moment.duration(d.statistics.uptime, "seconds").humanize()
  95. }
  96. function showFirstseen(d) {
  97. if (!("firstseen" in d))
  98. return
  99. return d.firstseen.fromNow(true)
  100. }
  101. function showClients(d) {
  102. if (!d.flags.online)
  103. return
  104. return function (el) {
  105. el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"))
  106. el.appendChild(document.createElement("br"))
  107. var span = document.createElement("span")
  108. span.classList.add("clients")
  109. span.textContent = " ".repeat(d.statistics.clients)
  110. el.appendChild(span)
  111. }
  112. }
  113. function showIPs(d) {
  114. var ips = dictGet(d.nodeinfo, ["network", "addresses"])
  115. if (ips === null)
  116. return
  117. ips.sort()
  118. return function (el) {
  119. ips.forEach( function (ip, i) {
  120. var link = !ip.startsWith("fe80:")
  121. if (i > 0)
  122. el.appendChild(document.createElement("br"))
  123. if (link) {
  124. var a = document.createElement("a")
  125. a.href = "http://[" + ip + "]/"
  126. a.textContent = ip
  127. el.appendChild(a)
  128. } else
  129. el.appendChild(document.createTextNode(ip))
  130. })
  131. }
  132. }
  133. function showRAM(d) {
  134. if (!("memory_usage" in d.statistics))
  135. return
  136. return function (el) {
  137. el.appendChild(showBar("memory-usage", d.statistics.memory_usage))
  138. }
  139. }
  140. function showBar(className, v) {
  141. var span = document.createElement("span")
  142. span.classList.add("bar")
  143. span.classList.add(className)
  144. var bar = document.createElement("span")
  145. bar.style.width = (v * 100) + "%"
  146. span.appendChild(bar)
  147. var label = document.createElement("label")
  148. label.textContent = (Math.round(v * 100)) + " %"
  149. span.appendChild(label)
  150. return span
  151. }
  152. }
  153. })