[Mirror] The Firmware for FFBSee Community
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

status 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/usr/bin/haserl
  2. <% echo -en "content-type: text/html\r\n\r\n" %>
  3. <!DOCTYPE html>
  4. <html lang="de">
  5. <head>
  6. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  7. <meta charset="utf-8">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <%
  10. name="$(uci -q get freifunk.@settings[0].name)"
  11. echo -n "<title>Freifunk${name:+ - $name}</title>"
  12. %>
  13. <link rel="stylesheet" href="/index.css">
  14. </head>
  15. <body>
  16. <noscript>
  17. <strong>JavaScript required</strong>
  18. </noscript>
  19. <div class="header">
  20. <div class="menu">
  21. <%
  22. url=$(uci -q get freifunk.@settings[0].community_url)
  23. community="$(echo -n $url | cut -d\/ -f3)"
  24. if [ -n "$url" -a -n "$community" ]; then
  25. echo " <a class=\"community\" href=\"$url\">$community</a>"
  26. fi
  27. echo " <ul>"
  28. contact="$(uci -q get freifunk.@settings[0].contact)"
  29. if [ -n "$contact" ]; then
  30. echo " <li><a href='#'>Kontakt: $contact</a></li>"
  31. fi
  32. lat="$(uci -q get freifunk.@settings[0].latitude)"
  33. lon="$(uci -q get freifunk.@settings[0].longitude)"
  34. if [ -n "$lat" -a -n "$lon" ]; then
  35. echo " <li><a href=\"https://www.openstreetmap.org?mlat=$lat&mlon=$lon&zoom=17\">Position: ${lat:0:8}N, ${lon:0:8}E</a></li>"
  36. fi
  37. %> <li><form action="https://<% echo -n "$HTTP_HOST" %>"><button type="submit" class="login-button">Login</button></form></li>
  38. </ul>
  39. </div>
  40. </div>
  41. <div class="header">
  42. <h1><% uci -q get freifunk.@settings[0].name | tr -d '\n' %></h1>
  43. <h2>Firmware Version <% uci -q get freifunk.@settings[0].version | tr -d '\n' %></h2>
  44. </div>
  45. <div class="content">
  46. <div class="pure-g">
  47. <div class="pure-u-md-1-3">
  48. <h2>Nachbarknoten</h2>
  49. <h3><% (batctl neighbors 2> /dev/null | tail -n +3 | grep -v '^No' | cut -c -17 | sort | uniq | wc -l) %></h3>
  50. </div>
  51. <div class="pure-u-md-1-3">
  52. <h2>Alle Knoten</h2>
  53. <h3><% echo -n $((`batctl transglobal 2> /dev/null | tail -n +3 | grep '^ [^ ]' | cut -b 39-55 | sort | uniq | wc -l`+1)) %></h3>
  54. </div>
  55. <div class="pure-u-md-1-3">
  56. <h2>Lokale Clients</h2>
  57. <h3><% echo -n $(batctl translocal 2> /dev/null | tail -n +3 | grep -c 'W') %></h3>
  58. </div>
  59. </div>
  60. </div>
  61. <%
  62. . /lib/ff_shared.sh
  63. echo '<div class="content">'
  64. echo ' <h2 class="content-subhead">Nachbarknoten:</h2>'
  65. echo ' <ul>'
  66. macs="$(batctl neighbors | tail -n +3 | grep -v '^No' | cut -c -17 | sort | uniq)"
  67. if [ -n "$macs" ]; then
  68. prefix="$(uci get network.globals.ula_prefix)"
  69. i=1
  70. for mac in $macs; do
  71. echo " <li><h3><a href=\"http://[$(ula_addr $prefix $mac)]\" class=\"neighbor\">Nachbarknoten $i</a></h3></li>"
  72. i=$((i+1))
  73. done
  74. else
  75. echo ' <li><h3>Keine Nachbarn gefunden.</h3></li>'
  76. fi
  77. echo ' </ul>'
  78. echo '</div>'
  79. max=$(uci -q get freifunk.@settings[0].service_display_max)
  80. if [ -n "$max" -a "$max" != "0" ]; then
  81. addr_prefix="${ula_prefix%%::*}:"
  82. echo '<div class="content">'
  83. echo ' <h2 class="content-subhead">Liste lokaler Angebote im Freifunk-Netz:</h2>'
  84. echo ' <ul>'
  85. link_list=$(
  86. printf "$(alfred -r 91 | head -$max)" | awk -F'["\\]+' -v addr_prefix="$addr_prefix" '{ if($5 == "link" && match($7, "^[][ #[:alnum:]_\/.:]{1,128}$") && $9 == "label" && match($11, "^[][ [:alnum:]_\/.:]{1,32}$") && match($7, addr_prefix "|\.ff[a-z]{0,3}")) printf(" <li><h3><a href=\"%s\">%s</a></h3></li>\n", $7, $11) }'
  87. )
  88. [ -n "$link_list" ] && echo "$link_list" || echo ' <li><h3>Keine Angebote gefunden.</h3></li>'
  89. echo ' </ul>'
  90. echo '</div>'
  91. fi
  92. %>
  93. <script>
  94. var own_data = <% /usr/sbin/print_map.sh %>;
  95. function createCORSRequest(method, url) {
  96. var xhr = new XMLHttpRequest();
  97. if ("withCredentials" in xhr) {
  98. // XHR for Chrome/Firefox/Opera/Safari.
  99. xhr.open(method, url, true);
  100. } else if (typeof XDomainRequest != "undefined") {
  101. // XDomainRequest for IE.
  102. xhr = new XDomainRequest();
  103. xhr.open(method, url);
  104. } else {
  105. // CORS not supported.
  106. xhr = null;
  107. }
  108. return xhr;
  109. }
  110. var neighbors = document.getElementsByClassName("neighbor");
  111. Array.prototype.forEach.call(neighbors, function(el) {
  112. var xhr = createCORSRequest('GET', el.href + "/cgi-bin/data");
  113. xhr.onload = function() {
  114. var neigh_data = JSON.parse(xhr.responseText);
  115. // set node name
  116. if('name' in neigh_data) {
  117. el.textContent = neigh_data.name;
  118. }
  119. // add connection quality
  120. var qual = -1;
  121. if('links' in neigh_data && 'links' in own_data) {
  122. Array.prototype.forEach.call(neigh_data.links, function(neigh_link) {
  123. Array.prototype.forEach.call(own_data.links, function(own_link) {
  124. if(own_link.dmac == neigh_link.smac) {
  125. qual = Math.max(qual, own_link.qual, neigh_link.qual);
  126. }
  127. });
  128. });
  129. }
  130. if(qual >= 0)
  131. {
  132. var e = document.createTextNode(" (" + qual.toFixed(0) + "%)");
  133. el.parentNode.appendChild(e);
  134. }
  135. };
  136. xhr.send();
  137. });
  138. </script>
  139. </body>
  140. </html>