tazpanel rev 106

network.cgi: Improve wifi settings
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 15 06:37:45 2011 +0200 (2011-04-15)
parents c847b9bf07c2
children 306b0bf62bb8
files network.cgi
line diff
     1.1 --- a/network.cgi	Fri Apr 15 05:52:46 2011 +0200
     1.2 +++ b/network.cgi	Fri Apr 15 06:37:45 2011 +0200
     1.3 @@ -5,6 +5,7 @@
     1.4  
     1.5  # Common functions from libtazpanel
     1.6  . lib/libtazpanel
     1.7 +. /etc/network.conf
     1.8  get_config
     1.9  header
    1.10  
    1.11 @@ -17,6 +18,56 @@
    1.12  
    1.13  TITLE="- Network"
    1.14  
    1.15 +# Catch ESSIDs and format output for GTK tree. We get the list of
    1.16 +# networks by Cell and without spaces.
    1.17 +detect_wifi_networks()
    1.18 +{
    1.19 +	table_start
    1.20 +	cat << EOT
    1.21 +<thead>
    1.22 +	<tr>
    1.23 +		<td>$(gettext "Name")</td>
    1.24 +		<td>$(gettext "Quality")</td>
    1.25 +		<td>$(gettext "Encryption")</td>
    1.26 +		<td>$(gettext "Status")</td>
    1.27 +	</tr>
    1.28 +</thead>
    1.29 +EOT
    1.30 +	if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
    1.31 +		ifconfig $WIFI_INTERFACE up
    1.32 +		for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'`
    1.33 +		do
    1.34 +			SCAN=`iwlist $WIFI_INTERFACE scan last | \
    1.35 +				awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
    1.36 +				sed s/"Cell "/Cell-/ | grep -A 5 "$i"`
    1.37 +			ESSID=`echo $SCAN | cut -d '"' -f 2`
    1.38 +			if echo "$SCAN" | grep -q Quality; then
    1.39 +				QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'`
    1.40 +			else
    1.41 +				QUALITY="-"
    1.42 +			fi
    1.43 +			ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
    1.44 +			# Check encryption type
    1.45 +			if echo "$SCAN" | grep -q WPA; then
    1.46 +				ENCRYPTION="${ENCRYPTION} (WPA)"
    1.47 +			fi
    1.48 +			# Connected or not connected...
    1.49 +			if ifconfig | grep -A 1 $WIFI_INTERFACE | \
    1.50 +				grep -q inet && iwconfig $WIFI_INTERFACE | \
    1.51 +				grep ESSID | grep -q -w "$ESSID"; then
    1.52 +				STATUS=$(gettext "Connected")
    1.53 +			else
    1.54 +				STATUS="-"
    1.55 +			fi
    1.56 +			echo '<tr>'
    1.57 +			echo "<td><img src='$IMAGES/wireless.png' />$ESSID</td>"
    1.58 +			echo "<td>$QUALITY</td><td>$ENCRYPTION</td><td>$STATUS</td>"
    1.59 +			echo '</tr>'
    1.60 +		done
    1.61 +	fi
    1.62 +	table_end
    1.63 +}
    1.64 +
    1.65  # Actions commands before page is displayed
    1.66  case " $(GET) " in
    1.67  	*\ start\ *)
    1.68 @@ -49,9 +100,17 @@
    1.69  	*\ wifi\ *)
    1.70  		# Wireless connections settings
    1.71  		xhtml_header
    1.72 +		LOADING_MSG=$(gettext "Scanning wireless interface...")
    1.73 +		loading_msg
    1.74  		cat << EOT
    1.75  <h2>`gettext "Wireless connection`</h2>
    1.76 -
    1.77 +<div id="actions">
    1.78 +	<a class="button" href="$SCRIPT_NAME?wifi=scan">
    1.79 +		<img src="$IMAGES/recharge.png" />$(gettext "Scan")</a>
    1.80 +</div>
    1.81 +$(detect_wifi_networks)
    1.82 +EOT
    1.83 +	cat << EOT
    1.84  <h3>$(gettext "Configuration file")</h3>
    1.85  <p>
    1.86  $(gettext "These values are the wifi settings in the main
    1.87 @@ -62,12 +121,16 @@
    1.88  </pre>
    1.89  <a class="button" href="index.cgi?file=/etc/network.conf&action=edit">
    1.90  	<img src="$IMAGES/edit.png" />$(gettext "Manual Edit")</a>
    1.91 +
    1.92 +<h3>$(gettext "Output of") iwconfig</h3>
    1.93 +<pre>
    1.94 +$(iwconfig)
    1.95 +</pre>
    1.96  EOT
    1.97  		;;
    1.98  	*)
    1.99  		# Main Network page starting with a summary
   1.100  		xhtml_header
   1.101 -		
   1.102  		cat << EOT
   1.103  <h2>`gettext "Networking`</h2>
   1.104  <p>
   1.105 @@ -85,26 +148,26 @@
   1.106  	</div>
   1.107  </div>
   1.108  
   1.109 -`list_network_interfaces`
   1.110 +$(list_network_interfaces)
   1.111  
   1.112 -<h3>`gettext "Output of ifconfig"`</h3>
   1.113 +<h3>$(gettext "Output of ") ifconfig</h3>
   1.114  <pre>
   1.115 -`ifconfig`
   1.116 +$(ifconfig)
   1.117  </pre>
   1.118  
   1.119  <h3>`gettext "Routing table"`</h3>
   1.120  <pre>
   1.121 -`route -n`
   1.122 +$(route -n)
   1.123  </pre>
   1.124  
   1.125  <h3>`gettext "Domain name resolution"`</h3>
   1.126  <pre>
   1.127 -`cat /etc/resolv.conf`
   1.128 +$(cat /etc/resolv.conf)
   1.129  </pre>
   1.130  
   1.131  <h3>`gettext "ARP table"`</h3>
   1.132  <pre>
   1.133 -`arp`
   1.134 +$(arp)
   1.135  </pre>
   1.136  EOT
   1.137  		;;