tazpanel annotate settings.cgi @ rev 80
pkgs.cgi: Smaller button and better CSS integration
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Apr 13 12:40:15 2011 +0200 (2011-04-13) |
parents | 730f8bcacabc |
children | 25602bc63ca7 |
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@52 | 4 # dont have multiple pages here there is only one case used to get command |
pankso@49 | 5 # values and the full content is following directly. |
pankso@42 | 6 # |
pankso@49 | 7 # Copyright (C) 2011 SliTaz GNU/Linux - GNU gpl v3 |
pankso@42 | 8 # |
pankso@42 | 9 echo "Content-Type: text/html" |
pankso@42 | 10 echo "" |
pankso@42 | 11 |
pankso@42 | 12 # Common functions from libtazpanel |
pankso@42 | 13 . lib/libtazpanel |
pankso@42 | 14 get_config |
pankso@42 | 15 |
pankso@42 | 16 # Include gettext helper script. |
pankso@42 | 17 . /usr/bin/gettext.sh |
pankso@42 | 18 |
pankso@42 | 19 # Export package name for gettext. |
pankso@42 | 20 TEXTDOMAIN='tazpanel' |
pankso@42 | 21 export TEXTDOMAIN |
pankso@42 | 22 |
pankso@42 | 23 TITLE="- Settings" |
pankso@42 | 24 |
pankso@42 | 25 # Get the list of system locales |
pankso@42 | 26 list_locales() { |
pankso@42 | 27 cd /usr/share/i18n/locales |
pankso@42 | 28 for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]` |
pankso@42 | 29 do |
pankso@42 | 30 echo "<option value='$locale'>$locale</option>" |
pankso@42 | 31 done |
pankso@42 | 32 } |
pankso@42 | 33 |
pankso@42 | 34 # |
pankso@42 | 35 # Commands executed before page loading. |
pankso@42 | 36 # |
pankso@42 | 37 |
pankso@42 | 38 case "$QUERY_STRING" in |
pankso@42 | 39 users|user=*) |
pankso@42 | 40 # |
pankso@42 | 41 # Manage system user accounts |
pankso@42 | 42 # |
pankso@42 | 43 cmdline=`echo ${QUERY_STRING#user*=} | sed s'/&/ /g'` |
pankso@42 | 44 # Parse cmdline |
pankso@42 | 45 for opt in $cmdline |
pankso@42 | 46 do |
pankso@42 | 47 case $opt in |
pankso@42 | 48 adduser=*) |
pankso@42 | 49 user=${opt#adduser=} |
pankso@42 | 50 cmd=adduser ;; |
pankso@42 | 51 deluser=*) |
pankso@42 | 52 user=${opt#deluser=} |
pankso@42 | 53 deluser $user ;; |
pankso@42 | 54 passwd=*) |
pankso@42 | 55 pass=${opt#passwd=} ;; |
pankso@42 | 56 esac |
pankso@42 | 57 done |
pankso@42 | 58 case "$cmd" in |
pankso@42 | 59 adduser) |
pankso@42 | 60 adduser -D $user |
pankso@42 | 61 echo "$pass" | chpasswd |
pankso@42 | 62 for g in audio cdrom floppy video |
pankso@42 | 63 do |
pankso@42 | 64 addgroup $user $g |
pankso@42 | 65 done ;; |
pankso@42 | 66 *) continue ;; |
pankso@42 | 67 esac ;; |
pankso@42 | 68 gen-locale=*) |
pankso@42 | 69 new_locale=${QUERY_STRING#gen-locale=} ;; |
pankso@42 | 70 rdate) |
pankso@42 | 71 rdate -s tick.greyware.com ;; |
pankso@42 | 72 hwclock) |
pankso@42 | 73 hwclock -w ;; |
pankso@42 | 74 *) |
pankso@42 | 75 continue ;; |
pankso@42 | 76 esac |
pankso@42 | 77 |
pankso@42 | 78 # |
pankso@42 | 79 # Default xHTML content |
pankso@42 | 80 # |
pankso@42 | 81 xhtml_header |
pankso@67 | 82 |
pankso@42 | 83 cat << EOT |
pankso@42 | 84 <div id="wrapper"> |
pankso@42 | 85 <h2>`gettext "System settings"`</h2> |
pankso@42 | 86 <p>`gettext "Manage system time, users or language settings"`<p> |
pankso@42 | 87 </div> |
pankso@42 | 88 |
pankso@42 | 89 <pre> |
pankso@42 | 90 `gettext "Time zome :"` `cat /etc/TZ` |
pankso@42 | 91 `gettext "System time :"` `date` |
pankso@42 | 92 `gettext "Hardware clock :"` `hwclock -r` |
pankso@42 | 93 </pre> |
pankso@42 | 94 <a class="button" href="$SCRIPT_NAME?rdate">`gettext "Sync online"`</a> |
paul@52 | 95 <a class="button" href="$SCRIPT_NAME?hwclock">`gettext "Set hardware clock"`</a> |
pankso@42 | 96 EOT |
pankso@42 | 97 # |
pankso@42 | 98 # Users management |
pankso@42 | 99 # |
pankso@42 | 100 |
pankso@42 | 101 cat <<EOT |
pankso@42 | 102 <h3>`gettext "Users"`</h3> |
pankso@42 | 103 <form method="get" action="$SCRIPT_NAME"> |
pankso@42 | 104 EOT |
pankso@42 | 105 table_start |
pankso@42 | 106 cat << EOT |
pankso@42 | 107 <tr class="thead"> |
pankso@42 | 108 <td>`gettext "Login"`</td> |
pankso@42 | 109 <td>`gettext "User ID"`</td> |
pankso@42 | 110 <td>`gettext "Name"`</td> |
pankso@42 | 111 <td>`gettext "Home"`</td> |
pankso@42 | 112 <td>`gettext "SHell"`</td> |
pankso@42 | 113 </tr> |
pankso@42 | 114 EOT |
pankso@42 | 115 for i in `cat /etc/passwd | cut -d ":" -f 1` |
pankso@42 | 116 do |
pankso@42 | 117 if [ -d /home/$i ]; then |
pankso@42 | 118 login=$i |
pankso@42 | 119 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3` |
pankso@42 | 120 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4` |
pankso@42 | 121 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | \ |
pankso@42 | 122 sed s/,,,//` |
pankso@42 | 123 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6` |
pankso@42 | 124 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7` |
pankso@42 | 125 echo '<tr>' |
pankso@42 | 126 echo "<td><input type='hidden' name='user' /> |
pankso@42 | 127 <input type='checkbox' name='deluser' value='$login' /> |
pankso@42 | 128 <img src='$IMAGES/user.png' />$login</td>" |
pankso@42 | 129 echo "<td>$uid:$gid</td>" |
pankso@42 | 130 echo "<td>$name</td>" |
pankso@42 | 131 echo "<td>$home</td>" |
pankso@42 | 132 echo "<td>$shell</td>" |
pankso@42 | 133 echo '</tr>' |
pankso@42 | 134 fi |
pankso@42 | 135 done |
pankso@42 | 136 table_end |
pankso@42 | 137 cat << EOT |
pankso@42 | 138 <div> |
pankso@42 | 139 <input type="submit" value="`gettext "Delete selected user"`" /> |
pankso@42 | 140 </div> |
pankso@42 | 141 </form> |
pankso@42 | 142 |
pankso@42 | 143 <h4>`gettext "Add a new user"`</h4> |
pankso@42 | 144 <form method="get" action="$SCRIPT_NAME"> |
pankso@42 | 145 <input type="hidden" name="user" /> |
pankso@42 | 146 <p>`gettext "User login:"`</p> |
pankso@42 | 147 <p><input type="text" name="adduser" size="30" /></p> |
pankso@42 | 148 <p>`gettext "User password:"`</p> |
pankso@42 | 149 <p><input type="password" name="passwd" size="30" /></p> |
pankso@42 | 150 <input type="submit" value="`gettext "Create user"`" /> |
pankso@42 | 151 </form> |
pankso@42 | 152 EOT |
pankso@42 | 153 |
pankso@42 | 154 # |
pankso@42 | 155 # Locale settings |
pankso@42 | 156 # |
pankso@42 | 157 cat << EOT |
pankso@42 | 158 <a name="locale"></a> |
pankso@42 | 159 <h3>`gettext "System language"`</h3> |
pankso@42 | 160 <p> |
pankso@42 | 161 EOT |
pankso@42 | 162 # Check if a new locale was requested |
pankso@42 | 163 if [ -n "$new_locale" ]; then |
pankso@42 | 164 rm -rf /usr/lib/locale/$new_locale |
pankso@42 | 165 localedef -i $new_locale -c -f UTF-8 \ |
pankso@42 | 166 /usr/lib/locale/$new_locale |
pankso@42 | 167 # System configuration |
pankso@42 | 168 echo "LANG=$new_locale" > /etc/locale.conf |
pankso@42 | 169 echo "LC_ALL=$new_locale" >> /etc/locale.conf |
paul@52 | 170 eval_gettext "You must logout and login again to your current |
pankso@42 | 171 session to use \$new_locale locale." |
pankso@42 | 172 else |
pankso@42 | 173 eval_gettext "Current system locales: " |
pankso@42 | 174 locale -a |
pankso@42 | 175 fi |
pankso@42 | 176 cat << EOT |
pankso@42 | 177 </p> |
pankso@42 | 178 <form method="get" action="$SCRIPT_NAME"> |
paul@52 | 179 `gettext "Available locales:"` |
pankso@42 | 180 <select name="gen-locale"> |
pankso@42 | 181 <option value="en_US">en_US</options> |
pankso@42 | 182 `list_locales` |
pankso@42 | 183 </select> |
pankso@42 | 184 <input type="submit" value="`gettext "Generated and use"`" /> |
pankso@42 | 185 </form> |
pankso@42 | 186 EOT |
pankso@42 | 187 |
pankso@42 | 188 xhtml_footer |
pankso@42 | 189 exit 0 |