# HG changeset patch # User Christophe Lincoln # Date 1302842265 -7200 # Node ID 21a86f36336d4c79097cb1aaddafff38a32ca8fc # Parent c847b9bf07c226e84db61511f2136ac1a7b6e9cd network.cgi: Improve wifi settings diff -r c847b9bf07c2 -r 21a86f36336d network.cgi --- a/network.cgi Fri Apr 15 05:52:46 2011 +0200 +++ b/network.cgi Fri Apr 15 06:37:45 2011 +0200 @@ -5,6 +5,7 @@ # Common functions from libtazpanel . lib/libtazpanel +. /etc/network.conf get_config header @@ -17,6 +18,56 @@ TITLE="- Network" +# Catch ESSIDs and format output for GTK tree. We get the list of +# networks by Cell and without spaces. +detect_wifi_networks() +{ + table_start + cat << EOT + + + $(gettext "Name") + $(gettext "Quality") + $(gettext "Encryption") + $(gettext "Status") + + +EOT + if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then + ifconfig $WIFI_INTERFACE up + for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'` + do + SCAN=`iwlist $WIFI_INTERFACE scan last | \ + awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \ + sed s/"Cell "/Cell-/ | grep -A 5 "$i"` + ESSID=`echo $SCAN | cut -d '"' -f 2` + if echo "$SCAN" | grep -q Quality; then + QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'` + else + QUALITY="-" + fi + ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'` + # Check encryption type + if echo "$SCAN" | grep -q WPA; then + ENCRYPTION="${ENCRYPTION} (WPA)" + fi + # Connected or not connected... + if ifconfig | grep -A 1 $WIFI_INTERFACE | \ + grep -q inet && iwconfig $WIFI_INTERFACE | \ + grep ESSID | grep -q -w "$ESSID"; then + STATUS=$(gettext "Connected") + else + STATUS="-" + fi + echo '' + echo "$ESSID" + echo "$QUALITY$ENCRYPTION$STATUS" + echo '' + done + fi + table_end +} + # Actions commands before page is displayed case " $(GET) " in *\ start\ *) @@ -49,9 +100,17 @@ *\ wifi\ *) # Wireless connections settings xhtml_header + LOADING_MSG=$(gettext "Scanning wireless interface...") + loading_msg cat << EOT

`gettext "Wireless connection`

- +
+ + $(gettext "Scan") +
+$(detect_wifi_networks) +EOT + cat << EOT

$(gettext "Configuration file")

$(gettext "These values are the wifi settings in the main @@ -62,12 +121,16 @@ $(gettext "Manual Edit") + +

$(gettext "Output of") iwconfig

+
+$(iwconfig)
+
EOT ;; *) # Main Network page starting with a summary xhtml_header - cat << EOT

`gettext "Networking`

@@ -85,26 +148,26 @@ -`list_network_interfaces` +$(list_network_interfaces) -

`gettext "Output of ifconfig"`

+

$(gettext "Output of ") ifconfig

-`ifconfig`
+$(ifconfig)
 

`gettext "Routing table"`

-`route -n`
+$(route -n)
 

`gettext "Domain name resolution"`

-`cat /etc/resolv.conf`
+$(cat /etc/resolv.conf)
 

`gettext "ARP table"`

-`arp`
+$(arp)
 
EOT ;;