Code-Schnipsel

Aus Weimarnetz Wiki
Version vom 25. Juli 2007, 15:42 Uhr von Fries43 (Diskussion | Beiträge) (→‎MAC-Adressenliste im ganzen Netz aktualisieren:: besser)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Netzkarte als .dot-Datei ausgeben mit olsrd-plaintext-plugin

  • speichern als /www/cgi-bin-map
  • beim aufruf wird direkt die datei heruntergeladen, danach:
  • neato -Goverlap=scale -Gsplines=true -Gstart=3 -v -Tpng -o karte.png karte.dot
  • GraphViz / Neato - Anleitung: http://www.graphviz.org/pub/graphviz/CURRENT/doxygen/html/classes.html
  • Handarbeit / Nacharbeit ist manchmal notwendig. (Nodes stehen noch in /etc/hosts, aber im OLSR nicht mehr etc.)
  • ToDo:
    • kumulieren der ETX-Werte ueber einen groesseren Zeitraum -> Durchschnittsbildung
    • Bandbreite anstatt ETX-Wert visualisieren
    • GPS-Daten miteinbeziehen
  • Zum ausprobieren: http://entoro.homelinux.net/cgi-bin-map
#!/bin/sh

D=$(date|sed -e's/[:T-]/ /g'|while read t m t h mi r r r y;do echo $y$m$t-$h"uhr"$mi;done)
F="netzkarte-("$(nvram get wl0_ssid)")-"$D".dot"

echo "Content-type: application/octet-stream"
echo "Content-Disposition: attachment; filename=\"$F\""
echo -e "\ngraph g {"

awk '/10.63./ {
 IP=$1
 gsub(/\./,"A",$1)
 gsub(/[^a-zA-Z0-9. ]/,"",$2)
 gsub(/.olsr/,"",$2)
 print "A"$1"[label=\""$2"\\n("IP")\"];"}' /etc/hosts
wget -O - http://127.0.0.1:2006|awk '{
 if(s==1){
  if($0=="")exit
  if($5!="0.00"&&$5<11){
   if($5<11)arg="dotted"
   if($5<7)arg="dashed"
   if($5<4)arg="normal"
   if($5<2)arg="bold"
   style="[style="arg"];"
   if(arg=="normal")style=";"
   gsub(/\./,"A",$1)
   gsub(/\./,"A",$2)
   print "A"$1" -- A"$2,style
  }}
  if($2=="Topology")s=1}END{print "}"}'

Massenmail aus Registrierung verschicken

  • erstmal datei mit allen mails erzeugen, doppelte werden aussortiert
cd /tmp
awk '{printf("\n%s\n%s\n%s\n%s",$3,$5,$7,$9)}' /www/cgi-bin/registrator-db1.txt >email-adr-db1.txt
awk '{printf("\n%s\n%s\n%s\n%s",$3,$5,$7,$9)}' /www/cgi-bin/registrator-db2.txt >email-adr-db2.txt
awk '{printf("\n%s\n%s\n%s\n%s",$3,$5,$7,$9)}' /www/cgi-bin/registrator-db3.txt >email-adr-db3.txt
cat email-adr-db1.txt email-adr-db2.txt email-adr-db3.txt | sort -n | uniq >email.txt
* nun mails verschicken

Backup der Registrierung ziehen

#!/bin/sh

D=$(date|sed -e's/[:T-]/ /g'|while read t m t h mi r r r y;do echo $y$m$t-$h"uhr"$mi;done)
F="Backup_Registrierung_"$D".tar.gz"

echo "Content-type: application/octet-stream"
echo "Content-Disposition: attachment; filename=\"$F\""
echo

cd /www/cgi-bin/
tar czO registrator-db*

Bandbreite zu einem beliebigen Nachbarn feststellen

#!/bin/sh

echo -e "Content-type: text/plain\n"

if [ -z "$QUERY_STRING" ]
        then
        echo "cgi-bin-speed             - diese Anleitung"
        echo "cgi-bin-speed?n           - OLSR-Nachbarn anzeigen"
        echo "cgi-bin-speed?n=10.1.2.3  - 10-Sekunden-Testdownload von diesem Nachbarn"
        echo "cgi-bin-speed?r           - Ausgabe der bisher generierten Resultate"
        echo "cgi-bin-speed?s           - Quellcode anzeigen"
        echo
        echo "\$VER 0.2 - 2006nov10 - bastian bittorf - weimarnetz.de"
        exit
fi

if [ "$QUERY_STRING" = "s" ]
then
cat $0
exit
fi

FILE="/tmp/last_speedtests.txt"

if [ "$QUERY_STRING" = "r" ]
        then
        cat $FILE
        exit
fi

WIFI_IP=$(nvram get wifi_ipaddr)

if [ "$QUERY_STRING" = "n" ]
        then
        wget -O - http://127.0.0.1:2006/neighbours|grep $WIFI_IP|grep "0.00"
        exit
fi

IFS=\&;set ${QUERY_STRING%%[^%&=+-:@-_a-z~]*};unset IFS;eval $*
WIFI_IF=$(nvram get wifi_ifname)

test -z $METRIK1 && METRIK1=$(ip route|grep "$n dev $WIFI_IF  scope"|cut -d' ' -f9)
test -z $METRIK1 && METRIK1=$(ip route|grep "$n"|cut -d' ' -f8)

iptables -I INPUT -p tcp -s $n -d $WIFI_IP --sport 80 -j ACCEPT
wget -qO /dev/null "http://$n/cgi-bin-dev-zero.bin" &
sleep 10
killall wget

test -z $METRIK2 && METRIK2=$(ip route|grep "$n dev eth1  scope"|cut -d' ' -f9)
test -z $METRIK2 && METRIK2=$(ip route|grep "$n"|cut -d' ' -f8)

RAW="$(iptables -nxvL INPUT|grep $WIFI_IP)"
KB=$(echo $RAW|while read A B A;do let d=B/10/1024;echo $d;done)
ERGEBNIS="$KB $METRIK1 $METRIK2 $RAW"
iptables -D INPUT -p tcp -s $n -d $WIFI_IP --sport 80 -j ACCEPT

echo "Kilobyte/s | Metrik vorher | nachher | Pakete | Bytes | Testnachbar | Testrouter - 10 Sekunden Testdownload"
echo
echo "$ERGEBNIS"
echo >>$FILE "$ERGEBNIS"

VPN umleiten in M18 / Portforwarding

