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