slitaz-tools view tinyutils/tazctrlbox @ 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 3aacdb8b9205
children aa61397a4475
line source
1 #!/bin/sh
2 #
3 # SliTaz Control Box is a tool to configure and manage a SliTaz system.
4 # The script use GTKdialog for the UI interface, some shell functions
5 # are called by argument. Individual window dialog are put into
6 # functions.
7 #
8 # (C) GNU gpl v3 - SliTaz GNU/Linux 2008.
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
11 VERSION=1.0
13 # Get init configuration.
14 . /etc/rcS.conf
16 # Tazctrlbox is only for root.
17 if test $(id -u) != 0 ; then
18 exec subox $0
19 exit 0
20 fi
22 # By default autologin is not configured on installed system
23 if ! grep -q 'auto_login' /etc/slim.conf; then
24 echo '# Auto login default user' >> /etc/slim.conf
25 echo 'auto_login no' >> /etc/slim.conf
26 fi
28 # Change Grub menu.lst timeout.
29 sed_grub_timeout()
30 {
31 CURRENT=`cat /boot/grub/menu.lst | grep ^timeout | cut -d " " -f2`
32 sed -i s/"timeout $CURRENT"/"timeout $GRUB_TIMEOUT"/ /boot/grub/menu.lst
33 }
35 # Change Grub menu.lst timeout.
36 sed_grub_color()
37 {
38 CURRENT=`cat /boot/grub/menu.lst | grep ^color | cut -d " " -f2-3`
39 sed -i s#"color $CURRENT"#"color $GRUB_COLOR"# /boot/grub/menu.lst
40 }
42 # Set checked fs on boot.
43 sed_check_fs()
44 {
45 sed -i s#"CHECK_FS=\"$CHECK_FS\""#"CHECK_FS=\"$NEW_CHECK_FS\""# \
46 /etc/rcS.conf
47 }
49 # Set loaded modules on boot.
50 sed_load_modules()
51 {
52 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$NEW_MODULES\""/ \
53 /etc/rcS.conf
54 }
56 # Set daemons to run on boot.
57 sed_run_daemons()
58 {
59 sed -i s/"RUN_DAEMONS=\"$RUN_DAEMONS\""/"RUN_DAEMONS=\"$NEW_DAEMONS\""/ \
60 /etc/rcS.conf
61 }
63 # Get user list
64 get_users()
65 {
66 for i in `cat /etc/passwd | cut -d ":" -f 1`
67 do
68 if [ -d /home/$i ]; then
69 login=$i
70 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
71 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
72 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | sed s/,,,//`
73 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
74 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
75 echo "system-users | $login | $uid:$gid | $name | $home | $shell"
76 fi
77 done
78 }
80 # Remove a user or change passwd.
81 manage_user()
82 {
83 export MANAGE_DIALOG="
84 <window title=\"Manage user: $USER\" icon-name=\"computer\">
85 <vbox>
86 <vbox>
87 <text wrap=\"false\" width-chars=\"34\">
88 <label>\"
89 Login name: $USER
90 \"</label>
91 </text>
92 </vbox>
93 <hbox>
94 <text wrap=\"false\">
95 <label>\"New password:\"</label>
96 </text>
97 <entry invisible_char=\"*\" visibility=\"false\" max_length=\"8\">
98 <variable>PASSWD</variable>
99 </entry>
100 <button>
101 <label>Change</label>
102 <input file icon=\"forward\"></input>
103 <action>echo \"$USER:$PASSWD\" | chpasswd</action>
104 <action type=\"closewindow\">MANAGE_USER</action>
105 </button>
106 </hbox>
107 <hbox>
108 <button>
109 <label>Delete user</label>
110 <input file icon=\"gtk-delete\"></input>
111 <action>deluser $USER</action>
112 <action type=\"closewindow\">MANAGE_USER</action>
113 </button>
114 <button cancel>
115 <action type=\"closewindow\">MANAGE_USER</action>
116 </button>
117 </hbox>
118 </vbox>
119 </window>
120 "
121 gtkdialog --center --program=MANAGE_DIALOG >/dev/null
122 }
124 # Add a new user.
125 add_user()
126 {
127 export ADD_USER_DIALOG='
128 <window title="New user" icon-name="gtk-add">
129 <vbox>
130 <vbox>
131 <text wrap="false" width-chars="34">
132 <label>"
133 New account information
134 "</label>
135 </text>
136 </vbox>
137 <hbox>
138 <text wrap="false">
139 <label>"Login: "</label>
140 </text>
141 <entry>
142 <variable>NEW_USER</variable>
143 </entry>
144 </hbox>
145 <hbox>
146 <text wrap="false">
147 <label>"Password:"</label>
148 </text>
149 <entry invisible_char="*" visibility="false" max_length="8">
150 <variable>PASSWD</variable>
151 </entry>
152 </hbox>
153 <hbox>
154 <button ok>
155 <action>adduser -D $NEW_USER</action>
156 <action>echo "$NEW_USER:$PASSWD" | chpasswd</action>
157 <action>adduser -G audio $NEW_USER</action>
158 <action>rmdir /home/$NEW_USER</action>
159 <action>cp -a /etc/skel /home/$NEW_USER</action>
160 <action>cp /root/.xinitrc /home/$NEW_USER</action>
161 <action>chown -R $NEW_USER:$NEW_USER /home/$NEW_USER</action>
162 <action type="closewindow">MANAGE_USER</action>
163 </button>
164 <button cancel>
165 <action type="closewindow">MANAGE_USER</action>
166 </button>
167 </hbox>
168 </vbox>
169 </window>
170 '
171 gtkdialog --center --program=ADD_USER_DIALOG >/dev/null
172 }
174 # i18n functions
175 list_locales()
176 {
177 cd /usr/share/i18n/locales
178 for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]`
179 do
180 echo "preferences-desktop-locale | $locale | UTF-8"
181 done
182 }
183 gen_utf8_locale()
184 {
185 rm -rf /usr/lib/locale/$LANGUAGE
186 localedef -i $LANGUAGE -c -f UTF-8 /usr/lib/locale/$LANGUAGE
187 # System configuration
188 echo "LANG=$LANGUAGE" > /etc/locale.conf
189 echo "LC_ALL=$LANGUAGE" >> /etc/locale.conf
190 }
192 # Main dialog with notebook.
193 #
194 export MAIN_DIALOG='
195 <window title="SliTaz Control Box" icon-name="computer">
196 <vbox>
198 <hbox>
199 <text use-markup="true">
200 <label>"<b>SliTaz Control Box</b>"</label>
201 </text>
202 <pixmap>
203 <input file>/usr/share/pixmaps/tazctrlbox.png</input>
204 </pixmap>
205 </hbox>
207 <notebook labels="Boot loader|Initialization|Login manager|Time|Language|Users">'
209 # GRUB
210 MAIN_DIALOG=${MAIN_DIALOG}"
211 <vbox>
212 <frame Grub boot loader>
213 <hbox>
214 <text wrap=\"false\">
215 <label>\"Timeout:\"</label>
216 </text>
217 <entry>
218 <input>cat /boot/grub/menu.lst | grep ^timeout | cut -d \" \" -f2</input>
219 <variable>GRUB_TIMEOUT</variable>
220 </entry>
221 <button>
222 <label>Change</label>
223 <input file icon=\"forward\"></input>
224 <action>$0 sed_grub_timeout</action>
225 </button>
226 </hbox>
227 <hbox>
228 <text wrap=\"false\">
229 <label>\"Color: \"</label>
230 </text>
231 <entry>
232 <input>cat /boot/grub/menu.lst | grep ^color | cut -d \" \" -f2-3</input>
233 <variable>GRUB_COLOR</variable>
234 </entry>
235 <button>
236 <label>Change</label>
237 <input file icon=\"forward\"></input>
238 <action>$0 sed_grub_color</action>
239 </button>
240 </hbox>
241 <hbox>
242 <text wrap=\"false\">
243 <label>\"Configuration file:\"</label>
244 </text>
245 <button>
246 <label>/boot/grub/menu.lst</label>
247 <input file icon=\"accessories-text-editor\"></input>
248 <action>leafpad /boot/grub/menu.lst</action>
249 <action>refresh:GRUB_COLOR</action>
250 <action>refresh:GRUB_TIMEOUT</action>
251 </button>
252 </hbox>
253 </frame>
254 </vbox>"
255 # Init script
256 MAIN_DIALOG=${MAIN_DIALOG}"
257 <vbox>
258 <frame rcS init scripts>
259 <hbox>
260 <text wrap=\"false\">
261 <label>\"Check filesystems:\"</label>
262 </text>
263 <entry>
264 <input>echo $CHECK_FS</input>
265 <variable>NEW_CHECK_FS</variable>
266 </entry>
267 <button>
268 <label>Change</label>
269 <input file icon=\"forward\"></input>
270 <action>$0 sed_check_fs</action>
271 </button>
272 </hbox>
273 <hbox>
274 <text wrap=\"false\">
275 <label>\"Load modules: \"</label>
276 </text>
277 <entry>
278 <input>echo $LOAD_MODULES</input>
279 <variable>NEW_MODULES</variable>
280 </entry>
281 <button>
282 <label>Change</label>
283 <input file icon=\"forward\"></input>
284 <action>$0 sed_load_modules</action>
285 </button>
286 </hbox>
287 <hbox>
288 <text wrap=\"false\">
289 <label>\"Run daemons: \"</label>
290 </text>
291 <entry>
292 <input>echo $RUN_DAEMONS</input>
293 <variable>NEW_DAEMONS</variable>
294 </entry>
295 <button>
296 <label>Change</label>
297 <input file icon=\"forward\"></input>
298 <action>$0 sed_run_daemons</action>
299 </button>
300 </hbox>
301 <hbox>
302 <text wrap=\"false\">
303 <label>\"Add local commands:\"</label>
304 </text>
305 <button>
306 <label>/etc/init.d/local.sh</label>
307 <input file icon=\"accessories-text-editor\"></input>
308 <action>leafpad /etc/init.d/local.sh</action>
309 </button>
310 </hbox>
311 </frame>
312 </vbox>"
313 # Slim login
314 MAIN_DIALOG=${MAIN_DIALOG}'
315 <vbox>
316 <frame Slim settings>
317 <hbox>
318 <text wrap="false">
319 <label>"Sessions: "</label>
320 </text>
321 <entry>
322 <input>cat /etc/slim.conf | grep ^session | sed s/"sessions. *"//</input>
323 <variable>SLIM_SESSIONS</variable>
324 </entry>
325 <button>
326 <label>Change</label>
327 <input file icon="forward"></input>
328 <action>sed -i "s/^sessions.*/sessions $SLIM_SESSIONS/" /etc/slim.conf</action>
329 </button>
330 </hbox>
331 <hbox>
332 <text wrap="false">
333 <label>"Default user: "</label>
334 </text>
335 <entry>
336 <input>cat /etc/slim.conf | grep ^default_user | sed s/"default_user. *"//</input>
337 <variable>SLIM_DEF_USER</variable>
338 </entry>
339 <button>
340 <label>Change</label>
341 <input file icon="forward"></input>
342 <action>sed -i "s/^default_user.*/default_user $SLIM_DEF_USER/" /etc/slim.conf</action>
343 </button>
344 </hbox>
345 <hbox>
346 <text wrap="false">
347 <label>"Auto login (yes|no): "</label>
348 </text>
349 <entry max_length="3">
350 <input>cat /etc/slim.conf | grep ^auto_login | sed s/"auto_login. *"//</input>
351 <variable>SLIM_AUTO_LOGIN</variable>
352 </entry>
353 <button>
354 <label>Change</label>
355 <input file icon="forward"></input>
356 <action>sed -i "s/^auto_login.*/auto_login $SLIM_AUTO_LOGIN/" /etc/slim.conf</action>
357 </button>
358 </hbox>
359 <hbox>
360 <text wrap="false">
361 <label>"Theme:"</label>
362 </text>
363 <combobox>
364 <variable>NEW_SLIM_THEME</variable>'
365 # List all installed Slim themes.
366 for dir in $(ls /usr/share/slim/themes)
367 do
368 THEME_ITEMS="<item>$dir</item>"
369 MAIN_DIALOG=${MAIN_DIALOG}${THEME_ITEMS}
370 done
371 MAIN_DIALOG=${MAIN_DIALOG}'
372 </combobox>
373 <button>
374 <label>Preview</label>
375 <input file icon="video-display"></input>
376 <action>slim -p /usr/share/slim/themes/$NEW_SLIM_THEME &</action>
377 </button>
378 <button>
379 <label>Change</label>
380 <input file icon="forward"></input>
381 <action>sed -i "s/^current_theme.*/current_theme $NEW_SLIM_THEME/" /etc/slim.conf</action>
382 <action>refresh:SLIM_THEME</action>
383 </button>
384 </hbox>
385 <hbox>
386 <text wrap="false">
387 <label>"Configuration file:"</label>
388 </text>
389 <button>
390 <label>/etc/slim.conf</label>
391 <input file icon="accessories-text-editor"></input>
392 <action>leafpad /etc/slim.conf</action>
393 <action>refresh:SLIM_SESSIONS</action>
394 <action>refresh:SLIM_DEF_USER</action>
395 </button>
396 </hbox>
397 </frame>
398 </vbox>'
399 # Time setting.
400 MAIN_DIALOG=${MAIN_DIALOG}'
401 <vbox>
402 <frame Date and time>
403 <hbox>
404 <text wrap="false">
405 <label>"System time: "</label>
406 </text>
407 <entry editable="false">
408 <input>LC_ALL=C date</input>
409 <variable>DATE</variable>
410 </entry>
411 <button>
412 <label>Sync online</label>
413 <input file icon="reload"></input>
414 <action>rdate -s tick.greyware.com</action>
415 <action>refresh:DATE</action>
416 <action>refresh:HWTIME</action>
417 </button>
418 </hbox>
419 <hbox>
420 <text wrap="false">
421 <label>"Hardware time:"</label>
422 </text>
423 <entry editable="false">
424 <input>LC_ALL=C hwclock</input>
425 <variable>HWTIME</variable>
426 </entry>
427 <button>
428 <label>Set from system</label>
429 <input file icon="reload"></input>
430 <action>hwclock -w -u</action>
431 <action>refresh:HWTIME</action>
432 <action>refresh:DATE</action>
433 </button>
434 </hbox>
435 <hbox>
436 <text wrap="true">
437 <label>"Timezone: "</label>
438 </text>
439 <entry>
440 <input>cat /etc/TZ</input>
441 <variable>NEW_TZ</variable>
442 </entry>
443 <button>
444 <label>Change</label>
445 <input file icon="forward"></input>
446 <action>echo "$NEW_TZ" > /etc/TZ</action>
447 </button>
448 </hbox>
449 </frame>
450 </vbox>'
451 # Language setting.
452 MAIN_DIALOG=${MAIN_DIALOG}"
453 <vbox>
454 <tree>
455 <width>600</width><height>210</height>
456 <variable>LANGUAGE</variable>
457 <label>Language|Charmap</label>
458 <input icon_column=\"0\">$0 list_locales</input>
459 <action>$0 gen_utf8_locale</action>
460 </tree>
461 <hbox>
462 <text width-chars=\"60\">
463 <label>
464 \"To change system language you can double-click on the locale name.\"
465 </label>
466 </text>
467 <button>
468 <label>Keymap</label>
469 <input file icon=\"input-keyboard\"></input>
470 <action>tazkeymap &</action>
471 </button>
472 </hbox>
473 </vbox>"
474 # Display users list throught get_users.
475 MAIN_DIALOG=${MAIN_DIALOG}"
476 <vbox>
477 <tree>
478 <width>600</width><height>210</height>
479 <variable>USER</variable>
480 <label>Login|uid:gid|Name|Home|SHell</label>
481 <input icon_column=\"0\">$0 get_users</input>
482 <action>$0 manage_user</action>
483 <action>refresh:USER</action>
484 </tree>
485 <hbox>
486 <text width-chars=\"60\">
487 <label>
488 \"To change passwords or delete users you can double-click on the user name.\"
489 </label>
490 </text>
491 <button>
492 <label>Add newuser</label>
493 <input file icon=\"gtk-add\"></input>
494 <action>$0 add_user</action>
495 <action>refresh:USER</action>
496 </button>
497 </hbox>
498 </vbox>"
499 export MAIN_DIALOG=${MAIN_DIALOG}'
500 </notebook>
502 <hbox>
504 <button>
505 <label>Network</label>
506 <input file icon="netbox"></input>
507 <action>netbox &</action>
508 </button>
509 <button>
510 <label>Wireless</label>
511 <input file icon="network-wireless"></input>
512 <action>wifibox &</action>
513 </button>
514 <button>
515 <label>Packages</label>
516 <input file icon="tazpkg"></input>
517 <action>tazpkgbox &</action>
518 </button>
519 <button>
520 <label>Hardware</label>
521 <input file icon="computer"></input>
522 <action>tazhw box &</action>
523 </button>
524 <button>
525 <label>Storage</label>
526 <input file icon="media-flash"></input>
527 <action>mountbox &</action>
528 </button>
529 <button>
530 <label>Exit</label>
531 <input file icon="exit"></input>
532 <action type="exit">Exit</action>
533 </button>
534 </hbox>
536 </vbox>
538 </window>'
540 # Script can be called with an arg to exec a function.
541 if [ -n "$1" ]; then
542 $1
543 else
544 gtkdialog --center --program=MAIN_DIALOG >/dev/null
545 fi
547 exit 0