slitaz-tools rev 467

wifibox: auto connect to favorites at boot
author Rohit Joshi <jozee@slitaz.org>
date Thu Mar 25 19:15:18 2010 +0000 (2010-03-25)
parents c725710d618b
children 9afb9b1944d0
files tinyutils/wifibox
line diff
     1.1 --- a/tinyutils/wifibox	Wed Mar 24 23:03:26 2010 +0100
     1.2 +++ b/tinyutils/wifibox	Thu Mar 25 19:15:18 2010 +0000
     1.3 @@ -121,6 +121,32 @@
     1.4  	sleep 2
     1.5  }
     1.6  
     1.7 +auto_connect_to_favorites_atboot()
     1.8 +{
     1.9 +	. $FAVORITES_WIFI/${FAVNET}.conf
    1.10 +	
    1.11 +	if grep -q "ssid=\"$FAVNET\"" /etc/wpa_supplicant.conf ; then
    1.12 +		# edit configuration
    1.13 +		sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/[^_]ssid=.*/  ssid=\"$WIFI_ESSID\"/  " /etc/wpa_supplicant.conf
    1.14 +		sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/psk=.*/psk=\"$WIFI_KEY\"/ " /etc/wpa_supplicant.conf
    1.15 +	else
    1.16 +		# add new configuration
    1.17 +		echo -e "
    1.18 +# start ${FAVNET}.conf configuration
    1.19 +network={ 
    1.20 +	ssid=\"$WIFI_ESSID\"
    1.21 +	scan_ssid=1 
    1.22 +	key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE 
    1.23 +	group=CCMP TKIP WEP104 WEP40 
    1.24 +	pairwise=CCMP TKIP 
    1.25 +	psk=\"$WIFI_KEY\" 
    1.26 +	priority=3  
    1.27 +} 
    1.28 +# end ${FAVNET}.conf configuration" >> /etc/wpa_supplicant.conf  
    1.29 +    fi
    1.30 +
    1.31 +}
    1.32 +
    1.33  # Favorite wireless networks use only 3 values: essid. key and type of
    1.34  # key
    1.35  favorites_wifi_list()
    1.36 @@ -169,13 +195,19 @@
    1.37  			<label>Edit settings</label>
    1.38  			<input file icon=\"accessories-text-editor\"></input>	
    1.39  			<action>leafpad $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
    1.40 -			<action>rm -f /tmp/wifi.conf</action>
    1.41 -			<action type=\"exit\">exit</action>
    1.42 +			<action>rm -f /tmp/wifi.conf</action>					
    1.43 +		</button>
    1.44 +		<button>
    1.45 +			<label>Save Edits</label>
    1.46 +			<input file icon=\"document-save\"></input>	
    1.47 +			<action>export FAVNET=$WIFI_ESSID; $0 auto_connect_to_favorites_atboot</action>
    1.48 +			<action type=\"exit\">exit</action>					
    1.49  		</button>
    1.50  		<button>
    1.51  			<label>Delete</label>
    1.52  			<input file icon=\"gtk-delete\"></input>	
    1.53  			<action>rm -f $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
    1.54 +			<action>sed -i \"/start ${FAVORITE}.conf/,/end ${FAVORITE}.conf/d\" /etc/wpa_supplicant.conf</action>
    1.55  			<action type=\"exit\">exit</action>
    1.56  		</button>
    1.57  		<button cancel></button>
    1.58 @@ -236,6 +268,7 @@
    1.59  			<action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
    1.60  			<action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
    1.61  			<action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
    1.62 +			<action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>
    1.63  			<action type="exit">exit</action>
    1.64  		</button>
    1.65  		<button cancel></button>
    1.66 @@ -385,10 +418,11 @@
    1.67  		</hbox>
    1.68  	</vbox>"
    1.69  	
    1.70 +	
    1.71  	# Favorite networks
    1.72  	WIFI_DIALOG=${WIFI_DIALOG}"	
    1.73  	<vbox>
    1.74 -		<tree icon=\"network-wireless\">
    1.75 +	    <tree icon=\"network-wireless\">
    1.76  			<width>500</width><height>160</height>
    1.77  			<variable>FAVORITE</variable>
    1.78  			<label>ESSID|Key Type|Key status</label>
    1.79 @@ -402,6 +436,13 @@
    1.80  			<action>refresh:WIFI_KEY_TYPE</action>
    1.81  		</tree>
    1.82  		<hbox>
    1.83 +			<text width-chars=\"65\">
    1.84 +				<label>
    1.85 +\"Favorites network connect automatically when computer is started           \"
    1.86 +				</label>
    1.87 +			</text>
    1.88 +		</hbox>
    1.89 +		<hbox>
    1.90  			<text width-chars=\"50\">
    1.91  				<label>
    1.92  \"Please double click on a network to modify or remove it\"
    1.93 @@ -490,6 +531,17 @@
    1.94  	# Start Button for manual configuration.
    1.95  	WIFI_DIALOG=${WIFI_DIALOG}'
    1.96  		<hbox>
    1.97 +		   <button>
    1.98 +				<label>Save to Favorites</label>
    1.99 +				<input file icon="document-save"></input>
   1.100 +				<action>echo "# Wireless connection configuration." > $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.101 +				<action>echo "#" >> /etc/wireless/"$WIFI_ESSID".conf</action>
   1.102 +				<action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.103 +				<action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.104 +				<action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
   1.105 +				<action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>	
   1.106 +				<action>refresh:FAVORITE</action>
   1.107 +			</button>
   1.108  			<button>
   1.109  				<label>Start connection</label>
   1.110  				<input file icon="forward"></input>