tazpanel view settings.cgi @ rev 456

boot.cgi: ISO mine: "table"izing input form.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Apr 13 01:44:08 2015 +0300 (2015-04-13)
parents 169f1ccfb613
children dd26a42bd40b
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-2015 SliTaz GNU/Linux - BSD License
8 #
11 # Common functions from libtazpanel
13 . lib/libtazpanel
14 get_config
15 header
17 TITLE=$(_ 'TazPanel - Settings')
20 # Get system database. LDAP compatible.
22 getdb() {
23 getent $1 2>/dev/null || cat /etc/$1
24 }
26 listdb() {
27 for item in $(getdb $1 | cut -d ":" -f 1); do
28 echo "<option>$item</option>\n"
29 done
30 }
36 #
37 # Commands executed before page loading.
38 #
40 case " $(GET) " in
41 *\ do\ *)
42 users=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="user") print $2}')
43 groups=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="group")print $2}')
45 case $(GET do) in
47 # Groups page
48 delgroups)
49 for i in $groups; do delgroup $i; done ;;
50 addgroup)
51 addgroup $groups ;;
52 addmember)
53 addgroup $(GET member) $groups ;;
54 delmember)
55 delgroup $(GET member) $groups ;;
57 # Users page
58 delusers)
59 for i in $users; do deluser $i; done ;;
60 lockusers)
61 for i in $users; do passwd -l $i | log; done ;;
62 unlockusers)
63 for i in $users; do passwd -u $i | log; done ;;
64 chpasswd)
65 echo "$users:$(GET password)" | chpasswd -m | log ;;
66 adduser)
67 if [ -n "$users" ]; then
68 name=$(GET name); name=${name:-SliTaz User}
69 adduser -D -s /bin/sh -g "$name" -G users -h /home/$users $users
70 echo "$user:$(GET passwd)" | chpasswd -m | log
71 for i in audio cdrom floppy video tty; do addgroup $users $i; done
72 fi ;;
74 # System time
75 settz)
76 GET tz > /etc/TZ;;
77 date) # normalize to two digits
78 date $(printf '%02d%02d%02d%02d%d.%02d' "$(GET month)" "$(GET day)" "$(GET hour)" "$(GET min)" "$(GET year)" "$(GET sec)") >/dev/null;;
79 rdate)
80 rdate -s tick.greyware.com ;;
81 hwclock)
82 hwclock -w -u ;;
84 esac
85 ;;
88 *\ gen_locale\ *)
89 new_locale=$(GET gen_locale) ;;
90 *\ gen_keymap\ *)
91 new_keymap=$(GET gen_keymap) ;;
92 *\ apply_xorg_kbd\ *)
93 sed -i "s/XkbLayout.*/XkbLayout \" \"$(GET apply_xorg_kbd)\"/" \
94 /etc/X11/xorg.conf.d/40-Keyboard.conf ;;
95 *\ panel_pass*)
96 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF ;;
97 *\ style*)
98 sed -i s/'^STYLE.*'/"STYLE=\"$(GET style)\""/ $CONFIG
99 . $CONFIG ;;
100 esac
106 #
107 # Default xHTML content
108 #
110 xhtml_header
111 check_root_tazpanel
113 case " $(GET) " in
114 *\ group*)
115 #
116 # Groups management
117 #
118 cat <<EOT
119 <h2 id="groups">$(_ 'Manage groups')</h2>
122 <section>
123 <form class="wide">
124 <header>
125 <input type="hidden" name="groups"/>
126 <!-- $(_ 'Selection:') -->
127 <button name="do" value="delgroups" data-icon="delete">$(_ 'Delete group')</button>
128 </header>
130 <div class="scroll">
131 <table class="wide zebra scroll">
132 <thead>
133 <tr class="thead">
134 <td>$(_ 'Group')</td>
135 <td>$(_ 'Group ID')</td>
136 <td>$(_ 'Members')</td>
137 </tr>
138 </thead>
139 <tbody>
140 EOT
141 for group in $(getdb group | cut -d ":" -f 1); do
142 IFS=':'
143 set -- $(getdb group | grep "^$group:")
144 unset IFS
145 gid=$3
146 members=$4
147 cat <<EOT
148 <tr>
149 <td><input type="checkbox" name="group" value="$group" id="$group"/>
150 <label for="$group" data-icon="group">$group</label></td>
151 <td>$gid</td>
152 <td>${members//,/, }</td>
153 </tr>
154 EOT
155 done
156 cat <<EOT
157 </tbody>
158 </table>
159 </div>
160 </form>
161 </section>
164 <section>
165 <header>$(_ 'Add a new group')</header>
166 <form>
167 <input type="hidden" name="groups"/>
168 <table>
169 <tr><td>$(_ 'Group name:')</td>
170 <td><input type="text" name="group"/></td>
171 </tr>
172 <tr><td colspan="2">
173 <button type="submit" name="do" value="addgroup" data-icon="add">$(_ 'Create group')</button>
174 </td></tr>
175 </table>
176 </form>
177 </section>
180 <section>
181 <header>$(_ 'Manage group membership')</header>
182 <form>
183 <input type="hidden" name="groups"/>
184 <table>
185 <tr>
186 <td>$(_ 'Group name:')</td>
187 <td><select name="group">$(listdb group)</select></td>
188 <td>$(_ 'User name:')</td>
189 <td><select name="member">$(listdb passwd)</select></td>
190 </tr>
191 <tr>
192 <td colspan="2">
193 <button name="do" value="addmember" data-icon="add">$(_ 'Add user')</button>
194 </td>
195 <td colspan="2">
196 <button name="do" value="delmember" data-icon="delete">$(_ 'Remove user')</button>
197 </td>
198 </tr>
199 </table>
200 </form>
201 </section>
203 EOT
204 ;;
207 *\ user*)
208 #
209 # Users management
210 #
211 cat <<EOT
212 <h2 id="users">$(_ 'Manage users')</h2>
214 <section>
215 <form class="wide">
216 <header>
217 <!--$(_ 'Selection:')-->
218 <button name="do" value="delusers" data-icon="delete">$(_ 'Delete user')</button>
219 <button name="do" value="lockusers" data-icon="lock" >$(_ 'Lock user' )</button>
220 <button name="do" value="unlockusers" data-icon="unlock">$(_ 'Unlock user')</button>
221 </header>
223 <table class="wide zebra center">
224 <thead>
225 <tr>
226 <td>$(_ 'Login')</td>
227 <td>$(_ 'User ID')</td>
228 <td>$(_ 'Name')</td>
229 <td>$(_ 'Home')</td>
230 <td>$(_ 'Shell')</td>
231 </tr>
232 </thead>
233 </tbody>
234 EOT
235 for login in $(getdb passwd | cut -d ":" -f 1); do
236 if [ -d /home/$login ]; then
237 colorlogin=$login
238 grep -qs "^$login:!" /etc/shadow &&
239 colorlogin="<span style='color: red;'>$login</span>"
240 IFS=':'
241 set -- $(getdb passwd | grep "^$login:")
242 unset IFS
243 cat <<EOT
244 <tr>
245 <td style="white-space: nowrap">
246 <input type="checkbox" name="user" value="$login" id="$login"/>
247 <label for="$login" data-icon="user">$colorlogin</label></td>
248 <td>$3:$4</td>
249 <td>$(echo $5 | sed s/,.*//)</td>
250 <td>$6</td>
251 <td>$7</td>
252 </tr>
253 EOT
254 fi
255 done
256 cat <<EOT
257 </tbody>
258 </table>
259 EOT
260 cat <<EOT
261 <footer>
262 <div>
263 $(_ 'Password:')
264 <input type="password" name="password"/>
265 <button type="submit" name="do" value="chpasswd" data-icon="ok">$(_ 'Change password')</button>
266 </div>
267 </footer>
268 </form>
269 </section>
272 <section>
273 <header>$(_ 'Add a new user')</header>
275 <form>
276 <input type="hidden" name="users"/>
277 <table class="summary">
278 <tr><td>$(_ 'User login:')</td>
279 <td><input type="text" name="user" size="30" pattern="[a-z]*"/></td></tr>
280 <tr><td>$(_ 'User name:')</td>
281 <td><input type="text" name="name" size="30"/></td></tr>
282 <tr><td>$(_ 'User password:')</td>
283 <td><input type="password" name="passwd" size="30"/></td></tr>
284 </table>
286 <footer>
287 <button type="submit" name="do" value="adduser" data-icon="add">$(_ 'Create user')</button>
288 </footer>
289 </form>
290 </section>
293 <section>
294 <header>$(_ 'Current user sessions')</header>
295 <pre>$(who)</pre>
296 </section>
299 <section>
300 <header>$(_ 'Last user sessions')</header>
301 <div class="scroll"><pre>$(last)</pre></div>
302 </section>
303 EOT
304 ;;
307 *\ locale*)
308 #
309 # Choose locale
310 #
311 LOADING_MSG="$(_ 'Please wait...')"; loading_msg
313 cur_loc=$(locale | grep LANG | cut -d= -f2)
314 cat <<EOT
315 <h2 id="locale">$(_ 'Choose locale')</h2>
317 <section>
318 <header>$(_ 'Current locale settings:')</header>
319 <div>
320 <pre>$(locale)</pre>
321 </div>
322 </section>
324 <section>
325 <header>$(_ 'Locales that are currently installed on the machine:')</header>
326 <div>
327 <pre>$(locale -a)</pre>
328 </div>
329 </section>
330 EOT
332 is_installed "glibc-locale"
333 [ $? = 1 ] &&
334 msg tip $(_ \
335 "Can't see your language?<br/>You can \
336 <a href='pkgs.cgi?do=Install&amp;glibc-locale'>install glibc-locale</a> \
337 to see a larger list of available locales.")
340 cat <<EOT
341 <section>
342 <header>$(_ 'Available locales:')</header>
343 <form class="wide">
344 <table class="wide zebra">
345 <thead>
346 <tr><td>$(_ 'Code')</td>
347 <td>$(_ 'Language')</td>
348 <td>$(_ 'Territory')</td>
349 <td>$(_ 'Description')</td>
350 </tr>
351 </thead>
352 <tbody>
353 EOT
354 for locale in $(find /usr/share/i18n/locales -type f | sort); do
355 locale_name=$(basename $locale)
356 locale_title=$(grep -m 1 -e '^ *title' $locale | cut -d'"' -f2)
357 if [ -n "$locale_title" ]; then
358 sel=''; [ "$locale_name" == "$cur_loc" ] && sel='checked="checked"'
359 cat <<EOT
360 <tr>
361 <td>
362 <input type="radio" name="gen_locale" value="$locale_name" $sel id="$locale_name"/>
363 <label for="$locale_name">$locale_name</label>
364 </td>
365 <td>$(gettext -d iso_639 "$(grep -m 1 -e '^ *language' $locale | cut -d '"' -f2)")</td>
366 <td>$(gettext -d iso_3166 "$(grep -m 1 -e '^ *territory' $locale | cut -d '"' -f2)")</td>
367 <td>$locale_title</td>
368 </tr>
369 EOT
370 fi
371 done
372 cat <<EOT
373 </tbody>
374 </table>
376 <footer>
377 <button type="submit" data-icon="ok">$(_ 'Activate')</button>
378 </footer>
379 </form>
380 </section>
381 EOT
382 ;;
385 *)
386 #
387 # Default system settings page
388 #
390 cat <<EOT
391 <h2>$(_ 'System settings')</h2>
393 <p>$(_ 'Manage system time, users or language settings')<p>
395 <form><!--
396 --><button name="users" data-icon="user" >$(_ 'Manage users' )</button><!--
397 --><button name="groups" data-icon="group">$(_ 'Manage groups')</button>
398 </form>
400 <section>
401 <header>$(_ 'System time')</header>
402 <div>
403 <form class="wide">
404 <fieldset><legend>$(_ 'Time zone:')</legend>
405 <select name="tz">
406 $(cd /usr/share/zoneinfo; find * -type f ! -name '*.tab' | sort | \
407 awk -vtz="$(cat /etc/TZ)" \
408 '{printf("<option%s>%s</option>", ($1 == tz)?" selected":"", $1)}')
409 </select>
410 <button name="do" value="settz" data-icon="ok">$(_ 'Change')</button>
411 </fieldset>
413 <fieldset><legend>$(_ 'System time:')</legend>
414 $(date | sed 's|[0-9][0-9]:[0-9:]*|<span id="time">&</span>|')
415 <button name="do" value="rdate" data-icon="sync">$(_ 'Sync online')</button>
416 </fieldset>
418 <fieldset id="hwclock1"><legend>$(_ 'Hardware clock:')</legend>
419 $(hwclock -ur | sed 's|0.000000 seconds||')
420 <button name="do" value="hwclock" id="hwclock" data-icon="clock">$(_ 'Set hardware clock')</button>
421 </fieldset>
423 <fieldset><legend>$(_ 'Set date')</legend>
424 <input type="number" name="day" value="$(date +%d)" min="1" max="31" size="4" required/>
425 <select name="month" value="$(date +%m)">
426 $(for i in $(seq 12); do
427 sel=''; [ "$i" == "$(date +%-m)" ] && sel=' selected'
428 printf "<option value=\"%s\"$sel>%s</option>" $(date -d $i.01-01:01 '+%m %B')
429 done)
430 </select>
431 <input type="number" name="year" value="$(date +%Y)" min="2015" max="2030" size="6" required/>
432 - <input type="number" name="hour" value="$(date +%H)" min="0" max="23" size="4" required/><!--
433 -->:<input type="number" name="min" value="$(date +%M)" min="0" max="59" size="4" required/><!--
434 -->:<input type="number" name="sec" value="00" min="0" max="59" size="4" required/>
435 <button name="do" value="date" data-icon="ok">$(_ 'Set date')</button>
436 </fieldset>
437 </form>
438 </div>
440 <script type="text/javascript">
441 // Live time on page
442 Date.prototype.timeNow = function() {
443 return ((this.getHours() < 10)?"0":"") + this.getHours() + ":" + ((this.getMinutes() < 10)?"0":"") + this.getMinutes() + ":" + ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
444 }
445 setInterval(function(){document.getElementById('time').innerText = new Date().timeNow()}, 1000);
447 //document.getElementById('hwclock').disabled = 'disabled';
448 </script>
449 </section>
450 EOT
453 #
454 # Locale settings
455 #
456 cat <<EOT
457 <section>
458 <header id="locale">$(_ 'System language')</header>
459 <div>
460 <form>
461 EOT
462 # Check if a new locale was requested
463 if [ -n "$new_locale" ]; then
464 rm -rf /usr/lib/locale/$new_locale
465 localedef -i $new_locale -c -f UTF-8 \
466 /usr/lib/locale/$new_locale
467 # System configuration
468 echo "LANG=$new_locale" > /etc/locale.conf
469 echo "LC_ALL=$new_locale" >> /etc/locale.conf
470 msg warn "$(_ \
471 'You must logout and login again to your current session to use %s locale.' $new_locale)"
472 else
473 cat <<EOT
474 $(_ 'Current system locale:')
475 <strong>$(locale | grep LANG | cut -d= -f2)</strong>
476 <button name="locale" data-icon="locale">$(_ 'Change')</button>
477 EOT
478 fi
479 cat <<EOT
480 </div>
481 </form>
482 </section>
485 <section>
486 <header id="keymap">$(_ 'Keyboard layout')</header>
487 <div>
488 EOT
489 # Check if a new keymap was requested
490 if [ -n "$new_keymap" ]; then
491 echo "$new_keymap" > /etc/keymap.conf
492 if [ -x /bin/loadkeys ]; then
493 loadkeys $new_keymap
494 else
495 loadkmap < /usr/share/kmap/$new_keymap.kmap
496 fi
497 fi
499 keymap=$(cat /etc/keymap.conf)
500 _ 'Current console keymap: %s' $keymap
501 if [ -n "$keymap" ]; then
502 case "$keymap" in
503 fr_CH*)
504 keymap="ch" ;;
505 ru)
506 keymap="us,ru" ;;
507 slovene)
508 keymap=si ;;
509 *)
510 keymap=${keymap%-lat*}
511 keymap=${keymap%-abnt2} ;;
512 esac
513 keyboard_config=/etc/X11/xorg.conf.d/40-Keyboard.conf
514 cat <<EOT
515 <form id="settings"></form>
516 <form id="index" action="index.cgi"></form>
517 <br/>
518 $(_ 'Suggested keymap for Xorg:') $keymap
519 <button form="settings" name="apply_xorg_kbd" value="$keymap" data-icon="ok">$(_ 'Activate')</button>
520 <button form="index" name="file" value="$keyboard_config" data-icon="edit">$(_ 'Edit')</button>
521 <br/>
522 EOT
523 fi
524 cat <<EOT
525 <form>
526 $(_ 'Available keymaps:')
527 <select name="gen_keymap">
528 $(list_keymaps)
529 </select>
530 <button type="submit" data-icon="ok">$(_ 'Activate')</button>
531 </form>
532 </div>
533 </section>
536 <section>
537 <header>$(_ 'Panel configuration')</header>
538 <div>
539 <form class="wide">
540 <fieldset><legend>$(_ 'Style:')</legend>
541 <select name="style">$(list_styles)</select>
542 <button data-icon="ok">$(_ 'Activate')</button>
543 </fieldset>
545 <fieldset><legend>$(_ 'Panel password:')</legend>
546 <input type="password" name="panel_pass"/>
547 <button data-icon="ok">$(_ 'Change')</button>
548 </fieldset>
549 </form>
551 <fieldset><legend>$(_ 'Configuration files:')</legend>
552 <button form="index" name="file" value="$CONFIG" data-icon="edit">$(_ 'Panel')</button>
553 <button form="index" name="file" value="$HTTPD_CONF" data-icon="edit">$(_ 'Server')</button>
554 </fieldset>
556 <p>$(_ 'TazPanel provides a debugging mode and page:')
557 <a href="index.cgi?debug">debug</a>
558 </p>
559 </div>
560 </section>
561 EOT
562 ;;
563 esac
565 xhtml_footer
566 exit 0