tazpanel view settings.cgi @ rev 165
libtazpanel: align status
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Apr 22 11:34:07 2011 +0200 (2011-04-22) |
parents | ac272f688afe |
children | f054918e093c |
line source
1 #!/bin/sh
2 #
3 # System settings CGI interface: user, locale, keyboard, date. Since we
4 # dont have multiple pages here there is only one case used to get command
5 # values and the full content is following 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="- Settings"
17 # Get the list of system locales
18 list_locales() {
19 cd /usr/share/i18n/locales
20 for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]`
21 do
22 echo "<option value='$locale'>$locale</option>"
23 done
24 }
26 # Get the list of console keymaps
27 list_keymaps() {
28 cd /usr/share/kmap
29 for keymap in *.kmap
30 do
31 basename $keymap .kmap | sed "s|.*|<option value='&'>&</option>|"
32 done
33 }
35 # Get the list of panel styles
36 list_styles() {
37 cd $PANEL/styles
38 for style in *
39 do
40 echo "<option value='$style'>$style</option>"
41 done
42 }
44 #
45 # Commands executed before page loading.
46 #
48 case " $(GET) " in
49 *\ do\ *)
50 # Assume not array support in httpd_helper.sh ;^)
51 users=""
52 IFS="&"
53 for i in $QUERY_STRING ; do
54 case "$i" in
55 user=*) users="$users ${i#user=}" ;;
56 esac
57 done
58 unset IFS
59 for cmd in "Delete user" "Lock user" "Unlock user" \
60 "Change password" ; do
61 [ "$(GET do)" == "$(gettext "$cmd")" ] || continue
62 for user in $users ; do
63 case "$cmd" in
64 Delete*) deluser $user ;;
65 Lock*) passwd -l $user | log ;;
66 Unlock*) passwd -u $user | log ;;
67 Change*) echo "$user:$(GET password)" | chpasswd | log ;;
68 esac
69 done
70 done ;;
71 *\ adduser\ *)
72 #
73 # Manage system user accounts
74 #
75 user=$(GET adduser)
76 passwd=$(GET passwd)
77 if [ -n "$user" ]; then
78 adduser -D $user
79 echo "$user:$passwd" | chpasswd | log
80 for g in audio cdrom floppy video
81 do
82 addgroup $user $g
83 done
84 fi ;;
85 *\ gen_locale\ *)
86 new_locale=$(GET gen_locale) ;;
87 *\ gen_keymap\ *)
88 new_keymap=$(GET gen_keymap) ;;
89 *\ apply_xorg_kbd\ *)
90 sed -i "s/XkbLayout.*/XkbLayout \" \"$(GET apply_xorg_kbd)\"/" \
91 /etc/X11/xorg.conf.d/40-Keyboard.conf ;;
92 *\ rdate\ *)
93 rdate -s tick.greyware.com ;;
94 *\ hwclock\ *)
95 hwclock -w -u ;;
96 *\ panel_pass*)
97 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF ;;
98 *\ style*)
99 sed -i s/'^STYLE.*'/"STYLE=\"$(GET style)\""/ $CONFIG
100 . $CONFIG ;;
101 esac
103 #
104 # Default xHTML content
105 #
106 xhtml_header
108 case " $(GET) " in
109 *\ user*)
110 #
111 # Users management
112 #
113 cat <<EOT
114 <a name="users"></a>
115 <h3>`gettext "Manage users"`</h3>
116 <form method="get" action="$SCRIPT_NAME">
117 <div id="actions">
118 <div class="float-left">
119 $(gettext "Selection:")
120 <input type="submit" name="do" value="`gettext "Delete user"`" />
121 <input type="submit" name="do" value="`gettext "Lock user"`" />
122 <input type="submit" name="do" value="`gettext "Unlock user"`" />
123 </div>
124 </div>
125 EOT
126 table_start
127 cat << EOT
128 <tr class="thead">
129 <td>`gettext "Login"`</td>
130 <td>`gettext "User ID"`</td>
131 <td>`gettext "Name"`</td>
132 <td>`gettext "Home"`</td>
133 <td>`gettext "Shell"`</td>
134 </tr>
135 EOT
136 for login in `cat /etc/passwd | cut -d ":" -f 1`
137 do
138 if [ -d /home/$login ]; then
139 colorlogin=$login
140 grep -qs "^$login:!" /etc/shadow &&
141 colorlogin="<span style='color: red;'>$login</span>"
142 IFS=':'
143 set -- $(grep "^$login:" /etc/passwd)
144 unset IFS
145 uid=$3
146 gid=$4
147 name="$(echo $5 | sed s/,.*//)"
148 home="$6"
149 shell=$7
150 cat <<EOT
151 <tr>
152 <td><input type='checkbox' name='user' value='$login' />
153 <img src='$IMAGES/user.png' />$colorlogin</td>
154 <td>$uid:$gid</td>
155 <td>$name</td>
156 <td>$home</td>
157 <td>$shell</td>
158 </tr>
159 EOT
160 fi
161 done
162 table_end
163 cat << EOT
164 <p>
165 $(gettext "Password":)
166 <input type="password" name="password" />
167 <input type="submit" name="do" value="`gettext "Change password"`" />
168 </p>
169 </form>
171 <h4>`gettext "Add a new user"`</h4>
172 <form method="get" action="$SCRIPT_NAME">
173 <input type="hidden" name="user" />
174 <p>`gettext "User login:"`</p>
175 <p><input type="text" name="adduser" size="30" /></p>
176 <p>`gettext "User password:"`</p>
177 <p><input type="password" name="passwd" size="30" /></p>
178 <input type="submit" value="`gettext "Create user"`" />
179 </form>
181 <h4>`gettext "Current user sessions"`</h4>
182 <pre>
183 $(who)
184 </pre>
186 <h4>`gettext "Last user sessions"`</h4>
187 <pre>
188 $(last)
189 </pre>
190 EOT
191 ;;
192 *)
193 #
194 # Defaut system settings page
195 #
196 cat << EOT
197 <div id="wrapper">
198 <h2>$(gettext "System settings")</h2>
199 <p>$(gettext "Manage system time, users or language settings")<p>
200 </div>
201 <div id="actions">
202 <a class="button" href="$SCRIPT_NAME?users">
203 <img src="$IMAGES/users.png" />$(gettext "Manage users")</a>
204 </div>
206 <h3>`gettext "System time"`</h3>
207 <pre>
208 `gettext "Time zome :"` `cat /etc/TZ`
209 `gettext "System time :"` `date`
210 `gettext "Hardware clock :"` `hwclock -r`
211 </pre>
212 <a class="button" href="$SCRIPT_NAME?rdate">`gettext "Sync online"`</a>
213 <a class="button" href="$SCRIPT_NAME?hwclock">`gettext "Set hardware clock"`</a>
214 EOT
215 #
216 # Locale settings
217 #
218 cat << EOT
219 <a name="locale"></a>
220 <h3>`gettext "System language"`</h3>
221 <p>
222 EOT
223 # Check if a new locale was requested
224 if [ -n "$new_locale" ]; then
225 rm -rf /usr/lib/locale/$new_locale
226 localedef -i $new_locale -c -f UTF-8 \
227 /usr/lib/locale/$new_locale
228 # System configuration
229 echo "LANG=$new_locale" > /etc/locale.conf
230 echo "LC_ALL=$new_locale" >> /etc/locale.conf
231 eval_gettext "You must logout and login again to your current
232 session to use \$new_locale locale."
233 else
234 gettext "Current system locales: "
235 locale -a
236 fi
237 cat << EOT
238 </p>
239 <form method="get" action="$SCRIPT_NAME">
240 $(gettext "Available locales:")
241 <select name="gen_locale">
242 <option value="en_US">en_US</options>
243 $(list_locales)
244 </select>
245 <input type="submit" value="$(gettext "Activate")" />
246 </form>
248 <a name="keymap"></a>
249 <h3>`gettext "Console keymap"`</h3>
250 <p>
251 EOT
252 # Check if a new keymap was requested
253 if [ -n "$new_keymap" ]; then
254 echo "$new_keymap" > /etc/keymap.conf
255 if [ -x /bin/loadkeys ]; then
256 loadkeys $new_keymap
257 else
258 loadkmap < /usr/share/kmap/$new_keymap.kmap
259 fi
260 fi
261 gettext "Current console keymap: "
262 keymap=$(cat /etc/keymap.conf)
263 echo $keymap
264 echo "</p>"
265 if [ -n "$keymap" ]; then
266 case "$keymap" in
267 fr_CH*)
268 keymap="ch" ;;
269 ru)
270 keymap="us,ru(winkeys)" ;;
271 slovene)
272 keymap=si ;;
273 *)
274 keymap=${keymap%-lat*}
275 keymap=${keymap%-abnt2} ;;
276 esac
277 keyboard_config=/etc/X11/xorg.conf.d/40-Keyboard.conf
278 cat << EOT
279 <form method="get" action="$SCRIPT_NAME">
280 $(gettext "Suggested keymap for Xorg:")
281 <input type="submit" name "apply_xorg_kbd" value="$keymap" />
282 <a class="button" href="index.cgi?file=$keyboard_config">
283 <img src="$IMAGES/edit.png" />$(gettext "Edit")</a>
284 </form>
285 EOT
286 fi
287 cat << EOT
288 <form method="get" action="$SCRIPT_NAME">
289 $(gettext "Available keymaps:")
290 <select name="gen_keymap">
291 $(list_keymaps)
292 </select>
293 <input type="submit" value="$(gettext "Activate")" />
294 </form>
296 <h3>$(gettext "Panel configuration")</h3>
297 <form method="get" action="$SCRIPT_NAME">
298 <p>
299 $(gettext "Style:")
300 <select name="style">
301 $(list_styles)
302 </select>
303 <input type="submit" value="$(gettext "Activate")" />
304 </p>
305 </form>
306 <form method="get" action="$SCRIPT_NAME">
307 <p>
308 $(gettext "Panel password:")
309 <input type="password" name="panel_pass"/>
310 <input type="submit" value="$(gettext "Change")" />
311 </p>
312 </form>
313 <p>
314 $(gettext "Configuration files: ")
315 <a class="button" href="index.cgi?file=$CONFIG">
316 <img src="$IMAGES/edit.png" />$(gettext "Panel")</a>
317 <a class="button" href="index.cgi?file=$HTTPD_CONF">
318 <img src="$IMAGES/edit.png" />$(gettext "Server")</a>
319 </p>
320 <p>
321 $(gettext "TazPanel provides a debuging mode and page:")
322 <a href='/index.cgi?debug'>debug</a>
323 </p>
324 EOT
325 ;;
326 esac
328 xhtml_footer
329 exit 0