node.js 6.0 KB

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