EXTERNES_INTERFACE_WO_ALLES_HERKOMMT="eth0"
IEXT=$EXTERNES_INTERFACE_WO_ALLES_HERKOMMT
PORT=5000
ZIEL="192.168.1.254"

iptables -t nat -A PREROUTING -p tcp --dport $PORT -i $IEXT -j DNAT --to $ZIEL:$PORT

M18 Webcam zum laufen bekommen

modprobe spca5xx /var/www/webcam.sh

NVRAM-Befehl auf Fonera nachbilden / nvram wrapper bzw. simulator

  • am besten nach /usr/sbin/nvram kopieren und mit chmod 777 nvram ausfuehrbar machen
#!/bin/sh

FILE="/etc/init.d/nvram-variablen-simulation.txt"
TEMP="/etc/init.d/nvram-variablen-simulation.txt2"

if [ "$1" = "get" ]
 then              
 grep $2"=" $FILE|sed "s/$2=//;s/\"//;s/[\"]*$//"
 exit            
fi   

if [ "$1" = "set" ]
 then              
 grep -v $2"=" $FILE >$TEMP
 cat   >$FILE $TEMP        
 NEWSTRING=$(echo $2|sed 's/=/="/')
 echo >>$FILE $NEWSTRING"\""       
 exit                       
fi   

if [ "$1" = "show" ]
 then               
 cat $FILE
 exit     
fi   

if [ "$1" = "commit" ]
 then                 
 echo "nvram_commit(): start"
 sleep 1                     
 echo "nvram_commit(): end"
 exit                      
fi

Dienst aus dem internen Kabelnetz auf den Dachrouter forwarden

EXTERNES_INTERFACE_WO_ALLES_HERKOMMT="eth1"
IEXT=$EXTERNES_INTERFACE_WO_ALLES_HERKOMMT
PORT=411
ZIEL="104.63.16.2"

iptables -t nat -I PREROUTING -p tcp --dport $PORT -i $IEXT -j DNAT --to $ZIEL:$PORT

OLSR-Traffic (nur drahtlos) messen

eval $(netparam)

iptables -I INPUT  -p udp -i $WIFIDEV --dport 698 -j ACCEPT
iptables -I OUTPUT -p udp -o $WIFIDEV --sport 698 -j ACCEPT

OLSR_REIN=$(iptables -nxvL INPUT |sed -e '/udp dpt:698/!d'|while read A B A;do echo $B;done)
OLSR_RAUS=$(iptables -nxvL OUTPUT|sed -e '/udp spt:698/!d'|while read A B A;do echo $B;done)

echo $OLSR_REIN
echo $OLSR_RAUS

VPN-Traffic messen

iptables -I INPUT -p tcp --dport 5000 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 5000 -j ACCEPT

iptables -vnxL|awk '/pt:5000/{if($11=="dpt:5000")a=$2;if($11=="dpt:5000")b=$2}END{print a+b}'

while true;do iptables -vnxL|awk '/pt:5000/{if($11=="dpt:5000")a=$2;if($11=="dpt:5000")b=$2}END{print "IN: "a/(1024*1024)" OUT: "b/(1024*1024)" Megabyte"}';sleep 60;done

Aus Registrierungsdatenbank dot-Datei fuer GraphViz generieren

awk 'BEGIN{print "graph g {"}{gsub(/[^a-zA-Z0-9 ]/,"");if($4==1&&$6==1&&$8==1&&$10==1){print $3" -- "$5;print $3" -- "$7;print $3" -- "$9";"}}END{print "}"}' registrator-db1.txt

neato -Earrowtail=normal -Goverlap=scale -Gsplines=true-v -Tjpg -o /tmp/vertrauen_overlap=scale.jpg /tmp/vertrauen.dot

auf dem Router eine Karte fuer GraphViz generieren

awk '{if($2=="localhost")s=1;z++;if(z>5){if($0=="")exit;print $1,substr($2,1,length($2)-5)}}END{print "---"}' /etc/hosts|sed -e 's/[^a-zA-Z0-9. ]//g'|awk -F'[. ]' '{print $1"."$2"."$3"."$4,$5""$3}' >/tmp/dat

wget -O - http://127.0.0.1:2006|awk '{if(s==1){if($0=="")exit;if($5<10&&$5!="0.00"&&$5<11)print $1,$2,$5};if($2=="Topology")s=1}' >>/tmp/dat

awk 'BEGIN{print "graph g {"}{if(s==1){if($3<12){pre="edge[style=";typ="dotted,weight=0] "};if($3<6)typ="dashed,weight=3] ";if($3<4){typ="";pre="edge[weigth=6] "};if($3<2){pre="edge[style=";typ="bold,weight=9] "};print pre""typ""node[$1]" -- "node[$2]";"};if(s!=1){node[$1]=$2};if($1=="...")s=1}END{print "}"}' /tmp/dat >/tmp/g.dot

neato -Goverlap=scale -v -Tjpg -o /tmp/vpnkarte.jpg /tmp/g.dot


IP-Bereich Traffic aufsummieren

INTERN1="104.0.0.0/8"
INTERN2="10.0.0.0/8"

STOERER="104.63.71.0/28"

# gute ports definieren
PORT1="21,22,23"
PORT2="80,443,8080"
PORT3="1863,5190,5222,5223,6661:6666"
PORT4="25,110,143,993,995"

# restlicher Datenverkehr ganz nach unten
iptables -I FORWARD -p all -d $STOERER -j ACCEPT
iptables -I FORWARD -p all -s $STOERER -j ACCEPT

# aller traffic vom stoerer zum internet
iptables -I FORWARD -p tcp -s $STOERER -m multiport --dport $PORT1 -j ACCEPT
iptables -I FORWARD -p tcp -s $STOERER -m multiport --dport $PORT2 -j ACCEPT
iptables -I FORWARD -p tcp -s $STOERER -m multiport --dport $PORT3 -j ACCEPT
iptables -I FORWARD -p tcp -s $STOERER -m multiport --dport $PORT4 -j ACCEPT

# aller traffic vom internet zum stoerer
iptables -I FORWARD -p tcp -d $STOERER -m multiport --sport $PORT1 -j ACCEPT
iptables -I FORWARD -p tcp -d $STOERER -m multiport --sport $PORT2 -j ACCEPT
iptables -I FORWARD -p tcp -d $STOERER -m multiport --sport $PORT3 -j ACCEPT
iptables -I FORWARD -p tcp -d $STOERER -m multiport --sport $PORT4 -j ACCEPT

