slitaz-tools view tinyutils/netbox @ rev 435

improve firewall and iptables_rules (thanks gokhlayeh)
author Rohit Joshi <jozee@slitaz.org>
date Fri Mar 12 12:01:54 2010 +0000 (2010-03-12)
parents 31c189734a0e
children 612580c57250
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 -qs '\$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 /*) [ -e $exe ] || continue;;
347 *) which $exe > /dev/null || continue
348 esac
349 if [ "$2" == "header" ]; then
350 echo -n "$tmp$name"
351 tmp='|'
352 else
353 $call
354 fi
355 done
356 ;;
357 *)
358 tmp=$(use_tab $1 header)
359 echo "$tmp" | grep -q \| && cat <<EOT
360 <notebook labels="$tmp">
361 EOT
362 [ -n "$tmp" ] && cat <<EOT
363 $(use_tab $1 body)
364 EOT
365 echo "$tmp" | grep -q \| && cat <<EOT
366 </notebook>
367 EOT
368 ;;
369 esac
370 }
372 #
373 # Status wire interfaces
374 #
375 tab_status_iface()
376 {
377 local eth
378 eth="$( (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) )"
379 which ethtool > /dev/null || eth=''
380 if [ -n "$eth" ]; then
381 cat <<EOT
382 <notebook labels="Ifconfig|$(echo $eth | sed 's/ /|/g')">
383 EOT
384 fi
385 cat <<EOT
386 <frame Ifconfig>
387 <text wrap="false" width-chars="58">
388 <input>ifconfig</input>
389 </text>
390 </frame>
391 EOT
392 if [ -n "$eth" ]; then
393 local i
394 for i in $eth ; do
395 cat <<EOT
396 <frame $i>
397 <text wrap="false" width-chars="58">
398 <input>ethtool $i</input>
399 </text>
400 </frame>
401 EOT
402 done
403 cat <<EOT
404 </notebook>
405 EOT
406 fi
407 }
409 #
410 # Status wifi interfaces
411 #
412 tab_status_wifi_iface()
413 {
414 cat <<EOT
415 <frame Iwconfig>
416 <text wrap="false" width-chars="58">
417 <input>iwconfig</input>
418 </text>
419 </frame>
420 EOT
421 }
423 #
424 # Status wifi network
425 #
426 tab_status_wifi_net()
427 {
428 cat <<EOT
429 <frame Wireless networks>
430 <text wrap="false" width-chars="58">
431 <input>iwlist scan</input>
432 </text>
433 </frame>
434 EOT
435 }
437 #
438 # Status routing
439 #
440 tab_status_route()
441 {
442 cat <<EOT
443 <frame Routing>
444 <frame Nameservers>
445 <text wrap="false" width-chars="58">
446 <input>cat /etc/resolv.conf</input>
447 </text>
448 </frame>
449 <frame Routing table>
450 <text wrap="false" width-chars="58">
451 <input>route</input>
452 </text>
453 </frame>
454 <frame Arp table>
455 <text wrap="false" width-chars="58">
456 <input>arp</input>
457 </text>
458 </frame>
459 </frame>
460 EOT
461 }
463 #
464 # Status servers
465 #
466 tab_status_servers()
467 {
468 local servers
469 servers="dropbear sshd inetd dhcpd dnsd named rsync httpd mbd vnc pppd knock"
470 cat <<EOT
471 <frame Servers>
472 <text wrap="false" width-chars="58">
473 <input>for i in $servers; do ps ww | grep \$i | grep -v grep | fold -s; done</input>
474 </text>
475 </frame>
476 EOT
477 }
479 data_status()
480 {
481 cat <<EOT
482 ifconfig Network\ interfaces tab_status_iface
483 iwconfig Wireless\ interfaces tab_status_wifi_iface
484 iwlist Wireless\ networks tab_status_wifi_net
485 route Routing tab_status_route
486 ps Servers tab_status_servers
487 EOT
488 }
490 #
491 # Status
492 #
493 tab_status()
494 {
495 use_tab data_status
496 }
498 #
499 # Interfaces list from detect_interfaces()
500 #
501 tab_connections()
502 {
503 cat <<EOT
504 <vbox>
505 <tree>
506 <width>520</width><height>120</height>
507 <variable>INTERFACE_LIST</variable>
508 <label>Interface|Type|Status</label>
509 <input icon_column="0">$0 detect_interfaces</input>
510 <action>refresh:INTERFACE_LIST</action>
511 </tree>
512 </vbox>
513 EOT
514 }
516 #
517 # DHCP
518 #
519 tab_udhcpc()
520 {
521 cat <<EOT
522 <frame Udhcpc (busybox)>
523 <text width-chars="58">
524 <label> "Ethernet (cable) default connection." </label>
525 </text>
526 <hbox>
527 <text use-markup="true">
528 <label>"<b>Interface:</b>"</label>
529 </text>
530 <entry>
531 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
532 <variable>INTERFACE</variable>
533 </entry>
534 </hbox>
535 <hbox>
536 <text use-markup="true">
537 <label>"<b>Options: </b>"</label>
538 </text>
539 <entry>
540 <default>-b</default>
541 <variable>UDHCPC_OPTS</variable>
542 </entry>
543 $(helpbutton udhcpc 80x30)
544 </hbox>
545 <hbox>
546 <text use-markup="true">
547 <label>"<b>Script: </b>"</label>
548 </text>
549 <entry editable="false">
550 <default>/usr/share/udhcpc/default.script</default>
551 <variable>UDHCPC_SCRIPT</variable>
552 </entry>
553 $(editbutton \$UDHCPC_SCRIPT)
554 </hbox>
555 <hbox>
556 <button>
557 <label>Start</label>
558 <input file icon="forward"></input>
559 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
560 <action>sed -i s/DHCP="no"/DHCP="yes"/ /etc/network.conf</action>
561 <action>sed -i s/STATIC="yes"/STATIC="no"/ /etc/network.conf</action>
562 <action>udhcpc \$UDHCPC_OPTS -i \$INTERFACE -p /var/run/udhcpc.\$INTERFACE.pid</action>
563 <action>refresh:INTERFACE_LIST</action>
564 </button>
565 <button>
566 <label>Stop</label>
567 <input file icon="stop"></input>
568 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
569 <action>ifconfig \$INTERFACE down</action>
570 <action>killall -q udhcpc; echo "done"</action>
571 <action>refresh:INTERFACE_LIST</action>
572 </button>
573 </hbox>
574 </frame>
575 EOT
576 }
578 #
579 # Static/fixed IP settings.
580 #
581 tab_fixed_ip()
582 {
583 cat <<EOT
584 <frame Ethernet fixed IP>
585 <hbox>
586 <text use-markup="true">
587 <label>"<b>Interface: </b>"</label>
588 </text>
589 <entry>
590 <input>. /etc/network.conf; echo "\$INTERFACE"</input>
591 <variable>INTERFACE</variable>
592 </entry>
593 </hbox>
594 <hbox>
595 <text use-markup="true">
596 <label>"<b>IP: </b>"</label>
597 </text>
598 <entry>
599 <input>. /etc/network.conf; echo "\$IP"</input>
600 <variable>IP</variable>
601 </entry>
602 </hbox>
603 <hbox>
604 <text use-markup="true">
605 <label>"<b>Netmask: </b>"</label>
606 </text>
607 <entry>
608 <input>. /etc/network.conf; echo "\$NETMASK"</input>
609 <variable>NETMASK</variable>
610 </entry>
611 </hbox>
612 <hbox>
613 <text use-markup="true">
614 <label>"<b>Gateway: </b>"</label>
615 </text>
616 <entry>
617 <input>. /etc/network.conf; echo "\$GATEWAY"</input>
618 <variable>GATEWAY</variable>
619 </entry>
620 </hbox>
621 <hbox>
622 <text use-markup="true">
623 <label>"<b>DNS server: </b>"</label>
624 </text>
625 <entry>
626 <input>. /etc/network.conf; echo "\$DNS_SERVER"</input>
627 <variable>DNS_SERVER</variable>
628 </entry>
629 </hbox>
630 <hbox>
631 <button>
632 <label>Start</label>
633 <input file icon="forward"></input>
634 <action>ifconfig lo down</action>
635 <action>ifconfig \$INTERFACE down</action>
636 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE="\$INTERFACE"/ /etc/network.conf</action>
637 <action>sed -i s/DHCP="yes"/DHCP="no"/ /etc/network.conf</action>
638 <action>sed -i s/WIFI="yes"/WIFI="no"/ /etc/network.conf</action>
639 <action>sed -i s/STATIC="no"/STATIC="yes"/ /etc/network.conf</action>
640 <action>sed -i s/`cat /etc/network.conf | grep ^IP=`/IP="\$IP"/ /etc/network.conf</action>
641 <action>sed -i s/`cat /etc/network.conf | grep ^NETMASK=`/NETMASK="\$NETMASK"/ /etc/network.conf</action>
642 <action>sed -i s/`cat /etc/network.conf | grep ^GATEWAY=`/GATEWAY="\$GATEWAY"/ /etc/network.conf</action>
643 <action>sed -i s/`cat /etc/network.conf | grep ^DNS_SERVER=`/DNS_SERVER="\$DNS_SERVER"/ /etc/network.conf</action>
644 <action>/etc/init.d/network.sh</action>
645 <action>refresh:INTERFACE_LIST</action>
646 </button>
647 <button>
648 <label>Stop</label>
649 <input file icon="stop"></input>
650 <action>ifconfig \$INTERFACE down</action>
651 <action>refresh:INTERFACE_LIST</action>
652 </button>
653 </hbox>
654 </frame>
655 EOT
656 }
658 #
659 # PPPoe settings.
660 #
661 tab_pppoe()
662 {
663 cat <<EOT
664 <frame PPPoE>
665 <hbox>
666 <text use-markup="true">
667 <label>"<b>Name: </b>"</label>
668 </text>
669 <entry>
670 <input>NAME=\$(grep -s ^name /etc/ppp/options); echo "\${NAME#* }"</input>
671 <variable>NAME</variable>
672 </entry>
673 </hbox>
674 <hbox>
675 <text use-markup="true">
676 <label>"<b>Username:</b>"</label>
677 </text>
678 <entry>
679 <variable>USER</variable>
680 </entry>
681 </hbox>
682 <hbox>
683 <text use-markup="true">
684 <label>"<b>Password:</b>"</label>
685 </text>
686 <entry>
687 <variable>PASS</variable>
688 </entry>
689 </hbox>
690 <hbox>
691 $(helpbutton pppd 80x30)
692 $(manbutton 8 pppd)
693 $(webbutton ppp)
694 <button>
695 <input file icon="accessories-text-editor"></input>
696 <label>Tune</label>
697 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
698 <action type="lauch">leafpad /etc/ppp/options</action>
699 </button>
700 <button>
701 <label>Start</label>
702 <input file icon="forward"></input>
703 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
704 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
705 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
706 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
707 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
708 <action>killall udhcpc</action>
709 <action>sed -i "s/DHCP=\"yes\"/DHCP=\"no\"/" /etc/network.conf</action>
710 <action>sed -i "s/PPPOE=\"no\"/PPPOE=\"yes\"/" /etc/network.conf</action>
711 <action>pppd \$INTERFACE &</action>
712 </button>
713 <button>
714 <label>Stop</label>
715 <input file icon="stop"></input>
716 <action>sed -i "s/PPPOE=\"yes\"/PPPOE=\"no\"/" /etc/network.conf</action>
717 <action>killall pppd</action>
718 </button>
719 </hbox>
720 </frame>
721 EOT
722 }
724 #
725 # PPP settings.
726 #
727 tab_ppp()
728 {
729 cat <<EOT
730 <frame PPP>
731 <hbox>
732 <text use-markup="true">
733 <label>"<b>Username: </b>"</label>
734 </text>
735 <entry>
736 <input>USER=\$(grep -s ^ACCOUNT= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${USER#*=}"</input>
737 <variable>USER</variable>
738 </entry>
739 </hbox>
740 <hbox>
741 <text use-markup="true">
742 <label>"<b>Password: </b>"</label>
743 </text>
744 <entry>
745 <input>PASS=\$(grep -s ^PASSWORD= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PASS#*=}"</input>
746 <variable>PASS</variable>
747 </entry>
748 </hbox>
749 <hbox>
750 <text use-markup="true">
751 <label>"<b>Telephone:</b>"</label>
752 </text>
753 <entry>
754 <input>PHONE=\$(grep -s ^TELEPHONE= /etc/ppp/scripts/ppp-on | cut -f1); echo "\${PHONE#*=}"</input>
755 <variable>PHONE</variable>
756 </entry>
757 </hbox>
758 <hbox>
759 $(helpbutton pppd 80x30)
760 $(manbutton 8 pppd)
761 $(webbutton ppp)
762 <button>
763 <input file icon="accessories-text-editor"></input>
764 <label>Tune</label>
765 <action>[ -n "\$NAME" ] && sed -i "s/^ACCOUNT=.*/ACCOUNT=\$NAME/" /etc/ppp/scripts/ppp-on</action>
766 <action>[ -n "\$PASS" ] && sed -i "s/^PASSWORD=.*/PASSWORD=\$PASS/" /etc/ppp/scripts/ppp-on</action>
767 <action>[ -n "\$PHONE" ] && sed -i "s/^TELEPHONE=.*/TELEPHONE=\$PHONE/" /etc/ppp/scripts/ppp-on</action>
768 <action type="lauch">leafpad /etc/ppp/scripts/ppp-on</action>
769 </button>
770 <button>
771 <label>Start</label>
772 <input file icon="forward"></input>
773 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/pap-secrets
774 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/pap-secrets</action>
775 <action>[ -n "\$USER" ] && grep -qs "^\"\$USER\"" /etc/ppp/chap-secrets
776 && echo "\"\$USER\" * \"\$PASS\"" >> /etc/ppp/chap-secrets</action>
777 <action>[ -n "\$NAME" ] && sed -i "s/^name .*/name \$NAME/" /etc/ppp/options</action>
778 <action>/etc/ppp/scripts/ppp-off</action>
779 <action>/etc/ppp/scripts/ppp-on &</action>
780 </button>
781 <button>
782 <label>Stop</label>
783 <input file icon="stop"></input>
784 <action>/etc/ppp/scripts/ppp-off</action>
785 </button>
786 </hbox>
787 </frame>
788 EOT
789 }
791 #
792 # System Wide configuration.
793 #
794 tab_system()
795 {
796 cat <<EOT
797 <frame Configuration files>
798 <hbox>
799 <text use-markup="true">
800 <label>"<b>Hosts :</b>"</label>
801 </text>
802 <entry editable="false">
803 <default>/etc/hosts</default>
804 <variable>HOSTS</variable>
805 </entry>
806 $(editbutton \$HOSTS)
807 </hbox>
808 <hbox>
809 <text use-markup="true">
810 <label>"<b>Host name :</b>"</label>
811 </text>
812 <entry editable="false">
813 <default>/etc/hostname</default>
814 <variable>HOSTNAME</variable>
815 </entry>
816 $(editbutton \$HOSTNAME)
817 </hbox>
818 <hbox>
819 <text use-markup="true">
820 <label>"<b>Network :</b>"</label>
821 </text>
822 <entry editable="false">
823 <default>/etc/network.conf</default>
824 <variable>CONFIG_FILE</variable>
825 </entry>
826 $(editbutton \$CONFIG_FILE)
827 </hbox>
828 <hbox>
829 <button>
830 <label>Restart</label>
831 <input file icon="reload"></input>
832 <action>echo -n "Stopping interface : \$INTERFACE... "</action>
833 <action>ifconfig \$INTERFACE down</action>
834 <action>killall -q udhcpc; echo "done"</action>
835 <action>/etc/init.d/network.sh restart</action>
836 </button>
837 </hbox>
838 </frame>
839 EOT
840 }
842 #
843 # ssh/ppp
844 #
845 tab_sshppp()
846 {
847 cat <<EOT
848 <frame Virtual Private Network with PPP/SSH>
849 <hbox>
850 <text use-markup="true">
851 <label>"<b>Peer :</b>"</label>
852 </text>
853 <entry>
854 <variable>DROPBEAR_PEERVPN</variable>
855 <default>user@elsewhere</default>
856 </entry>
857 </hbox>
858 <hbox>
859 <text use-markup="true">
860 <label>"<b>Local IP :</b>"</label>
861 </text>
862 <entry>
863 <variable>DROPBEAR_LOCAL</variable>
864 <default>192.168.254.1</default>
865 </entry>
866 </hbox>
867 <hbox>
868 <text use-markup="true">
869 <label>"<b>Remote IP :</b>"</label>
870 </text>
871 <entry>
872 <variable>DROPBEAR_REMOTE</variable>
873 <default>192.168.254.2</default>
874 </entry>
875 </hbox>
876 <hbox>
877 <text use-markup="true">
878 <label>"<b>Route(s) :</b>"</label>
879 </text>
880 <entry>
881 <variable>DROPBEAR_ROUTE</variable>
882 <default>192.168.10.0/24 192.168.20.0/28</default>
883 </entry>
884 </hbox>
885 <hbox>
886 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:vpn)
887 <button>
888 <input file icon="forward"></input>
889 <label>Connect</label>
890 <action>$0 call vpnssh \$DROPBEAR_PEERVPN \$DROPBEAR_LOCAL \$DROPBEAR_REMOTE "\$DROPBEAR_ROUTE" &</action>
891 </button>
892 <button>
893 <input file icon="stop"></input>
894 <label>Disconnect</label>
895 <action>$0 call killvpnssh</action>
896 </button>
897 <button>
898 <input file icon="go-up"></input>
899 <label>Send key</label>
900 <action>$xterm -geometry 80x10 -title "Send key" -e "$0 call sendsshkey \$DROPBEAR_PEERVPN; echo -e \"----\nENTER to continue...\" && read close"</action>
901 </button>
902 </hbox>
903 </frame>
904 EOT
905 }
907 #
908 # PPTP client
909 #
910 #FIXME
911 #cat > /etc/ppp/peers/$TUNNEL <<EOT
912 #pty "pptp $SERVER --nolaunchpppd"
913 #lock
914 #noauth
915 #nobsdcomp
916 #nodeflate
917 #name $DOMAIN\\$USERNAME
918 #remotename $TUNNEL
919 #ipparam $TUNNEL
920 #$(encryption && echo "require-mppe-128")
921 #EOT
922 #pppd call $TUNNEL updetach
924 tab_pptp()
925 {
926 [ -f /etc/ppp/options.pptp ] || cat >> /etc/ppp/options.pptp <<EOT
927 lock noauth nobsdcomp nodeflate remotename PPTP
928 EOT
929 [ -f /etc/ppp/pptp-servers ] || cat >> /etc/ppp/pptp-servers <<EOT
930 # PPTP servers list
931 EOT
932 cat <<EOT
933 <frame Virtual Private Network with PPTP>
934 <hbox>
935 <text use-markup="true">
936 <label>"<b>Server:</b>"</label>
937 </text>
938 <combobox>
939 <variable>PPTP_SERVER</variable>
940 EOT
941 grep -v ^\# /etc/ppp/pptp-servers | \
942 awk '{ printf " <item>%s</item>\n",$1 }'
943 cat <<EOT
944 <item>SERVER</item>
945 </combobox>
946 $(editbutton /etc/ppp/pptp-servers)
947 </hbox>
948 <hbox>
949 <text use-markup="true">
950 <label>"<b> User:</b>"</label>
951 </text>
952 <combobox>
953 <variable>PPTP_USER</variable>
954 EOT
955 grep '\\' /etc/ppp/chap-secrets | grep -v ^\# | \
956 awk '{ printf " <item>%s</item>\n",$1 }'
957 cat <<EOT
958 <item>DOMAIN\USERNAME</item>
959 </combobox>
960 $(editbutton /etc/ppp/chap-secrets)
961 </hbox>
962 <hbox>
963 <text use-markup="true">
964 <label>"<b>Password:</b>"</label>
965 </text>
966 <entry>
967 <variable>PPTP_PASS</variable>
968 </entry>
969 </hbox>
970 <hbox>
971 <checkbox>
972 <label>Encryption</label>
973 <variable>PPTP_ENC</variable>
974 <default>true</default>
975 </checkbox>
976 $(helpbutton pptp 80x35)
977 <button>
978 <input file icon="accessories-text-editor"></input>
979 <label>Options</label>
980 <action type="lauch">leafpad /etc/ppp/options.pptp</action>
981 </button>
982 $(webbutton pptpclient)
983 <button>
984 <input file icon="forward"></input>
985 <label>Connect</label>
986 <action>grep -qs ^\$PPTP_USER /etc/ppp/chap-secrets || \
987 echo "\$PPTP_USER PPTP \"$PPTP_PASS\" *" >> /etc/ppp/chap-secrets</action>
988 <action>grep -qs ^\$PPTP_SERVER /etc/ppp/pptp-servers || \
989 echo "\$PPTP_SERVER" >> /etc/ppp/pptp-servers</action>
990 <action>PASS=""; [ -n "\$PPTP_PASS" ] && PASS="password \$PASS"; \
991 ENC=""; [ x\$PPTP_ENC == xtrue ] && ENC="require-mppe-128"; \
992 /usr/sbin/pptp \$PPTP_SERVER file /etc/ppp/options.pptp \$ENC user \$PPTP_USER \$PASS &
993 </action>
994 </button>
995 <button>
996 <input file icon="stop"></input>
997 <label>Disconnect</label>
998 <action>killall pptp</action>
999 </button>
1000 </hbox>
1001 </frame>
1002 EOT
1006 # Cisco EasyVPN
1008 tab_easyvpn()
1010 cat <<EOT
1011 <frame Cisco EasyVPN>
1012 <hbox>
1013 <text use-markup="true">
1014 <label>"<b>VPNC_OPTIONS</b>"</label>
1015 </text>
1016 <entry editable="false">
1017 EOT
1018 [ -n "$VPNC_OPTIONS" ] && cat << EOT
1019 <default>$tmp</default>
1020 EOT
1021 cat << EOT
1022 <variable>VPNC_OPTS</variable>
1023 </entry>
1024 $(helpbutton vpnc 80x30)
1025 <button>
1026 <input file icon="help"></input>
1027 <label>more</label>
1028 <action>$xterm -geometry 80x40 -title "vpnc help (q to quit)" -e "$(which vpnc) --long-help 2>&1 | less"</action>
1029 </button>
1030 $(editbutton /etc/daemons.conf)
1031 </hbox>
1032 $(configfile /etc/vpnc/default.conf VPNC_CONF)
1033 $(datafile "/etc/vpnc/vpnc-script" VPNC_SCRIPT 'Script:')
1034 <hbox>
1035 $(startstopdaemon vpnc)
1036 </hbox>
1037 </frame>
1038 EOT
1042 # OpenVPN
1044 tab_openvpn()
1046 local i
1047 local n
1048 cat <<EOT
1049 <frame OpenVPN>
1050 EOT
1051 n=1
1052 for i in /etc/openvpn/*.conf ; do
1053 [ -f $i ] || continue
1054 configfile $i OPENVPN_CONF$n
1055 n=$(($n + 1))
1056 done
1057 cat <<EOT
1058 <hbox>
1059 $(helpbutton openvpn 80x40)
1060 $(startstopdaemon openvpn)
1061 </hbox>
1062 </frame>
1063 EOT
1066 data_vpn()
1068 cat <<EOT
1069 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "pppd" ||
1070 echo "#") PPP/SSH tab_sshppp
1071 pptp PPTP tab_pptp
1072 vpnc EasyVPN tab_easyvpn
1073 openvpn OpenVPN tab_openvpn
1074 EOT
1078 # VPN
1080 tab_vpn()
1082 use_tab data_vpn
1085 sshremote()
1087 cat << EOT
1088 <hbox>
1089 <text use-markup="true">
1090 <label>"<b>Remote :</b>"</label>
1091 </text>
1092 <entry>
1093 <variable>$2</variable>
1094 <default>user@elsewhere</default>
1095 </entry>
1096 <button>
1097 <input file icon="utilities-terminal"></input>
1098 <label>Connect</label>
1099 <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>
1100 </button>
1101 <button>
1102 <input file icon="go-up"></input>
1103 <label>Send key</label>
1104 <action>$xterm -geometry 80x10 -title "send ssh key" -e "$0 call sendsshkey \$$2; echo -e \"----\nENTER to continue...\" && read close"</action>
1105 </button>
1106 </hbox>
1107 EOT
1111 # Dropbear client & server
1113 tab_dropbear()
1115 . /etc/daemons.conf
1116 set -- $DROPBEAR_OPTIONS
1117 while [ -n "$2" ]; do
1118 [ "$1" = "-b" ] && DROPBEAR_BANNER="$2" && break
1119 shift
1120 done
1122 cat <<EOT
1123 <frame Dropbear>
1124 $(helpdaemon dropbear 80x30 DROPBEAR_OPTIONS DROPBEAR_OPTS)
1125 $(datafile /etc/dropbear/banner DROPBEAR_BANNER 'Banner :')
1126 $(sshremote DROPBEAR_PEER 'dbclient -i /etc/dropbear/dropbear_rsa_host_key')
1127 <hbox>
1128 $(startstopdaemon dropbear)
1129 </hbox>
1130 </frame>
1131 EOT
1135 # OpenSSH client & server
1137 tab_openssh()
1139 cat <<EOT
1140 <frame OpenSSH>
1141 $(helpdaemon sshd 80x30 OPENSSH_OPTIONS OPENSSH_OPTS 8 nohelp)
1142 $(configfile /etc/ssh/sshd_config OPENSSH_CONF '5 sshd_config')
1143 $(sshremote OPENSSH_PEER 'ssh -i /etc/ssh/ssh_host_rsa_key')
1144 <hbox>
1145 $(startstopdaemon openssh)
1146 </hbox>
1147 </frame>
1148 EOT
1151 data_sshd()
1153 cat <<EOT
1154 dropbear Dropbear tab_dropbear
1155 sshd OpenSSH tab_openssh
1156 EOT
1160 # SSH tab
1162 tab_sshd()
1164 use_tab data_sshd
1168 # Busybox Inetd
1170 tab_inetd()
1172 cat <<EOT
1173 <frame Inetd (busybox)>
1174 $(helpdaemon inetd 60x14 INETD_OPTIONS INETD_OPTS)
1175 $(configfile /etc/inetd.conf INETD_CONF)
1176 <hbox>
1177 EOT
1178 for i in $(grep bin /etc/inetd.conf | awk '{ print $6}'); do
1179 i=$(basename $i)
1180 helpbutton $i 60x19 $i
1181 done
1182 cat <<EOT
1183 $(startstopdaemon inetd)
1184 </hbox>
1185 </frame>
1186 EOT
1190 # ZeroConf
1192 tab_zcip()
1194 if [ -x /sbin/zcip -a -z "$ZCIP_OPTIONS" ]; then
1195 ZCIP_OPTIONS="eth0 /etc/zcip.script"
1196 cat >> /etc/daemons.conf <<EOT
1197 # ZeroConf options
1198 ZCIP_OPTIONS="$ZCIP_OPTIONS"
1200 EOT
1201 fi
1202 cat <<EOT
1203 <frame Zcip (busybox)>
1204 $(helpdaemon zcip 60x14 ZCIP_OPTIONS ZCIP_OPTS)
1205 $(datafile /etc/zcip.script CZIP_SCRIPT 'Script :')
1206 <hbox>
1207 $(startstopdaemon zcip)
1208 </hbox>
1209 </frame>
1210 EOT
1214 # Dhcpd ISC
1216 tab_isc_dhcpd()
1218 cat <<EOT
1219 <frame Dhcpd (ISC)>
1220 $(helpdaemon dhcpd 60x14 DHCPD_OPTIONS DHCPD_OPTS)
1221 $(configfile /etc/dhcpd.conf DHCPD_CONF)
1222 <hbox>
1223 $(startstopdaemon dhcpd dhcp)
1224 </hbox>
1225 </frame>
1226 EOT
1230 # Dhcpd Busybox
1232 tab_udhcpd()
1234 cat <<EOT
1235 <frame Udhcpd (busybox)>
1236 $(helpdaemon udhcpd 60x14 UDHCPD_OPTIONS UDHCPD_OPTS)
1237 $(configfile /etc/udhcpd.conf UDHCPD_CONF)
1238 <hbox>
1239 $(startstopdaemon udhcpd busybox)
1240 </hbox>
1241 </frame>
1242 EOT
1245 data_dhcpd()
1247 cat <<EOT
1248 udhcpd Udhcpd tab_udhcpd
1249 dhcpd Dhcpd tab_isc_dhcpd
1250 dnsmasq DNSmasq tab_dnsmasq
1251 EOT
1255 # dhcpd tab
1257 tab_dhcpd()
1259 use_tab data_dhcpd
1263 # PXE forwarder
1265 tab_gpxe()
1267 cat <<EOT
1268 <frame PXE forwarder>
1269 <hbox>
1270 <text use-markup="true">
1271 <label>"<b>WEB boot URL(s) :</b>"</label>
1272 </text>
1273 </hbox>
1274 <hbox>
1275 <entry editable="true">
1276 <default>
1277 "$(dd bs=1 skip=5 count=255 if=/usr/share/boot/gpxe.pxe 2> /dev/null | strings)"
1278 </default>
1279 <variable>WEB_PXE</variable>
1280 </entry>
1281 </hbox>
1282 <hbox>
1283 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:pxe)
1284 <button>
1285 <input file icon="go-jump"></input>
1286 <label>Install</label>
1287 <action>
1288 echo -n "\$WEB_PXE" | cat - /dev/zero | \
1289 dd conv=notrunc bs=1 seek=5 count=255 of=/usr/share/boot/gpxe.pxe
1290 </action>
1291 <action>
1292 sed -i "s|tftpd -r .*\$|tftpd -r /usr/share/boot|" /etc/inetd.conf
1293 </action>
1294 <action> sed -i "/^boot_file/d" \$UDHCPD_CONF </action>
1295 <action> echo "boot_file gpxe.pxe" >> \$UDHCPD_CONF </action>
1296 <action> /etc/init.d/inetd restart </action>
1297 <action> /etc/init.d/udhcpd restart </action>
1298 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)inetd \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
1299 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)udhcpd \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
1300 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)\\"/RUN_DAEMONS=\\"udhcpd inetd \1\\"/" /etc/rcS.conf</action>
1301 </button>
1302 </hbox>
1303 </frame>
1304 EOT
1308 # PXE server
1310 tab_pxelinux()
1312 cat <<EOT
1313 <frame PXElinux>
1314 <hbox>
1315 <text wrap="true">
1316 <label>
1317 "Launch Dhcpd and Inetd with Tftpd to start the PXE service."
1318 </label>
1319 </text>
1320 </hbox>
1321 <hbox>
1322 <text use-markup="true">
1323 <label>"<b>Configuration :</b>"</label>
1324 </text>
1325 <entry editable="false">
1326 <default>
1327 $(grep bin/tftpd /etc/inetd.conf | awk '{ print $NF }')/pxelinux.cfg/default
1328 </default>
1329 <variable>PXE_CONF</variable>
1330 </entry>
1331 <button>
1332 <input file icon="accessories-text-editor"></input>
1333 <action>dir=\$(dirname \$PXE_CONF); [ -d \$dir ] || mkdir -p \$dir</action>
1334 <action>lzma d /usr/share/boot/pxelinux.0.lzma \$(dirname \$PXE_CONF)/../pxelinux.0</action>
1335 <action>sed -i "/^boot_file/d" \$UDHCPD_CONF</action>
1336 <action>echo "boot_file pxelinux.0" >> \$UDHCPD_CONF</action>
1337 <action>grep -q "^siaddr" \$UDHCPD_CONF || echo "siaddr \$(ifconfig \$INTERFACE | grep inet.ad | cut -d: -f2 | cut -d\ -f1)" >> \$UDHCPD_CONF</action>
1338 <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>
1339 <action type="lauch">leafpad \$PXE_CONF</action>
1340 </button>
1341 </hbox>
1342 <hbox>
1343 $(wikibutton http://wiki.slitaz.org/doku.php?id=quickstart:pxe)
1344 <button>
1345 <input file icon="system-file-manager"></input>
1346 <label>Network boot files</label>
1347 <action>$xterm -geometry 100x25 -title "Network boot files (q to quit)" -e "find \$(dirname \$(dirname \$PXE_CONF)) -exec ls -ld {} \; | less"</action>
1348 </button>
1349 </hbox>
1350 </frame>
1351 EOT
1354 data_pxe()
1356 [ -f /usr/share/boot/pxelinux.0.lzma ] && cat <<EOT
1357 true PXElinux tab_pxelinux
1358 EOT
1359 [ -f /usr/share/boot/gpxe.pxe ] && cat <<EOT
1360 true PXE\ forwarder tab_gpxe
1361 EOT
1365 # PXE
1367 tab_pxe()
1369 use_tab data_pxe
1373 # Busybox dnsd
1375 tab_dnsd()
1377 cat <<EOT
1378 <frame Dnsd (busybox master dns)>
1379 $(helpdaemon dnsd 80x15 DNSD_OPTIONS DNSD_OPTS)
1380 $(configfile /etc/dnsd.conf DNSD_CONF)
1381 <hbox>
1382 $(startstopdaemon dnsd busybox)
1383 </hbox>
1384 </frame>
1385 EOT
1389 # ISC Bind
1391 tab_named()
1393 cat <<EOT
1394 <frame Named (ISC bind)>
1395 $(helpdaemon named 80x10 NAMED_OPTIONS NAMED_OPTS)
1396 $(configfile /etc/bind/named.conf.local NAMED_CONF)
1397 <hbox>
1398 $(startstopdaemon named bind)
1399 </hbox>
1400 </frame>
1401 EOT
1405 # DNSmasq
1407 tab_dnsmasq()
1409 cat <<EOT
1410 <frame DNSmasq (DNS/DHCP/TFTP)>
1411 $(helpdaemon dnsmasq 100x34 DNSMASQ_OPTIONS DNSMASQ_OPTS)
1412 $(configfile /etc/dnsmasq.conf DNSMASQ_CONF)
1413 <hbox>
1414 $(startstopdaemon dnsmasq)
1415 </hbox>
1416 </frame>
1417 EOT
1420 data_dns()
1422 cat <<EOT
1423 dnsd Dnsd tab_dnsd
1424 named Named tab_named
1425 dnsmasq DNSmasq tab_dnsmasq
1426 #TODO sheerdns Sheerdns tab_sheerdns
1427 EOT
1431 # dns tab
1433 tab_dns()
1435 use_tab data_dns
1439 # rsync server
1441 tab_rsync()
1443 cat <<EOT
1444 <frame Rsync>
1445 $(helpdaemon rsync 80x30 RSYNCD_OPTIONS RSYNCD_OPTS 1)
1446 $(configfile /etc/rsyncd.conf RSYNCD_CONF)
1447 $(datafile /etc/rsyncd.secrets RSYNCD_SECRETS 'Secrets file :')
1448 <hbox>
1449 $(startstopdaemon rsyncd rsync)
1450 </hbox>
1451 </frame>
1452 EOT
1455 php_ini()
1457 [ -f /etc/php.ini ] && cat <<EOT
1458 <frame PHP>
1459 $(configfile /etc/php.ini PHP_CONF)
1460 </frame>
1461 EOT
1465 # Apache server
1467 tab_apache()
1469 cat <<EOT
1470 <frame Apache>
1471 $(configfile /etc/apache/httpd.conf HTTPD_CONF)
1472 $(php_ini)
1473 <hbox>
1474 $(startstopdaemon apache)
1475 </hbox>
1476 </frame>
1477 EOT
1481 # Lighttpd server
1483 tab_lighttpd()
1485 cat <<EOT
1486 <frame Lighttpd>
1487 $(helpdaemon lighttpd 80x15 LIGHTTPD_OPTIONS LIGHTTPD_OPTS)
1488 $(configfile /etc/lighttpd/lighttpd.conf LIGHTTPD_CONF)
1489 $(php_ini)
1490 <hbox>
1491 $(startstopdaemon lighttpd)
1492 </hbox>
1493 </frame>
1494 EOT
1498 # Busybox httpd server
1500 tab_httpd()
1502 cat <<EOT
1503 <frame httpd (busybox)>
1504 $(helpdaemon httpd 80x30 HTTPD_OPTIONS HTTPD_OPTS)
1505 $(configfile /etc/httpd.conf HTTPD_CONF)
1506 $(php_ini)
1507 <hbox>
1508 $(startstopdaemon httpd busybox)
1509 </hbox>
1510 </frame>
1511 EOT
1514 data_http()
1516 cat <<EOT
1517 /etc/apache/httpd.conf Apache tab_apache
1518 lighttpd Lighttpd tab_lighttpd
1519 /etc/httpd.conf Busybox\ httpd tab_httpd
1520 EOT
1524 # http tab
1526 tab_http()
1528 use_tab data_http
1532 # Samba servers
1534 tab_wins()
1536 cat <<EOT
1537 <frame Samba: smbd & nmbd>
1538 $(configfile /etc/samba/smb.conf SMBD_CONF)
1539 <hbox>
1540 <button>
1541 <label>Reload</label>
1542 <input file icon="reload"></input>
1543 <action>/etc/init.d/samba reload</action>
1544 </button>
1545 $(startstopdaemon samba)
1546 </hbox>
1547 </frame>
1548 EOT
1552 # x11vnc
1554 tab_vnc()
1556 cat <<EOT
1557 <frame x11vnc>
1558 $(helpdaemon x11vnc 80x30 X11VNC_OPTIONS X11VNC_OPTS)
1559 <hbox>
1560 <text use-markup="true">
1561 <label>"<b>New password</b>"</label>
1562 </text>
1563 <entry>
1564 <variable>X11VNC_PASSWD</variable>
1565 </entry>
1566 <button>
1567 <input file icon="reload"></input>
1568 <label>Update</label>
1569 <action>x11vnc -storepasswd \$X11VNC_PASSWD /etc/vnc.secret</action>
1570 </button>
1571 </hbox>
1572 <hbox>
1573 $(startstopdaemon x11vnc)
1574 </hbox>
1575 </frame>
1576 EOT
1580 # knock server
1582 tab_knockd()
1584 cat <<EOT
1585 <frame Knockd: trigger backdoors>
1586 $(helpdaemon knockd 80x15 KNOCK_OPTIONS KNOCK_OPTS)
1587 $(configfile /etc/knockd.conf KNOCKD_CONF)
1588 <hbox>
1589 $(startstopdaemon knockd knock)
1590 </hbox>
1591 </frame>
1592 EOT
1595 data_servers()
1597 local $pxe
1598 pxe="#"
1599 [ -x /usr/bin/tftpd -a -x /usr/sbin/udhcpd ] && pxe="inetd"
1600 [ -x /usr/sbin/dnsmasq ] && pxe="true"
1601 [ -f /usr/share/boot/pxelinux.0.lzma -o /usr/share/boot/gpxe.pxe ] || pxe="#"
1602 cat <<EOT
1603 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "true" ||
1604 echo "#") SSH tab_sshd
1605 inetd Inetd tab_inetd
1606 zcip ZeroConf tab_zcip
1607 $([ -x /usr/sbin/udhcpd -o -x /usr/sbin/dhcpd -o -x /usr/sbin/dnsmasq ] &&
1608 echo "true" ||
1609 echo "#") DHCP tab_dhcpd
1610 $pxe PXE tab_pxe
1611 dnsmasq tftpd tab_dnsmasq
1612 $([ -x /usr/sbin/dnsd -o -x /usr/sbin/named -o -x /usr/sbin/dnsmasq ] &&
1613 echo "true" ||
1614 echo "#") DNS tab_dns
1615 rsync Rsync tab_rsync
1616 $([ -x /usr/sbin/lighttpd -o -x /usr/bin/httpd ] && echo "true" ||
1617 echo "#") HTTP tab_http
1618 smbd WINS tab_wins
1619 x11vnc VNC tab_vnc
1620 knockd Knock tab_knockd
1621 #TODO+callback pppd Pppd tab_pppd
1622 #TODO pptpd PoPToP tab_poptop
1623 #TODO squid *sql openldap
1624 EOT
1628 # Servers tab
1630 tab_servers()
1632 use_tab data_servers
1636 # Firewall tab
1638 tab_firewall()
1640 cat <<EOT
1641 <frame Iptables>
1642 $(configfile /etc/iptables.conf IPTABLES_CONF)
1643 <hbox>
1644 $(helpbutton iptables 80x30)
1645 $(manbutton 8 iptables)
1646 $(webbutton iptables)
1647 <button>
1648 <label>Load</label>
1649 <input file icon="reload"></input>
1650 <action>cat \$IPTABLES_CONF | /sbin/iptables-restore</action>
1651 </button>
1652 <button>
1653 <label>Save</label>
1654 <input file icon="go-jump"></input>
1655 <action>/sbin/iptables-save > \$IPTABLES_CONF</action>
1656 </button>
1657 </hbox>
1658 </frame>
1659 EOT
1663 # knock client
1665 tab_knock()
1667 cat <<EOT
1668 <frame Knock>
1669 <hbox>
1670 <text use-markup="true">
1671 <label>"<b>Options : </b>"</label>
1672 </text>
1673 <entry editable="true">
1674 <variable>KNOCK_OPTS</variable>
1675 <default>myserver.example.com 123:tcp 456:udp 789:tcp</default>
1676 </entry>
1677 </hbox>
1678 <hbox>
1679 $(helpbutton knock 80x12)
1680 <button>
1681 <label>Start</label>
1682 <input file icon="forward"></input>
1683 <action>knock \$KNOCK_OPTS</action>
1684 </button>
1685 </hbox>
1686 </frame>
1687 EOT
1691 # ether-wake
1693 tab_etherwake()
1695 cat <<EOT
1696 <frame Ether-wake (busybox)>
1697 <hbox>
1698 <text use-markup="true">
1699 <label>"<b>Machines :</b>"</label>
1700 </text>
1701 <entry editable="false">
1702 <default>/etc/ethers</default>
1703 <variable>ETHERS</variable>
1704 </entry>
1705 <button>
1706 <input file icon="accessories-text-editor"></input>
1707 <action>[ -s \$ETHERS ] || echo "#00:01:02:03:04:05 mystation" >\$ETHERS</action>
1708 <action type="lauch">leafpad \$ETHERS</action>
1709 </button>
1710 </hbox>
1711 <hbox>
1712 <text use-markup="true">
1713 <label>"<b>Options : </b>"</label>
1714 </text>
1715 <entry editable="true">
1716 <variable>ETHERWAKE_OPTS</variable>
1717 </entry>
1718 $(helpbutton ether-wake 80x15)
1719 <button>
1720 <label>Start</label>
1721 <input file icon="forward"></input>
1722 <action>ether-wake \$ETHERWAKE_OPTS</action>
1723 </button>
1724 </hbox>
1725 <frame>
1726 <hbox>
1727 EOT
1728 if which ethtool > /dev/null; then
1729 cat <<EOT
1730 <text use-markup="true">
1731 <label>"<b>Interface:</b>"</label>
1732 </text>
1733 <combobox>
1734 <variable>ETHERWAKE_ETH</variable>
1735 EOT
1736 (cd /sys/class/net ; [ -d eth0 ] && ls -d eth* ) | \
1737 awk '{ printf " <item>%s</item>\n",$1 }'
1738 cat <<EOT
1739 </combobox>
1740 <button>
1741 <label>Enable Wake On LAN</label>
1742 <input file icon="forward"></input>
1743 <action>ethtool -s \$ETHERWAKE_ETH wok g</action>
1744 </button>
1745 EOT
1746 else
1747 cat <<EOT
1748 <vbox>
1749 <text wrap="true" width-chars="58">
1750 <label>
1751 "Ethtool can enable the Wake-on-lan
1752 feature on many Ethernet cards.
1754 </label>
1755 </text>
1756 $(installbox ethtool)
1757 </vbox>
1758 EOT
1759 fi
1760 cat <<EOT
1761 </hbox>
1762 </frame>
1763 </frame>
1764 EOT
1767 data_main()
1769 cat <<EOT
1770 #program tab name function
1771 ifconfig Connections tab_connections
1772 udhcpc DHCP tab_udhcpc
1773 ifconfig Static\ IP tab_fixed_ip
1774 pppoe PPPoE tab_pppoe
1775 pppd PPP tab_ppp
1776 true System\ wide tab_system
1777 true VPN tab_vpn
1778 true Servers tab_servers
1779 iptables Firewall tab_firewall
1780 knock Knock tab_knock
1781 ether-wake Etherwake tab_etherwake
1782 EOT
1785 tab_main()
1787 use_tab data_main
1790 ######################################################
1792 # Netbox GUI
1794 ######################################################
1796 # English/French help dialog.
1797 export HELP='
1798 <window title="Network status" icon-name="network-wire">
1799 <vbox>
1800 <text use-markup="true">
1801 <label>
1803 <b>SliTaz - Netbox</b>"
1804 </label>
1805 </text>
1806 <frame English>
1807 <text wrap="true" width-chars="58">
1808 <label>
1809 "Netbox lets you manage network connections by getting a dynamic IP by
1810 DHCP or a static IP and setup servers. Netbox can start or stop
1811 networking, configure network interfaces or directly edit files."
1812 </label>
1813 </text>
1814 </frame>
1815 <frame Francais>
1816 <text wrap="true" width-chars="58">
1817 <label>
1818 "Netbox vous permet de gerer les connexions reseau avec une IP
1819 statique ou en obtenant une IP dynamique par DHCP, et de parametrer
1820 les serveurs. Netbox peut demarrer ou arreter le reseau, configurer
1821 les interfaces reseau ou editer directement les fichiers."
1822 </label>
1823 </text>
1824 </frame>
1825 </vbox>
1826 </window>
1829 # Interface status with ifconfig without arguments to show all
1830 # active connections.
1832 export IFCONFIG="
1833 <window title=\"Network status\" icon-name=\"network-wire\">
1834 <vbox>
1835 $(tab_status)
1836 <hbox>
1837 <button>
1838 <input file icon=\"gtk-close\"></input>
1839 <action type=\"closewindow\">IFCONFIG</action>
1840 </button>
1841 </hbox>
1842 </vbox>
1843 </window>"
1845 # The main dialog with notebook, start/stop buttons and all options.
1846 # Note that /etc/network.conf is seded when an interface is activated.
1848 head='
1849 <window title="SliTaz Netbox Manager" icon-name="network-wired">
1850 <vbox>
1852 <hbox>
1853 <text use-markup="true">
1854 <label>"<b>Network/Server Manager</b>"</label>
1855 </text>
1856 <pixmap>
1857 <input file>/usr/share/pixmaps/netbox.png</input>
1858 </pixmap>
1859 </hbox>
1861 bottom='
1862 <hbox>
1863 <button>
1864 <label>Wireless manager</label>
1865 <input file icon="network-wireless"></input>
1866 <action>wifibox &</action>
1867 </button>
1868 <button>
1869 <label>Refresh list</label>
1870 <input file icon="reload"></input>
1871 <action>refresh:INTERFACE_LIST</action>
1872 </button>
1873 <button>
1874 <label>Full status</label>
1875 <input file icon="dialog-information"></input>
1876 <action type="launch">IFCONFIG</action>
1877 </button>
1878 <button help>
1879 <label>Help</label>
1880 <action type="launch">HELP</action>
1881 </button>
1882 <button>
1883 <label>Quit</label>
1884 <input file icon="exit"></input>
1885 <action type="exit">Exit</action>
1886 </button>
1887 </hbox>
1889 </vbox>
1890 </window>
1893 NET_BOX="${head}$(tab_main)${bottom}"
1895 export NET_BOX
1897 # TODO: Modules(Network kernel modules)
1899 # Only root can configure network.
1900 check_root
1902 # Configure and connect if button Connect was pressed.
1903 if ! grep -qs ^name /etc/ppp/options ; then
1904 # Generate /etc/ppp/options
1905 cat > /etc/ppp/options << _EOT_
1906 plugin rp-pppoe.so
1907 name provider-ID
1908 noipdefault
1909 defaultroute
1910 mtu 1492
1911 mru 1492
1912 lock
1913 _EOT_
1914 # Generate /etc/ppp/pap-secrets
1915 cat > /etc/ppp/pap-secrets << _EOT_
1916 # Secrets for authentication using PAP
1917 # client server secret IP addresses
1918 _EOT_
1919 # Generate /etc/ppp/chap-secrets
1920 cat > /etc/ppp/chap-secrets << _EOT_
1921 # Secrets for authentication using CHAP
1922 # client server secret IP addresses
1923 _EOT_
1924 fi
1925 gtkdialog --center --program=NET_BOX | grep -a 'EXIT="restart"' && continue
1926 exit 0
1927 done