slitaz-tools view oldstuff/wifibox @ rev 686

Move wifibox to old stuff
author Christophe Lincoln <pankso@slitaz.org>
date Wed Feb 29 02:11:49 2012 +0100 (2012-02-29)
parents tinyutils/wifibox@0f5e3af5a51d
children
line source
1 #!/bin/sh
2 #
3 # GTKdialog interface to manage wireless connections in a simple way.
4 # Use tabs to indent, split commands from the GUI and use functions.
5 # Favorite networks are also supported
6 #
7 # (c) 2010 SliTaz GNU/Linux - GNU gpl v3
8 #
9 VERSION=20100118
11 # Export script path and others if needed so we can use them in 'quote'.
12 export BIN=$0
13 export FAVORITES_WIFI=/etc/wireless
14 . /etc/network.conf
16 # Wifibox is only for root.
17 if test $(id -u) != 0 ; then
18 exec subox wifibox
19 exit 0
20 fi
22 # Sanity check
23 [ -x /usr/sbin/iwconfig ] || tazpkg get-install wireless_tools
24 [ -d $FAVORITES_WIFI ] || mkdir -p $FAVORITES_WIFI
25 rm -f $FAVORITES_WIFI/any.conf
27 # Catch ESSIDs and format output for GTK tree. We get the list of
28 # networks by Cell and without spaces.
29 detect_wifi_networks()
30 {
31 desktopbox notify "Scanning Wireless interface: $WIFI_INTERFACE" &
32 if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
33 ifconfig $WIFI_INTERFACE up
34 for i in `iwlist $WIFI_INTERFACE scan | sed s/"Cell "/Cell-/ | grep "Cell-" | awk '{print $1}'`
35 do
36 SCAN=`iwlist $WIFI_INTERFACE scan last | \
37 awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
38 sed s/"Cell "/Cell-/ | grep -A 5 "$i"`
39 ESSID=`echo $SCAN | cut -d '"' -f 2`
40 if echo "$SCAN" | grep -q Quality; then
41 QUALITY=`echo $SCAN | sed 's/.*Quality=\([^ ]*\).*/\1/' | sed 's/.*Quality:\([^ ]*\).*/\1/'`
42 else
43 QUALITY="-"
44 fi
45 ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
46 # Check encryption type
47 if echo "$SCAN" | grep -q WPA; then
48 ENCRYPTION="${ENCRYPTION} (WPA)"
49 fi
50 # Connected or not connected...
51 if ifconfig | grep -A 1 $WIFI_INTERFACE | \
52 grep -q inet && iwconfig $WIFI_INTERFACE | \
53 grep ESSID | grep -q -w "$ESSID"; then
54 STATUS=connected
55 else
56 STATUS="-"
57 fi
58 echo -n ""
59 echo "$ESSID | $QUALITY | $ENCRYPTION | $STATUS"
60 done
61 fi
62 }
64 # cmdline functions
66 # Toggle Software RF Switch on some laptops
67 set_rfswitch()
68 {
69 for i in /proc/driver/acerhk/wirelessled /proc/acpi/asus/wled ; do
70 [ -e $i ] && echo $1 > $i
71 done
72 }
74 # Configure /etc/network.conf and restart connection with init script.
75 start_wifi_connection()
76 {
77 # Get tmp config created by connect_to_essid() if exists and set
78 # empty value to clean config file.
79 if [ -f /tmp/wifi.conf ]; then
80 . /tmp/wifi.conf
81 WIFI_MODE=""
82 WIFI_IWCONFIG_ARGS=""
83 WIFI_CHANNEL=""
84 fi
85 sed -i "s/`grep ^WIFI= /etc/network.conf`/WIFI=\"yes\"/" \
86 /etc/network.conf
87 sed -i "s/`grep ^WIFI_INTERFACE= /etc/network.conf`/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" \
88 /etc/network.conf
89 sed -i "s/`grep ^WIFI_ESSID= /etc/network.conf`/WIFI_ESSID=\"$WIFI_ESSID\"/" \
90 /etc/network.conf
91 sed -i "s/`grep ^WIFI_KEY= /etc/network.conf`/WIFI_KEY=\"$WIFI_KEY\"/" \
92 /etc/network.conf
93 sed -i "s/`grep ^WIFI_MODE= /etc/network.conf`/WIFI_MODE=\"$WIFI_MODE\"/" \
94 /etc/network.conf
95 sed -i "s/`grep ^WIFI_IWCONFIG_ARGS= /etc/network.conf`/WIFI_IWCONFIG_ARGS=\"$WIFI_IWCONFIG_ARGS\"/" \
96 /etc/network.conf
97 sed -i "s/`grep ^WIFI_KEY_TYPE= /etc/network.conf`/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/" \
98 /etc/network.conf
99 sed -i "s/`grep ^WIFI_CHANNEL= /etc/network.conf`/WIFI_CHANNEL=\"$WIFI_CHANNEL\"/" \
100 /etc/network.conf
101 [ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`
102 ifconfig $WIFI_INTERFACE down
103 set_rfswitch 1
104 iwconfig $WIFI_INTERFACE txpower auto
105 /etc/init.d/network.sh restart
106 # Remove tmp file (could be used to have wireless profiles)
107 rm -f /tmp/wifi.conf
108 sleep 2
109 }
111 # We must sleep 4 sec to refresh networks list.
112 stop_wifi_connexion()
113 {
114 sed -i s/`grep ^WIFI= /etc/network.conf`/WIFI=\"no\"/ \
115 /etc/network.conf
116 [ -x /etc/init.d/wpa_supplicant ] && /etc/init.d/wpa_supplicant stop
117 ifconfig $WIFI_INTERFACE down
118 iwconfig $WIFI_INTERFACE txpower off
119 set_rfswitch 0
120 [ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`
121 sleep 2
122 }
124 auto_connect_to_favorites_atboot()
125 {
126 . $FAVORITES_WIFI/${FAVNET}.conf
128 if grep -q "ssid=\"$FAVNET\"" /etc/wpa_supplicant.conf ; then
129 # edit configuration
130 sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/[^_]ssid=.*/ ssid=\"$WIFI_ESSID\"/ " /etc/wpa_supplicant.conf
131 sed -i "/start ${FAVNET}.conf/,/end ${FAVNET}.conf/s/psk=.*/psk=\"$WIFI_KEY\"/ " /etc/wpa_supplicant.conf
132 else
133 # add new configuration
134 echo -e "
135 # start ${FAVNET}.conf configuration
136 network={
137 ssid=\"$WIFI_ESSID\"
138 scan_ssid=1
139 key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
140 group=CCMP TKIP WEP104 WEP40
141 pairwise=CCMP TKIP
142 psk=\"$WIFI_KEY\"
143 priority=3
144 }
145 # end ${FAVNET}.conf configuration" >> /etc/wpa_supplicant.conf
146 fi
148 }
150 # Favorite wireless networks use only 3 values: essid. key and type of
151 # key
152 favorites_wifi_list()
153 {
154 for i in $FAVORITES_WIFI/*.conf
155 do
156 WIFI_ESSID=""
157 WIFI_KEY=""
158 WIFI_KEY_TYPE=""
159 . "$i"
160 [ -z "$WIFI_ESSID" ] && WIFI_ESSID="Bad config file: $i"
161 [ -z "$WIFI_KEY_TYPE" ] && WIFI_KEY_TYPE="-"
162 if [ -n "$WIFI_KEY" ]; then
163 WIFI_KEY="********"
164 else
165 WIFI_KEY="-"
166 fi
167 echo "$WIFI_ESSID | $WIFI_KEY_TYPE | $WIFI_KEY"
168 done
169 }
171 favorite_wifi_actions()
172 {
173 cp -a $FAVORITES_WIFI/"$FAVORITE".conf /tmp/wifi.conf
174 . /tmp/wifi.conf
175 export CONNECT_FAVORITE="
176 <window title=\"Connect to: $WIFI_ESSID\" icon-name=\"network-wireless\">
177 <vbox>
179 <text width-chars=\"54\">
180 <label>
181 \"
182 ESSID name: $WIFI_ESSID
183 \"
184 </label>
185 </text>
187 <hbox>
188 <button>
189 <label>Connect</label>
190 <input file icon=\"forward\"></input>
191 <action>$0 start_wifi_connection</action>
192 <action type=\"exit\">exit</action>
193 </button>
194 <button>
195 <label>Edit settings</label>
196 <input file icon=\"accessories-text-editor\"></input>
197 <action>leafpad $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
198 <action>rm -f /tmp/wifi.conf</action>
199 </button>
200 <button>
201 <label>Save Edits</label>
202 <input file icon=\"document-save\"></input>
203 <action>export FAVNET=$WIFI_ESSID; $0 auto_connect_to_favorites_atboot</action>
204 <action type=\"exit\">exit</action>
205 </button>
206 <button>
207 <label>Delete</label>
208 <input file icon=\"gtk-delete\"></input>
209 <action>rm -f $FAVORITES_WIFI/\"$FAVORITE\".conf</action>
210 <action>sed -i \"/start ${FAVORITE}.conf/,/end ${FAVORITE}.conf/d\" /etc/wpa_supplicant.conf</action>
211 <action type=\"exit\">exit</action>
212 </button>
213 <button cancel></button>
214 </hbox>
216 </vbox>
217 </window>"
218 gtkdialog --center --program=CONNECT_FAVORITE >/dev/null
219 }
221 add_favorite_network_box()
222 {
223 ADD_FAVORITE='
224 <window title="Add new favorite Wireless" icon-name="network-wireless">
225 <vbox>
226 <text width-chars="54">
227 <label>
228 "
229 Please configure your new favorite Wireless network
230 "
231 </label>
232 </text>
233 <hbox>
234 <text use-markup="true">
235 <label>"<b>ESSID:</b>"</label>
236 </text>
237 <entry>
238 <variable>WIFI_ESSID</variable>
239 </entry>
240 </hbox>
241 <hbox>
242 <text use-markup="true">
243 <label>"<b>Key: </b>"</label>
244 </text>
245 <entry>
246 <variable>WIFI_KEY</variable>
247 </entry>
248 </hbox>
249 <hbox>
250 <text use-markup="true">
251 <label>"<b>Key type:</b>"</label>
252 </text>
253 <combobox>'
254 tmp="${ADD_FAVORITE}<item>$WIFI_KEY_TYPE</item>"
255 for i in none WEP WPA any; do
256 tmp=${tmp}"<item>$i</item>"
257 done
258 export ADD_FAVORITE=${tmp}'
259 <variable>WIFI_KEY_TYPE</variable>
260 </combobox>
261 </hbox>
262 <hbox>
263 <button>
264 <label>Add to list</label>
265 <input file icon="forward"></input>
266 <action>echo "# Wireless connection configuration." > $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
267 <action>echo "#" >> /etc/wireless/"$WIFI_ESSID".conf</action>
268 <action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
269 <action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
270 <action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
271 <action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>
272 <action type="exit">exit</action>
273 </button>
274 <button cancel></button>
275 </hbox>
276 </vbox>
277 </window>'
278 gtkdialog --center --program=ADD_FAVORITE #>/dev/null
279 }
281 # GUI functions
283 helpbutton()
284 {
285 local label;
286 label="<label>$3</label>"
287 [ -n "$3" ] || label=""
288 cat << EOT
289 <button>
290 <input file icon="help"></input>$label
291 <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>
292 </button>
293 EOT
294 }
296 manbutton()
297 {
298 cat << EOT
299 <button>
300 <input file icon="browser"></input>
301 <label>man</label>
302 <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>
303 </button>
304 EOT
305 }
307 # Independent dialog to connect to a wireless network. If encryption
308 # is on we ask for the security key.
309 connect_to_essid()
310 {
311 SCAN=`iwlist $WIFI_INTERFACE scan | \
312 awk '/(Cell|ESS|Qual|Encry|IE: WPA)/ {print}' | \
313 grep -B 1 -A 1 "$ESSID_LIST"`
314 WIFI_ESSID="$ESSID_LIST"
315 ENCRYPTION=`echo $SCAN | sed 's/.*key:\([^ ]*\).*/\1/'`
316 # Create tmp file used by active_wifi_connexion()
317 cat > /tmp/wifi.conf << _EOF_
318 # Wireless connexion configuration file.
319 WIFI_ESSID="$ESSID_LIST"
320 _EOF_
321 CONNECT_ESSID="
322 <window title=\"Connect to: $WIFI_ESSID\" icon-name=\"network-wireless\">
323 <vbox>
324 <text width-chars=\"54\">
325 <label>
326 \"
327 Connect $WIFI_INTERFACE to: $WIFI_ESSID
328 \"
329 </label>
330 </text>"
331 # We maybe need a key to connect
332 if [ "$ENCRYPTION" = "on" ] && [ "$ESSID_LIST" != "any" ]; then
333 # WPA
334 if echo "$SCAN" | grep -q WPA; then
335 echo 'WIFI_KEY_TYPE="WPA"' >> /tmp/wifi.conf
336 CONNECT_ESSID=${CONNECT_ESSID}'
337 <hbox>
338 <text use-markup="true">
339 <label>"<b>WPA Key:</b>"</label>
340 </text>
341 <entry>
342 <input>. /etc/network.conf; echo "$WIFI_KEY"</input>
343 <variable>WIFI_KEY</variable>
344 </entry>
345 </hbox>'
346 else
347 # WEP
348 echo 'WIFI_KEY_TYPE="WEP"' >> /tmp/wifi.conf
349 CONNECT_ESSID=${CONNECT_ESSID}'
350 <hbox>
351 <text use-markup="true">
352 <label>"<b>WEP Key:</b>"</label>
353 </text>
354 <entry>
355 <input>. /etc/network.conf; echo "$WIFI_KEY"</input>
356 <variable>WIFI_KEY</variable>
357 </entry>
358 </hbox>'
359 fi
360 else
361 # No encryption
362 echo 'WIFI_KEY=""' >> /tmp/wifi.conf
363 echo 'WIFI_KEY_TYPE=""' >> /tmp/wifi.conf
364 start_wifi_connection
365 exit 0
366 fi
367 # Add key to config file so active_wifi_connexion() can use it.
368 # WIFI_KEY is not exported if we quote with --> "
369 export CONNECT_ESSID=${CONNECT_ESSID}'
370 <hbox>
371 <button>
372 <label>Connect</label>
373 <input file icon="forward"></input>
374 <action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> /tmp/wifi.conf</action>
375 <action>$BIN start_wifi_connection</action>
376 <action type="exit">exit</action>
377 </button>
378 <button cancel></button>
379 </hbox>
380 </vbox>
381 </window>'
382 gtkdialog --center --program=CONNECT_ESSID #>/dev/null
383 }
385 # Wifibox start with Networks tab.
386 box()
387 {
388 WIFI_DIALOG="
389 <window title=\"Wireless manager\" icon-name=\"network-wireless\">
390 <vbox>
392 <notebook labels=\"Networks|Favorites|Configuration|Drivers\">
394 <vbox>
395 <tree icon=\"network-wireless\">
396 <width>520</width><height>160</height>
397 <variable>ESSID_LIST</variable>
398 <label>ESSID|Quality|Encryption|Status</label>
399 <input>$0 detect_wifi_networks</input>
400 <item icon=\"network-wireless\">any | * | off | (auto-connect)</item>
401 <action>$0 connect_to_essid</action>
402 <action>refresh:ESSID_LIST</action>
403 <action>refresh:WIFI_ESSID</action>
404 <action>refresh:WIFI_KEY</action>
405 <action>refresh:WIFI_KEY_TYPE</action>
406 </tree>
407 <hbox>
408 <text width-chars=\"54\">
409 <label>
410 \"Please double click on a network to connect or enter security key\"
411 </label>
412 </text>
413 <button>
414 <label>Refresh list</label>
415 <input file icon=\"reload\"></input>
416 <action>refresh:ESSID_LIST</action>
417 </button>
418 </hbox>
419 </vbox>"
422 # Favorite networks
423 WIFI_DIALOG=${WIFI_DIALOG}"
424 <vbox>
425 <tree icon=\"network-wireless\">
426 <width>500</width><height>160</height>
427 <variable>FAVORITE</variable>
428 <label>ESSID|Key Type|Key status</label>
429 <input>$0 favorites_wifi_list</input>
430 <item icon=\"network-wireless\">any | - | -</item>
431 <action>$0 favorite_wifi_actions</action>
432 <action>refresh:FAVORITE</action>
433 <action>refresh:ESSID_LIST</action>
434 <action>refresh:WIFI_ESSID</action>
435 <action>refresh:WIFI_KEY</action>
436 <action>refresh:WIFI_KEY_TYPE</action>
437 </tree>
438 <hbox>
439 <text width-chars=\"65\">
440 <label>
441 \"Favorite networks connect automatically when the computer is started \"
442 </label>
443 </text>
444 </hbox>
445 <hbox>
446 <text width-chars=\"50\">
447 <label>
448 \"Please double click on a network to modify or remove it\"
449 </label>
450 </text>
451 <button>
452 <label>Add Network</label>
453 <input file icon=\"gtk-add\"></input>
454 <action>$0 add_favorite_network_box</action>
455 <action>refresh:FAVORITE</action>
456 </button>
457 </hbox>
458 </vbox>"
460 # Configuration tab
461 WIFI_DIALOG=${WIFI_DIALOG}'
462 <vbox>
463 <frame Basic>
464 <hbox>
465 <text use-markup="true">
466 <label>"<b>Interface:</b>"</label>
467 </text>
468 <entry>
469 <input>. /etc/network.conf; echo "$WIFI_INTERFACE"</input>
470 <variable>WIFI_INTERFACE</variable>
471 </entry>
472 </hbox>
473 <hbox>
474 <text use-markup="true">
475 <label>"<b>ESSID: </b>"</label>
476 </text>
477 <entry>
478 <input>. /etc/network.conf; echo "$WIFI_ESSID"</input>
479 <variable>WIFI_ESSID</variable>
480 </entry>
481 </hbox>
482 <hbox>
483 <text use-markup="true">
484 <label>"<b>Key: </b>"</label>
485 </text>
486 <entry>
487 <input>. /etc/network.conf; echo "$WIFI_KEY"</input>
488 <variable>WIFI_KEY</variable>
489 </entry>
490 <combobox>'
491 tmp2="${WIFI_DIALOG}<item>$WIFI_KEY_TYPE</item>"
492 for i in none WEP WPA any; do
493 [ "$i" = "$WIFI_KEY_TYPE" ] || tmp2="$tmp2<item>$i</item>"
494 done
495 tmp3=' <variable>WIFI_KEY_TYPE</variable>
496 </combobox>
497 </hbox>
498 </frame>
499 <frame Advanced>
500 <hbox>
501 <text use-markup="true">
502 <label>"<b>Channel/Mode:</b>"</label>
503 </text>
504 <entry>
505 <input>. /etc/network.conf; echo "$WIFI_CHANNEL"</input>
506 <variable>WIFI_CHANNEL</variable>
507 </entry>
509 <combobox>
510 <variable>WIFI_MODE</variable>'
511 tmp2="$tmp2$tmp3<item>$WIFI_MODE</item>"
512 for i in managed ad-hoc master repeater secondary monitor; do
513 [ "$i" = "$WIFI_MODE" ] || tmp2="$tmp2<item>$i</item>"
514 done
515 tmp3=' </combobox>
516 </hbox>
517 <hbox>
518 <text use-markup="true">
519 <label>"<b>Iwconfig args:</b> "</label>
520 </text>
521 <entry>
522 <input>. /etc/network.conf; echo "$WIFI_IWCONFIG_ARGS"</input>
523 <variable>WIFI_IWCONFIG_ARGS</variable>
524 </entry>'
525 WIFI_DIALOG="$tmp$tmp2$tmp3
526 $(helpbutton iwconfig 80x24)
527 $(manbutton 8 iwconfig)
528 </hbox>
529 </frame>"
531 # Start Button for manual configuration.
532 WIFI_DIALOG=${WIFI_DIALOG}'
533 <hbox>
534 <button>
535 <label>Save to Favorites</label>
536 <input file icon="document-save"></input>
537 <action>echo "# Wireless connection configuration." > $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
538 <action>echo "#" >> /etc/wireless/"$WIFI_ESSID".conf</action>
539 <action>echo "WIFI_ESSID=\"$WIFI_ESSID\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
540 <action>echo "WIFI_KEY=\"$WIFI_KEY\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
541 <action>echo "WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"" >> $FAVORITES_WIFI/"$WIFI_ESSID".conf</action>
542 <action>export FAVNET=$WIFI_ESSID; $BIN auto_connect_to_favorites_atboot</action>
543 <action>refresh:FAVORITE</action>
544 </button>
545 <button>
546 <label>Start connection</label>
547 <input file icon="forward"></input>
548 <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>
549 <action>sed -i s/`grep ^WIFI= /etc/network.conf`/WIFI=\"yes\"/ /etc/network.conf</action>
550 <action>sed -i s/`grep ^WIFI_INTERFACE= /etc/network.conf`/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/ /etc/network.conf</action>
551 <action>sed -i s/`grep ^WIFI_ESSID= /etc/network.conf`/WIFI_ESSID=\"$WIFI_ESSID\"/ /etc/network.conf</action>
552 <action>sed -i s/`grep ^WIFI_KEY= /etc/network.conf`/WIFI_KEY=\"$WIFI_KEY\"/ /etc/network.conf</action>
553 <action>sed -i s/`grep ^WIFI_MODE= /etc/network.conf`/WIFI_MODE=\"$WIFI_MODE\"/ /etc/network.conf</action>
554 <action>sed -i "s/`grep ^WIFI_IWCONFIG_ARGS= /etc/network.conf`/WIFI_IWCONFIG_ARGS=\"$WIFI_IWCONFIG_ARGS\"/" /etc/network.conf</action>
555 <action>sed -i s/`grep ^WIFI_KEY_TYPE= /etc/network.conf`/WIFI_KEY_TYPE=\"$WIFI_KEY_TYPE\"/ /etc/network.conf</action>
556 <action>sed -i s/`grep ^WIFI_CHANNEL= /etc/network.conf`/WIFI_CHANNEL=\"$WIFI_CHANNEL\"/ /etc/network.conf</action>
557 <action>[ -s /var/run/udhcpc.$WIFI_INTERFACE.pid ] && kill `cat /var/run/udhcpc.$WIFI_INTERFACE.pid`</action>
558 <action>ifconfig $WIFI_INTERFACE down</action>
559 <action>iwconfig $WIFI_INTERFACE txpower auto</action>
560 <action>/etc/init.d/network.sh restart</action>
561 <action>refresh:ESSID_LIST</action>
562 <action>refresh:WIFI_ESSID</action>
563 <action>refresh:WIFI_KEY</action>
564 <action>refresh:WIFI_KEY_TYPE</action>
565 </button>
566 </hbox>
567 </vbox>'
569 # Kernel Modules, firmware and tazndisbox note + button.
570 WIFI_DIALOG=${WIFI_DIALOG}"
571 <vbox>
572 <hbox>
573 <text width-chars=\"64\">
574 <label>
575 \"
576 Some Wireless Adapters need non-free firmware. Please install the
577 firmware before loading the corresponding module. Note that you can use
578 Tazhw to automatically detect your PCI, PCMCIA or USB Wireless adapter.
579 \"
580 </label>
581 </text>
582 </hbox>
583 <hbox>
584 <text use-markup=\"true\">
585 <label>\"<b>Tools:</b>\"</label>
586 </text>
587 <button>
588 <input file icon=\"computer\"></input>
589 <label>Auto detect devices</label>
590 <action>tazhw box</action>
591 <action>refresh:ESSID_LIST</action>
592 </button>"
593 # Display firmware stuff, tazndisbox button if installed and close
594 # tab + notebook
595 if [ -x /usr/bin/tazndisbox ]; then
596 WIFI_DIALOG=${WIFI_DIALOG}"
597 <button>
598 <input file icon=\"system-installer\"></input>
599 <label>Install Windows driver</label>
600 <action>tazndisbox</action>
601 <action>refresh:ESSID_LIST</action>
602 </button>"
603 fi
604 WIFI_DIALOG=${WIFI_DIALOG}"
605 </hbox>
606 <hbox>
607 <text use-markup=\"true\">
608 <label>\"<b>Module:</b>\"</label>
609 </text>
610 <combobox>
611 <variable>MODULE</variable>"
612 WIFI_DIALOG="${WIFI_DIALOG}$(find /lib/modules/$(uname -r)/kernel/drivers/net/wireless -type f 2> /dev/null | sed 's,/.*/\(.*\).ko.*,<item>\1</item>,')"
613 WIFI_DIALOG=${WIFI_DIALOG}'
614 </combobox>
615 <button>
616 <label>Load</label>
617 <input file icon="forward"></input>
618 <action>modprobe $MODULE</action>
619 </button>
620 <button>
621 <label>Unload</label>
622 <input file icon="undo"></input>
623 <action>modprobe -r $MODULE</action>
624 </button>
625 <button>
626 <label>Lsmod</label>
627 <input file icon="computer"></input>
628 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x25 -title "Modules (q to quit)" -e "lsmod | less"</action>
629 </button>
630 </hbox>'
631 # Firmware stuff.
632 tmp=$(for i in /usr/bin/get*firmware; do
633 [ -x $i ] || continue
634 [ "$i" = "/usr/bin/get-wifi-firmware" ] && continue
635 [ -d /var/lib/tazpkg/installed/${i#/usr/bin/get-} ] && continue
636 echo "<item>${i#/usr/bin/get-}</item>"; done)
637 [ -n "$tmp" ] && tmp="
638 <hbox>
639 <text use-markup=\"true\">
640 <label>\"<b>Firmware:</b>\"</label>
641 </text>
642 <combobox><variable>FIRMWARE</variable>$tmp</combobox>
643 <button>
644 <label>Install</label>
645 <input file icon=\"go-jump\"></input>
646 <action>xterm -fa MiscFixed -fs 11 -bg gray93 -fg black -geometry 80x25 -title \"Install \$FIRMWARE\" -e \"get-\$FIRMWARE\"</action>
647 <action>refresh:ESSID_LIST</action>
648 </button>
649 <button>
650 <input file icon=\"system-file-manager\"></input>
651 <label>List files</label>
652 <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>
653 <action>refresh:ESSID_LIST</action>
654 </button>
655 </hbox>"
657 # Bottom buttons
658 export WIFI_DIALOG=${WIFI_DIALOG}${tmp}"
659 </vbox>
660 </notebook>
661 <hbox>
662 <button>
663 <label>Stop connection</label>
664 <input file icon=\"stop\"></input>
665 <action>$0 stop_wifi_connexion</action>
666 <action>refresh:ESSID_LIST</action>
667 </button>
668 <button>
669 <label>Exit</label>
670 <input file icon=\"exit\"></input>
671 <action type=\"exit\">Exit</action>
672 </button>
673 </hbox>
675 </vbox>
676 </window>"
677 gtkdialog --center --program=WIFI_DIALOG #>/dev/null 2>&1
678 }
680 if [ -n "$1" ]; then
681 $1
682 else
683 box
684 fi
686 exit 0