tazbug annotate web/plugins/users/users.cgi @ rev 134
Tiny edits
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Tue Feb 21 19:12:22 2017 +0000 (2017-02-21) |
parents | 039c90c60494 |
children | 49fa101e75f5 |
rev | line source |
---|---|
pankso@66 | 1 #!/bin/sh |
pankso@66 | 2 # |
pankso@106 | 3 # TinyCM/TazBug Plugin - Users profile and admin |
pankso@66 | 4 # |
pankso@66 | 5 |
pankso@111 | 6 # Display user public profile. |
pankso@111 | 7 public_people() { |
pankso@111 | 8 echo "</pre>" |
pankso@111 | 9 } |
pankso@111 | 10 |
pankso@111 | 11 # Display authenticated user profile. TODO: change password |
pankso@111 | 12 auth_people() { |
pankso@111 | 13 cat << EOT |
pankso@111 | 14 Email : $MAIL |
pankso@111 | 15 </pre> |
pankso@123 | 16 |
pankso@111 | 17 <div id="tools"> |
pankso@123 | 18 $PLUGINS_TOOLS |
pankso@111 | 19 <a href="$script?modprofile">$(gettext "Modify profile")</a> |
pankso@111 | 20 </div> |
pankso@111 | 21 EOT |
pankso@123 | 22 } |
pankso@123 | 23 |
pankso@123 | 24 # List last active users. Usage: last_users NB |
pankso@123 | 25 list_last_users() { |
pankso@123 | 26 count=${1} |
pankso@123 | 27 echo "<h3>Last $count active users</h3>" |
pankso@123 | 28 echo "<pre>" |
pankso@123 | 29 find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last; |
pankso@123 | 30 do |
pankso@123 | 31 dir="$(dirname $last)" |
pankso@123 | 32 date="$(cat $last)" |
pankso@123 | 33 u=$(basename $dir) |
pankso@123 | 34 . "${PEOPLE}/${u}/account.conf" |
pankso@123 | 35 cat << EOT |
pankso@123 | 36 $(get_gravatar $MAIL 24) $date : <a href="?user=$u">$u</a> | $NAME |
pankso@111 | 37 EOT |
pankso@123 | 38 done |
pankso@123 | 39 echo "</pre>" |
pankso@111 | 40 } |
pankso@111 | 41 |
pankso@66 | 42 case " $(GET) " in |
pankso@66 | 43 *\ users\ *) |
pankso@66 | 44 d="Users" |
pankso@66 | 45 header |
pankso@66 | 46 html_header |
pankso@66 | 47 user_box |
pankso@123 | 48 # Admin only |
pankso@123 | 49 if admin_user; then |
pankso@123 | 50 tools="<a href='$script?userslist'>Users list</a>" |
pankso@118 | 51 fi |
pankso@123 | 52 # Logged users |
pankso@123 | 53 if check_auth; then |
pankso@123 | 54 cat << EOT |
pankso@118 | 55 <div id="tools"> |
pankso@118 | 56 <a href="$script?dashboard">Dashboard</a> |
pankso@123 | 57 <a href='$script?lastusers'>Last users</a> |
pankso@123 | 58 $tools |
pankso@118 | 59 </div> |
pankso@123 | 60 <h2>${d}</h2> |
pankso@118 | 61 <pre> |
pankso@118 | 62 User accounts : $(ls -1 $PEOPLE | wc -l) |
pankso@118 | 63 Logged users : $(ls $sessions | wc -l) |
pankso@123 | 64 </pre> |
pankso@123 | 65 EOT |
pankso@123 | 66 list_last_users 5 |
pankso@123 | 67 |
pankso@123 | 68 # Admin only |
pankso@123 | 69 if admin_user; then |
pankso@123 | 70 cat << EOT |
pankso@123 | 71 <h3>Config paths</h3> |
pankso@123 | 72 <pre> |
pankso@118 | 73 People DB : $PEOPLE |
pankso@123 | 74 Authfile : $AUTH_FILE |
pankso@123 | 75 Admin users : $ADMIN_USERS |
pankso@123 | 76 </pre> |
pankso@118 | 77 EOT |
pankso@123 | 78 # Get the list of administrators |
pankso@123 | 79 echo "<h3>Admin users</h3>" |
pankso@123 | 80 echo "<pre>" |
pankso@123 | 81 for u in $(cat $ADMIN_USERS) |
pankso@123 | 82 do |
pankso@123 | 83 . ${PEOPLE}/${u}/account.conf |
pankso@123 | 84 echo "<a href='?user=$u'>$u</a> - $NAME" |
pankso@123 | 85 done |
pankso@123 | 86 echo "</pre>" |
pankso@123 | 87 fi |
pankso@123 | 88 |
pankso@123 | 89 else |
paul@134 | 90 gettext "You must be logged in to check on admin users" |
pankso@123 | 91 fi |
pankso@118 | 92 html_footer && exit 0 ;; |
pankso@118 | 93 |
pankso@118 | 94 *\ userslist\ *) |
pankso@123 | 95 # List all users |
pankso@118 | 96 d="Users" |
pankso@118 | 97 header |
pankso@118 | 98 html_header |
pankso@118 | 99 user_box |
pankso@118 | 100 if check_auth && ! admin_user; then |
pankso@66 | 101 gettext "You must be admin to manage users" |
pankso@66 | 102 exit 0 |
pankso@66 | 103 fi |
pankso@66 | 104 users=$(ls -1 $PEOPLE | wc -l) |
pankso@66 | 105 cat << EOT |
pankso@66 | 106 <div id="tools"> |
pankso@66 | 107 <a href="$script?dashboard">Dashboard</a> |
pankso@123 | 108 <a href="$script?users">Users</a> |
pankso@123 | 109 <a href='$script?lastusers'>Last users</a> |
pankso@66 | 110 </div> |
pankso@123 | 111 <h2>Users: $users</h2> |
pankso@123 | 112 <div id="users"> |
pankso@123 | 113 <table> |
pankso@123 | 114 <thead> |
pankso@123 | 115 <td>$(gettext "Username")</td> |
pankso@123 | 116 <td>$(gettext "Action")</td> |
pankso@123 | 117 </thead> |
pankso@66 | 118 EOT |
pankso@66 | 119 for u in $(ls $PEOPLE) |
pankso@66 | 120 do |
pankso@93 | 121 # Skip corrupted accounts |
pankso@93 | 122 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then |
pankso@93 | 123 echo "${u} : Missing account.conf" |
pankso@93 | 124 continue |
pankso@93 | 125 fi |
pankso@66 | 126 cat << EOT |
pankso@123 | 127 <tr> |
pankso@123 | 128 <td><a href="$script?user=$u">$u</a></td> |
pankso@123 | 129 <td>TODO</td> |
pankso@123 | 130 </tr> |
pankso@66 | 131 EOT |
pankso@118 | 132 # deluser link --> use 'tazu' on SliTaz |
pankso@66 | 133 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> |
pankso@66 | 134 unset NAME USER |
pankso@66 | 135 done |
pankso@123 | 136 echo "</table></div>" |
pankso@93 | 137 html_footer && exit 0 ;; |
pankso@66 | 138 |
pankso@123 | 139 *\ lastusers\ *) |
pankso@66 | 140 # Show online users based on sessions files. |
pankso@123 | 141 d="Last users" |
pankso@66 | 142 header |
pankso@66 | 143 html_header |
pankso@66 | 144 user_box |
pankso@66 | 145 if ! check_auth; then |
paul@70 | 146 gettext "You must be logged in to view online users" |
pankso@66 | 147 exit 0 |
pankso@66 | 148 fi |
pankso@66 | 149 cat << EOT |
pankso@66 | 150 <div id="tools"> |
pankso@66 | 151 <a href="$script?dashboard">Dashboard</a> |
pankso@123 | 152 <a href="$script?users">Users</a> |
pankso@66 | 153 </div> |
pankso@66 | 154 EOT |
pankso@123 | 155 list_last_users 15 |
pankso@123 | 156 |
pankso@123 | 157 # Active cookies |
pankso@123 | 158 echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>" |
pankso@123 | 159 echo "<pre>" |
pankso@66 | 160 for u in $(ls $sessions) |
pankso@66 | 161 do |
pankso@66 | 162 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 163 cat << EOT |
pankso@66 | 164 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME |
pankso@66 | 165 EOT |
pankso@66 | 166 done |
pankso@66 | 167 echo "</pre>" |
pankso@66 | 168 html_footer && exit 0 ;; |
pankso@111 | 169 |
pankso@111 | 170 *\ user\ *) |
pankso@111 | 171 # User profile page |
pankso@111 | 172 d="$(GET user)" |
pankso@111 | 173 last="$(cat $PEOPLE/"$(GET user)"/last)" |
pankso@111 | 174 header |
pankso@111 | 175 html_header |
pankso@111 | 176 user_box |
pankso@123 | 177 account_config="$PEOPLE/$(GET user)/account.conf" |
pankso@123 | 178 profile_config="$PEOPLE/$(GET user)/profile.conf" |
pankso@123 | 179 if [ ! -f "$account_config" ]; then |
pankso@123 | 180 echo "No user profile for: $(GET user)" |
pankso@123 | 181 html_footer && exit 0 |
pankso@123 | 182 else |
pankso@123 | 183 . ${account_config} |
pankso@123 | 184 fi |
pankso@123 | 185 [ -f "$profile_config" ] && . ${profile_config} |
pankso@111 | 186 cat << EOT |
pankso@111 | 187 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@111 | 188 |
pankso@111 | 189 <pre> |
pankso@111 | 190 $(gettext "User name :") $USER |
pankso@111 | 191 $(gettext "Last login :") $last |
pankso@111 | 192 EOT |
pankso@111 | 193 if check_auth && [ "$(GET user)" == "$user" ]; then |
pankso@111 | 194 auth_people |
pankso@111 | 195 else |
pankso@111 | 196 # check_auth will set VARS to current logged user: re-source |
pankso@111 | 197 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 198 public_people |
pankso@111 | 199 fi |
pankso@123 | 200 |
pankso@123 | 201 # Messages plugin integration |
pankso@123 | 202 if [ -x "$plugins/messages/messages.cgi" ]; then |
pankso@123 | 203 if check_auth && [ "$(GET user)" != "$user" ]; then |
pankso@123 | 204 cat << EOT |
pankso@123 | 205 <div id="tools"> |
pankso@123 | 206 <a href="$script?messages&to=$(GET user)">$(gettext "Send message")</a> |
pankso@123 | 207 </div> |
pankso@123 | 208 EOT |
pankso@123 | 209 fi |
pankso@123 | 210 fi |
pankso@123 | 211 |
pankso@112 | 212 # Display personal user profile |
pankso@112 | 213 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@112 | 214 echo "<h2>$(gettext "About me")</h2>" |
pankso@112 | 215 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@112 | 216 fi |
pankso@111 | 217 html_footer && exit 0 ;; |
pankso@111 | 218 |
pankso@111 | 219 *\ modprofile\ *) |
pankso@118 | 220 # Let user edit their profile |
pankso@111 | 221 if ! check_auth; then |
pankso@111 | 222 echo "ERROR" && exit 0 |
pankso@111 | 223 fi |
pankso@111 | 224 d="$user profile" |
pankso@111 | 225 path=${PEOPLE}/${user} |
pankso@111 | 226 header |
pankso@111 | 227 html_header |
pankso@111 | 228 user_box |
pankso@111 | 229 cat << EOT |
pankso@111 | 230 <h2>$(gettext "User:") $user</h2> |
pankso@111 | 231 <p>$(gettext "Modify your profile settings") |
pankso@111 | 232 <div id="edit"> |
pankso@111 | 233 |
pankso@111 | 234 <form method="get" action="$script" name="editor"> |
pankso@111 | 235 <input type="hidden" name="saveprofile" /> |
pankso@111 | 236 <h3>Name</h3> |
pankso@111 | 237 <input type="text" name="name" value="$NAME" /> |
pankso@111 | 238 <h3>Email</h3> |
pankso@111 | 239 <input type="text" name="mail" value="$MAIL" /> |
pankso@111 | 240 <h3>About you</h3> |
pankso@111 | 241 <textarea name="profile">$(cat "$path/profile.txt")</textarea> |
pankso@111 | 242 <input type="submit" value="$(gettext "Save profile")" /> |
pankso@111 | 243 </form> |
pankso@111 | 244 |
pankso@111 | 245 </div> |
pankso@111 | 246 EOT |
pankso@111 | 247 html_footer && exit 0 ;; |
pankso@111 | 248 |
pankso@111 | 249 *\ saveprofile\ *) |
pankso@111 | 250 # Save a user profile |
pankso@111 | 251 if check_auth; then |
pankso@111 | 252 path="$PEOPLE/$user" |
pankso@111 | 253 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf |
pankso@111 | 254 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf |
pankso@111 | 255 cp -f ${path}/profile.txt ${path}/profile.bak |
pankso@111 | 256 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT |
pankso@111 | 257 $(GET profile) |
pankso@111 | 258 EOT |
pankso@111 | 259 header "Location: $script?user=$user" |
pankso@111 | 260 fi && exit 0 ;; |
pankso@111 | 261 |
pankso@66 | 262 esac |