slitaz-tools view tinyutils/netbox @ rev 461

netbox:split networking, server, gui and tab engine
author Rohit Joshi <jozee@slitaz.org>
date Wed Mar 24 06:33:32 2010 -0400 (2010-03-24)
parents 5a34e02fb165
children ca6804d9b56b
line source
1 #!/bin/sh
2 #
3 # Gtkdialog box to manage network connections and servers.
4 # Please use tab to indent.
5 #
6 # (c) - SliTaz GNU/Linux 2009.
7 #
8 VERSION=20100315
10 . /usr/lib/slitaz/gui_functions
12 # Check if user is root.
13 check_root()
14 {
15 if test $(id -u) != 0 ; then
16 echo -e "
17 You must be root to run `basename $0`. Please type 'su' and
18 root password to become super-user.\n"
19 exit 0
20 fi
21 }
24 #
25 # Functions called by the connection tab to list interfaces.
26 #
27 ############################################################
29 interface_status()
30 {
31 if ifconfig | grep -A 1 $i | grep -q inet; then
32 ip=`ifconfig | grep -A 1 $i | grep inet | awk '{ print $2 }' | cut -d ":" -f 2`
33 echo "connected ($ip)"
34 else
35 echo "-"
36 fi
37 }
38 # First column is for icon name.
39 detect_interfaces()
40 {
41 for i in `ls /sys/class/net`
42 do
43 case $i in
44 eth*)
45 echo "network-wired | $i | Ethernet | `interface_status`" ;;
46 wlan*|ath*|ra*)
47 echo "network-wireless | $i | Wireless | `interface_status`" ;;
48 lo)
49 echo "gtk-network | $i | Loopback | `interface_status`" ;;
50 *)
51 continue ;;
52 esac
54 done
55 }
57 # When users double click on a connection.
58 interfaces_List_actions()
59 {
60 echo "$INTERFACE_LIST"
61 }
63 # Netbox can be called with args.
64 case "$1" in
65 detect_interfaces|interfaces_List_actions)
66 $1
67 exit 0 ;;
68 *)
69 continue ;;
70 esac
72 set_ipup()
73 {
74 [ -f /etc/ppp/ip-up ] && return
75 cat > /etc/ppp/ip-up <<EOT
76 #!/bin/sh
77 exec $0 call ipup \$@
78 EOT
79 chmod +x /etc/ppp/ip-up
80 }
82 while true; do
84 # Detect WIFI_INTERFACE and update /etc/network.conf
85 . /etc/network.conf
86 if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
87 WIFI_INTERFACE=$(for i in /sys/class/net/*/wireless; do \
88 [ -d $i ] && echo $(basename $(dirname $i)) || echo wlan0; \
89 break; done)
90 [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf
91 fi
93 #
94 # Netbox internal calls
95 #
96 #########################################################
98 if [ "$1" = "call" ]; then
99 ppp="pppd local lock notty"
100 pppup=""
101 sub=$2
102 shift 2
103 case "$sub" in
104 sendsshkey)
105 check_root
106 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
107 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
108 grep ^ssh | ssh $1 "mkdir .ssh 2> /dev/null ; \
109 while read key; do for i in authorized_keys authorized_keys2; do \
110 grep -qs '\$key' .ssh/\$i || echo '\$key' >> .ssh/\$i ; done ; done ; \
111 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
112 exit 0;;
113 # OpenSSH VPN:
114 # PermitTunnel=point-to-point (or yes, ethernet, no)
115 # Tunnel="4" => tun4
116 # Local Client:
117 # # ssh -f -w 0:1 $REMOTE true => local tun0 [, remote tun1]
118 # # ifconfig $TUN $IP1 $IP2 netmask 255.255.255.252
119 # # route add $REMOTE_NETWORK $IP2
120 # Remote Server:
121 # # ifconfig $TUN $IP2 $IP1 netmask 255.255.255.252
122 # # route add $LOCAL_NETWORK $IP1
123 vpnssh) check_root
124 set_ipup
125 ps ww | grep -q "$ppp $2:$3" && exit 1
126 pipe="/tmp/ssh$$"
127 mkfifo $pipe
128 [ -n "$4" ] && pppup="ipparam 'addroutes,$(echo $4 | sed 's/ /,/g')'"
129 cat $pipe | dbclient -i /etc/dropbear/dropbear_rsa_host_key \
130 $1 "$ppp" | $ppp $2:$3 $pppup > $pipe
131 rm -f $pipe
132 exit 0;;
133 killvpnssh)
134 check_root
135 kill $(ps x | grep dbclient | grep "$ppp" | awk '{ print $1 }')
136 exit 0;;
137 ipup)
138 # Arg Name Example
139 # $1 Interface name ppp0
140 # $2 The tty ttyS1
141 # $3 The link speed 38400
142 # $4 Local IP number 12.34.56.78
143 # $5 Peer IP number 12.34.56.99
144 # $6 Optional ``ipparam'' value foo
145 iface=$1
146 # skip tty if present
147 case "$2" in [0-9]*);; *) shift; esac
148 peer=$4
149 IFS=","; set -- $(eval echo $5); unset IFS
150 set -- $1
151 if [ "$1" = "addroutes" ]; then
152 while [ -n "$2" ]; do
153 eval $(ipcalc -n $2)
154 eval $(ipcalc -m $2)
155 route add -net $NETWORK netmask $NETMASK \
156 gw $peer $iface
157 shift
158 done
159 fi
160 exit 0;;
161 esac
162 echo "call $sub unsupported."
163 exit 1
164 fi
168 #
169 # Status wire interfaces
170 #
171 tab_status_iface()
172 {
173 local eth
174 eth="$( (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) )"
175 which ethtool > /dev/null || eth=''
176 if [ -n "$eth" ]; then
177 cat <<EOT
178 <notebook labels="Ifconfig|$(echo $eth | sed 's/ /|/g')">
179 EOT
180 fi
181 cat <<EOT
182 <frame Ifconfig>
183 <text wrap="false" width-chars="58">
184 <input>ifconfig</input>
185 </text>
186 </frame>
187 EOT
188 if [ -n "$eth" ]; then
189 local i
190 for i in $eth ; do
191 cat <<EOT
192 <frame $i>
193 <text wrap="false" width-chars="58">
194 <input>ethtool $i</input>
195 </text>
196 </frame>
197 EOT
198 done
199 cat <<EOT
200 </notebook>
201 EOT
202 fi
203 }
205 #
206 # Status wifi interfaces
207 #
208 tab_status_wifi_iface()
209 {
210 cat <<EOT
211 <frame Iwconfig>
212 <text wrap="false" width-chars="58">
213 <input>iwconfig</input>
214 </text>
215 </frame>
216 EOT
217 }
219 #
220 # Status wifi network
221 #
222 tab_status_wifi_net()
223 {
224 cat <<EOT
225 <frame Wireless networks>
226 <text wrap="false" width-chars="58">
227 <input>iwlist scan</input>
228 </text>
229 </frame>
230 EOT
231 }
233 #
234 # Status routing
235 #
236 tab_status_route()
237 {
238 cat <<EOT
239 <frame Routing>
240 <frame Nameservers>
241 <text wrap="false" width-chars="58">
242 <input>cat /etc/resolv.conf</input>
243 </text>
244 </frame>
245 <frame Routing table>
246 <text wrap="false" width-chars="58">
247 <input>route</input>
248 </text>
249 </frame>
250 <frame Arp table>
251 <text wrap="false" width-chars="58">
252 <input>arp</input>
253 </text>
254 </frame>
255 </frame>
256 EOT
257 }
259 data_status()
260 {
261 cat <<EOT
262 ifconfig Network\ interfaces tab_status_iface
263 iwconfig Wireless\ interfaces tab_status_wifi_iface
264 iwlist Wireless\ networks tab_status_wifi_net
265 route Routing tab_status_route
266 EOT
267 }
269 #
270 # Status
271 #
272 tab_status()
273 {
274 use_tab data_status
275 }
277 #
278 # Interfaces list from detect_interfaces()
279 #
280 tab_connections()
281 {
282 cat <<EOT
283 <vbox>
284 <tree>
285 <width>520</width><height>120</height>
286 <variable>INTERFACE_LIST</variable>
287 <label>Interface|Type|Status</label>
288 <input icon_column="0">$0 detect_interfaces</input>
289 <action>refresh:INTERFACE_LIST</action>
290 </tree>
291 </vbox>
292 EOT
293 }
295 #
296 # DHCP
297 #
298 tab_udhcpc()
299 {
300 cat <<EOT
301 <frame Udhcpc (busybox)>
302 <text width-chars="58">
303 <label> "Ethernet (cable) default connection." </label>
304 </text>
305 <hbox>
306 <text use-markup="true">
307 <label>"<b>Interface:</b>"</label>
308 </text>
309 <entry>
310 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
311 <variable>INTERFACE</variable>
312 </entry>
313 </hbox>
314 <hbox>
315 <text use-markup="true">
316 <label>"<b>Options: </b>"</label>
317 </text>
318 <entry>
319 <default>-b</default>
320 <variable>UDHCPC_OPTS</variable>
321 </entry>
322 $(helpbutton udhcpc 80x30)
323 </hbox>
324 <hbox>
325 <text use-markup="true">
326 <label>"<b>Script: </b>"</label>
327 </text>
328 <entry editable="false">
329 <default>/usr/share/udhcpc/default.script</default>
330 <variable>UDHCPC_SCRIPT</variable>
331 </entry>
332 $(editbutton \$UDHCPC_SCRIPT)
333 </hbox>
334 <hbox>
335 <button>
336 <label>Start</label>
337 <input file icon="forward"></input>
338 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
339 <action>sed -i s/DHCP="no"/DHCP="yes"/ /etc/network.conf</action>
340 <action>sed -i s/STATIC="yes"/STATIC="no"/ /etc/network.conf</action>
341 <action>udhcpc \$UDHCPC_OPTS -i \$INTERFACE -p /var/run/udhcpc.\$INTERFACE.pid</action>
342 <action>refresh:INTERFACE_LIST</action>
343 </button>
344 <button>
345 <label>Stop</label>
346 <input file icon="stop"></input>
347 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
348 <action>ifconfig \$INTERFACE down</action>
349 <action>killall -q udhcpc; echo "done"</action>
350 <action>refresh:INTERFACE_LIST</action>
351 </button>
352 </hbox>
353 </frame>
354 EOT
355 }
357 #
358 # Static/fixed IP settings.
359 #
360 tab_fixed_ip()
361 {
362 cat <<EOT
363 <frame Ethernet fixed IP>
364 <hbox>
365 <text use-markup="true">
366 <label>"<b>Interface: </b>"</label>
367 </text>
368 <entry>
369 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
370 <variable>INTERFACE</variable>
371 </entry>
372 </hbox>
373 <hbox>
374 <text use-markup="true">
375 <label>"<b>IP: </b>"</label>
376 </text>
377 <entry>
378 <input>. /etc/network.conf; echo "\$IP"</input>
379 <variable>IP</variable>
380 </entry>
381 </hbox>
382 <hbox>
383 <text use-markup="true">
384 <label>"<b>Netmask: </b>"</label>
385 </text>
386 <entry>
387 <input>. /etc/network.conf; echo "\$NETMASK"</input>
388 <variable>NETMASK</variable>
389 </entry>
390 </hbox>
391 <hbox>
392 <text use-markup="true">
393 <label>"<b>Gateway: </b>"</label>
394 </text>
395 <entry>
396 <input>. /etc/network.conf; echo "\$GATEWAY"</input>
397 <variable>GATEWAY</variable>
398 </entry>
399 </hbox>
400 <hbox>
401 <text use-markup="true">
402 <label>"<b>DNS server: </b>"</label>
403 </text>
404 <entry>
405 <input>. /etc/network.conf; echo "\$DNS_SERVER"</input>
406 <variable>DNS_SERVER</variable>
407 </entry>
408 </hbox>
409 <hbox>
410 <button>
411 <label>Start</label>
412 <input file icon="forward"></input>
413 <action>ifconfig lo down</action>
414 <action>ifconfig \$INTERFACE down</action>
415 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
416 <action>sed -i s/DHCP="yes"/DHCP="no"/ /etc/network.conf</action>
417 <action>sed -i s/WIFI="yes"/WIFI="no"/ /etc/network.conf</action>
418 <action>sed -i s/STATIC="no"/STATIC="yes"/ /etc/network.conf</action>
419 <action>sed -i s/`cat /etc/network.conf | grep ^IP=`/IP="\$IP"/ /etc/network.conf</action>
420 <action>sed -i s/`cat /etc/network.conf | grep ^NETMASK=`/NETMASK="\$NETMASK"/ /etc/network.conf</action>
421 <action>sed -i s/`cat /etc/network.conf | grep ^GATEWAY=`/GATEWAY="\$GATEWAY"/ /etc/network.conf</action>
422 <action>sed -i s/`cat /etc/network.conf | grep ^DNS_SERVER=`/DNS_SERVER="\$DNS_SERVER"/ /etc/network.conf</action>
423 <action>/etc/init.d/network.sh</action>
424 <action>refresh:INTERFACE_LIST</action>
425 </button>
426 <button>
427 <label>Stop</label>
428 <input file icon="stop"></input>
429 <action>ifconfig \$INTERFACE down</action>
430 <action>refresh:INTERFACE_LIST</action>
431 </button>
432 </hbox>
433 </frame>
434 EOT
435 }
437 #
438 # PPPoe settings.
439 #
440 tab_pppoe()
441 {
442 cat <<EOT
443 <frame PPPoE>
444 <hbox>
445 <text use-markup="true">
446 <label>"<b>Name: </b>"</label>
447 </text>
448 <entry>
449 <input>NAME=\$(grep -s ^name /etc/ppp/options); echo "\${NAME#* }"</input>
450 <variable>NAME</variable>
451 </entry>
452 </hbox>
453 <hbox>
454 <text use-markup="true">
455 <label>"<b>Username:</b>"</label>
456 </text>
457 <entry>
458 <variable>USER</variable>
459 </entry>
460 </hbox>
461 <hbox>
462 <text use-markup="true">
463 <label>"<b>Password:</b>"</label>
464 </text>
465 <entry>
466 <variable>PASS</variable>
467 </entry>
468 </hbox>
469 <hbox>
470 $(helpbutton pppd 80x30)
471 $(manbutton 8 pppd)
472 $(webbutton ppp)
473 <button>
474 <input file icon="accessories-text-editor"></input>
475 <label>Tune</label>
476 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
477 <action type="lauch">leafpad /etc/ppp/options</action>
478 </button>
479 <button>
480 <label>Start</label>
481 <input file icon="forward"></input>
482 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
483 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
484 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
485 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
486 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
487 <action>killall udhcpc</action>
488 <action>sed -i "s/DHCP=\"yes\"/DHCP=\"no\"/" /etc/network.conf</action>
489 <action>sed -i "s/PPPOE=\"no\"/PPPOE=\"yes\"/" /etc/network.conf</action>
490 <action>pppd \$INTERFACE &</action>
491 </button>
492 <button>
493 <label>Stop</label>
494 <input file icon="stop"></input>
495 <action>sed -i "s/PPPOE=\"yes\"/PPPOE=\"no\"/" /etc/network.conf</action>
496 <action>killall pppd</action>
497 </button>
498 </hbox>
499 </frame>
500 EOT
501 }
503 #
504 # PPP settings.
505 #
506 tab_ppp()
507 {
508 cat <<EOT
509 <frame PPP>
510 <hbox>
511 <text use-markup="true">
512 <label>"<b>Username: </b>"</label>
513 </text>
514 <entry>
515 <input>USER=\$(grep -s ^ACCOUNT= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${USER#*=}"</input>
516 <variable>USER</variable>
517 </entry>
518 </hbox>
519 <hbox>
520 <text use-markup="true">
521 <label>"<b>Password: </b>"</label>
522 </text>
523 <entry>
524 <input>PASS=\$(grep -s ^PASSWORD= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PASS#*=}"</input>
525 <variable>PASS</variable>
526 </entry>
527 </hbox>
528 <hbox>
529 <text use-markup="true">
530 <label>"<b>Telephone:</b>"</label>
531 </text>
532 <entry>
533 <input>PHONE=\$(grep -s ^TELEPHONE= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PHONE#*=}"</input>
534 <variable>PHONE</variable>
535 </entry>
536 </hbox>
537 <hbox>
538 $(helpbutton pppd 80x30)
539 $(manbutton 8 pppd)
540 $(webbutton ppp)
541 <button>
542 <input file icon="accessories-text-editor"></input>
543 <label>Tune</label>
544 <action>[ -n "\$NAME" ] && sed -i "s/^ACCOUNT=.*/ACCOUNT=\$NAME/" /etc/ppp/scripts/ppp-on</action>
545 <action>[ -n "\$PASS" ] && sed -i "s/^PASSWORD=.*/PASSWORD=\$PASS/" /etc/ppp/scripts/ppp-on</action>
546 <action>[ -n "\$PHONE" ] && sed -i "s/^TELEPHONE=.*/TELEPHONE=\$PHONE/" /etc/ppp/scripts/ppp-on</action>
547 <action type="lauch">leafpad /etc/ppp/scripts/ppp-on</action>
548 </button>
549 <button>
550 <label>Start</label>
551 <input file icon="forward"></input>
552 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
553 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
554 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
555 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
556 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
557 <action>/etc/ppp/scripts/ppp-off</action>
558 <action>/etc/ppp/scripts/ppp-on &</action>
559 </button>
560 <button>
561 <label>Stop</label>
562 <input file icon="stop"></input>
563 <action>/etc/ppp/scripts/ppp-off</action>
564 </button>
565 </hbox>
566 </frame>
567 EOT
568 }
570 #
571 # System Wide configuration.
572 #
573 tab_system()
574 {
575 cat <<EOT
576 <frame Configuration files>
577 <hbox>
578 <text use-markup="true">
579 <label>"<b>Hosts :</b>"</label>
580 </text>
581 <entry editable="false">
582 <default>/etc/hosts</default>
583 <variable>HOSTS</variable>
584 </entry>
585 $(editbutton \$HOSTS)
586 </hbox>
587 <hbox>
588 <text use-markup="true">
589 <label>"<b>Host name :</b>"</label>
590 </text>
591 <entry editable="false">
592 <default>/etc/hostname</default>
593 <variable>HOSTNAME</variable>
594 </entry>
595 $(editbutton \$HOSTNAME)
596 </hbox>
597 <hbox>
598 <text use-markup="true">
599 <label>"<b>Network :</b>"</label>
600 </text>
601 <entry editable="false">
602 <default>/etc/network.conf</default>
603 <variable>CONFIG_FILE</variable>
604 </entry>
605 $(editbutton \$CONFIG_FILE)
606 </hbox>
607 <hbox>
608 <button>
609 <label>Restart</label>
610 <input file icon="reload"></input>
611 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
612 <action>ifconfig \$INTERFACE down</action>
613 <action>killall -q udhcpc; echo "done"</action>
614 <action>/etc/init.d/network.sh restart</action>
615 </button>
616 </hbox>
617 </frame>
618 EOT
619 }
621 #
622 # ssh/ppp
623 #
624 tab_sshppp()
625 {
626 cat <<EOT
627 <frame Virtual Private Network with PPP/SSH>
628 <hbox>
629 <text use-markup="true">
630 <label>"<b>Peer :</b>"</label>
631 </text>
632 <entry>
633 <variable>DROPBEAR_PEERVPN</variable>
634 <default>user@elsewhere</default>
635 </entry>
636 </hbox>
637 <hbox>
638 <text use-markup="true">
639 <label>"<b>Local IP :</b>"</label>
640 </text>
641 <entry>
642 <variable>DROPBEAR_LOCAL</variable>
643 <default>192.168.254.1</default>
644 </entry>
645 </hbox>
646 <hbox>
647 <text use-markup="true">
648 <label>"<b>Remote IP :</b>"</label>
649 </text>
650 <entry>
651 <variable>DROPBEAR_REMOTE</variable>
652 <default>192.168.254.2</default>
653 </entry>
654 </hbox>
655 <hbox>
656 <text use-markup="true">
657 <label>"<b>Route(s) :</b>"</label>
658 </text>
659 <entry>
660 <variable>DROPBEAR_ROUTE</variable>
661 <default>192.168.10.0/24 192.168.20.0/28</default>
662 </entry>
663 </hbox>
664 <hbox>
665 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:vpn)
666 <button>
667 <input file icon="forward"></input>
668 <label>Connect</label>
669 <action>$0 call vpnssh \$DROPBEAR_PEERVPN \$DROPBEAR_LOCAL \$DROPBEAR_REMOTE "\$DROPBEAR_ROUTE" &</action>
670 </button>
671 <button>
672 <input file icon="stop"></input>
673 <label>Disconnect</label>
674 <action>$0 call killvpnssh</action>
675 </button>
676 <button>
677 <input file icon="go-up"></input>
678 <label>Send key</label>
679 <action>$xterm -geometry 80x10 -title "Send key" -e "$0 call sendsshkey \$DROPBEAR_PEERVPN; echo -e \"----\nENTER to continue...\" && read close"</action>
680 </button>
681 </hbox>
682 </frame>
683 EOT
684 }
686 #
687 # PPTP client
688 #
689 #FIXME
690 #cat > /etc/ppp/peers/$TUNNEL <<EOT
691 #pty "pptp $SERVER --nolaunchpppd"
692 #lock
693 #noauth
694 #nobsdcomp
695 #nodeflate
696 #name $DOMAIN\\$USERNAME
697 #remotename $TUNNEL
698 #ipparam $TUNNEL
699 #$(encryption && echo "require-mppe-128")
700 #EOT
701 #pppd call $TUNNEL updetach
703 tab_pptp()
704 {
705 [ -f /etc/ppp/options.pptp ] || cat >> /etc/ppp/options.pptp <<EOT
706 lock noauth nobsdcomp nodeflate remotename PPTP
707 EOT
708 [ -f /etc/ppp/pptp-servers ] || cat >> /etc/ppp/pptp-servers <<EOT
709 # PPTP servers list
710 EOT
711 cat <<EOT
712 <frame Virtual Private Network with PPTP>
713 <hbox>
714 <text use-markup="true">
715 <label>"<b>Server:</b>"</label>
716 </text>
717 <combobox>
718 <variable>PPTP_SERVER</variable>
719 EOT
720 grep -v ^\# /etc/ppp/pptp-servers | \
721 awk '{ printf " <item>%s</item>\n",$1 }'
722 cat <<EOT
723 <item>SERVER</item>
724 </combobox>
725 $(editbutton /etc/ppp/pptp-servers)
726 </hbox>
727 <hbox>
728 <text use-markup="true">
729 <label>"<b> User:</b>"</label>
730 </text>
731 <combobox>
732 <variable>PPTP_USER</variable>
733 EOT
734 grep '\\' /etc/ppp/chap-secrets | grep -v ^\# | \
735 awk '{ printf " <item>%s</item>\n",$1 }'
736 cat <<EOT
737 <item>DOMAIN\USERNAME</item>
738 </combobox>
739 $(editbutton /etc/ppp/chap-secrets)
740 </hbox>
741 <hbox>
742 <text use-markup="true">
743 <label>"<b>Password:</b>"</label>
744 </text>
745 <entry>
746 <variable>PPTP_PASS</variable>
747 </entry>
748 </hbox>
749 <hbox>
750 <checkbox>
751 <label>Encryption</label>
752 <variable>PPTP_ENC</variable>
753 <default>true</default>
754 </checkbox>
755 $(helpbutton pptp 80x35)
756 <button>
757 <input file icon="accessories-text-editor"></input>
758 <label>Options</label>
759 <action type="lauch">leafpad /etc/ppp/options.pptp</action>
760 </button>
761 $(webbutton pptpclient)
762 <button>
763 <input file icon="forward"></input>
764 <label>Connect</label>
765 <action>grep -qs ^\$PPTP_USER /etc/ppp/chap-secrets || \
766 echo "\$PPTP_USER PPTP \"$PPTP_PASS\" *" >> /etc/ppp/chap-secrets</action>
767 <action>grep -qs ^\$PPTP_SERVER /etc/ppp/pptp-servers || \
768 echo "\$PPTP_SERVER" >> /etc/ppp/pptp-servers</action>
769 <action>PASS=""; [ -n "\$PPTP_PASS" ] && PASS="password \$PASS"; \
770 ENC=""; [ x\$PPTP_ENC == xtrue ] && ENC="require-mppe-128"; \
771 /usr/sbin/pptp \$PPTP_SERVER file /etc/ppp/options.pptp \$ENC user \$PPTP_USER \$PASS &
772 </action>
773 </button>
774 <button>
775 <input file icon="stop"></input>
776 <label>Disconnect</label>
777 <action>killall pptp</action>
778 </button>
779 </hbox>
780 </frame>
781 EOT
782 }
784 #
785 # Cisco EasyVPN
786 #
787 tab_easyvpn()
788 {
789 cat <<EOT
790 <frame Cisco EasyVPN>
791 <hbox>
792 <text use-markup="true">
793 <label>"<b>VPNC_OPTIONS</b>"</label>
794 </text>
795 <entry editable="false">
796 EOT
797 [ -n "$VPNC_OPTIONS" ] && cat << EOT
798 <default>$tmp</default>
799 EOT
800 cat << EOT
801 <variable>VPNC_OPTS</variable>
802 </entry>
803 $(helpbutton vpnc 80x30)
804 <button>
805 <input file icon="help"></input>
806 <label>more</label>
807 <action>$xterm -geometry 80x40 -title "vpnc help (q to quit)" -e "$(which vpnc) --long-help 2>&1 | less"</action>
808 </button>
809 $(editbutton /etc/daemons.conf)
810 </hbox>
811 $(configfile /etc/vpnc/default.conf VPNC_CONF)
812 $(datafile "/etc/vpnc/vpnc-script" VPNC_SCRIPT 'Script:')
813 <hbox>
814 $(startstopdaemon vpnc)
815 </hbox>
816 </frame>
817 EOT
818 }
820 #
821 # OpenVPN
822 #
823 tab_openvpn()
824 {
825 local i
826 local n
827 cat <<EOT
828 <frame OpenVPN>
829 EOT
830 n=1
831 for i in /etc/openvpn/*.conf ; do
832 [ -f $i ] || continue
833 configfile $i OPENVPN_CONF$n
834 n=$(($n + 1))
835 done
836 cat <<EOT
837 <hbox>
838 $(helpbutton openvpn 80x40)
839 $(startstopdaemon openvpn)
840 </hbox>
841 </frame>
842 EOT
843 }
845 data_vpn()
846 {
847 cat <<EOT
848 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "pppd" ||
849 echo "#") PPP/SSH tab_sshppp
850 pptp PPTP tab_pptp
851 vpnc EasyVPN tab_easyvpn
852 openvpn OpenVPN tab_openvpn
853 EOT
854 }
856 #
857 # VPN
858 #
859 tab_vpn()
860 {
861 use_tab data_vpn
862 }
864 #
865 # ether-wake
866 #
867 tab_etherwake()
868 {
869 cat <<EOT
870 <frame Ether-wake (busybox)>
871 <hbox>
872 <text use-markup="true">
873 <label>"<b>Machines :</b>"</label>
874 </text>
875 <entry editable="false">
876 <default>/etc/ethers</default>
877 <variable>ETHERS</variable>
878 </entry>
879 <button>
880 <input file icon="accessories-text-editor"></input>
881 <action>[ -s \$ETHERS ] || echo "#00:01:02:03:04:05 mystation" >\$ETHERS</action>
882 <action type="lauch">leafpad \$ETHERS</action>
883 </button>
884 </hbox>
885 <hbox>
886 <text use-markup="true">
887 <label>"<b>Options : </b>"</label>
888 </text>
889 <entry editable="true">
890 <variable>ETHERWAKE_OPTS</variable>
891 </entry>
892 $(helpbutton ether-wake 80x15)
893 <button>
894 <label>Start</label>
895 <input file icon="forward"></input>
896 <action>ether-wake \$ETHERWAKE_OPTS</action>
897 </button>
898 </hbox>
899 <frame>
900 <hbox>
901 EOT
902 if which ethtool > /dev/null; then
903 cat <<EOT
904 <text use-markup="true">
905 <label>"<b>Interface:</b>"</label>
906 </text>
907 <combobox>
908 <variable>ETHERWAKE_ETH</variable>
909 EOT
910 (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) | \
911 awk '{ printf " <item>%s</item>\n",$1 }'
912 cat <<EOT
913 </combobox>
914 <button>
915 <label>Enable Wake On LAN</label>
916 <input file icon="forward"></input>
917 <action>ethtool -s \$ETHERWAKE_ETH wok g</action>
918 </button>
919 EOT
920 else
921 cat <<EOT
922 <vbox>
923 <text wrap="true" width-chars="58">
924 <label>
925 "Ethtool can enable the Wake-on-lan
926 feature on many Ethernet cards.
927 "
928 </label>
929 </text>
930 $(installbox ethtool)
931 </vbox>
932 EOT
933 fi
934 cat <<EOT
935 </hbox>
936 </frame>
937 </frame>
938 EOT
939 }
941 data_main()
942 {
943 cat <<EOT
944 #program tab name function
945 ifconfig Connections tab_connections
946 udhcpc DHCP tab_udhcpc
947 ifconfig Static\ IP tab_fixed_ip
948 pppoe PPPoE tab_pppoe
949 pppd PPP tab_ppp
950 true VPN tab_vpn
951 ether-wake Etherwake tab_etherwake
952 true Configuration tab_system
953 EOT
954 }
956 tab_main()
957 {
958 use_tab data_main
959 }
961 ######################################################
962 #
963 # Netbox GUI
964 #
965 ######################################################
967 # English/French help dialog.
968 export HELP='
969 <window title="Network status" icon-name="network-wire">
970 <vbox>
971 <text use-markup="true">
972 <label>
973 "
974 <b>SliTaz - Netbox</b>"
975 </label>
976 </text>
977 <frame English>
978 <text wrap="true" width-chars="58">
979 <label>
980 "Netbox lets you manage network connections by getting a dynamic IP by
981 DHCP or a static IP and setup servers. Netbox can start or stop
982 networking, configure network interfaces or directly edit files."
983 </label>
984 </text>
985 </frame>
986 <frame Francais>
987 <text wrap="true" width-chars="58">
988 <label>
989 "Netbox vous permet de gerer les connexions reseau avec une IP
990 statique ou en obtenant une IP dynamique par DHCP, et de parametrer
991 les serveurs. Netbox peut demarrer ou arreter le reseau, configurer
992 les interfaces reseau ou editer directement les fichiers."
993 </label>
994 </text>
995 </frame>
996 </vbox>
997 </window>
998 '
1000 # Interface status with ifconfig without arguments to show all
1001 # active connections.
1003 export IFCONFIG="
1004 <window title=\"Network status\" icon-name=\"network-wire\">
1005 <vbox>
1006 $(tab_status)
1007 <hbox>
1008 <button>
1009 <input file icon=\"gtk-close\"></input>
1010 <action type=\"closewindow\">IFCONFIG</action>
1011 </button>
1012 </hbox>
1013 </vbox>
1014 </window>"
1016 # The main dialog with notebook, start/stop buttons and all options.
1017 # Note that /etc/network.conf is seded when an interface is activated.
1019 head='
1020 <window title="SliTaz Netbox Manager" icon-name="network-wired">
1021 <vbox>
1023 <hbox>
1024 <text use-markup="true">
1025 <label>"<b>Network Manager</b>"</label>
1026 </text>
1027 <pixmap>
1028 <input file>/usr/share/pixmaps/netbox.png</input>
1029 </pixmap>
1030 </hbox>
1032 bottom='
1033 <hbox>
1034 <button>
1035 <label>Wireless manager</label>
1036 <input file icon="network-wireless"></input>
1037 <action>wifibox &</action>
1038 </button>
1039 <button>
1040 <label>Refresh list</label>
1041 <input file icon="reload"></input>
1042 <action>refresh:INTERFACE_LIST</action>
1043 </button>
1044 <button>
1045 <label>Full status</label>
1046 <input file icon="dialog-information"></input>
1047 <action type="launch">IFCONFIG</action>
1048 </button>
1049 <button help>
1050 <label>Help</label>
1051 <action type="launch">HELP</action>
1052 </button>
1053 <button>
1054 <label>Quit</label>
1055 <input file icon="exit"></input>
1056 <action type="exit">Exit</action>
1057 </button>
1058 </hbox>
1060 </vbox>
1061 </window>
1064 NET_BOX="${head}$(tab_main)${bottom}"
1066 export NET_BOX
1068 # TODO: Modules(Network kernel modules)
1070 # Only root can configure network.
1071 check_root
1073 # Configure and connect if button Connect was pressed.
1074 if ! grep -qs ^name /etc/ppp/options ; then
1075 # Generate /etc/ppp/options
1076 cat > /etc/ppp/options << _EOT_
1077 plugin rp-pppoe.so
1078 name provider-ID
1079 noipdefault
1080 defaultroute
1081 mtu 1492
1082 mru 1492
1083 lock
1084 _EOT_
1085 # Generate /etc/ppp/pap-secrets
1086 cat > /etc/ppp/pap-secrets << _EOT_
1087 # Secrets for authentication using PAP
1088 # client server secret IP addresses
1089 _EOT_
1090 # Generate /etc/ppp/chap-secrets
1091 cat > /etc/ppp/chap-secrets << _EOT_
1092 # Secrets for authentication using CHAP
1093 # client server secret IP addresses
1094 _EOT_
1095 fi
1096 gtkdialog --center --program=NET_BOX | grep -a 'EXIT="restart"' && continue
1097 exit 0
1098 done