slitaz-tools view tinyutils/serverbox @ rev 516

tazx: incorrect tux; slitaz installer creates 1008 user
author Rohit Joshi <jozee@slitaz.org>
date Wed Nov 10 20:26:12 2010 -0500 (2010-11-10)
parents ca6804d9b56b
children 7fdb586cf6bf
line source
1 #!/bin/sh
2 #
3 # Gtkdialog box to manage servers.
4 # Please use tab to indent.
6 VERSION=20100315
8 . /usr/lib/slitaz/gui_functions
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 }
20 #
21 # Status servers
22 #
23 tab_status_servers()
24 {
25 local servers
26 servers="dropbear sshd inetd dhcpd dnsd named rsync httpd mbd vnc pppd knock"
27 cat <<EOT
28 <frame Servers>
29 <text wrap="false" width-chars="58">
30 <input>for i in $servers; do ps ww | grep \$i | grep -v grep | fold -s; done</input>
31 </text>
32 </frame>
33 EOT
34 }
36 data_status()
37 {
38 cat <<EOT
39 ps Servers tab_status_servers
40 EOT
41 }
43 #
44 # Status
45 #
46 tab_status()
47 {
48 use_tab data_status
49 }
51 sshremote()
52 {
53 cat << EOT
54 <hbox>
55 <text use-markup="true">
56 <label>"<b>Remote :</b>"</label>
57 </text>
58 <entry>
59 <variable>$2</variable>
60 <default>user@elsewhere</default>
61 </entry>
62 <button>
63 <input file icon="utilities-terminal"></input>
64 <label>Connect</label>
65 <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>
66 </button>
67 <button>
68 <input file icon="go-up"></input>
69 <label>Send key</label>
70 <action>$xterm -geometry 80x10 -title "send ssh key" -e "$0 call sendsshkey \$$2; echo -e \"----\nENTER to continue...\" && read close"</action>
71 </button>
72 </hbox>
73 EOT
74 }
75 #
76 # Dropbear client & server
77 #
78 tab_dropbear()
79 {
80 . /etc/daemons.conf
81 set -- $DROPBEAR_OPTIONS
82 while [ -n "$2" ]; do
83 [ "$1" = "-b" ] && DROPBEAR_BANNER="$2" && break
84 shift
85 done
87 cat <<EOT
88 <frame Dropbear>
89 $(helpdaemon dropbear 80x30 DROPBEAR_OPTIONS DROPBEAR_OPTS)
90 $(datafile /etc/dropbear/banner DROPBEAR_BANNER 'Banner :')
91 $(sshremote DROPBEAR_PEER 'dbclient -i /etc/dropbear/dropbear_rsa_host_key')
92 <hbox>
93 $(startstopdaemon dropbear)
94 </hbox>
95 </frame>
96 EOT
97 }
99 #
100 # OpenSSH client & server
101 #
102 tab_openssh()
103 {
104 cat <<EOT
105 <frame OpenSSH>
106 $(helpdaemon sshd 80x30 OPENSSH_OPTIONS OPENSSH_OPTS 8 nohelp)
107 $(configfile /etc/ssh/sshd_config OPENSSH_CONF '5 sshd_config')
108 $(sshremote OPENSSH_PEER 'ssh -i /etc/ssh/ssh_host_rsa_key')
109 <hbox>
110 $(startstopdaemon openssh)
111 </hbox>
112 </frame>
113 EOT
114 }
116 data_sshd()
117 {
118 cat <<EOT
119 dropbear Dropbear tab_dropbear
120 sshd OpenSSH tab_openssh
121 EOT
122 }
124 #
125 # SSH tab
126 #
127 tab_sshd()
128 {
129 use_tab data_sshd
130 }
132 #
133 # Busybox Inetd
134 #
135 tab_inetd()
136 {
137 cat <<EOT
138 <frame Inetd (busybox)>
139 $(helpdaemon inetd 60x14 INETD_OPTIONS INETD_OPTS)
140 $(configfile /etc/inetd.conf INETD_CONF)
141 <hbox>
142 EOT
143 for i in $(grep bin /etc/inetd.conf | awk '{ print $6}'); do
144 i=$(basename $i)
145 helpbutton $i 60x19 $i
146 done
147 cat <<EOT
148 $(startstopdaemon inetd)
149 </hbox>
150 </frame>
151 EOT
152 }
154 #
155 # ZeroConf
156 #
157 tab_zcip()
158 {
160 . /etc/daemons.conf
161 if [ -x /sbin/zcip -a -z "$ZCIP_OPTIONS" ]; then
162 ZCIP_OPTIONS="eth0 /etc/zcip.script"
163 cat >> /etc/daemons.conf <<EOT
164 # ZeroConf options
165 ZCIP_OPTIONS="$ZCIP_OPTIONS"
167 EOT
168 fi
169 cat <<EOT
170 <frame Zcip (busybox)>
171 $(helpdaemon zcip 60x14 ZCIP_OPTIONS ZCIP_OPTS)
172 $(datafile /etc/zcip.script CZIP_SCRIPT 'Script :')
173 <hbox>
174 $(startstopdaemon zcip)
175 </hbox>
176 </frame>
177 EOT
178 }
180 #
181 # Dhcpd ISC
182 #
183 tab_isc_dhcpd()
184 {
185 cat <<EOT
186 <frame Dhcpd (ISC)>
187 $(helpdaemon dhcpd 60x14 DHCPD_OPTIONS DHCPD_OPTS)
188 $(configfile /etc/dhcpd.conf DHCPD_CONF)
189 <hbox>
190 $(startstopdaemon dhcpd dhcp)
191 </hbox>
192 </frame>
193 EOT
194 }
196 #
197 # Dhcpd Busybox
198 #
199 tab_udhcpd()
200 {
201 cat <<EOT
202 <frame Udhcpd (busybox)>
203 $(helpdaemon udhcpd 60x14 UDHCPD_OPTIONS UDHCPD_OPTS)
204 $(configfile /etc/udhcpd.conf UDHCPD_CONF)
205 <hbox>
206 $(startstopdaemon udhcpd busybox)
207 </hbox>
208 </frame>
209 EOT
210 }
212 data_dhcpd()
213 {
214 cat <<EOT
215 udhcpd Udhcpd tab_udhcpd
216 dhcpd Dhcpd tab_isc_dhcpd
217 dnsmasq DNSmasq tab_dnsmasq
218 EOT
219 }
221 #
222 # dhcpd tab
223 #
224 tab_dhcpd()
225 {
226 use_tab data_dhcpd
227 }
229 #
230 # PXE forwarder
231 #
232 tab_gpxe()
233 {
234 cat <<EOT
235 <frame PXE forwarder>
236 <hbox>
237 <text use-markup="true">
238 <label>"<b>WEB boot URL(s) :</b>"</label>
239 </text>
240 </hbox>
241 <hbox>
242 <entry editable="true">
243 <default>
244 "$(dd bs=1 skip=5 count=255 if=/usr/share/boot/gpxe.pxe 2> /dev/null | strings)"
245 </default>
246 <variable>WEB_PXE</variable>
247 </entry>
248 </hbox>
249 <hbox>
250 $(wikibutton http://doc.slitaz.org/en:guides:pxe)
251 <button>
252 <input file icon="go-jump"></input>
253 <label>Install</label>
254 <action>
255 echo -n "\$WEB_PXE" | cat - /dev/zero | \
256 dd conv=notrunc bs=1 seek=5 count=255 of=/usr/share/boot/gpxe.pxe
257 </action>
258 <action>
259 sed -i "s|tftpd -r .*\$|tftpd -r /usr/share/boot|" /etc/inetd.conf
260 </action>
261 <action> sed -i "/^boot_file/d" \$UDHCPD_CONF </action>
262 <action> echo "boot_file gpxe.pxe" >> \$UDHCPD_CONF </action>
263 <action> /etc/init.d/inetd restart </action>
264 <action> /etc/init.d/udhcpd restart </action>
265 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)inetd \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
266 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)udhcpd \?\\(.*\\)\\"/RUN_DAEMONS=\\"\1\2\\"/" /etc/rcS.conf</action>
267 <action>sed -i "s/RUN_DAEMONS=\\"\\(.*\\)\\"/RUN_DAEMONS=\\"udhcpd inetd \1\\"/" /etc/rcS.conf</action>
268 </button>
269 </hbox>
270 </frame>
271 EOT
272 }
274 #
275 # PXE server
276 #
277 tab_pxelinux()
278 {
279 cat <<EOT
280 <frame PXElinux>
281 <hbox>
282 <text wrap="true">
283 <label>
284 "Launch Dhcpd and Inetd with Tftpd to start the PXE service."
285 </label>
286 </text>
287 </hbox>
288 <hbox>
289 <text use-markup="true">
290 <label>"<b>Configuration :</b>"</label>
291 </text>
292 <entry editable="false">
293 <default>
294 $(grep bin/tftpd /etc/inetd.conf | awk '{ print $NF }')/pxelinux.cfg/default
295 </default>
296 <variable>PXE_CONF</variable>
297 </entry>
298 <button>
299 <input file icon="accessories-text-editor"></input>
300 <action>dir=\$(dirname \$PXE_CONF); [ -d \$dir ] || mkdir -p \$dir</action>
301 <action>lzma d /usr/share/boot/pxelinux.0.lzma \$(dirname \$PXE_CONF)/../pxelinux.0</action>
302 <action>sed -i "/^boot_file/d" \$UDHCPD_CONF</action>
303 <action>echo "boot_file pxelinux.0" >> \$UDHCPD_CONF</action>
304 <action>grep -q "^siaddr" \$UDHCPD_CONF || echo "siaddr \$(ifconfig \$INTERFACE | grep inet.ad | cut -d: -f2 | cut -d\ -f1)" >> \$UDHCPD_CONF</action>
305 <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>
306 <action type="lauch">leafpad \$PXE_CONF</action>
307 </button>
308 </hbox>
309 <hbox>
310 $(wikibutton http://doc.slitaz.org/en:guides:pxe)
311 <button>
312 <input file icon="system-file-manager"></input>
313 <label>Network boot files</label>
314 <action>$xterm -geometry 100x25 -title "Network boot files (q to quit)" -e "find \$(dirname \$(dirname \$PXE_CONF)) -exec ls -ld {} \; | less"</action>
315 </button>
316 </hbox>
317 </frame>
318 EOT
319 }
321 data_pxe()
322 {
323 [ -f /usr/share/boot/pxelinux.0.lzma ] && cat <<EOT
324 true PXElinux tab_pxelinux
325 EOT
326 [ -f /usr/share/boot/gpxe.pxe ] && cat <<EOT
327 true PXE\ forwarder tab_gpxe
328 EOT
329 }
331 #
332 # PXE
333 #
334 tab_pxe()
335 {
336 use_tab data_pxe
337 }
339 #
340 # Busybox dnsd
341 #
342 tab_dnsd()
343 {
344 cat <<EOT
345 <frame Dnsd (busybox master dns)>
346 $(helpdaemon dnsd 80x15 DNSD_OPTIONS DNSD_OPTS)
347 $(configfile /etc/dnsd.conf DNSD_CONF)
348 <hbox>
349 $(startstopdaemon dnsd busybox)
350 </hbox>
351 </frame>
352 EOT
353 }
355 #
356 # ISC Bind
357 #
358 tab_named()
359 {
360 cat <<EOT
361 <frame Named (ISC bind)>
362 $(helpdaemon named 80x10 NAMED_OPTIONS NAMED_OPTS)
363 $(configfile /etc/bind/named.conf.local NAMED_CONF)
364 <hbox>
365 $(startstopdaemon named bind)
366 </hbox>
367 </frame>
368 EOT
369 }
371 #
372 # DNSmasq
373 #
374 tab_dnsmasq()
375 {
376 cat <<EOT
377 <frame DNSmasq (DNS/DHCP/TFTP)>
378 $(helpdaemon dnsmasq 100x34 DNSMASQ_OPTIONS DNSMASQ_OPTS)
379 $(configfile /etc/dnsmasq.conf DNSMASQ_CONF)
380 <hbox>
381 $(startstopdaemon dnsmasq)
382 </hbox>
383 </frame>
384 EOT
385 }
387 data_dns()
388 {
389 cat <<EOT
390 dnsd Dnsd tab_dnsd
391 named Named tab_named
392 dnsmasq DNSmasq tab_dnsmasq
393 #TODO sheerdns Sheerdns tab_sheerdns
394 EOT
395 }
397 #
398 # dns tab
399 #
400 tab_dns()
401 {
402 use_tab data_dns
403 }
405 #
406 # rsync server
407 #
408 tab_rsync()
409 {
410 cat <<EOT
411 <frame Rsync>
412 $(helpdaemon rsync 80x30 RSYNCD_OPTIONS RSYNCD_OPTS 1)
413 $(configfile /etc/rsyncd.conf RSYNCD_CONF)
414 $(datafile /etc/rsyncd.secrets RSYNCD_SECRETS 'Secrets file :')
415 <hbox>
416 $(startstopdaemon rsyncd rsync)
417 </hbox>
418 </frame>
419 EOT
420 }
422 php_ini()
423 {
424 [ -f /etc/php.ini ] && cat <<EOT
425 <frame PHP>
426 $(configfile /etc/php.ini PHP_CONF)
427 </frame>
428 EOT
429 }
431 #
432 # Apache server
433 #
434 tab_apache()
435 {
436 cat <<EOT
437 <frame Apache>
438 $(configfile /etc/apache/httpd.conf HTTPD_CONF)
439 $(php_ini)
440 <hbox>
441 $(startstopdaemon apache)
442 </hbox>
443 </frame>
444 EOT
445 }
447 #
448 # Lighttpd server
449 #
450 tab_lighttpd()
451 {
452 cat <<EOT
453 <frame Lighttpd>
454 $(helpdaemon lighttpd 80x15 LIGHTTPD_OPTIONS LIGHTTPD_OPTS)
455 $(configfile /etc/lighttpd/lighttpd.conf LIGHTTPD_CONF)
456 $(php_ini)
457 <hbox>
458 $(startstopdaemon lighttpd)
459 </hbox>
460 </frame>
461 EOT
462 }
464 #
465 # Busybox httpd server
466 #
467 tab_httpd()
468 {
469 cat <<EOT
470 <frame httpd (busybox)>
471 $(helpdaemon httpd 80x30 HTTPD_OPTIONS HTTPD_OPTS)
472 $(configfile /etc/httpd.conf HTTPD_CONF)
473 $(php_ini)
474 <hbox>
475 $(startstopdaemon httpd busybox)
476 </hbox>
477 </frame>
478 EOT
479 }
481 data_http()
482 {
483 cat <<EOT
484 /etc/apache/httpd.conf Apache tab_apache
485 lighttpd Lighttpd tab_lighttpd
486 /etc/httpd.conf Busybox\ httpd tab_httpd
487 EOT
488 }
490 #
491 # http tab
492 #
493 tab_http()
494 {
495 use_tab data_http
496 }
498 #
499 # Samba servers
500 #
501 tab_wins()
502 {
503 cat <<EOT
504 <frame Samba: smbd & nmbd>
505 $(configfile /etc/samba/smb.conf SMBD_CONF)
506 <hbox>
507 <button>
508 <label>Reload</label>
509 <input file icon="reload"></input>
510 <action>/etc/init.d/samba reload</action>
511 </button>
512 $(startstopdaemon samba)
513 </hbox>
514 </frame>
515 EOT
516 }
518 #
519 # x11vnc
520 #
521 tab_vnc()
522 {
523 cat <<EOT
524 <frame x11vnc>
525 $(helpdaemon x11vnc 80x30 X11VNC_OPTIONS X11VNC_OPTS)
526 <hbox>
527 <text use-markup="true">
528 <label>"<b>New password</b>"</label>
529 </text>
530 <entry>
531 <variable>X11VNC_PASSWD</variable>
532 </entry>
533 <button>
534 <input file icon="reload"></input>
535 <label>Update</label>
536 <action>x11vnc -storepasswd \$X11VNC_PASSWD /etc/vnc.secret</action>
537 </button>
538 </hbox>
539 <hbox>
540 $(startstopdaemon x11vnc)
541 </hbox>
542 </frame>
543 EOT
544 }
546 #
547 # knock server
548 #
549 tab_knockd()
550 {
551 cat <<EOT
552 <frame Knockd: trigger backdoors>
553 $(helpdaemon knockd 80x15 KNOCK_OPTIONS KNOCK_OPTS)
554 $(configfile /etc/knockd.conf KNOCKD_CONF)
555 <hbox>
556 $(startstopdaemon knockd knock)
557 </hbox>
558 </frame>
559 EOT
560 }
562 data_servers()
563 {
564 local $pxe
565 pxe="#"
566 [ -x /usr/bin/tftpd -a -x /usr/sbin/udhcpd ] && pxe="inetd"
567 [ -x /usr/sbin/dnsmasq ] && pxe="true"
568 [ -f /usr/share/boot/pxelinux.0.lzma -o /usr/share/boot/gpxe.pxe ] || pxe="#"
569 cat <<EOT
570 $([ -x /usr/sbin/dropbear -o -x /usr/sbin/sshd ] && echo "true" ||
571 echo "#") SSH tab_sshd
572 $([ -x /usr/sbin/lighttpd -o -x /usr/bin/httpd ] && echo "true" ||
573 echo "#") HTTP tab_http
574 rsync Rsync tab_rsync
575 smbd SAMBA tab_wins
576 inetd Inetd tab_inetd
577 zcip ZeroConf tab_zcip
578 $([ -x /usr/sbin/udhcpd -o -x /usr/sbin/dhcpd -o -x /usr/sbin/dnsmasq ] &&
579 echo "true" ||
580 echo "#") DHCP tab_dhcpd
581 $pxe PXE tab_pxe
582 dnsmasq tftpd tab_dnsmasq
583 $([ -x /usr/sbin/dnsd -o -x /usr/sbin/named -o -x /usr/sbin/dnsmasq ] &&
584 echo "true" ||
585 echo "#") DNS tab_dns
586 x11vnc VNC tab_vnc
587 knockd Knock tab_knockd
588 #TODO+callback pppd Pppd tab_pppd
589 #TODO pptpd PoPToP tab_poptop
590 #TODO squid *sql openldap
591 EOT
592 }
594 #
595 # Servers tab
596 #
597 tab_servers()
598 {
599 use_tab data_servers
600 }
602 #
603 # Firewall tab
604 #
605 tab_firewall()
606 {
607 cat <<EOT
608 <frame Iptables>
609 $(configfile /etc/firewall.conf IPTABLES_CONF)
610 <hbox>
611 $(helpbutton iptables 80x30)
612 $(manbutton 8 iptables)
613 $(webbutton iptables)
614 <button>
615 <label>Load</label>
616 <input file icon="reload"></input>
617 <action>cat \$IPTABLES_CONF | /sbin/iptables-restore</action>
618 </button>
619 <button>
620 <label>Save</label>
621 <input file icon="go-jump"></input>
622 <action>/sbin/iptables-save > \$IPTABLES_CONF</action>
623 </button>
624 </hbox>
625 </frame>
626 EOT
627 }
629 #
630 # knock client
631 #
632 tab_knock()
633 {
634 cat <<EOT
635 <frame Knock>
636 <hbox>
637 <text use-markup="true">
638 <label>"<b>Options : </b>"</label>
639 </text>
640 <entry editable="true">
641 <variable>KNOCK_OPTS</variable>
642 <default>myserver.example.com 123:tcp 456:udp 789:tcp</default>
643 </entry>
644 </hbox>
645 <hbox>
646 $(helpbutton knock 80x12)
647 <button>
648 <label>Start</label>
649 <input file icon="forward"></input>
650 <action>knock \$KNOCK_OPTS</action>
651 </button>
652 </hbox>
653 </frame>
654 EOT
655 }
657 data_main()
658 {
659 cat <<EOT
660 #program tab name function
661 true Servers tab_servers
662 iptables Firewall tab_firewall
663 knock Knock tab_knock
664 EOT
665 }
667 tab_main()
668 {
669 use_tab data_main
670 }
672 ######################################################
673 #
674 # Serverbox GUI
675 #
676 ######################################################
678 # Only root can configure server.
679 check_root
681 # English/French help dialog.
682 export HELP='
683 <window title="Network status" icon-name="network-wire">
684 <vbox>
685 <text use-markup="true">
686 <label>
687 "
688 <b>SliTaz - Serverbox</b>"
689 </label>
690 </text>
691 <frame English>
692 <text wrap="true" width-chars="58">
693 <label>
694 "Serverbox lets you manage and setup servers. First, install and
695 edit any configuration files. Then, start or stop the servers."
696 </label>
697 </text>
698 </frame>
699 <frame Francais>
700 <text wrap="true" width-chars="58">
701 <label>
702 "Serverbox peut demarrer ou arreter le reseau, configurer
703 les interfaces reseau ou editer directement les fichiers."
704 </label>
705 </text>
706 </frame>
707 </vbox>
708 </window>
709 '
711 # The main dialog with notebook, start/stop buttons and all options.
712 # Note that /etc/network.conf is seded when an interface is activated.
713 #
714 head='
715 <window title="SliTaz Server Manager" icon-name="network-wired">
716 <vbox>
718 <hbox>
719 <text use-markup="true">
720 <label>"<b>Server Manager</b>"</label>
721 </text>
722 <pixmap>
723 <input file>/usr/share/pixmaps/netbox.png</input>
724 </pixmap>
725 </hbox>
726 '
727 bottom='
728 <hbox>
729 <button help>
730 <label>Help</label>
731 <action type="launch">HELP</action>
732 </button>
733 <button>
734 <label>Quit</label>
735 <input file icon="exit"></input>
736 <action type="exit">Exit</action>
737 </button>
738 </hbox>
740 </vbox>
741 </window>
742 '
744 SERVER_BOX="${head}$(tab_main)${bottom}"
746 export SERVER_BOX
748 gtkdialog --center --program=SERVER_BOX >/dev/null