#!/bin/sh # # version.......: infopage_06-jan-2005 # author........: bastian bittorf # contact.......: infopage.20.bastian at spamgourmet dot org # licence.......: GPL # requirements..: 900kb runtime-memory # tools needed..: ash,wl,busybox (awk,cat,cut,echo,grep,ipcalc,wget) # tested........: fff v1.0.7 # # 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. # Total data-output should be around 1000 bytes. # # ToDo: # - determine exact hardware type from board values ("wrt54gs v1.1") # - traceroutes to all internetgateways # - localisation english,france (all in one file) # - determine runtime and memoryusage for each task # - automatically create network-topologie (SVG) # - reduce memoryusage # - speedups # # ----------------------------------------------------------------- # # # Introducing HTMLoutput for client-browser # Sadly we have to use text/html rather than text/plain,because # i want to use for some bold-text = better humanreadable # echo "Content-type: text/html";echo # # Evaluating query-string # For faster access the hole infopage will be silently generated # trough crond every 15mins. Only if you specify an url+"?l" # you get livedata, but you have to wait some seconds. # If query is not "l", precalculated page is delivered. # if [ "$QUERY_STRING" != "l" ]; then cat /tmp/infopage.txt;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 ""$( 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}')"
"
	    
	    #
	    # 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 "WLAN"
	    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: "$(nvram get wl0_ssid)
	     
	     #
	     # 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.
			# Here we can see the configured max-rate
			# and the real,actual rate. i.e. 0/5.5
			
			echo "RATE/_real: "$(
			 nvram get wl0_rate)/$(
			  wl rate|awk '{print $3}')
			   
			  #
			  # CTS & Frameburst
			  # Configured values.
			  #
			   
			  echo "CTS/BURST: "$(
			   nvram get wl0_gmode_protection)/$(
			    nvram get wl0_frameburst)
			    
			    #
			    # FragmentationHold, RTS , MTU
			    # Configrued values.
			    #
			    
			    echo "FRAG/RTS/MTU: "$(
			     nvram get wl0_frag)/$(
			      nvram get wl0_rts)/$(
			       nvram get ff_mtu)
			       
			       #
			       # 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 "KONTAKT"
				      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 gpsx)/$(
					   nvram get gpsy)
					   
					   #
					   # uptime
					   # Time since last reboot, calculated in hours.
					   #
					   
					   echo "SYSTEM"
					   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/THIS/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} }')/$(
								     ipkg status|awk '{ 
								       if(index($0,"infopage")>1) a++
								         if (a>0) {b++
									    if (b==5) print $2
									       break} }')/$(
									        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.txt|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}}'
										       
										       #
										       # Board-values
										       # Nothing to say.
										       # Maybe later I write a routine to
										       # determine from CPU/board-values the 
										       # machine behind. ("WRT54g v1.0","Siemens SE505" etc.)
										       #
										       
										       echo "BOARDrev/type/num/flags/2: "$(
										        nvram get boardrev|awk '{printf $0"/"}'
											 nvram get boardtype|awk '{printf $0"/"}'
											  nvram get boardnum|awk '{printf $0"/"}' 
											   nvram get boardflags|awk '{printf $0"/"}' 
											    nvram get boardflags2|awk '{printf $0}')
											    
											    #
											    # OLSR-uptime
											    # Maybe interesting to know.
											    # Hint: for all OLSR-infos should be
											    # the httpinfo-plugin enabled.
											    #
											    
											    echo "OLSR"
											    echo "UP: "$(
											     wget -O - http://127.0.0.1:8080|awk -F "i>" '{
											       if($1=="Olsrd uptime: <"){
											          print substr($2,1,length($2)-8)
												     exit}}')
												     
												     #
												     # 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 "CLIENTS"
														       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.
															      # Later I want to include traceroute-outputs to every IP
															      # and the affiliated and summarized ETX-values
															      # Maybe i should alter the downloadtime (5sec) in
															      # reference to ETX (better statistical method).
															      #
															      
															      echo "ETX/INETGATE/SPEED"
															      a=$(wget -O - http://127.0.0.1:8080/nodes|awk -F "<" '{
															       if($0=="

MID entries

"){ print "EOF" exit} if(substr($0,1,40)=="0.0.0.00.0.0.0"){ z=substr($7,4) printf z" (" system("wget -qO /tmp/testdownload http://"z"/cgi-bin-dev-zero.bin &") system("sleep 5") system("kill 2>/dev/null $(ps|grep qO|grep -v grep|cut -b 0-5)") system("a=$(ls -l /tmp/testdownload|cut -b 30-42);let b=a/5120;echo -n $b") system("echo "0" >/tmp/testdownload") print "kb/s)"}}') echo $a|awk '{ split($0,b) while(b[c+1]!="EOF"){ c++ while("wget -O - http://127.0.0.1:8080/routes"|getline){ split($0,r,"") 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". # An endless-download from each neighbour # is made for 5 seconds via wget. # Is there a better way? I you are # "unlucky" you get ~1500kb (300*5s). # Maybe i should also filter ETX 0.00 ? # Maybe i should make hyperlinks for faster # exploring some nodes ? (more output!) # echo "ETX/NACHBAR/SPEED" wget -O - http://127.0.0.1:8080/nodes|awk '{ if($0=="") exit a++ if(a>21){ split($0,b,"") c=substr(b[8],1,4) if(c>99) c="99.99" printf "%5.2f ",c z=b[2] printf "- "z" - (" system("wget -qO /tmp/testdownload http://"z"/cgi-bin-dev-zero.bin &") system("sleep 5") system("kill 2>/dev/null $(ps|grep qO|grep -v grep|cut -b 0-5)") system("a=$(ls -l /tmp/testdownload|cut -b 30-42);let b=a/5120;echo -n $b") system("echo "0" >/tmp/testdownload") print "kb/s)"}}'| 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 "SIGNALRAUSCHABSTAND/SSID/KANAL" 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-) #