slitaz-tools view tinyutils/netbox @ rev 719

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