tazpanel diff settings.cgi @ rev 47

Move old upgreadeable command to 'up' and small edit
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 08 20:17:30 2011 +0200 (2011-04-08)
parents
children cf15cb2ff715
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/settings.cgi	Fri Apr 08 20:17:30 2011 +0200
     1.3 @@ -0,0 +1,187 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# System settings CGI interface: user, locale, keyboard, date. Since we
     1.7 +# dont have multiple page here there is only one case used to get commands
     1.8 +# values and the full content is following directly. 
     1.9 +#
    1.10 +#
    1.11 +echo "Content-Type: text/html"
    1.12 +echo ""
    1.13 +
    1.14 +# Common functions from libtazpanel
    1.15 +. lib/libtazpanel
    1.16 +get_config
    1.17 +
    1.18 +# Include gettext helper script.
    1.19 +. /usr/bin/gettext.sh
    1.20 +
    1.21 +# Export package name for gettext.
    1.22 +TEXTDOMAIN='tazpanel'
    1.23 +export TEXTDOMAIN
    1.24 +
    1.25 +TITLE="- Settings"
    1.26 +
    1.27 +# Get the list of system locales
    1.28 +list_locales() {
    1.29 +	cd /usr/share/i18n/locales
    1.30 +	for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]`
    1.31 +	do
    1.32 +		echo "<option value='$locale'>$locale</option>"
    1.33 +	done
    1.34 +}
    1.35 +
    1.36 +#
    1.37 +# Commands executed before page loading.
    1.38 +#
    1.39 +
    1.40 +case "$QUERY_STRING" in
    1.41 +	users|user=*)
    1.42 +		#
    1.43 +		# Manage system user accounts
    1.44 +		#
    1.45 +		cmdline=`echo ${QUERY_STRING#user*=} | sed s'/&/ /g'`		
    1.46 +		# Parse cmdline
    1.47 +		for opt in $cmdline
    1.48 +		do
    1.49 +			case $opt in
    1.50 +				adduser=*)
    1.51 +					user=${opt#adduser=}
    1.52 +					cmd=adduser ;;
    1.53 +				deluser=*)
    1.54 +					user=${opt#deluser=}
    1.55 +					deluser $user ;;
    1.56 +				passwd=*)
    1.57 +					pass=${opt#passwd=} ;;
    1.58 +			esac
    1.59 +		done
    1.60 +		case "$cmd" in
    1.61 +			adduser)
    1.62 +				adduser -D $user
    1.63 +				echo "$pass" | chpasswd
    1.64 +				for g in audio cdrom floppy video
    1.65 +				do
    1.66 +					addgroup $user $g
    1.67 +				done ;;
    1.68 +			*) continue ;;
    1.69 +		esac ;;
    1.70 +	gen-locale=*)
    1.71 +		new_locale=${QUERY_STRING#gen-locale=} ;;
    1.72 +	rdate)
    1.73 +		rdate -s tick.greyware.com ;;
    1.74 +	hwclock)
    1.75 +		hwclock -w ;;
    1.76 +	*)
    1.77 +		continue ;;
    1.78 +esac
    1.79 +
    1.80 +#
    1.81 +# Default xHTML content
    1.82 +#
    1.83 +xhtml_header
    1.84 +cat << EOT
    1.85 +<div id="wrapper">
    1.86 +	<h2>`gettext "System settings"`</h2>
    1.87 +	<p>`gettext "Manage system time, users or language settings"`<p>
    1.88 +</div>
    1.89 +
    1.90 +<pre>
    1.91 +`gettext "Time zome      :"` `cat /etc/TZ`
    1.92 +`gettext "System time    :"` `date`
    1.93 +`gettext "Hardware clock :"` `hwclock -r`
    1.94 +</pre>
    1.95 +<a class="button" href="$SCRIPT_NAME?rdate">`gettext "Sync online"`</a>
    1.96 +<a class="button" href="$SCRIPT_NAME?hwclock">`gettext "Set harware clock"`</a>
    1.97 +EOT
    1.98 +#
    1.99 +# Users management
   1.100 +#
   1.101 +
   1.102 +cat <<EOT
   1.103 +<h3>`gettext "Users"`</h3>
   1.104 +<form method="get" action="$SCRIPT_NAME">
   1.105 +EOT
   1.106 +table_start
   1.107 +cat << EOT
   1.108 +<tr class="thead">
   1.109 +	<td>`gettext "Login"`</td>
   1.110 +	<td>`gettext "User ID"`</td>
   1.111 +	<td>`gettext "Name"`</td>
   1.112 +	<td>`gettext "Home"`</td>
   1.113 +	<td>`gettext "SHell"`</td>
   1.114 +</tr>
   1.115 +EOT
   1.116 +for i in `cat /etc/passwd | cut -d ":" -f 1`
   1.117 +do
   1.118 +	if [ -d /home/$i ]; then
   1.119 +		login=$i
   1.120 +		uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
   1.121 +		gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
   1.122 +		name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | \
   1.123 +			sed s/,,,//`
   1.124 +		home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
   1.125 +		shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
   1.126 +		echo '<tr>'
   1.127 +		echo "<td><input type='hidden' name='user' />
   1.128 +			<input type='checkbox' name='deluser' value='$login' />
   1.129 +			<img src='$IMAGES/user.png' />$login</td>"
   1.130 +		echo "<td>$uid:$gid</td>"
   1.131 +		echo "<td>$name</td>"
   1.132 +		echo "<td>$home</td>"
   1.133 +		echo "<td>$shell</td>"
   1.134 +		echo '</tr>'
   1.135 +	fi
   1.136 +done
   1.137 +table_end
   1.138 +cat << EOT
   1.139 +	<div>
   1.140 +		<input type="submit" value="`gettext "Delete selected user"`" />
   1.141 +	</div>
   1.142 +</form>
   1.143 +
   1.144 +<h4>`gettext "Add a new user"`</h4>
   1.145 +<form method="get" action="$SCRIPT_NAME">
   1.146 +	<input type="hidden" name="user" />
   1.147 +	<p>`gettext "User login:"`</p>
   1.148 +	<p><input type="text" name="adduser" size="30" /></p>
   1.149 +	<p>`gettext "User password:"`</p>
   1.150 +	<p><input type="password" name="passwd" size="30" /></p>
   1.151 +	<input type="submit" value="`gettext "Create user"`" />
   1.152 +</form>
   1.153 +EOT
   1.154 +
   1.155 +#
   1.156 +# Locale settings
   1.157 +#
   1.158 +cat << EOT
   1.159 +<a name="locale"></a>
   1.160 +<h3>`gettext "System language"`</h3>
   1.161 +<p>
   1.162 +EOT
   1.163 +		# Check if a new locale was requested
   1.164 +		if [ -n "$new_locale" ]; then
   1.165 +			rm -rf /usr/lib/locale/$new_locale
   1.166 +			localedef -i $new_locale -c -f UTF-8 \
   1.167 +				/usr/lib/locale/$new_locale
   1.168 +			# System configuration
   1.169 +			echo "LANG=$new_locale" > /etc/locale.conf
   1.170 +			echo "LC_ALL=$new_locale" >> /etc/locale.conf
   1.171 +			eval_gettext "You must logout and login again your current
   1.172 +				session to use \$new_locale locale."
   1.173 +		else
   1.174 +			eval_gettext "Current system locales: "
   1.175 +			locale -a
   1.176 +		fi
   1.177 +		cat << EOT
   1.178 +</p>
   1.179 +<form method="get" action="$SCRIPT_NAME">
   1.180 +	`gettext "Avalaible locales:"`
   1.181 +	<select name="gen-locale">
   1.182 +		<option value="en_US">en_US</options>
   1.183 +		`list_locales`
   1.184 +	</select>
   1.185 +	<input type="submit" value="`gettext "Generated and use"`" />
   1.186 +</form>
   1.187 +EOT
   1.188 +
   1.189 +xhtml_footer
   1.190 +exit 0