# netzinterner traffic interessiert uns nicht
iptables -I FORWARD -p all -s $STOERER -d $INTERN1 -j ACCEPT
iptables -I FORWARD -p all -s $STOERER -d $INTERN2 -j ACCEPT
iptables -I FORWARD -p all -d $STOERER -s $INTERN1 -j ACCEPT
iptables -I FORWARD -p all -d $STOERER -s $INTERN2 -j ACCEPT

# datenverkehr auf den boesen ports ausgeben
iptables -nvL FORWARD|tail -2

Nachbarn anzeigen - Methode0: - neues OLSR-PlugIn ab FFF v1.3

wget -O - http://127.0.0.1:2006/neighbours

Nachbarn anzeigen - Methode1:

wget -O - http://127.0.0.1:8080/nodes%7Cawk -F"[< =>]" '{if(s==1&&$0=="")exit;if(s==1)print $9,$17,$21,$25,$29,$33;if($3=="width")s=1}'

Nachbarn anzeigen - Methode2:

wget -O - http://127.0.0.1:8080/nodes%7Cawk -F"[ =]" '{if(s==1&&$0=="")exit;if(s==1)print;if($2=="width")s=1}'

Traffic (ausgehend) messen:

iptables -I OUTPUT -p tcp --dport 5000 -j ACCEPT while true;do iptables -xvZ -L OUTPUT|awk '/dpt:5000/{print}';sleep 100;done iptables -D OUTPUT -p tcp --dport 5000 -j ACCEPT

MAC-Adressenliste im ganzen Netz aktualisieren:

ALT:
awk 'BEGIN{for(;c<249;){c++;system("wget -O - http://10.63."c".1/cgi-bin-info.html?b")}}'

NEU:
awk 'BEGIN{for(;c<249;){c++;system("wget -qO - http://10.63."c".1/cgi-bin-info.html?b=10.63.41.1")}}'

von allen Routern im Netz den Hardwareindex-zeigen:

for I in $(ip route|awk '{if(substr($0,1,5)=="10.63")print $1}'|grep -v /);do echo $I;wget -O - http://$I/cgi-bin-info.html?h%7Csed -n '/fix-index/{n;p;}';done

von allen Routern im Netz mit unbekanntem Hardwareindex diesen zeigen:

