tazpanel view settings.cgi @ rev 335
fix bug 45: ask confirmation during page load
author | border |
---|---|
date | Fri Dec 21 01:49:21 2012 -0500 (2012-12-21) |
parents | 01e1839f6450 |
children | 288c37594662 |
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>
197 EOT
199 is_installed "glibc-locale"
200 [ $? = 1 ] &&
201 msg tip $(gettext \
202 "Can't see your language?<br/>You can \
203 <a href='/pkgs.cgi?do=Install&glibc-locale'>install glibc-locale</a> \
204 to see a larger list of available locales.")
206 cat << EOT
207 <form method="get" action="$SCRIPT_NAME">
208 <div class="outbox">
209 <table class="zebra fixed">
210 <thead>
211 <tr><td style="width:9em">$(gettext 'Code')</td>
212 <td style="width:10em">$(gettext 'Language')</td>
213 <td style="width:10em">$(gettext 'Territory')</td>
214 <td>$(gettext 'Description')</td>
215 </tr>
216 </thead>
217 </table>
219 <div style="max-height: 16em; overflow:auto">
220 <table class="zebra fixed">
221 <col style="width:9em">
222 <col style="width:10em">
223 <col style="width:10em">
224 <col>
225 <tbody style="max-height:10em; overflow:auto">
226 EOT
227 for locale in $(find /usr/share/i18n/locales -type f | sort)
228 do
229 locale_name=$(basename $locale)
230 locale_title=$(grep -m 1 -e '^ *title' $locale | cut -d'"' -f2)
231 if [ -n "$locale_title" ]; then
232 sel=""; [ "$locale_name" == "$cur_loc" ] && sel="checked"
233 cat << EOT
234 <tr><td><input type="radio" name="gen_locale" value="$locale_name" $sel />$locale_name</td>
235 <td>$(gettext -d iso_639 "$(grep -m 1 -e '^ *language' $locale | cut -d '"' -f2)")</td>
236 <td>$(gettext -d iso_3166 "$(grep -m 1 -e '^ *territory' $locale | cut -d '"' -f2)")</td>
237 <td>$locale_title</td>
238 </tr>
239 EOT
240 fi
241 done
242 cat << EOT
243 </tbody>
244 </table>
245 </div>
246 </div>
247 <p><input type="submit" value="$(gettext 'Activate')" /></p>
248 </form>
249 EOT
250 ;;
253 *)
254 #
255 # Defaut system settings page
256 #
257 cat << EOT
258 <div id="wrapper">
259 <h2>$(gettext 'System settings')</h2>
260 <p>$(gettext 'Manage system time, users or language settings')<p>
261 </div>
262 <div id="actions">
263 <a class="button" href="$SCRIPT_NAME?users">
264 <img src="$IMAGES/users.png" />$(gettext 'Manage users')</a>
265 </div>
267 <section>
268 <h3>$(gettext 'System time')</h3>
270 <table>
271 <tr><td>$(gettext 'Time zome:')</td><td>$(cat /etc/TZ)
272 <a class="button" href="$SCRIPT_NAME">$(gettext 'Change')</a></td></tr>
273 <tr><td>$(gettext 'System time:')</td><td>$(date)</td></tr>
274 <tr><td>$(gettext 'Hardware clock:')</td><td>$(hwclock -r)</tr>
275 </table>
276 <a class="button" href="$SCRIPT_NAME?rdate">$(gettext 'Sync online')</a>
277 <a class="button" href="$SCRIPT_NAME?hwclock">$(gettext 'Set hardware clock')</a>
278 </section>
279 EOT
280 #
281 # Locale settings
282 #
283 cat << EOT
284 <section>
285 <h3 id="locale">$(gettext 'System language')</h3>
286 <p>
287 EOT
288 # Check if a new locale was requested
289 if [ -n "$new_locale" ]; then
290 rm -rf /usr/lib/locale/$new_locale
291 localedef -i $new_locale -c -f UTF-8 \
292 /usr/lib/locale/$new_locale
293 # System configuration
294 echo "LANG=$new_locale" > /etc/locale.conf
295 echo "LC_ALL=$new_locale" >> /etc/locale.conf
296 msg warn "$(eval_gettext \
297 'You must logout and login again to your current session to use $new_locale locale.')"
298 else
299 gettext 'Current system locale:'; echo -n " <strong>"
300 locale | grep LANG | cut -d= -f2
301 fi
302 cat << EOT
303 </strong> <a class="button" href="$SCRIPT_NAME?locale">$(gettext 'Change')</a></p>
304 </section>
306 <section>
307 <h3 id="keymap">$(gettext 'Console keymap')</h3>
308 <p>
309 EOT
310 # Check if a new keymap was requested
311 if [ -n "$new_keymap" ]; then
312 echo "$new_keymap" > /etc/keymap.conf
313 if [ -x /bin/loadkeys ]; then
314 loadkeys $new_keymap
315 else
316 loadkmap < /usr/share/kmap/$new_keymap.kmap
317 fi
318 fi
319 keymap=$(cat /etc/keymap.conf)
320 eval_gettext 'Current console keymap: $keymap'
321 echo "</p>"
322 if [ -n "$keymap" ]; then
323 case "$keymap" in
324 fr_CH*)
325 keymap="ch" ;;
326 ru)
327 keymap="us,ru(winkeys)" ;;
328 slovene)
329 keymap=si ;;
330 *)
331 keymap=${keymap%-lat*}
332 keymap=${keymap%-abnt2} ;;
333 esac
334 keyboard_config=/etc/X11/xorg.conf.d/40-Keyboard.conf
335 cat << EOT
336 <form method="get" action="$SCRIPT_NAME">
337 $(gettext 'Suggested keymap for Xorg:')
338 <input type="submit" name "apply_xorg_kbd" value="$keymap" />
339 <a class="button" href="index.cgi?file=$keyboard_config">
340 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
341 </form>
342 EOT
343 fi
344 cat << EOT
345 <form method="get" action="$SCRIPT_NAME">
346 $(gettext 'Available keymaps:')
347 <select name="gen_keymap">
348 $(list_keymaps)
349 </select>
350 <input type="submit" value="$(gettext 'Activate')" />
351 </form>
352 </section>
354 <section>
355 <h2>$(gettext 'Panel configuration')</h2>
357 <form method="get" action="$SCRIPT_NAME">
358 <p>
359 $(gettext 'Style:')
360 <select name="style">
361 $(list_styles)
362 </select>
363 <input type="submit" value="$(gettext 'Activate')" />
364 </p>
365 </form>
366 <form method="get" action="$SCRIPT_NAME">
367 <p>
368 $(gettext 'Panel password:')
369 <input type="password" name="panel_pass"/>
370 <input type="submit" value="$(gettext 'Change')" />
371 </p>
372 </form>
373 <p>
374 $(gettext 'Configuration files:')
375 <a class="button" href="index.cgi?file=$CONFIG">
376 <img src="$IMAGES/edit.png" />$(gettext 'Panel')</a>
377 <a class="button" href="index.cgi?file=$HTTPD_CONF">
378 <img src="$IMAGES/edit.png" />$(gettext 'Server')</a>
379 </p>
380 <p>
381 $(gettext 'TazPanel provides a debuging mode and page:')
382 <a href="/index.cgi?debug">debug</a>
383 </p>
384 </section>
385 EOT
386 ;;
387 esac
389 xhtml_footer
390 exit 0