tazpanel annotate settings.cgi @ rev 330

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