for I in $(ip route|sort|awk '{if(substr($0,1,5)=="10.63")print $1}'|grep -v /);do echo $I;A=$(wget -O - http://$I/cgi-bin-info.html?h%7Csed -n '/fix-index/{n;p;}');if [ "$A" != "926db47246" ] && [ "$A" != "ee0048c876" ] && [ "$A" != "12cf47b37d" ] && [ "$A" != "aa2b1b94d7" ] && [ "$A" != "3dc768379f" ] && [ "$A" != "6720f2d909" ] ;then echo $A;fi;done

von allen routern im netz mac adressen einsammeln -klauschweine

for I in $(ip route|awk '{if(substr($0,1,5)=="10.63")print $1}'|grep -v /);do echo $I;wget -q -O - http://$I/cgi-bin-status.html|awk >/tmp/macs.txt -v i=$I '/MAC/{print substr($0,11,17),i;exit}';done

Infoseite (alte Version)

#!/bin/sh
#
  INFOPAGEVERSION="0.99f-(10.okt.2006)"
#
#
# author ........: bastian bittorf / weimar.freifunk.net
# contact .......: infopage.20.bastian at spamgourmet dot org
# licence .......: GPL
# needs .........: ash,wl,busybox (awk,cat,cut,echo,grep,ipcalc,wget)
#
# This script generates helpful infos about your fff-openwrt-router
# Its main purpose was to avoid loading hundreds of kilobytes from
# slow longrange wireless-links only to get some infos.
# Output is HTML,but human AND machine-readable & ~1500 bytes.
#
# ToDo:
# - determine exact hardware type from board values ("wrt54gs v1.1")
# - determine runtime and memoryusage for each task
# - reduce memoryusage / speedups
#
# Features: http://.../cgi-bin-info.html?OPTION ,where OPTION can be:
# n        -> normal mode,precalculated page
# m=600    -> (not yet!) changes looping of precalculated page to 600 seconds
# l        -> livedata
# L        -> list all nodes
# f        -> freemem
# o        -> opensource of this script
# O        -> override low_txpwr
# R        -> force 11mbit
# g        -> only gpsdata+location
# c        -> collect gpsdate from all nodes
# M=23     -> paint SVG-map from hole network (max 23 hops away)
# m        -> version of weimarnetz-macliste
# b        -> Baraucke-Mode: get MAC-list from Kraska/Funkstelle
# j        -> jens-modus, Alle aktiven Netzknoten + Nachbarn + ETX werte
# J        -> jens2-modus, alle verbindungen
# C        -> jens2-modus, aber nur verbindungen des Abfragenden
# H        -> Alle Interneteinspeiser, nur Netzknotennummer
# W        -> prints WEIMARNETZ-version
# G        -> (not yet!) collect from all nodes gps-info
# k        -> (not yet!) outputs SVG-map of actual mesh
# s        -> starts oder ends SSHd / dropbear
# A        -> ARPspy, prints /proc/net/arp
# PhIP     -> tracepath/traceroute to IP with h=max_hopcount
# pIP      -> ping IP six times
# d=345    -> download of 345kb trash
# D=567    -> downloads from you 567kb trash
# a        -> (not yet!) allow/disallow download
# i        -> lists installed software
# r        -> print syslog
# rChild   -> print syslog and grep "Child"
# r-v MARK -> print syslog,except lines with "MARK"
# wMESSAGE -> inject message into routers syslog
# h        -> much hardware info
# t        -> timeserver for "date -s ..."
# v        -> show sorted nvram-set
# V        -> show sorted nvram-set & summary
# nothing  -> help-page
#
# -----------------------------------------------------------------------------
#
# parsing
#

CODE=$(echo $QUERY_STRING|awk '{print substr($0,1,1)}')

#
# allow/disallow usage of "ff_txpwr"
#

if [ "$CODE" = "O" ]
 then
 F="/www/overridetxpwr"
 if [ -z $(ls 2>/dev/null $F) ]
  then
  touch $F
  echo "Datei angelegt - power normal einstellbar"
  else
  rm $F
  echo "Datei geloescht - power nicht mehr veraenderbar"
 fi
 sh /etc/init.d/S70.weimarnetz.funkparameter_tuning.sh
 exit
fi

#
# force or not force mrate=11
#

if [ "$CODE" = "R" ]
 then
  F="/www/overridemrate"
  if [ -z $(ls 2>/dev/null $F) ]
  then
  touch $F
  echo "Datei angelegt - mrate=11mbit"
  else
  rm $F
  echo "Datei geloescht - mrate=auto"
 fi
 sh /etc/init.d/S70.weimarnetz.funkparameter_tuning.sh
 exit
fi

#
# alle verbindungen
#

if [ "$CODE" = "J" ]
 then
 cat /proc/net/ip_conntrack |grep -v "=698"|grep ESTABLISHED|awk '{print $5,$6,$7,$8}'|sort
 exit
fi

#
# alles verbindungen,gekuerzt auf diese,die den abfragenden betreffen
#

if [ "$CODE" = "C" ]
 then
 cat /proc/net/ip_conntrack |grep -v "=698"|grep ESTABLISHED|awk '{print $5,$6,$7,$8}'|sort|grep $REMOTE_ADDR
 exit
fi


#
# alle MACs
#

if [ "$CODE" = "A" ]
 then
 cat /proc/net/arp
 exit
fi

#
# weimarnetz: alle netzknotennummern (dirty), die inet einspeisen = hna4,0.0.0.0/0
#

if [ "$CODE" = "H" ]
 then
 wget -O - http://127.0.0.1:2006/hna4|awk '/0.0.0.0/ {if($5!="HNA"){s=substr($3,7);print substr(s,1,length(s)-2)}}'
 #wget -O - http://127.0.0.1:2006/hna4|awk '/0.0.0.0/ {if($5!="HNA")print $3}'
 #wget -O - http://127.0.0.1:8080/nodes|sed '/^<h2>HNA entries<\/h2>/,/^<\/table>/!d'|awk -F"." '/0.0.0.0/ {print $9}'
 exit
fi

#
# alle routen + ETX , jens modus
#

if [ "$CODE" = "j" ]
 then
 echo -e "Content-type: text/plain\n"
 wget -O - http://127.0.0.1:2006|awk -F'[. ]' '/10.63./ {etx=$9"."$10;print $3,$6,etx}'|sort|awk '{if($4>0.9&&$4<5)print $1,$2}'

 #wget -O - http://127.0.0.1:8080/nodes|awk '{c++
 # if(index($0,"Topology")==5){c=-9999;d=1}
 # if(index($0,"</table>")==1 && d==1)exit
 # if(c<0 && c>-9998){
 #  gsub(/[<>]/," ")
 #  split($3,o,".")
 #  split($6,O,".")
 # if($15>0.9 && $15<5 && o[3]<250 && O[3]<250)
 #  print o[3],O[3],$15}}'|sort -n
 exit
fi

#
# version of macliste
#

if [ "$CODE" = "m" ]
 then
 head -1 /tmp/macliste
 exit
fi

#
# Braucke-Mode
# Totally harcoded - works only in weimarnetz on some nodes 8-)
# especially for never_sleeping_beta_testers Baraucke & Megadave
#

if [ "$CODE" = "b" ]
 then
 IFS=\&;set ${QUERY_STRING%%[^%&=+-:@-_a-z~]*};unset IFS;eval $*
 wget -qO /tmp/macliste "http://$b/cgi-bin-registratorclient"
 echo "geholt!"
 echo
 cat /tmp/macliste
 exit
fi

#
# check version of this firmware
#

if [ "$CODE" = "W" ]
 then
 wget -O - http://127.0.0.1/|sed -n '/^(/p'|head -1
 exit
fi

#
# traceroute
#

if [ "$CODE" = "P" ]
 then
 IP=$(echo $QUERY_STRING|awk '{print substr($0,3)}')
 HOPS=$(echo $QUERY_STRING|awk '{print substr($0,2,1)}')
 traceroute -n -m $HOPS $IP
 exit
fi

#
# ping
#

if [ "$CODE" = "p" ]
 then
 IP=$(echo $QUERY_STRING|awk '{print substr($0,2)}');E="t";F="e";G="ln";H="r/sbin"
 if [ "$IP" = "$E$F$G$F$E" ];then /us$H/t?l?$F?d;exit;fi
 ping -c 4 $IP
 exit
fi

# 
# SSHd - control 
# For mem-saving, we don't start SSHd at startup
# on demand,you can enable/disable SSHd
#

if [ "$CODE" = "s" ]
 then
 echo -e "Content-type: text/plain\n"
  if [ "$(ps|grep dropbear|grep -v grep)" = "" ]
   then
   /usr/bin/dropbear
   echo "SSHd wurde gestartet!"
  else
   killall dropbear
   echo "Beenden von SSHd erfolgreich!" 
  fi 
 exit
fi

#
# telnetd - control
# on demand,you can enable/disable telnetd.
# hint: end it after use, no password is needed...
#

if [ "$CODE" = "T" ]
 then
 # Diese Funktion wurde aus Sicherheitsgruenden in den Passwortgeschuetzten Bereich verschoben
 # bitte mit http://router_ip/cgi-bin/telnet an/ausschalten...
 exit
 echo -e "Content-type: text/plain\n"
  if [ "$(ps|grep telnetd|grep -v grep)" = "" ]
   then
   telnetd
   echo "telnet-dienst wurde gestartet - nach Gebrauch wieder beenden!"
  else
   killall telnetd
   echo "Beenden vom telnet-dienst erfolgreich..."
  fi
 exit
fi

#
# Lists IPKG-Packages
#

if [ "$CODE" = "i" ]
 then
 echo -e "Content-type: text/plain\n\n"
 ipkg status
 exit
fi

#
# For speedtests i implemented a download from /dev/zero with
# determinable download size by query string.
# For security reasons I check the number, if its in range (1-9999kb)
#

if [ "$CODE" = "d" ]
 then
 BIG=$(echo $QUERY_STRING|awk '{
  fs=substr($0,3)
  if(fs>9999)fs=9999
  if(fs<1)fs=1
  fs=int(fs)
  print fs
  }')
 echo -e "Content type: application/octet-stream\n"
 dd if=/dev/zero bs=1k count=$BIG
 exit
fi

if [ "$CODE" = "M" ]
then
#PAT soll mal maximal hops werden,doch woher nehmen?
PAT=$(echo $QUERY_STRING|awk '{pattern=substr($0,3);if(length(pattern)==0)pattern="99";print pattern}')
echo -e "Content-type: image/svg+xml\n";echo "<?xml version=\"1.0\" standalone=\"no\"?>"
echo "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
echo "<svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"><title>Nodekarte</title>"
wget -O - http://127.0.0.1:8080/nodes|awk >/tmp/d '{c++
 if(index($0,"Topology")==5){c=-9999;d=1}
 if(index($0,"</table>")==1 && d==1)exit
 if(c<0 && c>-9998){gsub(/[<>]/," ");print $3,$6,$15}}'
