#!/usr/bin/webif-page # Dmytro Dykhman # # Major revisions: # # # Configuration files referenced: # none # # TODO: # I originally wrote this before I had bothered to learn much about # awk, so it uses 'pure' shell scripting. It would be much simpler # and probably more efficient to use awk. Maybe recode someday, but # why fix what's isn't broken... # . "/usr/lib/webif/webif.sh" ##### Variables MAX_TRIES=4 MAX_CELLS=100 Wimg=0 color=0 counter=0 current=1 tempfile=$(mktemp /tmp/.survtemp.XXXXXX) tempfile2=$(mktemp /tmp/.survtemp.XXXXXX) tempscan=$(mktemp /tmp/.survscan.XXXXXX) ####################################### header "Status" "Site Survey" " @TR<>" ######## Join WIFI ######## if [ "$FORM_joinwifi" != "" ]; then if is_kamikaze; then . "/lib/config/uci.sh" config_cb() { config_get TYPE "$CONFIG_SECTION" TYPE case "$TYPE" in wifi-iface) config_get device "$CONFIG_SECTION" device config_get vifs "$device" vifs append vface "$CONFIG_SECTION" "$N" ;; esac } config_load wireless for vcfg in $vface; do config_get FORM_device $vcfg device if [ "$FORM_device" = "$device" ]; then uci_set "wireless" "$vcfg" "network" "lan" uci_set "wireless" "$vcfg" "mode" "sta" uci_set "wireless" "$vcfg" "ssid" "$FORM_wifi" if [ "$FORM_wepkey" != "" ]; then uci_set "wireless" "$vcfg" "encryption" "$FORM_keytype" uci_set "wireless" "$vcfg" "key" "$FORM_wepkey" else uci_set "wireless" "$vcfg" "encryption" "none" uci_set "wireless" "$vcfg" "key" "" fi fi done uci_commit "wireless" #iwconfig wl0 mode "repeater" iwconfig wl0 essid "$FORM_wifi" cat <
Successfully joined "$FORM_wifi" network... EOF footer exit else #<- if kamikaze nvram set wl0_mode="sta" nvram set wl0_infra="1" nvram set wl_ssid="$FORM_wifi" nvram commit WL_MODE=$(nvram get wl0_ifname) #wifi up 2>/dev/null >/dev/null
Successfully joined "$FORM_wifi" network ... EOF footer exit fi #<- end if kamikaze fi #<- end if Join WIFI DisplayTable() { cat <
@TR<>

