slitaz-tools diff oldstuff/wifibox @ rev 722

Make POT and msgmerge
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 24 14:35:09 2012 +0100 (2012-03-24)
parents 0f5e3af5a51d
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/oldstuff/wifibox	Sat Mar 24 14:35:09 2012 +0100
     1.3 @@ -0,0 +1,686 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# GTKdialog interface to manage wireless connections in a simple way.
     1.7 +# Use tabs to indent, split commands from the GUI and use functions.
     1.8 +# Favorite networks are also supported
     1.9 +#
    1.10 +# (c) 2010 SliTaz GNU/Linux - GNU gpl v3
    1.11 +#
    1.12 +VERSION=20100118
    1.13 +
    1.14 +# Export script path and others if needed so we can use them in 'quote'.
    1.15 +export BIN=$0
    1.16 +export FAVORITES_WIFI=/etc/wireless
    1.17 +. /etc/network.conf
    1.18 +
    1.19 +# Wifibox is only for root.
    1.20 +if test $(id -u) != 0 ; then
    1.21 +	exec subox wifibox
    1.22 +	exit 0
    1.23 +fi
    1.24 +
    1.25 +# Sanity check
    1.26 +[ -x /usr/sbin/iwconfig ] || tazpkg get-install wireless_tools
    1.27 +[ -d $FAVORITES_WIFI ] || mkdir -p $FAVORITES_WIFI
    1.28 +rm -f $FAVORITES_WIFI/any.conf
    1.29 +
    1.30 +# Catch ESSIDs and format output for GTK tree. We get the list of
    1.31 +# networks by Cell and without spaces.
    1.32 +detect_wifi_networks()
    1.33 +{
    1.34 +	desktopbox notify "Scanning Wireless interface: $WIFI_INTERFACE" &
    1.35 +	if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
    1.36 +		ifconfig $WIFI_INTERFACE up
    1.37 +		for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'`
    1.38 +		do
    1.39 +			SCAN=`iwlist $WIFI_INTERFACE scan last | \
    1.40 +				awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
    1.41 +				sed s/"Cell "/Cell-/ | grep -A 5 "$i"`
    1.42 +			ESSID=`echo $SCAN | cut -d '"' -f 2`
    1.43 +			if echo "$SCAN" | grep -q Quality; then
    1.44 +				QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'`
    1.45 +			else
    1.46 +				QUALITY="-"
    1.47 +			fi
    1.48 +			ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
    1.49 +			# Check encryption type
    1.50 +			if echo "$SCAN" | grep -q WPA; then
    1.51 +				ENCRYPTION="${ENCRYPTION} (WPA)"
    1.52 +			fi
    1.53 +			# Connected or not connected...
    1.54 +			if ifconfig | grep -A 1 $WIFI_INTERFACE | \
    1.55 +				grep -q inet && iwconfig $WIFI_INTERFACE | \
    1.56 +				grep ESSID | grep -q -w "$ESSID"; then
    1.57 +				STATUS=connected
    1.58 +			else
    1.59 +				STATUS="-"
    1.60 +			fi
    1.61 +			echo -n ""
    1.62 +			echo "$ESSID | $QUALITY | $ENCRYPTION | $STATUS"
    1.63 +		done
    1.64 +	fi
    1.65 +}
    1.66 +
    1.67 +# cmdline functions
    1.68 +
    1.69 +# Toggle Software RF Switch on some laptops
    1.70 +set_rfswitch()
    1.71 +{
    1.72 +	for i in /proc/driver/acerhk/wirelessled /proc/acpi/asus/wled ; do
    1.73 +		[ -e $i ] && echo $1 > $i
    1.74 +	done
    1.75 +}
    1.76 +
    1.77 +# Configure /etc/network.conf and restart connection with init script.
    1.78 +start_wifi_connection()
    1.79 +{
    1.80 +	# Get tmp config created by connect_to_essid() if exists and set 
    1.81 +	# empty value to clean config file.
    1.82 +	if [ -f /tmp/wifi.conf ]; then
    1.83 +		. /tmp/wifi.conf
    1.84 +		WIFI_MODE=""
    1.85 +		WIFI_IWCONFIG_ARGS=""
    1.86 +		WIFI_CHANNEL=""
    1.87 +	fi
    1.88 +	sed -i "s/`grep ^WIFI= /etc/network.conf`/WIFI=\"yes\"/" \
    1.89 +		/etc/network.conf
    1.90 +	sed -i "s/`grep ^WIFI_INTERFACE= /etc/network.conf`/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" \
    1.91 +		/etc/network.conf
    1.92 +	sed -i "s/`grep ^WIFI_ESSID= /etc/network.conf`/WIFI_ESSID=\"$WIFI_ESSID\"/" \
    1.93 +		/etc/network.conf
    1.94 +	sed -i "s/`grep ^WIFI_KEY= /etc/network.conf`/WIFI_KEY=\"$WIFI_KEY\"/" \
    1.95 +		/etc/network.conf
    1.96 +	sed -i "s/`grep ^WIFI_MODE= /etc/network.conf`/WIFI_MODE=\"$WIFI_MODE\"/" \
    1.97 +		/etc/network.conf
    1.98 +	sed -i "s/`grep ^WIFI_IWCONFIG_ARGS= /etc/network.conf`/WIFI_IWCONFIG_ARGS=\"$WIFI_IWCONFIG_ARGS\"/" \
    1.99 +		/etc/network.conf
   1.100 +	sed -i "s/`grep ^WIFI_KEY_TYPE= /etc/network.conf`/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
   1.101 +		/etc/network.conf
   1.102 +	sed -i "s/`grep ^WIFI_CHANNEL= /etc/network.conf`/WIFI_CHANNEL=\"$WIFI_CHANNEL\"/" \
   1.103 +		/etc/network.conf	
   1.104 +	[ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`
   1.105 +	ifconfig $WIFI_INTERFACE down
   1.106 +	set_rfswitch 1 
   1.107 +	iwconfig $WIFI_INTERFACE txpower auto
   1.108 +	/etc/init.d/network.sh restart
   1.109 +	# Remove tmp file (could be used to have wireless profiles)
   1.110 +	rm -f /tmp/wifi.conf
   1.111 +	sleep 2
   1.112 +}
   1.113 +
   1.114 +# We must sleep 4 sec to refresh networks list.
   1.115 +stop_wifi_connexion()
   1.116 +{
   1.117 +	sed -i s/`grep ^WIFI= /etc/network.conf`/WIFI=\"no\"/ \
   1.118 +		/etc/network.conf
   1.119 +	[ -x /etc/init.d/wpa_supplicant ] && /etc/init.d/wpa_supplicant stop
   1.120 +	ifconfig $WIFI_INTERFACE down
   1.121 +	iwconfig $WIFI_INTERFACE txpower off
   1.122 +	set_rfswitch 0 
   1.123 +	[ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`
   1.124 +	sleep 2
   1.125 +}
   1.126 +
   1.127 +auto_connect_to_favorites_atboot()
   1.128 +{
   1.129 +	. $FAVORITES_WIFI/${FAVNET}.conf
   1.130 +	
   1.131 +	if grep -q "ssid=\"$FAVNET\"" /etc/wpa_supplicant.conf ; then
   1.132 +		# edit configuration
   1.133 +		sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/[^_]ssid=.*/  ssid=\"$WIFI_ESSID\"/  " /etc/wpa_supplicant.conf
   1.134 +		sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/psk=.*/psk=\"$WIFI_KEY\"/ " /etc/wpa_supplicant.conf
   1.135 +	else
   1.136 +		# add new configuration
   1.137 +		echo -e "
   1.138 +# start ${FAVNET}.conf configuration
   1.139 +network={ 
   1.140 +	ssid=\"$WIFI_ESSID\"
   1.141 +	scan_ssid=1 
   1.142 +	key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE 
   1.143 +	group=CCMP TKIP WEP104 WEP40 
   1.144 +	pairwise=CCMP TKIP 
   1.145 +	psk=\"$WIFI_KEY\" 
   1.146 +	priority=3  
   1.147 +} 
   1.148 +# end ${FAVNET}.conf configuration" >> /etc/wpa_supplicant.conf  
   1.149 +    fi
   1.150 +
   1.151 +}
   1.152 +
   1.153 +# Favorite wireless networks use only 3 values: essid. key and type of
   1.154 +# key
   1.155 +favorites_wifi_list()
   1.156 +{
   1.157 +	for i in $FAVORITES_WIFI/*.conf
   1.158 +	do
   1.159 +		WIFI_ESSID=""
   1.160 +		WIFI_KEY=""
   1.161 +		WIFI_KEY_TYPE=""
   1.162 +		. "$i"
   1.163 +		[ -z "$WIFI_ESSID" ] && WIFI_ESSID="Bad config file: $i"
   1.164 +		[ -z "$WIFI_KEY_TYPE" ] && WIFI_KEY_TYPE="-"
   1.165 +		if [ -n "$WIFI_KEY" ]; then
   1.166 +			WIFI_KEY="********"
   1.167 +		else
   1.168 +			WIFI_KEY="-"
   1.169 +		fi
   1.170 +		echo "$WIFI_ESSID | $WIFI_KEY_TYPE | $WIFI_KEY"
   1.171 +	done
   1.172 +}
   1.173 +
   1.174 +favorite_wifi_actions()
   1.175 +{
   1.176 +	cp -a $FAVORITES_WIFI/"$FAVORITE".conf /tmp/wifi.conf
   1.177 +	. /tmp/wifi.conf
   1.178 +	export CONNECT_FAVORITE="
   1.179 +<window title=\"Connect to: $WIFI_ESSID\" icon-name=\"network-wireless\">
   1.180 +<vbox>
   1.181 +	
   1.182 +	<text width-chars=\"54\">
   1.183 +		<label>
   1.184 +\"
   1.185 +ESSID name: $WIFI_ESSID
   1.186 +\"
   1.187 +		</label>
   1.188 +	</text>
   1.189 +	
   1.190 +	<hbox>
   1.191 +		<button>
   1.192 +			<label>Connect</label>
   1.193 +			<input file icon=\"forward\"></input>	
   1.194 +			<action>$0 start_wifi_connection</action>
   1.195 +			<action type=\"exit\">exit</action>
   1.196 +		</button>
   1.197 +		<button>
   1.198 +			<label>Edit settings</label>
   1.199 +			<input file icon=\"accessories-text-editor\"></input>	
   1.200 +			<action>leafpad $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
   1.201 +			<action>rm -f /tmp/wifi.conf</action>					
   1.202 +		</button>
   1.203 +		<button>
   1.204 +			<label>Save Edits</label>
   1.205 +			<input file icon=\"document-save\"></input>	
   1.206 +			<action>export FAVNET=$WIFI_ESSID; $0 auto_connect_to_favorites_atboot</action>
   1.207 +			<action type=\"exit\">exit</action>					
   1.208 +		</button>
   1.209 +		<button>
   1.210 +			<label>Delete</label>
   1.211 +			<input file icon=\"gtk-delete\"></input>	
   1.212 +			<action>rm -f $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
   1.213 +			<action>sed -i \"/start ${FAVORITE}.conf/,/end ${FAVORITE}.conf/d\" /etc/wpa_supplicant.conf</action>
   1.214 +			<action type=\"exit\">exit</action>
   1.215 +		</button>
   1.216 +		<button cancel></button>
   1.217 +	</hbox>
   1.218 +	
   1.219 +</vbox>
   1.220 +</window>"
   1.221 +	gtkdialog --center --program=CONNECT_FAVORITE >/dev/null
   1.222 +}
   1.223 +
   1.224 +add_favorite_network_box()
   1.225 +{
   1.226 +	ADD_FAVORITE='
   1.227 +<window title="Add new favorite Wireless" icon-name="network-wireless">
   1.228 +<vbox>
   1.229 +	<text width-chars="54">
   1.230 +		<label>
   1.231 +"
   1.232 +Please configure your new favorite Wireless network
   1.233 +"
   1.234 +		</label>
   1.235 +	</text>
   1.236 +	<hbox>
   1.237 +		<text use-markup="true">
   1.238 +			<label>"<b>ESSID:</b>"</label>
   1.239 +		</text>
   1.240 +		<entry>
   1.241 +			<variable>WIFI_ESSID</variable>
   1.242 +		</entry>
   1.243 +	</hbox>
   1.244 +	<hbox>
   1.245 +		<text use-markup="true">
   1.246 +			<label>"<b>Key:   </b>"</label>
   1.247 +		</text>
   1.248 +		<entry>
   1.249 +			<variable>WIFI_KEY</variable>
   1.250 +		</entry>
   1.251 +	</hbox>
   1.252 +	<hbox>
   1.253 +		<text use-markup="true">
   1.254 +			<label>"<b>Key type:</b>"</label>
   1.255 +		</text>
   1.256 +		<combobox>'
   1.257 +	tmp="${ADD_FAVORITE}<item>$WIFI_KEY_TYPE</item>"
   1.258 +	for i in none WEP WPA any; do
   1.259 +		tmp=${tmp}"<item>$i</item>"
   1.260 +	done
   1.261 +	export ADD_FAVORITE=${tmp}'
   1.262 +			<variable>WIFI_KEY_TYPE</variable>
   1.263 +		</combobox>
   1.264 +	</hbox>
   1.265 +	<hbox>
   1.266 +		<button>
   1.267 +			<label>Add to list</label>
   1.268 +			<input file icon="forward"></input>
   1.269 +			<action>echo "# Wireless connection configuration." > $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.270 +			<action>echo "#" >> /etc/wireless/"$WIFI_ESSID".conf</action>
   1.271 +			<action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.272 +			<action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.273 +			<action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.274 +			<action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>
   1.275 +			<action type="exit">exit</action>
   1.276 +		</button>
   1.277 +		<button cancel></button>
   1.278 +	</hbox>
   1.279 +</vbox>
   1.280 +</window>'
   1.281 +	gtkdialog --center --program=ADD_FAVORITE #>/dev/null
   1.282 +}
   1.283 +
   1.284 +# GUI functions
   1.285 +
   1.286 +helpbutton()
   1.287 +{
   1.288 +	local label;
   1.289 +        label="<label>$3</label>"
   1.290 +	[ -n "$3" ] || label=""
   1.291 +	cat << EOT
   1.292 +<button>
   1.293 +	<input file icon="help"></input>$label
   1.294 +	<action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry $2 -title "$1 help" -e "$(which $1) --help ; echo -e \\"----\\nENTER to continue...\\" && read close"</action>
   1.295 +</button>
   1.296 +EOT
   1.297 +}
   1.298 +
   1.299 +manbutton()
   1.300 +{
   1.301 +	cat << EOT
   1.302 +<button>
   1.303 +	<input file icon="browser"></input>
   1.304 +	<label>man</label>
   1.305 +	<action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x24 -title "$2 man (q to quit)" -e ". /etc/profile; man $1 $2"</action>
   1.306 +</button>
   1.307 +EOT
   1.308 +}
   1.309 +
   1.310 +# Independent dialog to connect to a wireless network. If encryption
   1.311 +# is on we ask for the security key.
   1.312 +connect_to_essid()
   1.313 +{
   1.314 +	SCAN=`iwlist $WIFI_INTERFACE scan | \
   1.315 +		awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
   1.316 +		grep -B 1 -A 1 "$ESSID_LIST"`
   1.317 +	WIFI_ESSID="$ESSID_LIST"
   1.318 +	ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
   1.319 +	# Create tmp file used by active_wifi_connexion()
   1.320 +	cat > /tmp/wifi.conf << _EOF_
   1.321 +# Wireless connexion configuration file.
   1.322 +WIFI_ESSID="$ESSID_LIST"
   1.323 +_EOF_
   1.324 +	CONNECT_ESSID="
   1.325 +<window title=\"Connect to: $WIFI_ESSID\" icon-name=\"network-wireless\">
   1.326 +<vbox>
   1.327 +	<text width-chars=\"54\">
   1.328 +		<label>
   1.329 +\"
   1.330 +Connect $WIFI_INTERFACE to: $WIFI_ESSID
   1.331 +\"
   1.332 +		</label>
   1.333 +	</text>"
   1.334 +	# We maybe need a key to connect
   1.335 +	if [ "$ENCRYPTION" = "on" ] && [ "$ESSID_LIST" != "any" ]; then
   1.336 +		# WPA
   1.337 +		if echo "$SCAN" | grep -q WPA; then
   1.338 +			echo 'WIFI_KEY_TYPE="WPA"' >> /tmp/wifi.conf
   1.339 +			CONNECT_ESSID=${CONNECT_ESSID}'
   1.340 +			<hbox>
   1.341 +				<text use-markup="true">
   1.342 +					<label>"<b>WPA Key:</b>"</label>
   1.343 +				</text>
   1.344 +				<entry>
   1.345 +					<input>. /etc/network.conf; echo "$WIFI_KEY"</input>
   1.346 +					<variable>WIFI_KEY</variable>
   1.347 +				</entry>
   1.348 +			</hbox>'
   1.349 +		else
   1.350 +			# WEP
   1.351 +			echo 'WIFI_KEY_TYPE="WEP"' >> /tmp/wifi.conf
   1.352 +			CONNECT_ESSID=${CONNECT_ESSID}'
   1.353 +			<hbox>
   1.354 +				<text use-markup="true">
   1.355 +					<label>"<b>WEP Key:</b>"</label>
   1.356 +				</text>
   1.357 +				<entry>
   1.358 +					<input>. /etc/network.conf; echo "$WIFI_KEY"</input>
   1.359 +					<variable>WIFI_KEY</variable>
   1.360 +				</entry>
   1.361 +			</hbox>'
   1.362 +		fi
   1.363 +	else
   1.364 +		# No encryption
   1.365 +		echo 'WIFI_KEY=""' >> /tmp/wifi.conf
   1.366 +		echo 'WIFI_KEY_TYPE=""' >> /tmp/wifi.conf
   1.367 +		start_wifi_connection
   1.368 +		exit 0
   1.369 +	fi
   1.370 +	# Add key to config file so active_wifi_connexion() can use it.
   1.371 +	# WIFI_KEY is not exported if we quote with --> "
   1.372 +	export CONNECT_ESSID=${CONNECT_ESSID}'
   1.373 +	<hbox>
   1.374 +		<button>
   1.375 +			<label>Connect</label>
   1.376 +			<input file icon="forward"></input>	
   1.377 +			<action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> /tmp/wifi.conf</action>
   1.378 +			<action>$BIN start_wifi_connection</action>
   1.379 +			<action type="exit">exit</action>
   1.380 +		</button>
   1.381 +		<button cancel></button>
   1.382 +	</hbox>
   1.383 +</vbox>
   1.384 +</window>'
   1.385 +	gtkdialog --center --program=CONNECT_ESSID #>/dev/null
   1.386 +}
   1.387 +
   1.388 +# Wifibox start with Networks tab.
   1.389 +box()
   1.390 +{
   1.391 +	WIFI_DIALOG="
   1.392 +<window title=\"Wireless manager\" icon-name=\"network-wireless\">
   1.393 +<vbox>
   1.394 +	
   1.395 +	<notebook labels=\"Networks|Favorites|Configuration|Drivers\">
   1.396 +	
   1.397 +	<vbox>
   1.398 +		<tree icon=\"network-wireless\">
   1.399 +			<width>520</width><height>160</height>
   1.400 +			<variable>ESSID_LIST</variable>
   1.401 +			<label>ESSID|Quality|Encryption|Status</label>
   1.402 +			<input>$0 detect_wifi_networks</input>
   1.403 +			<item icon=\"network-wireless\">any | * | off | (auto-connect)</item>
   1.404 +			<action>$0 connect_to_essid</action>
   1.405 +			<action>refresh:ESSID_LIST</action>
   1.406 +			<action>refresh:WIFI_ESSID</action>
   1.407 +			<action>refresh:WIFI_KEY</action>
   1.408 +			<action>refresh:WIFI_KEY_TYPE</action>
   1.409 +		</tree>
   1.410 +		<hbox>
   1.411 +			<text width-chars=\"54\">
   1.412 +				<label>
   1.413 +\"Please double click on a network to connect or enter security key\"
   1.414 +				</label>
   1.415 +			</text>
   1.416 +			<button>
   1.417 +				<label>Refresh list</label>
   1.418 +				<input file icon=\"reload\"></input>
   1.419 +				<action>refresh:ESSID_LIST</action>
   1.420 +			</button>
   1.421 +		</hbox>
   1.422 +	</vbox>"
   1.423 +	
   1.424 +	
   1.425 +	# Favorite networks
   1.426 +	WIFI_DIALOG=${WIFI_DIALOG}"	
   1.427 +	<vbox>
   1.428 +	    <tree icon=\"network-wireless\">
   1.429 +			<width>500</width><height>160</height>
   1.430 +			<variable>FAVORITE</variable>
   1.431 +			<label>ESSID|Key Type|Key status</label>
   1.432 +			<input>$0 favorites_wifi_list</input>
   1.433 +			<item icon=\"network-wireless\">any | - | -</item>
   1.434 +			<action>$0 favorite_wifi_actions</action>
   1.435 +			<action>refresh:FAVORITE</action>
   1.436 +			<action>refresh:ESSID_LIST</action>
   1.437 +			<action>refresh:WIFI_ESSID</action>
   1.438 +			<action>refresh:WIFI_KEY</action>
   1.439 +			<action>refresh:WIFI_KEY_TYPE</action>
   1.440 +		</tree>
   1.441 +		<hbox>
   1.442 +			<text width-chars=\"65\">
   1.443 +				<label>
   1.444 +\"Favorite networks connect automatically when the computer is started           \"
   1.445 +				</label>
   1.446 +			</text>
   1.447 +		</hbox>
   1.448 +		<hbox>
   1.449 +			<text width-chars=\"50\">
   1.450 +				<label>
   1.451 +\"Please double click on a network to modify or remove it\"
   1.452 +				</label>
   1.453 +			</text>
   1.454 +			<button>
   1.455 +				<label>Add Network</label>
   1.456 +				<input file icon=\"gtk-add\"></input>
   1.457 +				<action>$0 add_favorite_network_box</action>
   1.458 +				<action>refresh:FAVORITE</action>
   1.459 +			</button>
   1.460 +		</hbox>
   1.461 +	</vbox>"
   1.462 +
   1.463 +	# Configuration tab
   1.464 +	WIFI_DIALOG=${WIFI_DIALOG}'
   1.465 +	<vbox>
   1.466 +		<frame Basic>
   1.467 +			<hbox>
   1.468 +				<text use-markup="true">
   1.469 +					<label>"<b>Interface:</b>"</label>
   1.470 +				</text>
   1.471 +				<entry>
   1.472 +					<input>. /etc/network.conf; echo "$WIFI_INTERFACE"</input>
   1.473 +					<variable>WIFI_INTERFACE</variable>
   1.474 +				</entry>
   1.475 +			</hbox>
   1.476 +			<hbox>
   1.477 +				<text use-markup="true">
   1.478 +					<label>"<b>ESSID:        </b>"</label>
   1.479 +				</text>
   1.480 +				<entry>
   1.481 +					<input>. /etc/network.conf; echo "$WIFI_ESSID"</input>
   1.482 +					<variable>WIFI_ESSID</variable>
   1.483 +				</entry>
   1.484 +			</hbox>
   1.485 +			<hbox>
   1.486 +				<text use-markup="true">
   1.487 +					<label>"<b>Key:           </b>"</label>
   1.488 +				</text>
   1.489 +				<entry>
   1.490 +					<input>. /etc/network.conf; echo "$WIFI_KEY"</input>
   1.491 +					<variable>WIFI_KEY</variable>
   1.492 +				</entry>
   1.493 +				<combobox>'
   1.494 +	tmp2="${WIFI_DIALOG}<item>$WIFI_KEY_TYPE</item>"
   1.495 +	for i in none WEP WPA any; do
   1.496 +		[ "$i" = "$WIFI_KEY_TYPE" ] || tmp2="$tmp2<item>$i</item>"
   1.497 +	done
   1.498 +	tmp3='		<variable>WIFI_KEY_TYPE</variable>
   1.499 +				</combobox>
   1.500 +			</hbox>
   1.501 +		</frame>
   1.502 +		<frame Advanced>
   1.503 +			<hbox>
   1.504 +				<text use-markup="true">
   1.505 +					<label>"<b>Channel/Mode:</b>"</label>
   1.506 +				</text>
   1.507 +				<entry>
   1.508 +					<input>. /etc/network.conf; echo "$WIFI_CHANNEL"</input>
   1.509 +					<variable>WIFI_CHANNEL</variable>
   1.510 +				</entry>
   1.511 +				
   1.512 +				<combobox>
   1.513 +					<variable>WIFI_MODE</variable>'
   1.514 +	tmp2="$tmp2$tmp3<item>$WIFI_MODE</item>"
   1.515 +	for i in managed ad-hoc master repeater secondary monitor; do
   1.516 +		[ "$i" = "$WIFI_MODE" ] || tmp2="$tmp2<item>$i</item>"
   1.517 +	done
   1.518 +	tmp3='		</combobox>
   1.519 +			</hbox>
   1.520 +			<hbox>
   1.521 +				<text use-markup="true">
   1.522 +					<label>"<b>Iwconfig args:</b> "</label>
   1.523 +				</text>
   1.524 +				<entry>
   1.525 +					<input>. /etc/network.conf; echo "$WIFI_IWCONFIG_ARGS"</input>
   1.526 +					<variable>WIFI_IWCONFIG_ARGS</variable>
   1.527 +				</entry>'
   1.528 +	WIFI_DIALOG="$tmp$tmp2$tmp3
   1.529 +	$(helpbutton iwconfig 80x24)
   1.530 +	$(manbutton 8 iwconfig)
   1.531 +			</hbox>
   1.532 +		</frame>"
   1.533 +		
   1.534 +	# Start Button for manual configuration.
   1.535 +	WIFI_DIALOG=${WIFI_DIALOG}'
   1.536 +		<hbox>
   1.537 +		   <button>
   1.538 +				<label>Save to Favorites</label>
   1.539 +				<input file icon="document-save"></input>
   1.540 +				<action>echo "# Wireless connection configuration." > $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.541 +				<action>echo "#" >> /etc/wireless/"$WIFI_ESSID".conf</action>
   1.542 +				<action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.543 +				<action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.544 +				<action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.545 +				<action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>	
   1.546 +				<action>refresh:FAVORITE</action>
   1.547 +			</button>
   1.548 +			<button>
   1.549 +				<label>Start connection</label>
   1.550 +				<input file icon="forward"></input>
   1.551 +				<action>[ "$WIFI_KEY_TYPE" = "WPA" -a ! -x /usr/bin/wpa_supplicant ] && xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x17 -title "wpa_supplicant install" -e "tazpkg get-install wpa_supplicant ; echo -e \"----\n\nENTER to continue...\" && read close"</action>
   1.552 +				<action>sed -i s/`grep ^WIFI= /etc/network.conf`/WIFI=\"yes\"/ /etc/network.conf</action>
   1.553 +				<action>sed -i s/`grep ^WIFI_INTERFACE= /etc/network.conf`/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/ /etc/network.conf</action>
   1.554 +				<action>sed -i s/`grep ^WIFI_ESSID= /etc/network.conf`/WIFI_ESSID=\"$WIFI_ESSID\"/ /etc/network.conf</action>
   1.555 +				<action>sed -i s/`grep ^WIFI_KEY= /etc/network.conf`/WIFI_KEY=\"$WIFI_KEY\"/ /etc/network.conf</action>
   1.556 +				<action>sed -i s/`grep ^WIFI_MODE= /etc/network.conf`/WIFI_MODE=\"$WIFI_MODE\"/ /etc/network.conf</action>
   1.557 +				<action>sed -i "s/`grep ^WIFI_IWCONFIG_ARGS= /etc/network.conf`/WIFI_IWCONFIG_ARGS=\"$WIFI_IWCONFIG_ARGS\"/" /etc/network.conf</action>
   1.558 +				<action>sed -i s/`grep ^WIFI_KEY_TYPE= /etc/network.conf`/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/ /etc/network.conf</action>
   1.559 +				<action>sed -i s/`grep ^WIFI_CHANNEL= /etc/network.conf`/WIFI_CHANNEL=\"$WIFI_CHANNEL\"/ /etc/network.conf</action>
   1.560 +				<action>[ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`</action>
   1.561 +				<action>ifconfig $WIFI_INTERFACE down</action>
   1.562 +				<action>iwconfig $WIFI_INTERFACE txpower auto</action>
   1.563 +				<action>/etc/init.d/network.sh restart</action>
   1.564 +				<action>refresh:ESSID_LIST</action>
   1.565 +				<action>refresh:WIFI_ESSID</action>
   1.566 +				<action>refresh:WIFI_KEY</action>
   1.567 +				<action>refresh:WIFI_KEY_TYPE</action>
   1.568 +			</button>
   1.569 +		</hbox>
   1.570 +	</vbox>'
   1.571 +
   1.572 +	# Kernel Modules, firmware and tazndisbox note + button.
   1.573 +	WIFI_DIALOG=${WIFI_DIALOG}"
   1.574 +	<vbox>
   1.575 +		<hbox>
   1.576 +			<text width-chars=\"64\">
   1.577 +				<label>
   1.578 +\"
   1.579 +Some Wireless Adapters need non-free firmware. Please install the
   1.580 +firmware before loading the corresponding module. Note that you can use 
   1.581 +Tazhw to automatically detect your PCI, PCMCIA or USB Wireless adapter.
   1.582 +\"
   1.583 +				</label>
   1.584 +			</text>
   1.585 +		</hbox>
   1.586 +		<hbox>
   1.587 +			<text use-markup=\"true\">
   1.588 +				<label>\"<b>Tools:</b>\"</label>
   1.589 +			</text>
   1.590 +			<button>
   1.591 +				<input file icon=\"computer\"></input>
   1.592 +				<label>Auto detect devices</label>
   1.593 +				<action>tazhw box</action>
   1.594 +				<action>refresh:ESSID_LIST</action>
   1.595 +			</button>"
   1.596 +			# Display firmware stuff, tazndisbox button if installed and close 
   1.597 +			# tab + notebook
   1.598 +			if [ -x /usr/bin/tazndisbox ]; then
   1.599 +				WIFI_DIALOG=${WIFI_DIALOG}"
   1.600 +			<button>
   1.601 +				<input file icon=\"system-installer\"></input>
   1.602 +				<label>Install Windows driver</label>
   1.603 +				<action>tazndisbox</action>
   1.604 +				<action>refresh:ESSID_LIST</action>
   1.605 +			</button>"
   1.606 +			fi
   1.607 +		WIFI_DIALOG=${WIFI_DIALOG}"
   1.608 +		</hbox>
   1.609 +		<hbox>
   1.610 +			<text use-markup=\"true\">
   1.611 +				<label>\"<b>Module:</b>\"</label>
   1.612 +			</text>
   1.613 +			<combobox>
   1.614 +				<variable>MODULE</variable>"
   1.615 +	WIFI_DIALOG="${WIFI_DIALOG}$(find /lib/modules/$(uname -r)/kernel/drivers/net/wireless -type f 2> /dev/null |  sed 's,/.*/\(.*\).ko.*,<item>\1</item>,')"
   1.616 +	WIFI_DIALOG=${WIFI_DIALOG}'
   1.617 +			</combobox>
   1.618 +			<button>
   1.619 +				<label>Load</label>
   1.620 +				<input file icon="forward"></input>
   1.621 +				<action>modprobe $MODULE</action>
   1.622 +			</button>
   1.623 +			<button>
   1.624 +				<label>Unload</label>
   1.625 +				<input file icon="undo"></input>
   1.626 +				<action>modprobe -r $MODULE</action>
   1.627 +			</button>
   1.628 +			<button>
   1.629 +				<label>Lsmod</label>
   1.630 +				<input file icon="computer"></input>
   1.631 +				<action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x25 -title "Modules (q to quit)" -e "lsmod | less"</action>
   1.632 +			</button>
   1.633 +		</hbox>'
   1.634 +	# Firmware stuff.
   1.635 +	tmp=$(for i in /usr/bin/get*firmware; do
   1.636 +		[ -x $i ] || continue
   1.637 +		[ "$i" = "/usr/bin/get-wifi-firmware" ] && continue
   1.638 +		[ -d /var/lib/tazpkg/installed/${i#/usr/bin/get-} ] && continue
   1.639 +		echo "<item>${i#/usr/bin/get-}</item>"; done)
   1.640 +		[ -n "$tmp" ] && tmp="
   1.641 +		<hbox>
   1.642 +			<text use-markup=\"true\">
   1.643 +				<label>\"<b>Firmware:</b>\"</label>
   1.644 +			</text>
   1.645 +			<combobox><variable>FIRMWARE</variable>$tmp</combobox>
   1.646 +			<button>
   1.647 +				<label>Install</label>
   1.648 +				<input file icon=\"go-jump\"></input>
   1.649 +				<action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x25 -title \"Install \$FIRMWARE\" -e \"get-\$FIRMWARE\"</action>
   1.650 +				<action>refresh:ESSID_LIST</action>
   1.651 +			</button>
   1.652 +			<button>
   1.653 +				<input file icon=\"system-file-manager\"></input>
   1.654 +				<label>List files</label>
   1.655 +				<action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 100x25 -title \"Firmware files (q to quit)\" -e \"find /lib/firmware -exec ls -ld {} \; | less\"</action>
   1.656 +				<action>refresh:ESSID_LIST</action>
   1.657 +			</button>
   1.658 +		</hbox>"
   1.659 +
   1.660 +# Bottom buttons
   1.661 +export WIFI_DIALOG=${WIFI_DIALOG}${tmp}"
   1.662 +		</vbox>
   1.663 +	</notebook>
   1.664 +	<hbox>
   1.665 +		<button>
   1.666 +			<label>Stop connection</label>
   1.667 +			<input file icon=\"stop\"></input>
   1.668 +			<action>$0 stop_wifi_connexion</action>
   1.669 +			<action>refresh:ESSID_LIST</action>
   1.670 +		</button>
   1.671 +		<button>
   1.672 +			<label>Exit</label>
   1.673 +			<input file icon=\"exit\"></input>
   1.674 +			<action type=\"exit\">Exit</action>
   1.675 +		</button>
   1.676 +	</hbox>
   1.677 +	
   1.678 +</vbox>
   1.679 +</window>"
   1.680 +	gtkdialog --center --program=WIFI_DIALOG #>/dev/null 2>&1
   1.681 +}
   1.682 +
   1.683 +if [ -n "$1" ]; then
   1.684 +	$1
   1.685 +else
   1.686 +	box
   1.687 +fi
   1.688 +
   1.689 +exit 0