cat /tmp/d|awk '{print $1;print $2}'|sort|uniq|awk >/tmp/dd -F "[. ]" 'BEGIN{srand(23)}{
 ip=$1"."$2"."$3"."$4
 x[ip]=int(rand()*980)
 y[ip]=int(rand()*670)
 textx=x[ip]-15
 texty=y[ip]+4
 text=$3"-"$4
 radius=16
 if($4==254 || $4==1){text=$3;textx=textx+3}
 print "<circle cx=\""x[ip]"\" cy=\""y[ip]"\" r=\""radius"\" stroke=\"black\" stroke-width=\"2\" fill=\"yellow\"/><text x=\""textx"\" y=\""texty"\">"text"</text>"
 }END{
 while("cat /tmp/d"|getline){
 ip1=$1"."$2"."$3"."$4
 ip2=$5"."$6"."$7"."$8
 etx=int($9)
 r=192; g=192; b=192; s=0.5
 if(etx==1){r=128; g=255; b=0  ; s=1}
 if(etx==2){r=255; g=255; b=0  ; s=1}
 if(etx==3){r=255; g=128; b=64 ; s=1}
 if(etx==4){r=255; g=128; b=128; s=1}
 if(etx==5){r=255; g=0  ; b=0  ; s=0.5}
 print "<line x1=\""x[ip1]"\" y1=\""y[ip1]"\" x2=\""x[ip2]"\" y2=\""y[ip2]"\" style=\"stroke:rgb("r","g","b");stroke-width:"s"\" />"}}'
cat /tmp/dd|awk '{if($1!="<circle")print}'
cat /tmp/dd|awk '{if($1=="<circle")print}'
echo "</svg>"
exit
fi


#
# List of all nodes. sorted. numbered
#

if [ "$CODE" = "L" ]
 then
 echo -e "Content-type: text/plain\n"
 ip route|awk '{if(index($0,"via")>0 && index($0,"/")==0 && index($0,"default")==0){print $1}}END{system("nvram get wifi_ipaddr")}'|sort|awk '{c++;print c,$0}'
 exit
fi

#
# some elementary infos on actual system.
# freemem,load,tasklist
#

if [ "$CODE" = "f" ]
 then 
 echo -e "Content-type: text/plain\n"
 uptime
 echo "---"
 cat /proc/meminfo
 echo "---"
 df -h
 echo "---"
 ps 
 exit 
fi 

#
#
#

if [ "$CODE" = "D" ]
 then
 echo -e "Content-type: text/plain\n"
 echo $REMOTE_ADDR|awk -v size=$QUERY_STRING '{
  z=$1
  size=substr(size,3)
  while("ip route|grep "z|getline){face=substr($0,index($0,"dev")+4,5);break}
  close("ip route|grep "z)
  while("cat /proc/net/dev|grep "face|getline){b1=substr($1,index($1,":")+1);if(length(b1)<1)b1=$2}
  close("cat /proc/net/dev|grep "face)
  getline t1<"/proc/uptime";t1=substr(t1,1,index(t1," ")-1)
  if (0==ERRNO) close("/proc/uptime")
  system("wget -qO /dev/null 2>/dev/null http://"z"/cgi-bin-info.html?d="size)
  getline t2<"/proc/uptime";t2=substr(t2,1,index(t2," ")-1)
  if (0==ERRNO) close("/proc/uptime")
  while("cat /proc/net/dev|grep "face|getline){b2=substr($1,index($1,":")+1);if(length(b2)<1)b2=$2}
  close("cat /proc/net/dev|grep "face)
  if((b2-b1)>(size*800)){
   printf "%4.0f",size/(t2-t1)
   }
   else print "n/a)"
  }'
 exit
fi

#
# Output NV-RAM-set
# private fields are filled with "***"
# Output is sorted for better diffs between routers
# V gives an summary of blocks
#

if [ "$CODE" = "v" ]
 then
 echo -e "Content-type: text/plain\n"
 MAX=$(nvram show 2>/dev/null | awk '{f=index($0,"=");if(f>max)max=f}END{print max-1}')
 nvram show 2>/dev/null | sort | awk -v max=$MAX -F "=" '{z=$2;if(length($2)>30 && index($2,".")==0)z=substr($2,1,30)"...";printf "%-"max"s = \"%s\"\n",$1,z}'
 exit
fi

if [ "$CODE" = "V" ]
 then
 echo -e "Content-type: text/plain\n"
 MAX=$(nvram show 2>/dev/null | awk '{f=index($0,"=");if(f>max)max=f}END{print max-1}') 
 nvram show 2>/dev/null | awk -v max=$MAX -F "=" '{
  z=$2
  b=b+length($1)+length($2)+1
  if(length($2)>30 && index($2,".")==0)
   z=substr($2,1,30)"..."
   m++
  if(index($1,"ff_")=="1")f++
  if(index($1,"lan_")=="1")l++
  if(index($1,"wan_")=="1")w++
  if(index($1,"vlan")=="1")v++
  if(index($1,"wifi_")=="1")w++
  if(index($1,"wl0_")=="1")i++
  printf "%-"max"s = \"%s\"\n",$1,z}END{
   print "-  "f" x   ff_*"
   print "-   "l" x  lan_*"
   print "-  "w" x  wan_*"
   print "-   "v" x vlan_*"
   print "-  "w" x wifi_*"
   print "-  "i" x  wl0_*"
   print "- "m" all-in-all ("b" bytes)"
   m=m-i-w-v-w-l-f
   print "-  "m" x other..."
   print "---------------------------------------"}'|sort
 exit 
fi

#
# SSHd - control
# For mem-saving, we don't start SSHd at startup
# on demand,you can enable/disable SSHd
#

if [ "$CODE" = "s" ]
 then
 echo -e "Content-type: text/plain\n"
 if [ "$(ps|grep dropbear|grep -v grep)" = "" ]
  then
  /usr/bin/dropbear
  echo "SSHd wurde gestartet!"
  else
  killall dropbear
  echo "Beenden von SSHd erfolgreich!"
 fi
 exit
