slitaz-tools view oldstuff/gtkdialog/netbox @ rev 1002
Tiny edits
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Wed Oct 05 18:38:16 2016 +0100 (2016-10-05) |
parents | 1cfb0314e3ff |
children | 491239328786 |
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>Username:</b>"</label>
446 </text>
447 <entry>
448 <input>PPoE_ID=\$(grep -s ^name /etc/ppp/options); echo "\${PPoE_ID#* }"</input>
449 <variable>PPoE_ID</variable>
450 </entry>
451 </hbox>
452 <hbox>
453 <text use-markup="true">
454 <label>"<b>Password:</b>"</label>
455 </text>
456 <entry>
457 <input>PPoE_PASS=\$(ID=\$(awk '/^name/{print \$2}' /etc/ppp/options) ; \
458 awk -v KEY="\$ID" '\$1==KEY{print \$3}' /etc/ppp/pap-secrets); \
459 echo "\$PPoE_PASS"</input>
460 <variable>PPoE_PASS</variable>
461 </entry>
462 </hbox>
463 <hbox>
464 $(helpbutton pppd 80x30)
465 $(manbutton 8 pppd)
466 $(webbutton ppp)
467 <button>
468 <input file icon="accessories-text-editor"></input>
469 <label>Tune</label>
470 <action>[ -n "\$PPoE_ID" ] && sed -i 's/^name .*/name \$PPoE_ID/' /etc/ppp/options</action>
471 <action type="lauch">leafpad /etc/ppp/options</action>
472 </button>
473 <button>
474 <label>Start</label>
475 <input file icon="forward"></input>
476 <action>[ -n "\$PPoE_ID" ] && grep -qs "^\$PPoE_ID" /etc/ppp/pap-secrets \
477 || echo "\$PPoE_ID * \$PPoE_PASS" >> /etc/ppp/pap-secrets</action>
478 <action>[ -n "\$PPoE_ID" ] && grep -qs "^\$PPoE_ID" /etc/ppp/chap-secrets \
479 || echo "\$PPoE_ID * \$PPoE_PASS" >> /etc/ppp/chap-secrets</action>
480 <action>[ -n "\$PPoE_ID" ] && sed -i "s/^name .*/name \$PPoE_ID/" /etc/ppp/options</action>
481 <action>killall udhcpc</action>
482 <action>sed -i 's/DHCP=.*/DHCP="no"/' /etc/network.conf</action>
483 <action>sed -i 's/PPPOE=.*/PPPOE="yes"/' /etc/network.conf</action>
484 <action>. /etc/network.conf ; pppd \$INTERFACE &</action>
485 </button>
486 <button>
487 <label>Stop</label>
488 <input file icon="stop"></input>
489 <action>sed -i 's/PPPOE=.*/PPPOE="no"/' /etc/network.conf</action>
490 <action>killall pppd</action>
491 </button>
492 </hbox>
493 </frame>
494 EOT
495 }
497 #
498 # PPP settings.
499 #
500 tab_ppp()
501 {
502 cat <<EOT
503 <frame PPP>
504 <hbox>
505 <text use-markup="true">
506 <label>"<b>Username: </b>"</label>
507 </text>
508 <entry>
509 <input>NAME=\$(grep -s ^ACCOUNT= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${NAME#*=}"</input>
510 <variable>NAME</variable>
511 </entry>
512 </hbox>
513 <hbox>
514 <text use-markup="true">
515 <label>"<b>Password: </b>"</label>
516 </text>
517 <entry>
518 <input>PASS=\$(grep -s ^PASSWORD= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PASS#*=}"</input>
519 <variable>PASS</variable>
520 </entry>
521 </hbox>
522 <hbox>
523 <text use-markup="true">
524 <label>"<b>Telephone:</b>"</label>
525 </text>
526 <entry>
527 <input>PHONE=\$(grep -s ^TELEPHONE= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PHONE#*=}"</input>
528 <variable>PHONE</variable>
529 </entry>
530 </hbox>
531 <hbox>
532 $(helpbutton pppd 80x30)
533 $(manbutton 8 pppd)
534 $(webbutton ppp)
535 <button>
536 <input file icon="accessories-text-editor"></input>
537 <label>Tune</label>
538 <action>[ -n "\$NAME" ] && sed -i "s/^ACCOUNT=.*/ACCOUNT=\$NAME/" /etc/ppp/scripts/ppp-on</action>
539 <action>[ -n "\$PASS" ] && sed -i "s/^PASSWORD=.*/PASSWORD=\$PASS/" /etc/ppp/scripts/ppp-on</action>
540 <action>[ -n "\$PHONE" ] && sed -i "s/^TELEPHONE=.*/TELEPHONE=\$PHONE/" /etc/ppp/scripts/ppp-on</action>
541 <action type="lauch">leafpad /etc/ppp/scripts/ppp-on</action>
542 </button>
543 <button>
544 <label>Start</label>
545 <input file icon="forward"></input>
546 <action>[ -n "\$NAME" ] && grep -qs "^\$NAME" /etc/ppp/pap-secrets \
547 || echo "\$NAME * \$PASS" >> /etc/ppp/pap-secrets</action>
548 <action>[ -n "\$NAME" ] && grep -qs "^\$NAME" /etc/ppp/chap-secrets \
549 || echo "\$NAME * \$PASS" >> /etc/ppp/chap-secrets</action>
550 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
551 <action>/etc/ppp/scripts/ppp-off</action>
552 <action>/etc/ppp/scripts/ppp-on &</action>
553 </button>
554 <button>
555 <label>Stop</label>
556 <input file icon="stop"></input>
557 <action>/etc/ppp/scripts/ppp-off</action>
558 </button>
559 </hbox>
560 </frame>
561 EOT
562 }
564 #
565 # System Wide configuration.
566 #
567 tab_system()
568 {
569 cat <<EOT
570 <frame Configuration files>
571 <hbox>
572 <text use-markup="true">
573 <label>"<b>Hosts :</b>"</label>
574 </text>
575 <entry editable="false">
576 <default>/etc/hosts</default>
577 <variable>HOSTS</variable>
578 </entry>
579 $(editbutton \$HOSTS)
580 </hbox>
581 <hbox>
582 <text use-markup="true">
583 <label>"<b>Host name :</b>"</label>
584 </text>
585 <entry editable="false">
586 <default>/etc/hostname</default>
587 <variable>HOSTNAME</variable>
588 </entry>
589 $(editbutton \$HOSTNAME)
590 </hbox>
591 <hbox>
592 <text use-markup="true">
593 <label>"<b>Network :</b>"</label>
594 </text>
595 <entry editable="false">
596 <default>/etc/network.conf</default>
597 <variable>CONFIG_FILE</variable>
598 </entry>
599 $(editbutton \$CONFIG_FILE)
600 </hbox>
601 <hbox>
602 <button>
603 <label>Restart</label>
604 <input file icon="reload"></input>
605 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
606 <action>ifconfig \$INTERFACE down</action>
607 <action>killall -q udhcpc; echo "done"</action>
608 <action>/etc/init.d/network.sh restart</action>
609 </button>
610 </hbox>
611 </frame>
612 EOT
613 }
615 #
616 # ssh/ppp
617 #
618 tab_sshppp()
619 {
620 cat <<EOT
621 <frame Virtual Private Network with PPP/SSH>
622 <hbox>
623 <text use-markup="true">
624 <label>"<b>Peer :</b>"</label>
625 </text>
626 <entry>
627 <variable>DROPBEAR_PEERVPN</variable>
628 <default>user@elsewhere</default>
629 </entry>
630 </hbox>
631 <hbox>
632 <text use-markup="true">
633 <label>"<b>Local IP :</b>"</label>
634 </text>
635 <entry>
636 <variable>DROPBEAR_LOCAL</variable>
637 <default>192.168.254.1</default>
638 </entry>
639 </hbox>
640 <hbox>
641 <text use-markup="true">
642 <label>"<b>Remote IP :</b>"</label>
643 </text>
644 <entry>
645 <variable>DROPBEAR_REMOTE</variable>
646 <default>192.168.254.2</default>
647 </entry>
648 </hbox>
649 <hbox>
650 <text use-markup="true">
651 <label>"<b>Route(s) :</b>"</label>
652 </text>
653 <entry>
654 <variable>DROPBEAR_ROUTE</variable>
655 <default>192.168.10.0/24 192.168.20.0/28</default>
656 </entry>
657 </hbox>
658 <hbox>
659 $(wikibutton http://doc.slitaz.org/en:guides:vpn)
660 <button>
661 <input file icon="forward"></input>
662 <label>Connect</label>
663 <action>$0 call vpnssh \$DROPBEAR_PEERVPN \$DROPBEAR_LOCAL \$DROPBEAR_REMOTE "\$DROPBEAR_ROUTE" &</action>
664 </button>
665 <button>
666 <input file icon="stop"></input>
667 <label>Disconnect</label>
668 <action>$0 call killvpnssh</action>
669 </button>
670 <button>
671 <input file icon="go-up"></input>
672 <label>Send key</label>
673 <action>$xterm -geometry 80x10 -title "Send key" -e "$0 call sendsshkey \$DROPBEAR_PEERVPN; echo -e \"----\nENTER to continue...\" && read close"</action>
674 </button>
675 </hbox>
676 </frame>
677 EOT
678 }
680 #
681 # PPTP client
682 #
683 #FIXME
684 #cat > /etc/ppp/peers/$TUNNEL <<EOT
685 #pty "pptp $SERVER --nolaunchpppd"
686 #lock
687 #noauth
688 #nobsdcomp
689 #nodeflate
690 #name $DOMAIN\\$USERNAME
691 #remotename $TUNNEL
692 #ipparam $TUNNEL
693 #$(encryption && echo "require-mppe-128")
694 #EOT
695 #pppd call $TUNNEL updetach
697 tab_pptp()
698 {
699 [ -f /etc/ppp/options.pptp ] || cat >> /etc/ppp/options.pptp <<EOT
700 lock noauth nobsdcomp nodeflate remotename PPTP
701 EOT
702 [ -f /etc/ppp/pptp-servers ] || cat >> /etc/ppp/pptp-servers <<EOT
703 # PPTP servers list
704 EOT
705 cat <<EOT
706 <frame Virtual Private Network with PPTP>
707 <hbox>
708 <text use-markup="true">
709 <label>"<b>Server:</b>"</label>
710 </text>
711 <combobox>
712 <variable>PPTP_SERVER</variable>
713 EOT
714 grep -v ^\# /etc/ppp/pptp-servers | \
715 awk '{ printf " <item>%s</item>\n",$1 }'
716 cat <<EOT
717 <item>SERVER</item>
718 </combobox>
719 $(editbutton /etc/ppp/pptp-servers)
720 </hbox>
721 <hbox>
722 <text use-markup="true">
723 <label>"<b> User:</b>"</label>
724 </text>
725 <combobox>
726 <variable>PPTP_USER</variable>
727 EOT
728 grep '\\' /etc/ppp/chap-secrets | grep -v ^\# | \
729 awk '{ printf " <item>%s</item>\n",$1 }'
730 cat <<EOT
731 <item>DOMAIN\USERNAME</item>
732 </combobox>
733 $(editbutton /etc/ppp/chap-secrets)
734 </hbox>
735 <hbox>
736 <text use-markup="true">
737 <label>"<b>Password:</b>"</label>
738 </text>
739 <entry>
740 <variable>PPTP_PASS</variable>
741 </entry>
742 </hbox>
743 <hbox>
744 <checkbox>
745 <label>Encryption</label>
746 <variable>PPTP_ENC</variable>
747 <default>true</default>
748 </checkbox>
749 $(helpbutton pptp 80x35)
750 <button>
751 <input file icon="accessories-text-editor"></input>
752 <label>Options</label>
753 <action type="lauch">leafpad /etc/ppp/options.pptp</action>
754 </button>
755 $(webbutton pptpclient)
756 <button>
757 <input file icon="forward"></input>
758 <label>Connect</label>
759 <action>grep -qs ^\$PPTP_USER /etc/ppp/chap-secrets || \
760 echo "\$PPTP_USER PPTP \"$PPTP_PASS\" *" >> /etc/ppp/chap-secrets</action>
761 <action>grep -qs ^\$PPTP_SERVER /etc/ppp/pptp-servers || \
762 echo "\$PPTP_SERVER" >> /etc/ppp/pptp-servers</action>
763 <action>PASS=""; [ -n "\$PPTP_PASS" ] && PASS="password \$PASS"; \
764 ENC=""; [ x\$PPTP_ENC == xtrue ] && ENC="require-mppe-128"; \
765 /usr/sbin/pptp \$PPTP_SERVER file /etc/ppp/options.pptp \$ENC user \$PPTP_USER \$PASS &
766 </action>
767 </button>
768 <button>
769 <input file icon="stop"></input>
770 <label>Disconnect</label>
771 <action>killall pptp</action>
772 </button>
773 </hbox>
774 </frame>
775 EOT
776 }
778 #
779 # Cisco EasyVPN
780 #
781 tab_easyvpn()
782 {
783 cat <<EOT
784 <frame Cisco EasyVPN>
785 <hbox>
786 <text use-markup="true">
787 <label>"<b>VPNC_OPTIONS</b>"</label>
788 </text>
789 <entry editable="false">
790 EOT
791 [ -n "$VPNC_OPTIONS" ] && cat << EOT
792 <default>$tmp</default>
793 EOT
794 cat << EOT
795 <variable>VPNC_OPTS</variable>
796 </entry>
797 $(helpbutton vpnc 80x30)
798 <button>
799 <input file icon="help"></input>
800 <label>more</label>
801 <action>$xterm -geometry 80x40 -title "vpnc help (q to quit)" -e "$(which vpnc) --long-help 2>&1 | less"</action>
802 </button>
803 $(editbutton /etc/daemons.conf)
804 </hbox>
805 $(configfile /etc/vpnc/default.conf VPNC_CONF)
806 $(datafile "/etc/vpnc/vpnc-script" VPNC_SCRIPT 'Script:')
807 <hbox>
808 $(startstopdaemon vpnc)
809 </hbox>
810 </frame>
811 EOT
812 }
814 #
815 # OpenVPN
816 #
817 tab_openvpn()
818 {
819 local i
820 local n
821 cat <<EOT
822 <frame OpenVPN>
823 EOT
824 n=1
825 for i in /etc/openvpn/*.conf ; do
826 [ -f $i ] || continue
827 configfile $i OPENVPN_CONF$n
828 n=$(($n + 1))
829 done
830 cat <<EOT
831 <hbox>
832 $(helpbutton openvpn 80x40)
833 $(startstopdaemon openvpn)
834 </hbox>
835 </frame>
836 EOT
837 }
839 data_vpn()
840 {
841 cat <<EOT
842 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "pppd" ||
843 echo "#") PPP/SSH tab_sshppp
844 pptp PPTP tab_pptp
845 vpnc EasyVPN tab_easyvpn
846 openvpn OpenVPN tab_openvpn
847 EOT
848 }
850 #
851 # VPN
852 #
853 tab_vpn()
854 {
855 use_tab data_vpn
856 }
858 #
859 # ether-wake
860 #
861 tab_etherwake()
862 {
863 cat <<EOT
864 <frame Ether-wake (busybox)>
865 <hbox>
866 <text use-markup="true">
867 <label>"<b>Machines :</b>"</label>
868 </text>
869 <entry editable="false">
870 <default>/etc/ethers</default>
871 <variable>ETHERS</variable>
872 </entry>
873 <button>
874 <input file icon="accessories-text-editor"></input>
875 <action>[ -s \$ETHERS ] || echo "#00:01:02:03:04:05 mystation" >\$ETHERS</action>
876 <action type="lauch">leafpad \$ETHERS</action>
877 </button>
878 </hbox>
879 <hbox>
880 <text use-markup="true">
881 <label>"<b>Options : </b>"</label>
882 </text>
883 <entry editable="true">
884 <variable>ETHERWAKE_OPTS</variable>
885 </entry>
886 $(helpbutton ether-wake 80x15)
887 <button>
888 <label>Start</label>
889 <input file icon="forward"></input>
890 <action>ether-wake \$ETHERWAKE_OPTS</action>
891 </button>
892 </hbox>
893 <frame>
894 <hbox>
895 EOT
896 if which ethtool > /dev/null; then
897 cat <<EOT
898 <text use-markup="true">
899 <label>"<b>Interface:</b>"</label>
900 </text>
901 <combobox>
902 <variable>ETHERWAKE_ETH</variable>
903 EOT
904 (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) | \
905 awk '{ printf " <item>%s</item>\n",$1 }'
906 cat <<EOT
907 </combobox>
908 <button>
909 <label>Enable Wake On LAN</label>
910 <input file icon="forward"></input>
911 <action>ethtool -s \$ETHERWAKE_ETH wok g</action>
912 </button>
913 EOT
914 else
915 cat <<EOT
916 <vbox>
917 <text wrap="true" width-chars="58">
918 <label>
919 "Ethtool can enable the Wake-on-lan
920 feature on many Ethernet cards.
921 "
922 </label>
923 </text>
924 $(installbox ethtool)
925 </vbox>
926 EOT
927 fi
928 cat <<EOT
929 </hbox>
930 </frame>
931 </frame>
932 EOT
933 }
935 data_main()
936 {
937 cat <<EOT
938 #program tab name function
939 ifconfig Connections tab_connections
940 udhcpc DHCP tab_udhcpc
941 ifconfig Static\ IP tab_fixed_ip
942 pppoe PPPoE tab_pppoe
943 pppd PPP tab_ppp
944 true VPN tab_vpn
945 ether-wake Etherwake tab_etherwake
946 true Configuration tab_system
947 EOT
948 }
950 tab_main()
951 {
952 use_tab data_main
953 }
955 ######################################################
956 #
957 # Netbox GUI
958 #
959 ######################################################
961 # English/French help dialog.
962 export HELP='
963 <window title="Network status" icon-name="network-wire">
964 <vbox>
965 <text use-markup="true">
966 <label>
967 "
968 <b>SliTaz - Netbox</b>"
969 </label>
970 </text>
971 <frame English>
972 <text wrap="true" width-chars="58">
973 <label>
974 "Netbox lets you manage network connections by getting a dynamic IP by
975 DHCP or a static IP and setup servers. Netbox can start or stop
976 networking, configure network interfaces or directly edit files."
977 </label>
978 </text>
979 </frame>
980 <frame Francais>
981 <text wrap="true" width-chars="58">
982 <label>
983 "Netbox vous permet de gerer les connexions reseau avec une IP
984 statique ou en obtenant une IP dynamique par DHCP, et de parametrer
985 les serveurs. Netbox peut demarrer ou arreter le reseau, configurer
986 les interfaces reseau ou editer directement les fichiers."
987 </label>
988 </text>
989 </frame>
990 </vbox>
991 </window>
992 '
994 # Interface status with ifconfig without arguments to show all
995 # active connections.
996 #
997 export IFCONFIG="
998 <window title=\"Network status\" icon-name=\"network-wire\">
999 <vbox>
1000 $(tab_status)
1001 <hbox>
1002 <button>
1003 <input file icon=\"gtk-close\"></input>
1004 <action type=\"closewindow\">IFCONFIG</action>
1005 </button>
1006 </hbox>
1007 </vbox>
1008 </window>"
1010 # The main dialog with notebook, start/stop buttons and all options.
1011 # Note that /etc/network.conf is seded when an interface is activated.
1012 #
1013 head='
1014 <window title="SliTaz Netbox Manager" icon-name="network-wired">
1015 <vbox>
1017 <hbox>
1018 <text use-markup="true">
1019 <label>"<b>Network Manager</b>"</label>
1020 </text>
1021 <pixmap>
1022 <input file>/usr/share/pixmaps/netbox.png</input>
1023 </pixmap>
1024 </hbox>
1025 '
1026 bottom='
1027 <hbox>
1028 <button>
1029 <label>Wireless manager</label>
1030 <input file icon="network-wireless"></input>
1031 <action>wifibox &</action>
1032 </button>
1033 <button>
1034 <label>Refresh list</label>
1035 <input file icon="reload"></input>
1036 <action>refresh:INTERFACE_LIST</action>
1037 </button>
1038 <button>
1039 <label>Full status</label>
1040 <input file icon="dialog-information"></input>
1041 <action type="launch">IFCONFIG</action>
1042 </button>
1043 <button help>
1044 <label>Help</label>
1045 <action type="launch">HELP</action>
1046 </button>
1047 <button>
1048 <label>Quit</label>
1049 <input file icon="exit"></input>
1050 <action type="exit">Exit</action>
1051 </button>
1052 </hbox>
1054 </vbox>
1055 </window>
1056 '
1058 NET_BOX="${head}$(tab_main)${bottom}"
1060 export NET_BOX
1062 # TODO: Modules(Network kernel modules)
1064 # Only root can configure network.
1065 check_root
1067 # Configure and connect if button Connect was pressed.
1068 if ! grep -qs ^name /etc/ppp/options ; then
1069 # Generate /etc/ppp/options
1070 cat > /etc/ppp/options << _EOT_
1071 plugin rp-pppoe.so
1072 name provider-ID
1073 noipdefault
1074 defaultroute
1075 mtu 1492
1076 mru 1492
1077 lock
1078 _EOT_
1079 # Generate /etc/ppp/pap-secrets
1080 cat > /etc/ppp/pap-secrets << _EOT_
1081 # Secrets for authentication using PAP
1082 # client server secret IP addresses
1083 _EOT_
1084 # Generate /etc/ppp/chap-secrets
1085 cat > /etc/ppp/chap-secrets << _EOT_
1086 # Secrets for authentication using CHAP
1087 # client server secret IP addresses
1088 _EOT_
1089 fi
1090 gtkdialog --center --program=NET_BOX | grep -a 'EXIT="restart"' && continue
1091 exit 0
1092 done