2
0

vizdata.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. echo Content-type: text/html
  3. echo
  4. cat<<EOF
  5. <HTML>
  6. <HEAD>
  7. <TITLE>OLSR-VIZ Data</TITLE>
  8. <META CONTENT="text/html; charset=iso-8859-1" HTTP-EQUIV="Content-Type">
  9. <META CONTENT="no-cache" HTTP-EQUIV="cache-control">
  10. </HEAD>
  11. <BODY>
  12. <script language='JavaScript1.2' type='text/javascript'>
  13. EOF
  14. # sed + txtinfo plugin
  15. re_ip='[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}'
  16. re_sep='[[:space:]]\{1,\}'
  17. re_nosep='[^[:space:]]\{1,\}'
  18. wget http://127.0.0.1:2006/all -qO - | sed -n "
  19. /^Table: Links$/,/^$/ {
  20. s# # - #g
  21. s#\($re_ip\)$re_sep\($re_ip\)\($re_sep$re_nosep\)\{3\}$re_sep\($re_nosep\)#parent.touch_edge(parent.touch_node('\1').set_metric(1).update(),parent.touch_node('\2').set_metric(1).update(),'\4');#p
  22. }
  23. /^Table: Topology$/,/^$/ {
  24. s#\($re_ip\)$re_sep\($re_ip\)\($re_sep$re_nosep\)\{2\}$re_sep\($re_nosep\)#parent.touch_edge(parent.touch_node('\1').update(),parent.touch_node('\2').update(),'\4');#p
  25. }
  26. /^Table: HNA$/,/^$/ {
  27. s#\($re_ip\)/\([0-9]\{1,\}\)$re_sep\($re_ip\)#parent.touch_hna(parent.touch_node('\3'),'\1','\2');#p
  28. }
  29. /^Table: Routes$/,/^$/ {
  30. s#\($re_ip\)/32$re_sep$re_nosep$re_sep\($re_nosep\).*#parent.touch_node('\1').set_metric('\2').update();#p
  31. }
  32. "
  33. hosts=$(uci show olsrd|grep hosts_file|cut -d "=" -f 2)
  34. if [ -n $hosts ]; then
  35. sed -n "
  36. s#\($re_ip\)$re_sep\($re_nosep\)$re_sep.*#parent.touch_node('\1').set_desc('\2');#p
  37. " < $hosts
  38. fi
  39. cat<<EOF
  40. parent.viz_callback();
  41. </script>
  42. </BODY></HTML>
  43. EOF