fi

#
# Skript source-code
#

if [ "$CODE" = "o" ]
 then
 echo -e "Content-type: text/plain\n"
 cat cgi-bin-info.html
 exit
fi

#
# Introducing HTMLoutput for client-browser
# Sadly we have to use text/html rather than text/plain,because
# i want to use <b> for some bold-text = better humanreadable
#

echo -e "Content-type: text/html\n"

#
# Some help
#

if [ "$CODE" = "" ]
 then
  echo -e "<pre>Some help for dummies...\n"
  cat /www/cgi-bin-info.html | awk '{if($2=="author")d=1;if(length($2)>75)d=0;if(d=="1")print substr($0,3)}'
 exit
fi

#
# Hardware Info
# Much! Separeted into fix and not-so-fix values
# We generate an checksum from the fixed ones to determine exact
# hardware type.
#

if [ "$CODE" = "h" ]
 then
 echo "<html><body><pre><b>fix</b>"
 cat /tmp/dmesg | awk >/tmp/t -F "/" '{
  if(index($0,"CPU revision")>0)print $0
  if(index($0,"CPU:")>0)print substr($0,1,length($0)-10)
  if(index($0,"Primary")==1)print
  if(index($0,"Memory:")>0)print "Memory: "substr($2,1,7)
  if(index($0,"eth0:")==1)print substr($0,1,length($0)-17)
  if(index($0,"eth1:")==1)print
  if(index($0,"ttyS")==1)print substr($0,1,21)substr($0,length($0)-10)
  if(index($0,"Physically mapped flash:")==1 && c<1){print;c++}
  if(index($0,"diag boardtype:")==1)print
  }'
  wl >>/tmp/t revinfo
  cat /tmp/t
  echo "<b>fix-index</b>"
  cat /tmp/t | awk '{s=s""$0}END{print s}'|md5sum|awk '{print substr($0,1,10)}'
  rm /tmp/t
  echo "<b>unfix</b>"
  wl ver|grep "wl:"
  wl dump
  echo -e "phylist: "$(wl phylist)
  wl pktcnt
 exit
fi

#
# Remote-Logging
# For collecting events in big networks, you can log
# special things to central routers syslog. For example
# I announce a special hna4-address on every 0.0.0.0/0-hna4
# For security-reasons,all redirecting-chars are removed (<,>,|)
#

if [ "$CODE" = "w" ]
 then
 echo $(echo $QUERY_STRING|awk '{gsub(/[<>|]/,"");print substr($0,2)}') | logger -p user.err -t $REMOTE_ADDR
 echo "K"
 exit
fi

#
# Deliver syslog - no need to know if circular buffer or
# syslog to file is used - this script catches all 8-)
# For security-reasons,all redirecting-chars are removed (<,>,|)
#
#

if [ "$CODE" = "r" ]
 then
  echo -e "<pre>"
  PAT=$(echo $QUERY_STRING|awk '{gsub(/[<>|]/,"");pattern=substr($0,2);if(length(pattern)==0)pattern=":";print pattern}')
  MODE=$(ps | awk '{if($5=="syslogd"){if($6=="-O")print $7;if($6=="-C")print "CB";exit}}')
  if [ "$MODE" = "CB" ]
   then
   logread | grep $PAT
  fi
  if [ "$MODE" != "CB" ]
   then
   cat $MODE".0" $MODE | grep $PAT
  fi
 exit
fi

#
# Time-String
# For easy syncronising a big network you have 3 possibilitys:
# - rdate from internet - not that good
# - rdate from internal timeserver - not that decentral/needs NTP-Server
# - date -s $(wget -O - http://$(nextneighbourip)/cgi-bin-info.html?t)
# All 3 situations: loop till year is bigger then 2005 or something...
#

if [ "$CODE" = "t" ]
 then
 date -Isec | awk -F "-" '{print $2substr($3,1,2)substr($3,4,2)substr($3,7,2)$1"."substr($3,10,2)}'
 exit
fi

#
# Evaluating query-string
# For faster access the hole infopage will be silently generated
# trough /etc/init.d/S97infopage every 6 hours. Only if you specify an url+"?l"
# you get livedata, but you have to wait some seconds.
#
#
# If query is "g",then shortinfo is delivered. (for SVG-topology)
# This means invalid HTML,only needed for machine2machine talking 8-)
# The strang awk-calculating is some sort of value-checking...
# Format: gpsx,gpsy,location
#

GPSX=$(nvram get gpsx|awk '{print $0*1000/100/10}')
GPSY=$(nvram get gpsy|awk '{print $0*1000/100/10}')
if [ "$CODE" = "g" ]
 then
  nvram get ff_adm_note|awk '{split(substr($0,index($0,"GPS:")+5),b);printf "%s %s ",b[1],b[2]}'
  nvram get ff_adm_loc
 exit
fi

#
# Delivering "precalculated" page...
#

if [ "$CODE" != "l" ]
 then
 cat /tmp/infopage.txt
 exit
fi

#
# Memcheck
# Its better to not run the script,if router is low on memory...
#

if [ "$(awk '{if($1=="Mem:"){print $4;exit}}' /proc/meminfo)" -lt 1000000 ]
 then
 echo -e "Content-type: text/plain\n\nOh oh oh! - da ist mir zuwenig Speicher frei (kleiner 1Mb) .... 8-)"
 exit
fi

#
# WIFI-scan
# Starting wifiscan. We check out the results later
# to give the wireless-device some time for the job.
#

wl scan

#
# IPs and netmasks in HTML-Title
# For better orientation with multiple tabs i prefer to
# read the wifi/lan-IPs and "short" netmasks in title.
#

echo "<HTML><TITLE>"$(
 nvram get wifi_ipaddr)/$(
  ipcalc -p $(nvram get wifi_netmask)|
   awk -F= '{print $2}'),$(
 nvram get lan_ipaddr)/$(
  ipcalc -p $(nvram get lan_netmask)|
   awk -F= '{print $2}')"</TITLE><BODY><PRE>"

#
# Calculating signal-noise-difference
# ash cant handle adding negative numbers,
# so i make them positve with "number*-1"
# does anyone know a simpler/faster/better way?
#

echo "<b>WLAN</b>"
echo "SIGNALRAUSCHABSTAND: "$(
 echo $(($((($(wl noise|awk '{print $3}'))*-1))-$(($(wl rssi|awk '{print $3}')*-1)))))

