tazpanel view settings.cgi @ rev 346
hardware.cgi: add menu shortcut
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Feb 02 14:49:17 2013 +0100 (2013-02-02) |
parents | 1bccb526ff67 |
children | cc5d96a08b68 |
line source
1 #!/bin/sh
2 #
3 # System settings CGI interface: user, locale, keyboard, date. Since we
4 # don't have multiple pages here there is only one case used to get command
5 # values and the full content is followed directly.
6 #
7 # Copyright (C) 2011 SliTaz GNU/Linux - BSD License
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 TITLE=$(gettext 'TazPanel - Settings')
17 # Get system database. LDAP compatible.
18 getdb()
19 {
20 getent $1 2>/dev/null || cat /etc/$1
21 }
23 listdb()
24 {
25 for item in $(getdb $1 | cut -d ":" -f 1); do
26 echo "<option>$item</option>\n"
27 done
28 }
30 #
31 # Commands executed before page loading.
32 #
34 case " $(GET) " in
35 *\ do\ *)
36 # Assume no array support in httpd_helper.sh ;^)
37 users=""
38 groups=""
39 IFS="&"
40 for i in $QUERY_STRING ; do
41 case "$i" in
42 user=*) users="$users ${i#user=}" ;;
43 group=*) groups="$groups ${i#group=}" ;;
44 esac
45 done
46 unset IFS
47 for cmd in "Delete group" ; do
48 [ "$(GET do)" == "$(gettext "$cmd")" ] || continue
49 for group in $groups ; do
50 case "$cmd" in
51 Delete*) delgroup $group ;;
52 esac
53 done
54 done
55 for cmd in "Delete user" "Lock user" "Unlock user" \
56 "Change password" ; do
57 [ "$(GET do)" == "$(gettext "$cmd")" ] || continue # BUGGY
58 for user in $users ; do
59 case "$cmd" in
60 Delete*) deluser $user ;;
61 Lock*) passwd -l $user | log ;;
62 Unlock*) passwd -u $user | log ;;
63 Change*) echo "$user:$(GET password)" | chpasswd -m | log ;;
64 esac
65 done
66 done ;;
67 *\ addmember\ *)
68 addgroup $(GET member) $(GET group) ;;
69 *\ delmember\ *)
70 delgroup $(GET member) $(GET group) ;;
71 *\ addgroup\ *)
72 addgroup $(GET addgroup) ;;
73 *\ adduser\ *)
74 #
75 # Manage system user accounts
76 #
77 user=$(GET adduser)
78 passwd=$(GET passwd)
79 if [ -n "$user" ]; then
80 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$user $user
81 echo "$user:$passwd" | chpasswd -m | log
82 for g in audio cdrom floppy video tty
83 do
84 addgroup $user $g
85 done
86 fi ;;
87 *\ gen_locale\ *)
88 new_locale=$(GET gen_locale) ;;
89 *\ gen_keymap\ *)
90 new_keymap=$(GET gen_keymap) ;;
91 *\ apply_xorg_kbd\ *)
92 sed -i "s/XkbLayout.*/XkbLayout \" \"$(GET apply_xorg_kbd)\"/" \
93 /etc/X11/xorg.conf.d/40-Keyboard.conf ;;
94 *\ date\ *)
95 date $(GET month)$(GET day)$(GET hour)$(GET min)$(GET year).$(GET sec) ;;
96 *\ rdate\ *)
97 rdate -s tick.greyware.com ;;
98 *\ hwclock\ *)
99 hwclock -w -u ;;
100 *\ panel_pass*)
101 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF ;;
102 *\ style*)
103 sed -i s/'^STYLE.*'/"STYLE=\"$(GET style)\""/ $CONFIG
104 . $CONFIG ;;
105 *\ settz\ *)
106 GET tz > /etc/TZ ;;
107 esac
109 #
110 # Default xHTML content
111 #
112 xhtml_header
114 case " $(GET) " in
115 *\ group*)
116 #
117 # Groups management
118 #
119 cat <<EOT
120 <h3 id="groups">$(gettext 'Manage groups')</h3>
122 <form method="get" action="$SCRIPT_NAME">
123 <input type="hidden" name="groups" />
124 <div id="actions">
125 <div class="float-left">
126 $(gettext 'Selection:')
127 <input type="submit" name="do" value="$(gettext 'Delete group')" />
128 </div>
129 </div>
131 <table class="zebra outbox">
132 <thead>
133 <tr class="thead">
134 <td>$(gettext 'Group')</td>
135 <td>$(gettext 'Group ID')</td>
136 <td>$(gettext 'Members')</td>
137 </tr>
138 </thead>
139 </tbody>
140 EOT
141 for group in `getdb group | cut -d ":" -f 1`
142 do
143 IFS=':'
144 set -- $(getdb group | grep "^$group:")
145 unset IFS
146 gid=$3
147 members=$4
148 cat <<EOT
149 <tr>
150 <td><input type='checkbox' name='group' value='$group' />
151 <img src='$IMAGES/users.png' />$group</td>
152 <td>$gid</td>
153 <td>${members//,/, }</td>
154 </tr>
155 EOT
156 done
157 cat << EOT
158 </tbody>
159 </table>
160 </form>
162 <section>
163 <h4>$(gettext 'Add a new group')</h4>
165 <form method="get" action="$SCRIPT_NAME">
166 <input type="hidden" name="groups" />
167 <table>
168 <tr><td>$(gettext 'Group name:')</td>
169 <td><input type="text" name="addgroup" size="30" /></td>
170 <td>
171 <input type="submit" value="$(gettext 'Create group')" /></td></tr>
172 </table>
173 </form>
174 </section>
176 <section>
177 <h4>$(gettext 'Manage group membership')</h4>
179 <form method="get" action="$SCRIPT_NAME">
180 <input type="hidden" name="groups" />
181 <table>
182 <tr><td>$(gettext 'Group name:')</td>
183 <td><select name="group">
184 $(listdb group)
185 </select></td>
186 <td>$(gettext 'User name:')</td>
187 <td><select name="member">
188 $(listdb passwd)
189 </select></td></tr>
190 <tr><td colspan="4"><input type="submit" name="addmember" value="$(gettext 'Add user')" />
191 <input type="submit" name="delmember" value="$(gettext 'Remove user')" /></td></tr>
192 </table>
193 </form>
194 </section>
196 EOT
197 ;;
199 *\ user*)
200 #
201 # Users management
202 #
203 cat <<EOT
204 <h3 id="users">$(gettext 'Manage users')</h3>
206 <form method="get" action="$SCRIPT_NAME">
207 <div id="actions">
208 <div class="float-left">
209 $(gettext 'Selection:')
210 <input type="submit" name="do" value="$(gettext 'Delete user')" />
211 <input type="submit" name="do" value="$(gettext 'Lock user')" />
212 <input type="submit" name="do" value="$(gettext 'Unlock user')" />
213 </div>
214 </div>
216 <table class="zebra outbox">
217 <thead>
218 <tr class="thead">
219 <td>$(gettext 'Login')</td>
220 <td>$(gettext 'User ID')</td>
221 <td>$(gettext 'Name')</td>
222 <td>$(gettext 'Home')</td>
223 <td>$(gettext 'Shell')</td>
224 </tr>
225 </thead>
226 </tbody>
227 EOT
228 for login in `getdb passwd | cut -d ":" -f 1`
229 do
230 if [ -d /home/$login ]; then
231 colorlogin=$login
232 grep -qs "^$login:!" /etc/shadow &&
233 colorlogin="<span style='color: red;'>$login</span>"
234 IFS=':'
235 set -- $(getdb passwd | grep "^$login:")
236 unset IFS
237 uid=$3
238 gid=$4
239 name="$(echo $5 | sed s/,.*//)"
240 home="$6"
241 shell=$7
242 cat <<EOT
243 <tr>
244 <td><input type='checkbox' name='user' value='$login' />
245 <img src='$IMAGES/user.png' />$colorlogin</td>
246 <td>$uid:$gid</td>
247 <td>$name</td>
248 <td>$home</td>
249 <td>$shell</td>
250 </tr>
251 EOT
252 fi
253 done
254 cat << EOT
255 </tbody>
256 </table>
257 EOT
258 cat << EOT
259 <p>
260 $(gettext 'Password:')
261 <input type="password" name="password" />
262 <input type="submit" name="do" value="$(gettext 'Change password')" />
263 </p>
264 </form>
266 <section>
267 <h4>$(gettext 'Add a new user')</h4>
269 <form method="get" action="$SCRIPT_NAME">
270 <input type="hidden" name="user" />
271 <table>
272 <tr><td>$(gettext 'User login:')</td>
273 <td><input type="text" name="adduser" size="30" /></td></tr>
274 <tr><td>$(gettext 'User password:')</td>
275 <td><input type="password" name="passwd" size="30" /></td></tr>
276 <tr><td colspan="2">
277 <input type="submit" value="$(gettext 'Create user')" /></td></tr>
278 </table>
279 </form>
280 </section>
282 <section>
283 <h4>$(gettext 'Current user sessions')</h4>
285 <pre>$(who)</pre>
286 </section>
288 <section>
289 <h4>$(gettext 'Last user sessions')</h4>
291 <pre>$(last)</pre>
292 </section>
293 EOT
294 ;;
297 *\ locale*)
298 #
299 # Choose locale
300 #
301 LOADING_MSG="$(gettext 'Please wait...')"
302 loading_msg
303 cur_loc=$(locale | grep LANG | cut -d= -f2)
304 cat << EOT
305 <h3 id="locale">$(gettext 'Choose locale')</h3>
307 <p>$(gettext 'Current locale settings:')</p>
308 <pre>$(locale)</pre>
310 <p>$(gettext 'Locales that are currently installed on the machine:')</p>
311 <pre>$(locale -a)</pre>
313 <p>$(gettext 'Available locales:')</p>
314 EOT
316 is_installed "glibc-locale"
317 [ $? = 1 ] &&
318 msg tip $(gettext \
319 "Can't see your language?<br/>You can \
320 <a href='/pkgs.cgi?do=Install&glibc-locale'>install glibc-locale</a> \
321 to see a larger list of available locales.")
323 cat << EOT
324 <form method="get" action="$SCRIPT_NAME">
325 <div class="outbox">
326 <table class="zebra fixed">
327 <thead>
328 <tr><td style="width:9em">$(gettext 'Code')</td>
329 <td style="width:10em">$(gettext 'Language')</td>
330 <td style="width:10em">$(gettext 'Territory')</td>
331 <td>$(gettext 'Description')</td>
332 </tr>
333 </thead>
334 </table>
336 <div style="max-height: 16em; overflow:auto">
337 <table class="zebra fixed">
338 <col style="width:9em">
339 <col style="width:10em">
340 <col style="width:10em">
341 <col>
342 <tbody style="max-height:10em; overflow:auto">
343 EOT
344 for locale in $(find /usr/share/i18n/locales -type f | sort)
345 do
346 locale_name=$(basename $locale)
347 locale_title=$(grep -m 1 -e '^ *title' $locale | cut -d'"' -f2)
348 if [ -n "$locale_title" ]; then
349 sel=""; [ "$locale_name" == "$cur_loc" ] && sel="checked"
350 cat << EOT
351 <tr><td><input type="radio" name="gen_locale" value="$locale_name" $sel />$locale_name</td>
352 <td>$(gettext -d iso_639 "$(grep -m 1 -e '^ *language' $locale | cut -d '"' -f2)")</td>
353 <td>$(gettext -d iso_3166 "$(grep -m 1 -e '^ *territory' $locale | cut -d '"' -f2)")</td>
354 <td>$locale_title</td>
355 </tr>
356 EOT
357 fi
358 done
359 cat << EOT
360 </tbody>
361 </table>
362 </div>
363 </div>
364 <p><input type="submit" value="$(gettext 'Activate')" /></p>
365 </form>
366 EOT
367 ;;
370 *)
371 #
372 # Defaut system settings page
373 #
374 cat << EOT
375 <div id="wrapper">
376 <h2>$(gettext 'System settings')</h2>
377 <p>$(gettext 'Manage system time, users or language settings')<p>
378 </div>
379 <div id="actions">
380 <a class="button" href="$SCRIPT_NAME?users">
381 <img src="$IMAGES/user.png" />$(gettext 'Manage users')</a>
382 <a class="button" href="$SCRIPT_NAME?groups">
383 <img src="$IMAGES/users.png" />$(gettext 'Manage groups')</a>
384 </div>
386 <section>
387 <h3>$(gettext 'System time')</h3>
389 <form method="get" action="$SCRIPT_NAME">
390 <table>
391 <tr><td>$(gettext 'Time zome:')</td><td>
392 <select name="tz">
393 $(cd /usr/share/zoneinfo ; find * -type f | while read tz; do
394 if [ "$(cat /etc/TZ)" == "$tz" ]; then
395 echo "<option selected>$tz</option>"
396 else
397 echo "<option>$tz</option>"
398 fi
399 done)
400 </select>
401 <input type="submit" name="settz" value="$(gettext 'Change')" /></td></tr>
402 <tr><td>$(gettext 'System time:')</td><td>$(date)</td></tr>
403 <tr><td>$(gettext 'Hardware clock:')</td><td>$(hwclock -r)</tr>
404 </table>
405 </form>
406 <form method="get" action="$SCRIPT_NAME">
407 <input type="submit" name="date" value="$(gettext 'Set date')" />
408 <select name="day">
409 $(for i in $(seq 1 31); do echo "<option>$i</option>"; done)
410 </select>
411 <select name="month">
412 $(for i in 01 02 03 04 05 06 07 08 09 10 11 12; do
413 date -d ${i}010101 '+%m %B' | \
414 sed 's|\(.*\) \(.*\)|<option value="\1">\2</option>|'
415 done)
416 </select>
417 <select name="year">
418 $(for i in $(seq 2010 2030); do echo "<option>$i</option>"; done)
419 </select>
420 - <select name="hour">
421 $(for i in $(seq 0 23); do printf "<option>%02d</option>" $i; done)
422 </select>
423 : <select name="min">
424 $(for i in $(seq 0 59); do printf "<option>%02d</option>" $i; done)
425 </select>
426 : <select name="sec">
427 $(for i in $(seq 0 59); do printf "<option>%02d</option>" $i; done)
428 </select>
429 </form>
430 <a class="button" href="$SCRIPT_NAME?rdate">$(gettext 'Sync online')</a>
431 <a class="button" href="$SCRIPT_NAME?hwclock">$(gettext 'Set hardware clock')</a>
432 </section>
433 EOT
434 #
435 # Locale settings
436 #
437 cat << EOT
438 <section>
439 <h3 id="locale">$(gettext 'System language')</h3>
440 <p>
441 EOT
442 # Check if a new locale was requested
443 if [ -n "$new_locale" ]; then
444 rm -rf /usr/lib/locale/$new_locale
445 localedef -i $new_locale -c -f UTF-8 \
446 /usr/lib/locale/$new_locale
447 # System configuration
448 echo "LANG=$new_locale" > /etc/locale.conf
449 echo "LC_ALL=$new_locale" >> /etc/locale.conf
450 msg warn "$(eval_gettext \
451 'You must logout and login again to your current session to use $new_locale locale.')"
452 else
453 gettext 'Current system locale:'; echo -n " <strong>"
454 locale | grep LANG | cut -d= -f2
455 fi
456 cat << EOT
457 </strong> <a class="button" href="$SCRIPT_NAME?locale">$(gettext 'Change')</a></p>
458 </section>
460 <section>
461 <h3 id="keymap">$(gettext 'Console keymap')</h3>
462 <p>
463 EOT
464 # Check if a new keymap was requested
465 if [ -n "$new_keymap" ]; then
466 echo "$new_keymap" > /etc/keymap.conf
467 if [ -x /bin/loadkeys ]; then
468 loadkeys $new_keymap
469 else
470 loadkmap < /usr/share/kmap/$new_keymap.kmap
471 fi
472 fi
473 keymap=$(cat /etc/keymap.conf)
474 eval_gettext 'Current console keymap: $keymap'
475 echo "</p>"
476 if [ -n "$keymap" ]; then
477 case "$keymap" in
478 fr_CH*)
479 keymap="ch" ;;
480 ru)
481 keymap="us,ru(winkeys)" ;;
482 slovene)
483 keymap=si ;;
484 *)
485 keymap=${keymap%-lat*}
486 keymap=${keymap%-abnt2} ;;
487 esac
488 keyboard_config=/etc/X11/xorg.conf.d/40-Keyboard.conf
489 cat << EOT
490 <form method="get" action="$SCRIPT_NAME">
491 $(gettext 'Suggested keymap for Xorg:')
492 <input type="submit" name "apply_xorg_kbd" value="$keymap" />
493 <a class="button" href="index.cgi?file=$keyboard_config">
494 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
495 </form>
496 EOT
497 fi
498 cat << EOT
499 <form method="get" action="$SCRIPT_NAME">
500 $(gettext 'Available keymaps:')
501 <select name="gen_keymap">
502 $(list_keymaps)
503 </select>
504 <input type="submit" value="$(gettext 'Activate')" />
505 </form>
506 </section>
508 <section>
509 <h2>$(gettext 'Panel configuration')</h2>
511 <form method="get" action="$SCRIPT_NAME">
512 <p>
513 $(gettext 'Style:')
514 <select name="style">
515 $(list_styles)
516 </select>
517 <input type="submit" value="$(gettext 'Activate')" />
518 </p>
519 </form>
520 <form method="get" action="$SCRIPT_NAME">
521 <p>
522 $(gettext 'Panel password:')
523 <input type="password" name="panel_pass"/>
524 <input type="submit" value="$(gettext 'Change')" />
525 </p>
526 </form>
527 <p>
528 $(gettext 'Configuration files:')
529 <a class="button" href="index.cgi?file=$CONFIG">
530 <img src="$IMAGES/edit.png" />$(gettext 'Panel')</a>
531 <a class="button" href="index.cgi?file=$HTTPD_CONF">
532 <img src="$IMAGES/edit.png" />$(gettext 'Server')</a>
533 </p>
534 <p>
535 $(gettext 'TazPanel provides a debuging mode and page:')
536 <a href="/index.cgi?debug">debug</a>
537 </p>
538 </section>
539 EOT
540 ;;
541 esac
543 xhtml_footer
544 exit 0