tazpanel view settings.cgi @ rev 313
new locale chooser
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu May 17 15:03:15 2012 +0300 (2012-05-17) |
parents | 42367a53cf50 |
children | 01e1839f6450 |
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 #
18 # Commands executed before page loading.
19 #
21 case " $(GET) " in
22 *\ do\ *)
23 # Assume no array support in httpd_helper.sh ;^)
24 users=""
25 IFS="&"
26 for i in $QUERY_STRING ; do
27 case "$i" in
28 user=*) users="$users ${i#user=}" ;;
29 esac
30 done
31 unset IFS
32 for cmd in "Delete user" "Lock user" "Unlock user" \
33 "Change password" ; do
34 [ "$(GET do)" == "$(gettext "$cmd")" ] || continue # BUGGY
35 for user in $users ; do
36 case "$cmd" in
37 Delete*) deluser $user ;;
38 Lock*) passwd -l $user | log ;;
39 Unlock*) passwd -u $user | log ;;
40 Change*) echo "$user:$(GET password)" | chpasswd -m | log ;;
41 esac
42 done
43 done ;;
44 *\ adduser\ *)
45 #
46 # Manage system user accounts
47 #
48 user=$(GET adduser)
49 passwd=$(GET passwd)
50 if [ -n "$user" ]; then
51 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$user $user
52 echo "$user:$passwd" | chpasswd -m | log
53 for g in audio cdrom floppy video tty
54 do
55 addgroup $user $g
56 done
57 fi ;;
58 *\ gen_locale\ *)
59 new_locale=$(GET gen_locale) ;;
60 *\ gen_keymap\ *)
61 new_keymap=$(GET gen_keymap) ;;
62 *\ apply_xorg_kbd\ *)
63 sed -i "s/XkbLayout.*/XkbLayout \" \"$(GET apply_xorg_kbd)\"/" \
64 /etc/X11/xorg.conf.d/40-Keyboard.conf ;;
65 *\ rdate\ *)
66 rdate -s tick.greyware.com ;;
67 *\ hwclock\ *)
68 hwclock -w -u ;;
69 *\ panel_pass*)
70 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF ;;
71 *\ style*)
72 sed -i s/'^STYLE.*'/"STYLE=\"$(GET style)\""/ $CONFIG
73 . $CONFIG ;;
74 esac
76 #
77 # Default xHTML content
78 #
79 xhtml_header
81 case " $(GET) " in
82 *\ user*)
83 #
84 # Users management
85 #
86 cat <<EOT
87 <h3 id="users">$(gettext 'Manage users')</h3>
89 <form method="get" action="$SCRIPT_NAME">
90 <div id="actions">
91 <div class="float-left">
92 $(gettext 'Selection:')
93 <input type="submit" name="do" value="$(gettext 'Delete user')" />
94 <input type="submit" name="do" value="$(gettext 'Lock user')" />
95 <input type="submit" name="do" value="$(gettext 'Unlock user')" />
96 </div>
97 </div>
99 <table class="zebra outbox">
100 <thead>
101 <tr class="thead">
102 <td>$(gettext 'Login')</td>
103 <td>$(gettext 'User ID')</td>
104 <td>$(gettext 'Name')</td>
105 <td>$(gettext 'Home')</td>
106 <td>$(gettext 'Shell')</td>
107 </tr>
108 </thead>
109 </tbody>
110 EOT
111 for login in `cat /etc/passwd | cut -d ":" -f 1`
112 do
113 if [ -d /home/$login ]; then
114 colorlogin=$login
115 grep -qs "^$login:!" /etc/shadow &&
116 colorlogin="<span style='color: red;'>$login</span>"
117 IFS=':'
118 set -- $(grep "^$login:" /etc/passwd)
119 unset IFS
120 uid=$3
121 gid=$4
122 name="$(echo $5 | sed s/,.*//)"
123 home="$6"
124 shell=$7
125 cat <<EOT
126 <tr>
127 <td><input type='checkbox' name='user' value='$login' />
128 <img src='$IMAGES/user.png' />$colorlogin</td>
129 <td>$uid:$gid</td>
130 <td>$name</td>
131 <td>$home</td>
132 <td>$shell</td>
133 </tr>
134 EOT
135 fi
136 done
137 cat << EOT
138 </tbody>
139 </table>
140 EOT
141 cat << EOT
142 <p>
143 $(gettext 'Password:')
144 <input type="password" name="password" />
145 <input type="submit" name="do" value="$(gettext 'Change password')" />
146 </p>
147 </form>
149 <section>
150 <h4>$(gettext 'Add a new user')</h4>
152 <form method="get" action="$SCRIPT_NAME">
153 <input type="hidden" name="user" />
154 <table>
155 <tr><td>$(gettext 'User login:')</td>
156 <td><input type="text" name="adduser" size="30" /></td></tr>
157 <tr><td>$(gettext 'User password:')</td>
158 <td><input type="password" name="passwd" size="30" /></td></tr>
159 <tr><td colspan="2">
160 <input type="submit" value="$(gettext 'Create user')" /></td></tr>
161 </table>
162 </form>
163 </section>
165 <section>
166 <h4>$(gettext 'Current user sessions')</h4>
168 <pre>$(who)</pre>
169 </section>
171 <section>
172 <h4>$(gettext 'Last user sessions')</h4>
174 <pre>$(last)</pre>
175 </section>
176 EOT
177 ;;
180 *\ locale*)
181 #
182 # Choose locale
183 #
184 LOADING_MSG="$(gettext 'Please wait...')"
185 loading_msg
186 cur_loc=$(locale | grep LANG | cut -d= -f2)
187 cat <<EOT
188 <h3 id="locale">$(gettext 'Choose locale')</h3>
190 <p>$(gettext 'Current locale settings:')</p>
191 <pre>$(locale)</pre>
193 <p>$(gettext 'Locales that are currently installed on the machine:')</p>
194 <pre>$(locale -a)</pre>
196 <p>$(gettext 'Available locales:')</p>
198 <form method="get" action="$SCRIPT_NAME">
199 <div class="outbox">
200 <table class="zebra fixed">
201 <thead>
202 <tr><td style="width:9em">$(gettext 'Code')</td>
203 <td style="width:10em">$(gettext 'Language')</td>
204 <td style="width:10em">$(gettext 'Territory')</td>
205 <td>$(gettext 'Description')</td>
206 </tr>
207 </thead>
208 </table>
210 <div style="max-height: 16em; overflow:auto">
211 <table class="zebra fixed">
212 <col style="width:9em">
213 <col style="width:10em">
214 <col style="width:10em">
215 <col>
216 <tbody style="max-height:10em; overflow:auto">
217 EOT
218 for locale in $(find /usr/share/i18n/locales -type f | sort)
219 do
220 locale_name=$(basename $locale)
221 locale_title=$(grep -m 1 -e '^ *title' $locale | cut -d'"' -f2)
222 if [ -n "$locale_title" ]; then
223 sel=""; [ "$locale_name" == "$cur_loc" ] && sel="checked"
224 cat << EOT
225 <tr><td><input type="radio" name="gen_locale" value="$locale_name" $sel />$locale_name</td>
226 <td>$(gettext -d iso_639 "$(grep -m 1 -e '^ *language' $locale | cut -d '"' -f2)")</td>
227 <td>$(gettext -d iso_3166 "$(grep -m 1 -e '^ *territory' $locale | cut -d '"' -f2)")</td>
228 <td>$locale_title</td>
229 </tr>
230 EOT
231 fi
232 done
233 cat << EOT
234 </tbody>
235 </table>
236 </div>
237 </div>
238 <p><input type="submit" value="$(gettext 'Activate')" /></p>
239 </form>
240 EOT
241 ;;
244 *)
245 #
246 # Defaut system settings page
247 #
248 cat << EOT
249 <div id="wrapper">
250 <h2>$(gettext 'System settings')</h2>
251 <p>$(gettext 'Manage system time, users or language settings')<p>
252 </div>
253 <div id="actions">
254 <a class="button" href="$SCRIPT_NAME?users">
255 <img src="$IMAGES/users.png" />$(gettext 'Manage users')</a>
256 </div>
258 <section>
259 <h3>$(gettext 'System time')</h3>
261 <table>
262 <tr><td>$(gettext 'Time zome:')</td><td>$(cat /etc/TZ)
263 <a class="button" href="$SCRIPT_NAME">$(gettext 'Change')</a></td></tr>
264 <tr><td>$(gettext 'System time:')</td><td>$(date)</td></tr>
265 <tr><td>$(gettext 'Hardware clock:')</td><td>$(hwclock -r)</tr>
266 </table>
267 <a class="button" href="$SCRIPT_NAME?rdate">$(gettext 'Sync online')</a>
268 <a class="button" href="$SCRIPT_NAME?hwclock">$(gettext 'Set hardware clock')</a>
269 </section>
270 EOT
271 #
272 # Locale settings
273 #
274 cat << EOT
275 <section>
276 <h3 id="locale">$(gettext 'System language')</h3>
277 <p>
278 EOT
279 # Check if a new locale was requested
280 if [ -n "$new_locale" ]; then
281 rm -rf /usr/lib/locale/$new_locale
282 localedef -i $new_locale -c -f UTF-8 \
283 /usr/lib/locale/$new_locale
284 # System configuration
285 echo "LANG=$new_locale" > /etc/locale.conf
286 echo "LC_ALL=$new_locale" >> /etc/locale.conf
287 eval_gettext "You must logout and login again to your current \
288 session to use \$new_locale locale."
289 else
290 gettext 'Current system locale:'; echo -n " <strong>"
291 locale | grep LANG | cut -d= -f2
292 fi
293 cat << EOT
294 </strong> <a class="button" href="$SCRIPT_NAME?locale">$(gettext 'Change')</a></p>
295 </section>
297 <section>
298 <h3 id="keymap">$(gettext 'Console keymap')</h3>
299 <p>
300 EOT
301 # Check if a new keymap was requested
302 if [ -n "$new_keymap" ]; then
303 echo "$new_keymap" > /etc/keymap.conf
304 if [ -x /bin/loadkeys ]; then
305 loadkeys $new_keymap
306 else
307 loadkmap < /usr/share/kmap/$new_keymap.kmap
308 fi
309 fi
310 keymap=$(cat /etc/keymap.conf)
311 eval_gettext 'Current console keymap: $keymap'
312 echo "</p>"
313 if [ -n "$keymap" ]; then
314 case "$keymap" in
315 fr_CH*)
316 keymap="ch" ;;
317 ru)
318 keymap="us,ru(winkeys)" ;;
319 slovene)
320 keymap=si ;;
321 *)
322 keymap=${keymap%-lat*}
323 keymap=${keymap%-abnt2} ;;
324 esac
325 keyboard_config=/etc/X11/xorg.conf.d/40-Keyboard.conf
326 cat << EOT
327 <form method="get" action="$SCRIPT_NAME">
328 $(gettext 'Suggested keymap for Xorg:')
329 <input type="submit" name "apply_xorg_kbd" value="$keymap" />
330 <a class="button" href="index.cgi?file=$keyboard_config">
331 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
332 </form>
333 EOT
334 fi
335 cat << EOT
336 <form method="get" action="$SCRIPT_NAME">
337 $(gettext 'Available keymaps:')
338 <select name="gen_keymap">
339 $(list_keymaps)
340 </select>
341 <input type="submit" value="$(gettext 'Activate')" />
342 </form>
343 </section>
345 <section>
346 <h2>$(gettext 'Panel configuration')</h2>
348 <form method="get" action="$SCRIPT_NAME">
349 <p>
350 $(gettext 'Style:')
351 <select name="style">
352 $(list_styles)
353 </select>
354 <input type="submit" value="$(gettext 'Activate')" />
355 </p>
356 </form>
357 <form method="get" action="$SCRIPT_NAME">
358 <p>
359 $(gettext 'Panel password:')
360 <input type="password" name="panel_pass"/>
361 <input type="submit" value="$(gettext 'Change')" />
362 </p>
363 </form>
364 <p>
365 $(gettext 'Configuration files:')
366 <a class="button" href="index.cgi?file=$CONFIG">
367 <img src="$IMAGES/edit.png" />$(gettext 'Panel')</a>
368 <a class="button" href="index.cgi?file=$HTTPD_CONF">
369 <img src="$IMAGES/edit.png" />$(gettext 'Server')</a>
370 </p>
371 <p>
372 $(gettext 'TazPanel provides a debuging mode and page:')
373 <a href="/index.cgi?debug">debug</a>
374 </p>
375 </section>
376 EOT
377 ;;
378 esac
380 xhtml_footer
381 exit 0