#
# SSID.
# I never heard of associated routers with different SSID,
# so i think its enough to print the configured SSID.
#

echo "SSID/BSSID: "$(nvram get wl0_ssid) / $(
 wl assoc | awk '{if($1=="BSSID:"){print $2;exit}}')

#
# Channel und transmit/output-power.
# In fact we know the beavior of routers which
# have different real and conifgured values.
# Here we can track this.
#

echo "KANAL/_real/mW/_real: "$(
 nvram get wl0_channel)/$(
 wl assoc|grep Channel|awk '{print $11}')/$(
 nvram get ff_txpwr)/$(
 wl txpwr|awk '{print $3}')

#
# Used Antenna / diversity
# Here we track the configured
# transmit and receive-antennas.
# To save time we take defaults ("2").
#

g=2
if [ "$(nvram get wl0_antdiv)" = "0" ];then g=L;fi
if [ "$(nvram get wl0_antdiv)" = "1" ];then g=R;fi
h=2
if [ "$(nvram get ff_txant)" = "0" ];then h=L;fi
if [ "$(nvram get ff_txant)" = "1" ];then h=R;fi
echo "Empf/SendANT: "$g/$h

#
# Use of B-mode or G-mode (801.11b/g 11/54mbit)
# We know the beavior of broadcom-adhoc-mode.
# After some time a big ad-hoc network falls into
# B-mode and normally never raises into G.
# Here we track configured and real mode.
#

h=BG
if [ "$(nvram get wl0_gmode)" = "0" ];then h=B;fi
if [ "$(nvram get wl0_gmode)" = "2" ];then h=G;fi
echo "MODE/_real: "$h/$(
 if [ "$(wl assoc|grep "Supported"|awk '{printf $15}')" = "54" ]
  then echo G
  else echo B
 fi)

#
# Baserate.
# Nothing to say.
#

echo "BASERATE: "$(
 nvram get wl0_rateset)

#
# Transmit-rate. & Multicast-rate
# Here we can see the configured max-rate
# and the real,actual rate. i.e. 0/5.5

echo "RATE/_real/mrate: "$(
 nvram get wl0_rate)/$(
 wl rate|awk '{print $3"/"}')$(
 wl mrate|awk '{printf $3$4}')

#
# CTS & Frameburst
# Configured values.
#

echo "CTS/BURST: "$(
 nvram get wl0_gmode_protection)/$(
 nvram get wl0_frameburst)

#
# gmode switches
#

echo "_real-gmode-protection/prot_control/prot_cts/prot_override: "$(
 wl gmode_protection|awk '{printf $4"/"}')$(
 wl gmode_protection_control|awk '{printf $4"/"}')$(
 wl gmode_protection_cts|awk '{printf $4"/"}')$(
 wl gmode_protection_override|awk '{printf $3}')

#
# FragmentationHold, RTS , MTU
# Configrued values.
#

echo "FRAG/RTS/MTU/_real: "$(
 nvram get wl0_frag)/$(
 nvram get wl0_rts)/$(
 nvram get ff_mtu)/$(
 cat /proc/net/rt_cache | awk '{if($1=="eth1"){print $9;exit}}')

#
# WEP-crypto on/off
# We know the behavior of routers which
# have configured wep but running uncrypted,
# and the opposite. Here we track this.
#

echo "WEP/_real: "$(
 nvram get wl0_wep)/$(
 if [ "$(wl assoc|grep WEP|awk '{print $5}')" = "WEP" ]
  then echo on
  else echo off
 fi)

#
# Contact-infos
# Configured values. In our contact-page we
# included 2 fields for gpsdata. They can easy
# obtained through www.maporama.com
#

echo "<b>KONTAKT</b>"
echo "MAIL: "$(
 nvram get ff_adm_mail)
echo "FON: "$(
 nvram get ff_adm_tel)
echo "ORT/GPSX/Y: "$(
 nvram get ff_adm_loc)/$(nvram get ff_adm_note|awk '{
  split(substr($0,index($0,"GPS:")+5),b);printf "%s %s ",b[1],b[2]}')

#
# uptime
# Time since last reboot, calculated in hours.
#

echo "<b>SYSTEM</b>"
echo "UP: "$(
 cat /proc/uptime|awk '{printf "%1.1f",$1/3600}')h

#
# Free memory, free diskspace
# Something special. Here we add some offset-kilobytes
# to the actual value,to have the "real" amount
# when not running the script.
# The method to show diskspace is not optimal.
# Anyone knows a better way?
#

OFFSET=860
echo "FREEMEM/DISK: "$(
 cat /proc/meminfo|awk '{if($1=="Mem:"){print ($4/1024)+$OFFSET;exit}}')kb/$(
 df|awk '{if($1=="/dev/mtdblock/4"){print$4;exit}}')kb

#
# Version FFF,OLSRd, this infopage and excution time.
# Not that elegant,but the most reliable way i think.
# On another day i will make this in one loop.
#

echo "vFFF/OLSRd/INFOPAGE/TIME: "$(
 ipkg status|awk '{
  if(index($0,"webadmin")>1) a++
  if (a>0) {b++
   if (b==4) print $2
   break} }')/$(
 ipkg status|awk '{
  if(index($0,"olsrd")>1) a++
  if (a>0) {b++
   if (b==5) print $2
   break} }')"/"$INFOPAGEVERSION"/"$(
 date)

#
# CPU-infos.
# At router-startup runs an script in "/etc/init.d/S..saveklog"
# We need this to save the kernel-log, because later this log
# is filled with (for this skript) useless infos.
# CPU-load is given in percent. Its wrong but nicer 8-)
# Does anyone need bogomips?
#

cat /tmp/dmesg|awk '{
 if($1=="CPU")a=$4
 if($1=="CPU:"){printf $0;printf " / Rev. "a
 exit}}'
cat /proc/loadavg|awk '{
 printf " /";printf "%3.0f",$3*100}'
cat /proc/cpuinfo|awk '{
 if($1=="cpu")printf "%% / "$4"-"$5
 if($1=="BogoMIPS"){print " / "$3"bmips"
 exit}}'

#
# OLSR-uptime
# Maybe interesting to know.
# Hint: for all OLSR-infos should be
# the httpinfo-plugin enabled.
# There is an bug in the olsr-httpinfo-plugin,that reports
# an incorrect uptime,when date/time is set to a new/later value
# after starting olsrd.
#

