slitaz-tools view tinyutils/netbox @ rev 375

netbox: add openvpn & ethtool status
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 13 14:13:04 2009 +0200 (2009-08-13)
parents f42ec52d7e54
children afcfdf317aa1
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=20090812
10 # Check if user is root.
11 check_root()
12 {
13 if test $(id -u) != 0 ; then
14 echo -e "
15 You must be root to run `basename $0`. Please type 'su' and
16 root password to become super-user.\n"
17 exit 0
18 fi
19 }
21 #
22 # Functions called by the connection tab to list interfaces.
23 #
24 ############################################################
26 interface_status()
27 {
28 if ifconfig | grep -A 1 $i | grep -q inet; then
29 ip=`ifconfig | grep -A 1 $i | grep inet | awk '{ print $2 }' | cut -d ":" -f 2`
30 echo "connected ($ip)"
31 else
32 echo "-"
33 fi
34 }
35 # First column is for icon name.
36 detect_interfaces()
37 {
38 for i in `ls /sys/class/net`
39 do
40 case $i in
41 eth*)
42 echo "network-wired | $i | Ethernet | `interface_status`" ;;
43 wlan*|ath*|ra*)
44 echo "network-wireless | $i | Wireless | `interface_status`" ;;
45 lo)
46 echo "gtk-network | $i | Loopback | `interface_status`" ;;
47 *)
48 continue ;;
49 esac
51 done
52 }
54 # When users double click on a connection.
55 interfaces_List_actions()
56 {
57 echo "$INTERFACE_LIST"
58 }
60 # Netbox can be called with args.
61 case "$1" in
62 detect_interfaces|interfaces_List_actions)
63 $1
64 exit 0 ;;
65 *)
66 continue ;;
67 esac
69 #
70 # GUI functions
71 #
72 ############################################################
74 xterm="xterm -fa MiscFixed -fs 11 -bg gray93 -fg black"
75 helpbutton()
76 {
77 local label;
78 label="<label>$3</label>"
79 [ -n "$3" ] || label=""
80 cat << EOT
81 <button>
82 <input file icon="help"></input>$label
83 <action>$xterm -geometry $2 -title "$1 help (q to quit)" -e "( echo ; $(which $1) --help 2>&1 ) | less"</action>
84 </button>
85 EOT
86 }
88 editbutton()
89 {
90 cat << EOT
91 <button>
92 <input file icon="accessories-text-editor"></input>
93 <action type="lauch">leafpad $1</action>
94 </button>
95 EOT
96 }
98 manbutton()
99 {
100 cat << EOT
101 <button>
102 <input file icon="browser"></input>
103 <label>man</label>
104 <action>$xterm -geometry 80x24 -title "$2 man (q to quit)" -e ". /etc/profile; man $1 $2"</action>
105 </button>
106 EOT
107 }
109 helpdaemon()
110 {
111 cat << EOT
112 <hbox>
113 <text use-markup="true">
114 <label>"<b>$3</b>"</label>
115 </text>
116 <entry editable="false">
117 EOT
118 eval tmp=\$$3
119 [ -n "$tmp" ] && cat << EOT
120 <default>$tmp</default>
121 EOT
122 cat << EOT
123 <variable>$4</variable>
124 </entry>
125 EOT
126 [ -n "$6" ] || cat << EOT
127 $(helpbutton $1 $2)
128 EOT
129 [ -n "$5" ] && cat << EOT
130 $(manbutton $5 $1)
131 EOT
132 cat << EOT
133 $(editbutton /etc/daemons.conf)
134 </hbox>
135 EOT
136 }
138 datafile()
139 {
140 cat << EOT
141 <hbox>
142 <text use-markup="true">
143 <label>"<b>$3</b>"</label>
144 </text>
145 <entry editable="false">
146 EOT
147 [ -n "$1" ] && cat << EOT
148 <default>$1</default>
149 EOT
150 cat << EOT
151 <variable>$2</variable>
152 </entry>
153 EOT
154 [ -n "$4" ] && cat << EOT
155 $(manbutton $4)
156 EOT
157 cat << EOT
158 $(editbutton \$$2)
159 </hbox>
160 EOT
161 }
163 configfile()
164 {
165 datafile "$1" $2 'Configuration:' "$3"
166 }
168 BROWSER=''
169 for i in firefox opera dillo midori netsurf links ; do
170 which $i > /dev/null && BROWSER="$i" && break
171 done
172 case "$BROWSER" in
173 links) BROWSER="links -g ";;
174 esac
176 webbutton()
177 {
178 [ -f "/var/lib/tazpkg/installed/$1/receipt" ] &&
179 [ -n "$BROWSER" ] && cat << EOT
180 <button>
181 <input file icon="browser"></input>
182 <label>web</label>
183 <action>. /var/lib/tazpkg/installed/$1/receipt ; $BROWSER \$WEB_SITE &</action>
184 </button>
185 EOT
186 }
188 wikibutton()
189 {
190 [ -n "$BROWSER" ] && cat <<EOT
191 <button>
192 <input file icon="browser"></input>
193 <label>Wiki</label>
194 <action>$BROWSER $1 &</action>
195 </button>
196 EOT
197 }
199 startstopdaemon()
200 {
201 local pkg
202 pkg=$1
203 [ -n "$2" ] && pkg=$2
204 webbutton $pkg
205 cat << EOT
206 <button>
207 <label>Start</label>
208 <input file icon="forward"></input>
209 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)$1 \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
210 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)\\"/RUN_DAEMONS=\\"$1 \1\\"/" /etc/rcS.conf</action>
211 <action>/etc/init.d/$1 start</action>
212 </button>
213 <button>
214 <label>Stop</label>
215 <input file icon="stop"></input>
216 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)$1 \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
217 <action>/etc/init.d/$1 stop</action>
218 </button>
219 EOT
220 }
222 installbox()
223 {
224 cat << EOT
225 <hbox>
226 <text wrap="true" use-markup="true">
227 <label>"<i>The package <b>$1</b> is not yet installed</i>"</label>
228 </text>
229 <button>
230 <input file icon="go-jump"></input>
231 <label>Install</label>
232 <action>$xterm -geometry 80x17 -title "$1 install" -e "yes y | tazpkg get-install $1 ; echo -e \"----\n\nENTER to continue...\" && read close"</action>
233 <action type="exit">restart</action>
234 </button>
235 </hbox>
236 EOT
237 }
239 set_ipup()
240 {
241 [ -f /etc/ppp/ip-up ] && return
242 cat > /etc/ppp/ip-up <<EOT
243 #!/bin/sh
244 exec $0 call ipup \$@
245 EOT
246 chmod +x /etc/ppp/ip-up
247 }
249 while true; do
251 # Detect WIFI_INTERFACE and update /etc/network.conf
252 . /etc/network.conf
253 if [ ! -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
254 WIFI_INTERFACE=$(for i in /sys/class/net/*/wireless; do \
255 [ -d $i ] && echo $(basename $(dirname $i)) || echo wlan0; \
256 break; done)
257 [ -n "$WIFI_INTERFACE" ] && sed -i "s/^WIFI_INTERFACE=.*/WIFI_INTERFACE=\"$WIFI_INTERFACE\"/" /etc/network.conf
258 fi
260 #
261 # Netbox internal calls
262 #
263 #########################################################
265 if [ "$1" = "call" ]; then
266 ppp="pppd local lock notty"
267 pppup=""
268 sub=$2
269 shift 2
270 case "$sub" in
271 sendsshkey)
272 check_root
273 ( dropbearkey -y -f /etc/dropbear/dropbear_rsa_host_key ;
274 cat /etc/ssh/ssh_host_rsa_key.pub ) 2> /dev/null | \
275 grep ^ssh | ssh $1 "mkdir .ssh 2> /dev/null ; \
276 while read key; do for i in authorized_keys authorized_keys2; do \
277 grep -q \$key .ssh/\$i || echo \$key >> .ssh/\$i ; done ; done ; \
278 chmod 700 .ssh ; chmod 600 .ssh/authorized_keys*"
279 exit 0;;
280 # OpenSSH VPN:
281 # PermitTunnel=point-to-point (or yes, ethernet, no)
282 # Tunnel="4" => tun4
283 # Local Client:
284 # # ssh -f -w 0:1 $REMOTE true => local tun0 [, remote tun1]
285 # # ifconfig $TUN $IP1 $IP2 netmask 255.255.255.252
286 # # route add $REMOTE_NETWORK $IP2
287 # Remote Server:
288 # # ifconfig $TUN $IP2 $IP1 netmask 255.255.255.252
289 # # route add $LOCAL_NETWORK $IP1
290 vpnssh) check_root
291 set_ipup
292 ps ww | grep -q "$ppp $2:$3" && exit 1
293 pipe="/tmp/ssh$$"
294 mkfifo $pipe
295 [ -n "$4" ] && pppup="ipparam 'addroutes,$(echo $4 | sed 's/ /,/g')'"
296 cat $pipe | dbclient -i /etc/dropbear/dropbear_rsa_host_key \
297 $1 "$ppp" | $ppp $2:$3 $pppup > $pipe
298 rm -f $pipe
299 exit 0;;
300 killvpnssh)
301 check_root
302 kill $(ps x | grep dbclient | grep "$ppp" | awk '{ print $1 }')
303 exit 0;;
304 ipup)
305 # Arg Name Example
306 # $1 Interface name ppp0
307 # $2 The tty ttyS1
308 # $3 The link speed 38400
309 # $4 Local IP number 12.34.56.78
310 # $5 Peer IP number 12.34.56.99
311 # $6 Optional ``ipparam'' value foo
312 iface=$1
313 # skip tty if present
314 case "$2" in [0-9]*);; *) shift; esac
315 peer=$4
316 IFS=","; set -- $(eval echo $5); unset IFS
317 set -- $1
318 if [ "$1" = "addroutes" ]; then
319 while [ -n "$2" ]; do
320 eval $(ipcalc -n $2)
321 eval $(ipcalc -m $2)
322 route add -net $NETWORK netmask $NETMASK \
323 gw $peer $iface
324 shift
325 done
326 fi
327 exit 0;;
328 esac
329 echo "call $sub unsupported."
330 exit 1
331 fi
333 #
334 # Tab display engine
335 #
336 ######################################################
338 use_tab()
339 {
340 local tmp=''
341 case "$2" in
342 header|body)
343 $1 | while read exe name call; do
344 case "$exe" in
345 \#*) continue;;
346 esac
347 which $exe > /dev/null || continue
348 if [ "$2" == "header" ]; then
349 echo -n "$tmp$name"
350 tmp='|'
351 else
352 $call
353 fi
354 done
355 ;;
356 *)
357 tmp=$(use_tab $1 header)
358 echo "$tmp" | grep -q \| && cat <<EOT
359 <notebook labels="$tmp">
360 EOT
361 [ -n "$tmp" ] && cat <<EOT
362 $(use_tab $1 body)
363 EOT
364 echo "$tmp" | grep -q \| && cat <<EOT
365 </notebook>
366 EOT
367 ;;
368 esac
369 }
371 #
372 # Status wire interfaces
373 #
374 tab_status_iface()
375 {
376 local eth
377 eth="$( (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) )"
378 which ethtool > /dev/null || eth=''
379 if [ -n "$eth" ]; then
380 cat <<EOT
381 <notebook labels="Ifconfig|$(echo $eth | sed 's/ /|/g')">
382 EOT
383 fi
384 cat <<EOT
385 <frame Ifconfig>
386 <text wrap="false" width-chars="58">
387 <input>ifconfig</input>
388 </text>
389 </frame>
390 EOT
391 if [ -n "$eth" ]; then
392 local i
393 for i in $eth ; do
394 cat <<EOT
395 <frame $i>
396 <text wrap="false" width-chars="58">
397 <input>ethtool $i</input>
398 </text>
399 </frame>
400 EOT
401 done
402 cat <<EOT
403 </notebook>
404 EOT
405 fi
406 }
408 #
409 # Status wifi interfaces
410 #
411 tab_status_wifi_iface()
412 {
413 cat <<EOT
414 <frame Iwconfig>
415 <text wrap="false" width-chars="58">
416 <input>iwconfig</input>
417 </text>
418 </frame>
419 EOT
420 }
422 #
423 # Status wifi network
424 #
425 tab_status_wifi_net()
426 {
427 cat <<EOT
428 <frame Wireless networks>
429 <text wrap="false" width-chars="58">
430 <input>iwlist scan</input>
431 </text>
432 </frame>
433 EOT
434 }
436 #
437 # Status routing
438 #
439 tab_status_route()
440 {
441 cat <<EOT
442 <frame Routing>
443 <frame Nameservers>
444 <text wrap="false" width-chars="58">
445 <input>cat /etc/resolv.conf</input>
446 </text>
447 </frame>
448 <frame Routing table>
449 <text wrap="false" width-chars="58">
450 <input>route</input>
451 </text>
452 </frame>
453 <frame Arp table>
454 <text wrap="false" width-chars="58">
455 <input>arp</input>
456 </text>
457 </frame>
458 </frame>
459 EOT
460 }
462 #
463 # Status servers
464 #
465 tab_status_servers()
466 {
467 local servers
468 servers="dropbear sshd inetd dhcpd dnsd named rsync httpd mbd vnc pppd knock"
469 cat <<EOT
470 <frame Servers>
471 <text wrap="false" width-chars="58">
472 <input>for i in $servers; do ps ww | grep \$i | grep -v grep | fold -s; done</input>
473 </text>
474 </frame>
475 EOT
476 }
478 data_status()
479 {
480 cat <<EOT
481 ifconfig Network\ interfaces tab_status_iface
482 iwconfig Wireless\ interfaces tab_status_wifi_iface
483 iwlist Wireless\ networks tab_status_wifi_net
484 route Routing tab_status_route
485 ps Servers tab_status_servers
486 EOT
487 }
489 #
490 # Status
491 #
492 tab_status()
493 {
494 use_tab data_status
495 }
497 #
498 # Interfaces list from detect_interfaces()
499 #
500 tab_connections()
501 {
502 cat <<EOT
503 <vbox>
504 <tree>
505 <width>520</width><height>120</height>
506 <variable>INTERFACE_LIST</variable>
507 <label>Interface|Type|Status</label>
508 <input icon_column="0">$0 detect_interfaces</input>
509 <action>refresh:INTERFACE_LIST</action>
510 </tree>
511 </vbox>
512 EOT
513 }
515 #
516 # DHCP
517 #
518 tab_udhcpc()
519 {
520 cat <<EOT
521 <frame Udhcpc (busybox)>
522 <text width-chars="58">
523 <label> "Ethernet (cable) default connection." </label>
524 </text>
525 <hbox>
526 <text use-markup="true">
527 <label>"<b>Interface:</b>"</label>
528 </text>
529 <entry>
530 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
531 <variable>INTERFACE</variable>
532 </entry>
533 </hbox>
534 <hbox>
535 <text use-markup="true">
536 <label>"<b>Options: </b>"</label>
537 </text>
538 <entry>
539 <default>-b</default>
540 <variable>UDHCPC_OPTS</variable>
541 </entry>
542 $(helpbutton udhcpc 80x30)
543 </hbox>
544 <hbox>
545 <text use-markup="true">
546 <label>"<b>Script: </b>"</label>
547 </text>
548 <entry editable="false">
549 <default>/usr/share/udhcpc/default.script</default>
550 <variable>UDHCPC_SCRIPT</variable>
551 </entry>
552 <button>
553 <input file icon="accessories-text-editor"></input>
554 <action type="lauch">leafpad \$UDHCPC_SCRIPT</action>
555 </button>
556 </hbox>
557 <hbox>
558 <button>
559 <label>Start</label>
560 <input file icon="forward"></input>
561 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
562 <action>sed -i s/DHCP="no"/DHCP="yes"/ /etc/network.conf</action>
563 <action>sed -i s/STATIC="yes"/STATIC="no"/ /etc/network.conf</action>
564 <action>udhcpc \$UDHCPC_OPTS -i \$INTERFACE -p /var/run/udhcpc.\$INTERFACE.pid</action>
565 <action>refresh:INTERFACE_LIST</action>
566 </button>
567 <button>
568 <label>Stop</label>
569 <input file icon="stop"></input>
570 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
571 <action>ifconfig \$INTERFACE down</action>
572 <action>killall -q udhcpc; echo "done"</action>
573 <action>refresh:INTERFACE_LIST</action>
574 </button>
575 </hbox>
576 </frame>
577 EOT
578 }
580 #
581 # Static/fixed IP settings.
582 #
583 tab_fixed_ip()
584 {
585 cat <<EOT
586 <frame Ethernet fixed IP>
587 <hbox>
588 <text use-markup="true">
589 <label>"<b>Interface: </b>"</label>
590 </text>
591 <entry>
592 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
593 <variable>INTERFACE</variable>
594 </entry>
595 </hbox>
596 <hbox>
597 <text use-markup="true">
598 <label>"<b>IP: </b>"</label>
599 </text>
600 <entry>
601 <input>. /etc/network.conf; echo "\$IP"</input>
602 <variable>IP</variable>
603 </entry>
604 </hbox>
605 <hbox>
606 <text use-markup="true">
607 <label>"<b>Netmask: </b>"</label>
608 </text>
609 <entry>
610 <input>. /etc/network.conf; echo "\$NETMASK"</input>
611 <variable>NETMASK</variable>
612 </entry>
613 </hbox>
614 <hbox>
615 <text use-markup="true">
616 <label>"<b>Gateway: </b>"</label>
617 </text>
618 <entry>
619 <input>. /etc/network.conf; echo "\$GATEWAY"</input>
620 <variable>GATEWAY</variable>
621 </entry>
622 </hbox>
623 <hbox>
624 <text use-markup="true">
625 <label>"<b>DNS server: </b>"</label>
626 </text>
627 <entry>
628 <input>. /etc/network.conf; echo "\$DNS_SERVER"</input>
629 <variable>DNS_SERVER</variable>
630 </entry>
631 </hbox>
632 <hbox>
633 <button>
634 <label>Start</label>
635 <input file icon="forward"></input>
636 <action>ifconfig lo down</action>
637 <action>ifconfig \$INTERFACE down</action>
638 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
639 <action>sed -i s/DHCP="yes"/DHCP="no"/ /etc/network.conf</action>
640 <action>sed -i s/WIFI="yes"/WIFI="no"/ /etc/network.conf</action>
641 <action>sed -i s/STATIC="no"/STATIC="yes"/ /etc/network.conf</action>
642 <action>sed -i s/`cat /etc/network.conf | grep ^IP=`/IP="\$IP"/ /etc/network.conf</action>
643 <action>sed -i s/`cat /etc/network.conf | grep ^NETMASK=`/NETMASK="\$NETMASK"/ /etc/network.conf</action>
644 <action>sed -i s/`cat /etc/network.conf | grep ^GATEWAY=`/GATEWAY="\$GATEWAY"/ /etc/network.conf</action>
645 <action>sed -i s/`cat /etc/network.conf | grep ^DNS_SERVER=`/DNS_SERVER="\$DNS_SERVER"/ /etc/network.conf</action>
646 <action>/etc/init.d/network.sh</action>
647 <action>refresh:INTERFACE_LIST</action>
648 </button>
649 <button>
650 <label>Stop</label>
651 <input file icon="stop"></input>
652 <action>ifconfig \$INTERFACE down</action>
653 <action>refresh:INTERFACE_LIST</action>
654 </button>
655 </hbox>
656 </frame>
657 EOT
658 }
660 #
661 # PPPoe settings.
662 #
663 tab_pppoe()
664 {
665 cat <<EOT
666 <frame PPPoE>
667 <hbox>
668 <text use-markup="true">
669 <label>"<b>Name: </b>"</label>
670 </text>
671 <entry>
672 <input>NAME=\$(grep -s ^name /etc/ppp/options); echo "\${NAME#* }"</input>
673 <variable>NAME</variable>
674 </entry>
675 </hbox>
676 <hbox>
677 <text use-markup="true">
678 <label>"<b>Username:</b>"</label>
679 </text>
680 <entry>
681 <variable>USER</variable>
682 </entry>
683 </hbox>
684 <hbox>
685 <text use-markup="true">
686 <label>"<b>Password:</b>"</label>
687 </text>
688 <entry>
689 <variable>PASS</variable>
690 </entry>
691 </hbox>
692 <hbox>
693 $(helpbutton pppd 80x30)
694 $(manbutton 8 pppd)
695 $(webbutton ppp)
696 <button>
697 <input file icon="accessories-text-editor"></input>
698 <label>Tune</label>
699 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
700 <action type="lauch">leafpad /etc/ppp/options</action>
701 </button>
702 <button>
703 <label>Start</label>
704 <input file icon="forward"></input>
705 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
706 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
707 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
708 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
709 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
710 <action>killall udhcpc</action>
711 <action>sed -i "s/DHCP=\"yes\"/DHCP=\"no\"/" /etc/network.conf</action>
712 <action>sed -i "s/PPPOE=\"no\"/PPPOE=\"yes\"/" /etc/network.conf</action>
713 <action>pppd \$INTERFACE &</action>
714 </button>
715 <button>
716 <label>Stop</label>
717 <input file icon="stop"></input>
718 <action>sed -i "s/PPPOE=\"yes\"/PPPOE=\"no\"/" /etc/network.conf</action>
719 <action>killall pppd</action>
720 </button>
721 </hbox>
722 </frame>
723 EOT
724 }
726 #
727 # PPP settings.
728 #
729 tab_ppp()
730 {
731 cat <<EOT
732 <frame PPP>
733 <hbox>
734 <text use-markup="true">
735 <label>"<b>Username: </b>"</label>
736 </text>
737 <entry>
738 <input>USER=\$(grep -s ^ACCOUNT= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${USER#*=}"</input>
739 <variable>USER</variable>
740 </entry>
741 </hbox>
742 <hbox>
743 <text use-markup="true">
744 <label>"<b>Password: </b>"</label>
745 </text>
746 <entry>
747 <input>PASS=\$(grep -s ^PASSWORD= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PASS#*=}"</input>
748 <variable>PASS</variable>
749 </entry>
750 </hbox>
751 <hbox>
752 <text use-markup="true">
753 <label>"<b>Telephone:</b>"</label>
754 </text>
755 <entry>
756 <input>PHONE=\$(grep -s ^TELEPHONE= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PHONE#*=}"</input>
757 <variable>PHONE</variable>
758 </entry>
759 </hbox>
760 <hbox>
761 $(helpbutton pppd 80x30)
762 $(manbutton 8 pppd)
763 $(webbutton ppp)
764 <button>
765 <input file icon="accessories-text-editor"></input>
766 <label>Tune</label>
767 <action>[ -n "\$NAME" ] && sed -i "s/^ACCOUNT=.*/ACCOUNT=\$NAME/" /etc/ppp/scripts/ppp-on</action>
768 <action>[ -n "\$PASS" ] && sed -i "s/^PASSWORD=.*/PASSWORD=\$PASS/" /etc/ppp/scripts/ppp-on</action>
769 <action>[ -n "\$PHONE" ] && sed -i "s/^TELEPHONE=.*/TELEPHONE=\$PHONE/" /etc/ppp/scripts/ppp-on</action>
770 <action type="lauch">leafpad /etc/ppp/scripts/ppp-on</action>
771 </button>
772 <button>
773 <label>Start</label>
774 <input file icon="forward"></input>
775 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
776 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
777 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
778 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
779 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
780 <action>/etc/ppp/scripts/ppp-off</action>
781 <action>/etc/ppp/scripts/ppp-on &</action>
782 </button>
783 <button>
784 <label>Stop</label>
785 <input file icon="stop"></input>
786 <action>/etc/ppp/scripts/ppp-off</action>
787 </button>
788 </hbox>
789 </frame>
790 EOT
791 }
793 #
794 # System Wide configuration.
795 #
796 tab_system()
797 {
798 cat <<EOT
799 <frame Configuration files>
800 <hbox>
801 <text use-markup="true">
802 <label>"<b>Hosts :</b>"</label>
803 </text>
804 <entry editable="false">
805 <default>/etc/hosts</default>
806 <variable>HOSTS</variable>
807 </entry>
808 <button>
809 <input file icon="accessories-text-editor"></input>
810 <action type="lauch">leafpad \$HOSTS</action>
811 </button>
812 </hbox>
813 <hbox>
814 <text use-markup="true">
815 <label>"<b>Host name :</b>"</label>
816 </text>
817 <entry editable="false">
818 <default>/etc/hostname</default>
819 <variable>HOSTNAME</variable>
820 </entry>
821 <button>
822 <input file icon="accessories-text-editor"></input>
823 <action type="lauch">leafpad \$HOSTNAME</action>
824 </button>
825 </hbox>
826 <hbox>
827 <text use-markup="true">
828 <label>"<b>Network :</b>"</label>
829 </text>
830 <entry editable="false">
831 <default>/etc/network.conf</default>
832 <variable>CONFIG_FILE</variable>
833 </entry>
834 <button>
835 <input file icon="accessories-text-editor"></input>
836 <action type="lauch">leafpad \$CONFIG_FILE</action>
837 </button>
838 </hbox>
839 <hbox>
840 <button>
841 <label>Restart</label>
842 <input file icon="reload"></input>
843 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
844 <action>ifconfig \$INTERFACE down</action>
845 <action>killall -q udhcpc; echo "done"</action>
846 <action>/etc/init.d/network.sh restart</action>
847 </button>
848 </hbox>
849 </frame>
850 EOT
851 }
853 #
854 # ssh/ppp
855 #
856 tab_sshppp()
857 {
858 cat <<EOT
859 <frame Virtual Private Network with PPP/SSH>
860 <hbox>
861 <text use-markup="true">
862 <label>"<b>Peer :</b>"</label>
863 </text>
864 <entry>
865 <variable>DROPBEAR_PEERVPN</variable>
866 <default>user@elsewhere</default>
867 </entry>
868 </hbox>
869 <hbox>
870 <text use-markup="true">
871 <label>"<b>Local IP :</b>"</label>
872 </text>
873 <entry>
874 <variable>DROPBEAR_LOCAL</variable>
875 <default>192.168.254.1</default>
876 </entry>
877 </hbox>
878 <hbox>
879 <text use-markup="true">
880 <label>"<b>Remote IP :</b>"</label>
881 </text>
882 <entry>
883 <variable>DROPBEAR_REMOTE</variable>
884 <default>192.168.254.2</default>
885 </entry>
886 </hbox>
887 <hbox>
888 <text use-markup="true">
889 <label>"<b>Route(s) :</b>"</label>
890 </text>
891 <entry>
892 <variable>DROPBEAR_ROUTE</variable>
893 <default>192.168.10.0/24 192.168.20.0/28</default>
894 </entry>
895 </hbox>
896 <hbox>
897 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:vpn)
898 <button>
899 <input file icon="forward"></input>
900 <label>Connect</label>
901 <action>$0 call vpnssh \$DROPBEAR_PEERVPN \$DROPBEAR_LOCAL \$DROPBEAR_REMOTE "\$DROPBEAR_ROUTE" &</action>
902 </button>
903 <button>
904 <input file icon="stop"></input>
905 <label>Disconnect</label>
906 <action>$0 call killvpnssh</action>
907 </button>
908 <button>
909 <input file icon="go-up"></input>
910 <label>Send key</label>
911 <action>$xterm -geometry 80x10 -title "Send key" -e "$0 call sendsshkey \$DROPBEAR_PEERVPN; echo -e \"----\nENTER to continue...\" && read close"</action>
912 </button>
913 </hbox>
914 </frame>
915 EOT
916 }
918 #
919 # PPTP client
920 #
921 #FIXME
922 #cat > /etc/ppp/peers/$TUNNEL <<EOT
923 #pty "pptp $SERVER --nolaunchpppd"
924 #lock
925 #noauth
926 #nobsdcomp
927 #nodeflate
928 #name $DOMAIN\\$USERNAME
929 #remotename $TUNNEL
930 #ipparam $TUNNEL
931 #$(encryption && echo "require-mppe-128")
932 #EOT
933 #pppd call $TUNNEL updetach
935 tab_pptp()
936 {
937 [ -f /etc/ppp/options.pptp ] || cat >> /etc/ppp/options.pptp <<EOT
938 lock noauth nobsdcomp nodeflate remotename PPTP
939 EOT
940 [ -f /etc/ppp/pptp-servers ] || cat >> /etc/ppp/pptp-servers <<EOT
941 # PPTP servers list
942 EOT
943 cat <<EOT
944 <frame Virtual Private Network with PPTP>
945 <hbox>
946 <text use-markup="true">
947 <label>"<b>Server:</b>"</label>
948 </text>
949 <combobox>
950 <variable>PPTP_SERVER</variable>
951 EOT
952 grep -v ^\# /etc/ppp/pptp-servers | \
953 awk '{ printf " <item>%s</item>\n",$1 }'
954 cat <<EOT
955 <item>SERVER</item>
956 </combobox>
957 <button>
958 <input file icon="accessories-text-editor"></input>
959 <action type="lauch">leafpad /etc/ppp/pptp-servers</action>
960 </button>
961 </hbox>
962 <hbox>
963 <text use-markup="true">
964 <label>"<b> User:</b>"</label>
965 </text>
966 <combobox>
967 <variable>PPTP_USER</variable>
968 EOT
969 grep '\\' /etc/ppp/chap-secrets | grep -v ^\# | \
970 awk '{ printf " <item>%s</item>\n",$1 }'
971 cat <<EOT
972 <item>DOMAIN\USERNAME</item>
973 </combobox>
974 <button>
975 <input file icon="accessories-text-editor"></input>
976 <action type="lauch">leafpad /etc/ppp/chap-secrets</action>
977 </button>
978 </hbox>
979 <hbox>
980 <text use-markup="true">
981 <label>"<b>Password:</b>"</label>
982 </text>
983 <entry>
984 <variable>PPTP_PASS</variable>
985 </entry>
986 </hbox>
987 <hbox>
988 <checkbox>
989 <label>Encryption</label>
990 <variable>PPTP_ENC</variable>
991 <default>true</default>
992 </checkbox>
993 $(helpbutton pptp 80x35)
994 <button>
995 <input file icon="accessories-text-editor"></input>
996 <label>Options</label>
997 <action type="lauch">leafpad /etc/ppp/options.pptp</action>
998 </button>
999 $(webbutton pptpclient)
1000 <button>
1001 <input file icon="forward"></input>
1002 <label>Connect</label>
1003 <action>grep -qs ^\$PPTP_USER /etc/ppp/chap-secrets || \
1004 echo "\$PPTP_USER PPTP \"$PPTP_PASS\" *" >> /etc/ppp/chap-secrets</action>
1005 <action>grep -qs ^\$PPTP_SERVER /etc/ppp/pptp-servers || \
1006 echo "\$PPTP_SERVER" >> /etc/ppp/pptp-servers</action>
1007 <action>PASS=""; [ -n "\$PPTP_PASS" ] && PASS="password \$PASS"; \
1008 ENC=""; [ x\$PPTP_ENC == xtrue ] && ENC="require-mppe-128"; \
1009 /usr/sbin/pptp \$PPTP_SERVER file /etc/ppp/options.pptp \$ENC user \$PPTP_USER \$PASS &
1010 </action>
1011 </button>
1012 <button>
1013 <input file icon="stop"></input>
1014 <label>Disconnect</label>
1015 <action>killall pptp</action>
1016 </button>
1017 </hbox>
1018 </frame>
1019 EOT
1023 # Cisco EasyVPN
1025 tab_easyvpn()
1027 cat <<EOT
1028 <frame Cisco EasyVPN>
1029 <hbox>
1030 <text use-markup="true">
1031 <label>"<b>VPNC_OPTIONS</b>"</label>
1032 </text>
1033 <entry editable="false">
1034 EOT
1035 [ -n "$VPNC_OPTIONS" ] && cat << EOT
1036 <default>$tmp</default>
1037 EOT
1038 cat << EOT
1039 <variable>VPNC_OPTS</variable>
1040 </entry>
1041 $(helpbutton vpnc 80x30)
1042 <button>
1043 <input file icon="help"></input>
1044 <label>more</label>
1045 <action>$xterm -geometry 80x40 -title "vpnc help (q to quit)" -e "$(which vpnc) --long-help 2>&1 | less"</action>
1046 </button>
1047 $(editbutton /etc/daemons.conf)
1048 </hbox>
1049 $(configfile /etc/vpnc/default.conf VPNC_CONF)
1050 $(datafile "/etc/vpnc/vpnc-script" VPNC_SCRIPT 'Script:')
1051 <hbox>
1052 $(startstopdaemon vpnc)
1053 </hbox>
1054 </frame>
1055 EOT
1059 # OpenVPN
1061 tab_openvpn()
1063 local i
1064 local n
1065 cat <<EOT
1066 <frame OpenVPN>
1067 EOT
1068 n=1
1069 for i in /etc/openvpn/*.conf ; do
1070 [ -f $i ] || continue
1071 configfile $i OPENVPN_CONF$n
1072 n=$(($n + 1))
1073 done
1074 cat <<EOT
1075 <hbox>
1076 $(helpbutton openvpn 80x40)
1077 $(startstopdaemon openvpn)
1078 </hbox>
1079 </frame>
1080 EOT
1083 data_vpn()
1085 cat <<EOT
1086 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "pppd" ||
1087 echo "#") PPP/SSH tab_sshppp
1088 pptp PPTP tab_pptp
1089 vpnc EasyVPN tab_easyvpn
1090 openvpn OpenVPN tab_openvpn
1091 EOT
1095 # VPN
1097 tab_vpn()
1099 use_tab data_vpn
1102 sshremote()
1104 cat << EOT
1105 <hbox>
1106 <text use-markup="true">
1107 <label>"<b>Remote :</b>"</label>
1108 </text>
1109 <entry>
1110 <variable>$2</variable>
1111 <default>user@elsewhere</default>
1112 </entry>
1113 <button>
1114 <input file icon="utilities-terminal"></input>
1115 <label>Connect</label>
1116 <action>xterm -fa MiscFixed -fs 11 -bg black -fg white -geometry 80x25 -title "$1" -e "$1 \$$2 ; echo -e \"----\nENTER to continue...\" && read close" &</action>
1117 </button>
1118 <button>
1119 <input file icon="go-up"></input>
1120 <label>Send key</label>
1121 <action>$xterm -geometry 80x10 -title "send ssh key" -e "$0 call sendsshkey \$$2; echo -e \"----\nENTER to continue...\" && read close"</action>
1122 </button>
1123 </hbox>
1124 EOT
1128 # Dropbear client & server
1130 tab_dropbear()
1132 . /etc/daemons.conf
1133 set -- $DROPBEAR_OPTIONS
1134 while [ -n "$2" ]; do
1135 [ "$1" = "-b" ] && DROPBEAR_BANNER="$2" && break
1136 shift
1137 done
1139 cat <<EOT
1140 <frame Dropbear>
1141 $(helpdaemon dropbear 80x30 DROPBEAR_OPTIONS DROPBEAR_OPTS)
1142 $(datafile /etc/dropbear/banner DROPBEAR_BANNER 'Banner :')
1143 $(sshremote DROPBEAR_PEER 'dbclient -i /etc/dropbear/dropbear_rsa_host_key')
1144 <hbox>
1145 $(startstopdaemon dropbear)
1146 </hbox>
1147 </frame>
1148 EOT
1152 # OpenSSH client & server
1154 tab_openssh()
1156 cat <<EOT
1157 <frame OpenSSH>
1158 $(helpdaemon sshd 80x30 OPENSSH_OPTIONS OPENSSH_OPTS 8 nohelp)
1159 $(configfile /etc/ssh/sshd_config OPENSSH_CONF '5 sshd_config')
1160 $(sshremote OPENSSH_PEER 'ssh -i /etc/ssh/ssh_host_rsa_key')
1161 <hbox>
1162 $(startstopdaemon openssh)
1163 </hbox>
1164 </frame>
1165 EOT
1168 data_sshd()
1170 cat <<EOT
1171 dropbear Dropbear tab_dropbear
1172 sshd OpenSSH tab_openssh
1173 EOT
1177 # SSH tab
1179 tab_sshd()
1181 use_tab data_sshd
1185 # Busybox Inetd
1187 tab_inetd()
1189 cat <<EOT
1190 <frame Inetd (busybox)>
1191 $(helpdaemon inetd 60x14 INETD_OPTIONS INETD_OPTS)
1192 $(configfile /etc/inetd.conf INETD_CONF)
1193 <hbox>
1194 EOT
1195 for i in $(grep bin /etc/inetd.conf | awk '{ print $6}'); do
1196 i=$(basename $i)
1197 helpbutton $i 60x19 $i
1198 done
1199 cat <<EOT
1200 $(startstopdaemon inetd)
1201 </hbox>
1202 </frame>
1203 EOT
1207 # ZeroConf
1209 tab_zcip()
1211 if [ -x /sbin/zcip -a -z "$ZCIP_OPTIONS" ]; then
1212 ZCIP_OPTIONS="eth0 /etc/zcip.script"
1213 cat >> /etc/daemons.conf <<EOT
1214 # ZeroConf options
1215 ZCIP_OPTIONS="$ZCIP_OPTIONS"
1217 EOT
1218 fi
1219 cat <<EOT
1220 <frame Zcip (busybox)>
1221 $(helpdaemon zcip 60x14 ZCIP_OPTIONS ZCIP_OPTS)
1222 $(datafile /etc/zcip.script CZIP_SCRIPT 'Script :')
1223 <hbox>
1224 $(startstopdaemon zcip)
1225 </hbox>
1226 </frame>
1227 EOT
1231 # Dhcpd ISC
1233 tab_isc_dhcpd()
1235 cat <<EOT
1236 <frame Dhcpd (ISC)>
1237 $(helpdaemon dhcpd 60x14 DHCPD_OPTIONS DHCPD_OPTS)
1238 $(configfile /etc/dhcpd.conf DHCPD_CONF)
1239 <hbox>
1240 $(startstopdaemon dhcpd dhcp)
1241 </hbox>
1242 </frame>
1243 EOT
1247 # Dhcpd Busybox
1249 tab_udhcpd()
1251 cat <<EOT
1252 <frame Udhcpd (busybox)>
1253 $(helpdaemon udhcpd 60x14 UDHCPD_OPTIONS UDHCPD_OPTS)
1254 $(configfile /etc/udhcpd.conf UDHCPD_CONF)
1255 <hbox>
1256 $(startstopdaemon udhcpd)
1257 </hbox>
1258 </frame>
1259 EOT
1262 data_dhcpd()
1264 cat <<EOT
1265 udhcpd Udhcpd tab_udhcpd
1266 dhcpd Dhcpd tab_isc_dhcpd
1267 dnsmasq DNSmasq tab_dnsmasq
1268 EOT
1272 # dhcpd tab
1274 tab_dhcpd()
1276 use_tab data_dhcpd
1280 # PXE
1282 tab_pxe()
1284 cat <<EOT
1285 <frame Pxelinux>
1286 <hbox>
1287 <text wrap="true">
1288 <label>
1289 "Launch Dhcpd and Inetd with Tftpd to start the PXE service."
1290 </label>
1291 </text>
1292 </hbox>
1293 <hbox>
1294 <text use-markup="true">
1295 <label>"<b>Configuration :</b>"</label>
1296 </text>
1297 <entry editable="false">
1298 <default>
1299 $(grep bin/tftpd /etc/inetd.conf | awk '{ print $NF }')/pxelinux.cfg/default
1300 </default>
1301 <variable>PXE_CONF</variable>
1302 </entry>
1303 <button>
1304 <input file icon="accessories-text-editor"></input>
1305 <action>dir=\$(dirname \$PXE_CONF); [ -d \$dir ] || mkdir -p \$dir</action>
1306 <action>lzma d /usr/share/boot/pxelinux.0.lzma \$(dirname \$PXE_CONF)/../pxelinux.0</action>
1307 <action>grep -q "^boot_file" \$UDHCPD_CONF || echo "boot_file pxelinux.0" >> \$UDHCPD_CONF</action>
1308 <action>grep -q "^siaddr" \$UDHCPD_CONF || echo "siaddr \$(ifconfig \$INTERFACE | grep inet.ad | cut -d: -f2 | cut -d\ -f1)" >> \$UDHCPD_CONF</action>
1309 <action>[ -f \$PXE_CONF ] || echo -e "label linux\n\tkernel bzImage\n\tappend initrd=rootfs.gz rw root=/dev/null vga=normal" > \$PXE_CONF</action>
1310 <action type="lauch">leafpad \$PXE_CONF</action>
1311 </button>
1312 </hbox>
1313 <hbox>
1314 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:pxe)
1315 <button>
1316 <input file icon="system-file-manager"></input>
1317 <label>Network boot files</label>
1318 <action>$xterm -geometry 100x25 -title "Network boot files (q to quit)" -e "find \$(dirname \$(dirname \$PXE_CONF)) -exec ls -ld {} \; | less"</action>
1319 </button>
1320 </hbox>
1321 </frame>
1322 EOT
1326 # Busybox dnsd
1328 tab_dnsd()
1330 cat <<EOT
1331 <frame Dnsd (busybox master dns)>
1332 $(helpdaemon dnsd 80x15 DNSD_OPTIONS DNSD_OPTS)
1333 $(configfile /etc/dnsd.conf DNSD_CONF)
1334 <hbox>
1335 $(startstopdaemon dnsd)
1336 </hbox>
1337 </frame>
1338 EOT
1342 # ISC Bind
1344 tab_named()
1346 cat <<EOT
1347 <frame Named (ISC bind)>
1348 $(helpdaemon named 80x10 NAMED_OPTIONS NAMED_OPTS)
1349 $(configfile /etc/bind/named.conf.local NAMED_CONF)
1350 <hbox>
1351 $(startstopdaemon named bind)
1352 </hbox>
1353 </frame>
1354 EOT
1358 # DNSmasq
1360 tab_dnsmasq()
1362 cat <<EOT
1363 <frame DNSmasq (DNS/DHCP/TFTP)>
1364 $(helpdaemon dnsmasq 100x34 DNSMASQ_OPTIONS DNSMASQ_OPTS)
1365 $(configfile /etc/dnsmasq.conf DNSMASQ_CONF)
1366 <hbox>
1367 $(startstopdaemon dnsmasq)
1368 </hbox>
1369 </frame>
1370 EOT
1373 data_dns()
1375 cat <<EOT
1376 dnsd Dnsd tab_dnsd
1377 named Named tab_named
1378 dnsmasq DNSmasq tab_dnsmasq
1379 #TODO sheerdns Sheerdns tab_sheerdns
1380 EOT
1384 # dns tab
1386 tab_dns()
1388 use_tab data_dns
1392 # rsync server
1394 tab_rsync()
1396 cat <<EOT
1397 <frame Rsync>
1398 $(helpdaemon rsync 80x30 RSYNCD_OPTIONS RSYNCD_OPTS 1)
1399 $(configfile /etc/rsyncd.conf RSYNCD_CONF)
1400 $(datafile /etc/rsyncd.secrets RSYNCD_SECRETS 'Secrets file :')
1401 <hbox>
1402 $(startstopdaemon rsyncd rsync)
1403 </hbox>
1404 </frame>
1405 EOT
1408 php_ini()
1410 [ -f /etc/php.ini ] && cat <<EOT
1411 <frame PHP>
1412 $(configfile /etc/php.ini PHP_CONF)
1413 </frame>
1414 EOT
1418 # Apache server
1420 tab_apache()
1422 cat <<EOT
1423 <frame Apache>
1424 $(php_ini)
1425 $(configfile /etc/apache/httpd.conf HTTPD_CONF)
1426 <hbox>
1427 $(startstopdaemon apache)
1428 </hbox>
1429 </frame>
1430 EOT
1434 # Lighttpd server
1436 tab_lighttpd()
1438 cat <<EOT
1439 <frame Lighttpd>
1440 $(php_ini)
1441 $(configfile /etc/lighttpd/lighttpd.conf LIGHTTPD_CONF)
1442 <hbox>
1443 $(startstopdaemon lighttpd)
1444 </hbox>
1445 </frame>
1446 EOT
1449 data_http()
1451 cat <<EOT
1452 httpd Apache tab_apache
1453 lighttpd Named tab_lighttpd
1454 EOT
1455 #TODO busybox httpd
1459 # http tab
1461 tab_http()
1463 use_tab data_http
1467 # Samba servers
1469 tab_wins()
1471 cat <<EOT
1472 <frame Samba: smbd & nmbd>
1473 $(configfile /etc/samba/smb.conf SMBD_CONF)
1474 <hbox>
1475 <button>
1476 <label>Reload</label>
1477 <input file icon="reload"></input>
1478 <action>/etc/init.d/samba reload</action>
1479 </button>
1480 $(startstopdaemon samba)
1481 </hbox>
1482 </frame>
1483 EOT
1487 # x11vnc
1489 tab_vnc()
1491 cat <<EOT
1492 <frame x11vnc>
1493 $(helpdaemon x11vnc 80x30 X11VNC_OPTIONS X11VNC_OPTS)
1494 <hbox>
1495 <text use-markup="true">
1496 <label>"<b>New password</b>"</label>
1497 </text>
1498 <entry>
1499 <variable>X11VNC_PASSWD</variable>
1500 </entry>
1501 <button>
1502 <input file icon="reload"></input>
1503 <label>Update</label>
1504 <action>x11vnc -storepasswd \$X11VNC_PASSWD /etc/vnc.secret</action>
1505 </button>
1506 </hbox>
1507 <hbox>
1508 $(startstopdaemon x11vnc)
1509 </hbox>
1510 </frame>
1511 EOT
1515 # knock server
1517 tab_knockd()
1519 cat <<EOT
1520 <frame Knockd: trigger backdoors>
1521 $(helpdaemon knockd 80x15 KNOCK_OPTIONS KNOCK_OPTS)
1522 $(configfile /etc/knockd.conf KNOCKD_CONF)
1523 <hbox>
1524 $(startstopdaemon knockd knock)
1525 </hbox>
1526 </frame>
1527 EOT
1530 data_servers()
1532 local $pxe
1533 pxe="#"
1534 [ -x /usr/bin/tftpd -a -x /usr/sbin/udhcpd ] && pxe="inetd"
1535 [ -x /usr/sbin/dnsmasq ] && pxe="true"
1536 [ -f /usr/share/boot/pxelinux.0.lzma ] || pxe="#"
1537 cat <<EOT
1538 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "true" ||
1539 echo "#") SSH tab_sshd
1540 inetd Inetd tab_inetd
1541 zcip ZeroConf tab_zcip
1542 $([ -x /usr/sbin/udhcpd -o -x /usr/sbin/dhcpd -o -x /usr/sbin/dnsmasq ] &&
1543 echo "true" ||
1544 echo "#") DHCP tab_dhcpd
1545 $pxe PXE tab_pxe
1546 dnsmasq tftpd tab_dnsmasq
1547 $([ -x /usr/sbin/dnsd -o -x /usr/sbin/named -o -x /usr/sbin/dnsmasq ] &&
1548 echo "true" ||
1549 echo "#") DNS tab_dns
1550 rsync Rsync tab_rsync
1551 $([ -x /usr/sbin/lighttpd -o -x /usr/bin/httpd ] && echo "true" ||
1552 echo "#") HTTP tab_http
1553 smbd WINS tab_wins
1554 x11vnc VNC tab_vnc
1555 knockd Knock tab_knockd
1556 EOT
1560 # Servers tab
1562 tab_servers()
1564 use_tab data_servers
1568 # Firewall tab
1570 tab_firewall()
1572 cat <<EOT
1573 <frame Iptables>
1574 $(configfile /etc/iptables.conf IPTABLES_CONF)
1575 <hbox>
1576 $(helpbutton iptables 80x30)
1577 $(manbutton 8 iptables)
1578 $(webbutton iptables)
1579 <button>
1580 <label>Load</label>
1581 <input file icon="reload"></input>
1582 <action>cat \$IPTABLES_CONF | /sbin/iptables-restore</action>
1583 </button>
1584 <button>
1585 <label>Save</label>
1586 <input file icon="go-jump"></input>
1587 <action>/sbin/iptables-save > \$IPTABLES_CONF</action>
1588 </button>
1589 </hbox>
1590 </frame>
1591 EOT
1595 # knock client
1597 tab_knock()
1599 cat <<EOT
1600 <frame Knock>
1601 <hbox>
1602 <text use-markup="true">
1603 <label>"<b>Options : </b>"</label>
1604 </text>
1605 <entry editable="true">
1606 <variable>KNOCK_OPTS</variable>
1607 <default>myserver.example.com 123:tcp 456:udp 789:tcp</default>
1608 </entry>
1609 </hbox>
1610 <hbox>
1611 $(helpbutton knock 80x12)
1612 <button>
1613 <label>Start</label>
1614 <input file icon="forward"></input>
1615 <action>knock \$KNOCK_OPTS</action>
1616 </button>
1617 </hbox>
1618 </frame>
1619 EOT
1623 # ether-wake
1625 tab_etherwake()
1627 cat <<EOT
1628 <frame Ether-wake (busybox)>
1629 <hbox>
1630 <text use-markup="true">
1631 <label>"<b>Machines :</b>"</label>
1632 </text>
1633 <entry editable="false">
1634 <default>/etc/ethers</default>
1635 <variable>ETHERS</variable>
1636 </entry>
1637 <button>
1638 <input file icon="accessories-text-editor"></input>
1639 <action>[ -s \$ETHERS ] || echo "#00:01:02:03:04:05 mystation" >\$ETHERS</action>
1640 <action type="lauch">leafpad \$ETHERS</action>
1641 </button>
1642 </hbox>
1643 <hbox>
1644 <text use-markup="true">
1645 <label>"<b>Options : </b>"</label>
1646 </text>
1647 <entry editable="true">
1648 <variable>ETHERWAKE_OPTS</variable>
1649 </entry>
1650 $(helpbutton ether-wake 80x15)
1651 <button>
1652 <label>Start</label>
1653 <input file icon="forward"></input>
1654 <action>ether-wake \$ETHERWAKE_OPTS</action>
1655 </button>
1656 </hbox>
1657 <frame>
1658 <hbox>
1659 EOT
1660 if which ethtool > /dev/null; then
1661 cat <<EOT
1662 <text use-markup="true">
1663 <label>"<b>Interface:</b>"</label>
1664 </text>
1665 <combobox>
1666 <variable>ETHERWAKE_ETH</variable>
1667 EOT
1668 (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) | \
1669 awk '{ printf " <item>%s</item>\n",$1 }'
1670 cat <<EOT
1671 </combobox>
1672 <button>
1673 <label>Enable Wake On LAN</label>
1674 <input file icon="forward"></input>
1675 <action>ethtool -s \$ETHERWAKE_ETH wok g</action>
1676 </button>
1677 EOT
1678 else
1679 cat <<EOT
1680 <vbox>
1681 <text wrap="true" width-chars="58">
1682 <label>
1683 "Ethtool utility can enable Wake-on-lan
1684 feature on many Ethernet card.
1686 </label>
1687 </text>
1688 $(installbox ethtool)
1689 </vbox>
1690 EOT
1691 fi
1692 cat <<EOT
1693 </hbox>
1694 </frame>
1695 </frame>
1696 EOT
1699 data_main()
1701 cat <<EOT
1702 #program tab name function
1703 ifconfig Connections tab_connections
1704 udhcpc DHCP tab_udhcpc
1705 ifconfig Static\ IP tab_fixed_ip
1706 pppoe PPPoE tab_pppoe
1707 pppd PPP tab_ppp
1708 true System\ wide tab_system
1709 true VPN tab_vpn
1710 true Servers tab_servers
1711 iptables Firewall tab_firewall
1712 knock Knock tab_knock
1713 ether-wake Etherwake tab_etherwake
1714 EOT
1717 tab_main()
1719 use_tab data_main
1722 ######################################################
1724 # Netbox GUI
1726 ######################################################
1728 # English/French help dialog.
1729 export HELP='
1730 <window title="Network status" icon-name="network-wire">
1731 <vbox>
1732 <text use-markup="true">
1733 <label>
1735 <b>SliTaz - Netbox</b>"
1736 </label>
1737 </text>
1738 <frame English>
1739 <text wrap="true" width-chars="58">
1740 <label>
1741 "Netbox lets you manage network connections by getting a dynamic IP by
1742 DHCP or a static IP and setup servers. Netbox can start or stop
1743 networking, configure network interfaces or directly edit files."
1744 </label>
1745 </text>
1746 </frame>
1747 <frame Francais>
1748 <text wrap="true" width-chars="58">
1749 <label>
1750 "Netbox vous permet de gerer les connexions reseau avec une IP
1751 statique ou en obtenant une IP dynamique par DHCP, et de parametrer
1752 les serveurs. Netbox peut demarrer ou arreter le reseau, configurer
1753 les interfaces reseau ou editer directement les fichiers."
1754 </label>
1755 </text>
1756 </frame>
1757 </vbox>
1758 </window>
1761 # Interface status with ifconfig without arguments to show all
1762 # active connections.
1764 export IFCONFIG="
1765 <window title=\"Network status\" icon-name=\"network-wire\">
1766 <vbox>
1767 $(tab_status)
1768 <hbox>
1769 <button>
1770 <input file icon=\"gtk-close\"></input>
1771 <action type=\"closewindow\">IFCONFIG</action>
1772 </button>
1773 </hbox>
1774 </vbox>
1775 </window>"
1777 # The main dialog with notebook, start/stop buttons and all options.
1778 # Note that /etc/network.conf is seded when an interface is activated.
1780 head='
1781 <window title="SliTaz Netbox Manager" icon-name="network-wired">
1782 <vbox>
1784 <hbox>
1785 <text use-markup="true">
1786 <label>"<b>Network/Server Manager</b>"</label>
1787 </text>
1788 <pixmap>
1789 <input file>/usr/share/pixmaps/netbox.png</input>
1790 </pixmap>
1791 </hbox>
1793 bottom='
1794 <hbox>
1795 <button>
1796 <label>Wireless manager</label>
1797 <input file icon="network-wireless"></input>
1798 <action>wifibox &</action>
1799 </button>
1800 <button>
1801 <label>Refresh list</label>
1802 <input file icon="reload"></input>
1803 <action>refresh:INTERFACE_LIST</action>
1804 </button>
1805 <button>
1806 <label>Full status</label>
1807 <input file icon="dialog-information"></input>
1808 <action type="launch">IFCONFIG</action>
1809 </button>
1810 <button help>
1811 <label>Help</label>
1812 <action type="launch">HELP</action>
1813 </button>
1814 <button>
1815 <label>Quit</label>
1816 <input file icon="exit"></input>
1817 <action type="exit">Exit</action>
1818 </button>
1819 </hbox>
1821 </vbox>
1822 </window>
1825 NET_BOX="${head}$(tab_main)${bottom}"
1827 export NET_BOX
1829 # TODO: Modules(Network kernel modules)
1831 # Only root can configure network.
1832 check_root
1834 # Configure and connect if button Connect was pressed.
1835 if ! grep -qs ^name /etc/ppp/options ; then
1836 # Generate /etc/ppp/options
1837 cat > /etc/ppp/options << _EOT_
1838 plugin rp-pppoe.so
1839 name provider-ID
1840 noipdefault
1841 defaultroute
1842 mtu 1492
1843 mru 1492
1844 lock
1845 _EOT_
1846 # Generate /etc/ppp/pap-secrets
1847 cat > /etc/ppp/pap-secrets << _EOT_
1848 # Secrets for authentication using PAP
1849 # client server secret IP addresses
1850 _EOT_
1851 # Generate /etc/ppp/chap-secrets
1852 cat > /etc/ppp/chap-secrets << _EOT_
1853 # Secrets for authentication using CHAP
1854 # client server secret IP addresses
1855 _EOT_
1856 fi
1857 gtkdialog --center --program=NET_BOX | grep -a 'EXIT="restart"' && continue
1858 exit 0
1859 done