EOF } DisplayTR() { if [ "$color" = "1" ] ; then color="2" ; else color="1" ; fi echo "" ##### Signal Ratio if [ $RSSI -lt 60 ]; then Wimg=5 ; elif [ $RSSI -lt 72 ]; then Wimg=4 ; elif [ $RSSI -lt 81 ]; then Wimg=3 ; elif [ $RSSI -lt 85 ]; then Wimg=2 ; elif [ $RSSI -lt 92 ]; then Wimg=1 ; else Wimg=0 ; fi echo "" ##### Noise Ratio if [ $NOISE -gt 95 ]; then Wimg=0 ; elif [ $NOISE -gt 92 ]; then Wimg=1 ; elif [ $NOISE -gt 88 ]; then Wimg=2 ; elif [ $NOISE -gt 85 ]; then Wimg=3 ; elif [ $NOISE -gt 80 ]; then Wimg=4 ; else Wimg=5 ; fi echo "" ##### Security if [ "$SEC" = "ESS WEP" ] || [ "$SEC" = "on" ] ; then Wimg="wep" ; else Wimg="opn" ; fi echo "" echo "" echo "" echo "" ##### Speed (needs improvements!) if [ "$RATE" = "66" ] ; then Wimg="54 Mbps" ; elif [ "$RATE" = "75" ] ; then Wimg="54 Mbps" ; elif [ "$RATE" = "44" ] ; then Wimg="11 Mbps" ; else Wimg="(?)" ; fi echo "" echo "" } ######################### The Scanning Part > ##### wl scanning ####### WL() { Dopurge () { sed 1d < $tempfile > $tempfile2 rm $tempfile mv $tempfile2 $tempfile } for counter in $(seq 1 $MAX_TRIES); do wl scan wl scanresults > $tempscan 2> /dev/null if equal $(sed '2,$ d' $tempscan | cut -c0-4) "SSID" ; then break ; fi sleep 1 done if [ $counter -gt $MAX_TRIES ]; then echo "" else #------------------------- # We need to add a "break" on the first line! current_line=$(grep -i '' < $tempscan) echo "" > $tempfile echo "$current_line" >> $tempfile rm $tempscan #------------------------ DisplayTable # Read File #------------------------ while read f do # DEBUG #------\/ #echo $f "
" current_line=$(sed '2,$ d' $tempfile) #echo "-> '" $current_line "'
" if equal "$current_line" "" ; then let "current=1" #echo "->" $current else let "current=0" fi if equal "$current" "1" ;then Dopurge current_line=$(sed '2,$ d' $tempfile) if equal "$current_line" "" ;then echo "" else ##### Set Variables #current_line=$(sed '2,$ d' $tempfile) SSID=$(sed '2,$ d' $tempfile | sed -e s/'SSID: '//g -e s/'"'//g) Dopurge RSSI=$(sed '2,$ d' $tempfile | cut -c22-23) NOISE=$(sed '2,$ d' $tempfile | cut -c37-38) CHANNEL=$(sed '2,$ d' $tempfile | cut -c53-55 ) Dopurge BSSID=$(sed '2,$ d' $tempfile | cut -c7-24 ) SEC=$(sed '2,$ d' $tempfile | cut -c38-44 ) Dopurge RATE=$(sed '2,$ d' $tempfile | wc -c) #RATED=$(sed '2,$ d' $tempfile) DisplayTR fi fi Dopurge done < $tempfile rm $tempfile #rm $tempfile2 echo "
@TR<>/ @TR<> @TR<> @TR<> @TR<> @TR<> @TR<>  
-" $RSSI "dBm
-" $NOISE "dBm
$SEC
  " $SSID #echo "$current_line" | cut -c8-20 | cut -d '"' -f1 echo "
" $BSSID "
" $CHANNEL "
$Wimg
" if [ "$SEC" = "ESS WEP" ] || [ "$SEC" = "on" ] ; then echo "" else echo "
" fi echo "
@TR<>

@TR<>
" fi } ######### iwlist scanning ####### IWLIST() { #echo " Please wait while scan is performed ...

" found_networks=0 counter=0 for counter in $(seq 1 $MAX_TRIES); do #echo "." iwlist scan > $tempfile 2> /dev/null grep -i "Address" < $tempfile >> /dev/null equal "$?" "0" && break sleep 1 done first_hit=1 if [ $counter -gt $MAX_TRIES ]; then echo "@TR<>" else DisplayTable current=0 counter=0 for counter in $(seq 1 $MAX_CELLS); do current_line=$(sed '2,$ d' < $tempfile) empty "$current_line" && break # line must contain both "Cell" and "Address" to be considered # start of a new cell.. echo "$current_line" | grep "Cell" >> /dev/null result_one=$? echo "$current_line" | grep "Address" >> /dev/null result_two=$? if equal "$result_one" "0" && equal "$result_two" "0" ; then if equal "$first_hit" "0" ; then let "current+=1" fi first_hit=0 fi if equal "$first_hit" "0" ; then echo "$current_line" >> "$tempfile"_"${current}" fi sed 1d < $tempfile > $tempfile2 rm $tempfile mv $tempfile2 $tempfile done current=0 counter=0 for counter in $(seq 1 $MAX_CELLS); do ! exists "$tempfile"_"${current}" && break #################################################### # parse out MAC address_pre=$(sed '2,$ d' < "$tempfile"_"${current}" | sed -e s/'Cell'//g -e s/'Address'//g -e s/'-'//g) count=0 for i in $address_pre; do case $count in 0) CELL_ID=$i;; 2) BSSID=$i;; 3) break;; esac let "count+=1" done ################################ SSID=$(grep -i "ESSID" < "$tempfile"_"${current}" | sed -e s/'ESSID:'//g -e s/'"'//g -e s/' '//g) CHANNEL=$(grep -i "Channel" < "$tempfile"_"${current}" | sed -e s/'Channel:'//g -e s/' '//g) quality_pre=$(grep -i "Quality" < "$tempfile"_"${current}" | sed -e s/'Quality:'//g -e s/'Signal level:'//g -e s/'dBm'//g -e s/'Noise level:'//g -e s/'-'//g) count=0 for i in $quality_pre; do case $count in 0) QUALITY=$i;; 1) RSSI=$i;; 2) NOISE=$i break;; esac let "count+=1" done SEC=$(grep -i "Encryption key" < "$tempfile"_"${current}" | sed -e s/'Encryption key:'//g -e s/' '//g) RATE=1 DisplayTR rm -f "$tempfile"_"${current}" let "found_networks+=1" let "current+=1" done echo "
@TR<>
" fi #<- end if were scan results rm -f "$tempfile" rm -f "$tempfile2" } if is_kamikaze; then if is_package_installed "wl" ; then #<- for Broadcom units where iwlist is broken WL else IWLIST fi else IWLIST fi footer ?>