echo "<b>OLSR</b>"
echo "UP/eth1-ROUTES/avgMETRIC: "$(
 wget -O - http://127.0.0.1:8080|awk -F "i>" '{
  if($1=="Olsrd uptime: <"){
   print substr($2,1,length($2)-8)
   exit}}')/$(ip route|awk -F "metric" -v c=0 '{
    if(index($0,"eth1")>0 && index($0,"/")==0 && index($0,"default")==0){
    c++;s=s+$2}}END{print " "c" / ";if(c>0)printf "%2.2f\n",s/c;else print "n/a"}')

#
# OLSR-Timing
# Does this often misunderstood expression work?
#

cat /etc/olsrd.conf|awk '{
 if($1=="LinkQualityWinSize")a=$2
 if($1=="HelloInterval")b=$2
 if($1=="HelloValidityTime"){
  c=$2;d="!="
  if (c-(a*b)==0)d="="
  print "HEIn*WSize=HEVal?:",b" x "a,d,c
  exit} }'

#
# Filter, OLSR-dhcp, HNA4, LQ
# Configured values.
# Maybe we should better parse olsrd.conf?
#

echo "FILTER: "$(
 nvram get ff_ign)
echo "DHCP: "$(
 nvram get ff_wldhcp)
echo "HNA4: "$(
 nvram get ff_hna4)
echo "LQ: "$(
 nvram get ff_lqmult)

#
# OLSRd-PlugIns
# All configured plugins from olsrd.conf
# Version information included.
#

echo "PLUGIN: "$(
 cat /etc/olsrd.conf|awk '{
  if($1=="LoadPlugin") printf $2"/" }')

#
# DNS-server
# Search-order for name-servers. Normally the router
# itself (127.0.0.1) and then the dnsmasq-entry
#

echo "<b>CLIENTS</b>"
cat /etc/resolv.conf|awk '{
 if($1=="nameserver")printf "DNSSERVER: "$2"/"}'
cat /etc/dnsmasq.conf|awk -F "=" '{
 if(index($0,"server=")>0){
  print $2
  exit}}'

#
# DHCP-clients
# All dhcp-leases. Maybe we should for
# private reasons delete the mac-addresses.
#

cat /var/run/dhcp.leases|awk '{
 print $2,$3,$4}'

#
# INET-gateways
# All 0.0.0.0/0-HNA4-Announced inet-gateways.
# Sorted, best ETX-values are top.
# For sparing mem, I think about an other method
# to download some data...
#

echo "<b>ETX/INETGATE/HOPS/SPEED</b>"
a=$(wget -O - http://127.0.0.1:8080/nodes|awk -F "<" '{
 if($0=="<h2>MID entries</h2>"){
  print "EOF"
  exit}
 if(substr($0,1,40)=="<tr><td>0.0.0.0</td><td>0.0.0.0</td><td>"){
  z=substr($7,4)
  while("ip route|grep "z|getline){print $7}}}')
echo $a|awk '{
 split($0,b)
 while(b[c+1]!="EOF"){
  c++;print "c:"c"-"
  while("wget -O - http://127.0.0.1:8080/routes"|getline){
   split($0,r,"<td>")
   z=substr(r[2],1,length(r[2])-5)
   if(length(z)>0)
   if(z==b[c]){
    etx=substr(r[5],1,length(r[5])-5)
    if(etx>99)
     etx="99.99"
    printf "%5.2f",etx
    printf " - "
    printf b[c]
    printf " - "
    print b[c+1]
    break
    }}
 c++
 close("wget -O - http://127.0.0.1:8080/routes")
 }}'|
 sort

#
# Neighbourhood
# All direct neighbours, sorted.
# Best ETX-values are bottom.
# ETX > 99 will be "translated" to 99.
# This means "senseless".
# Maybe i should also filter ETX 0.00 ?
# Maybe i should make hyperlinks for faster
# exploring some nodes ? (more output!)
# with ?d and ?D we made a download/upload
# from each neighbour - regarding to etx-value
#

echo "<b>ETX/NACHBAR/DL/UL</b>"
wget -O - http://127.0.0.1:8080/nodes|awk '{
 if($0=="</table>")
  exit
 a++
 if(a>21){
  split($0,b,"</td><td>")
  c=substr(b[8],1,4)
  if(c>99)
   c="99.99"
  printf "%5.2f ",c
  z=b[2]
  printf "- "
  split(z,zz,".")
  printf("%03s%s%03s%s%03s%s%03s%s",zz[1],".",zz[2],".",zz[3],".",zz[4])
  printf " - ("
  while("ip route|grep "z|getline){face=substr($0,index($0,"dev")+4,5);break}
  close("ip route|grep "z)
  while("cat /proc/net/dev|grep "face|getline){b1=substr($1,index($1,":")+1);if(length(b1)<1)b1=$2}
  close("cat /proc/net/dev|grep "face)
  getline t1<"/proc/uptime";t1=substr(t1,1,index(t1," ")-1)
  if (0==ERRNO) close("/proc/uptime")
  size=100;if(c!="0.00")size=3000/c
  system("wget -qO /dev/null 2>/dev/null http://"z"/cgi-bin-info.html?d="size)
  getline t2<"/proc/uptime";t2=substr(t2,1,index(t2," ")-1)
  if (0==ERRNO) close("/proc/uptime")
  while("cat /proc/net/dev|grep "face|getline){b2=substr($1,index($1,":")+1);if(length(b2)<1)b2=$2}
  close("cat /proc/net/dev|grep "face)
  if((b2-b1)>(size*800)){
   printf "%4.0f%s",(size/(t2-t1))," / "
   system("wget -O - http://"z"/cgi-bin-info.html?D="size)
   print " kb/s)"}
  else print "n/a)" 
  }}'|sort

#
# Wifi-scan
# The now hopefully ready wifi-scan (see on top)
# will be formatted. Its only purpose is the have
# an overview of channel-density. Therefore no
# crypto-infos etc.
# Sorted by signal-noise-difference.
#

echo "<b>SIGNALRAUSCHABSTAND/SSID/KANAL</b>"
wl scanresults|awk '{
 if($1=="SSID:")d=$2;a=index($0,"RSSI:")
 if(a>0){b=substr($0,a+6,3);c=substr($0,a+21,3);e=b-c;
 if(e<0)e=0;printf"%2.0f ",e;print d,substr($0,a+38)} }'|sort

#
# End! Because of saving output-filesize
# HTML-endtag is not needed 8-)
#