tazbug annotate web/plugins/users/users.cgi @ rev 141
Improve mybugs plugin
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Feb 22 21:18:03 2017 +0100 (2017-02-22) |
parents | 49fa101e75f5 |
children | 6db228036db5 |
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@141 | 18 $PROFILE_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@140 | 179 # account.conf |
pankso@123 | 180 if [ ! -f "$account_config" ]; then |
pankso@123 | 181 echo "No user profile for: $(GET user)" |
pankso@123 | 182 html_footer && exit 0 |
pankso@123 | 183 else |
pankso@123 | 184 . ${account_config} |
pankso@123 | 185 fi |
pankso@140 | 186 # Init profile.conf |
pankso@140 | 187 if [ -f "${profile_config}" ]; then |
pankso@140 | 188 . ${profile_config} |
pankso@140 | 189 else |
pankso@140 | 190 cat > $PEOPLE/$user/profile.conf << EOT |
pankso@140 | 191 # User profile |
pankso@140 | 192 WEBSITE="$website" |
pankso@140 | 193 FACEBOOK="$facebook" |
pankso@140 | 194 TWITTER="$twitter" |
pankso@140 | 195 EOT |
pankso@140 | 196 chmod 0600 $PEOPLE/$user/profile.conf |
pankso@140 | 197 fi |
pankso@140 | 198 cat << EOT |
pankso@111 | 199 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@111 | 200 |
pankso@111 | 201 <pre> |
pankso@111 | 202 $(gettext "User name :") $USER |
pankso@111 | 203 $(gettext "Last login :") $last |
pankso@111 | 204 EOT |
pankso@111 | 205 if check_auth && [ "$(GET user)" == "$user" ]; then |
pankso@111 | 206 auth_people |
pankso@111 | 207 else |
pankso@111 | 208 # check_auth will set VARS to current logged user: re-source |
pankso@111 | 209 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 210 public_people |
pankso@111 | 211 fi |
pankso@123 | 212 |
pankso@112 | 213 # Display personal user profile |
pankso@112 | 214 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@112 | 215 echo "<h2>$(gettext "About me")</h2>" |
pankso@112 | 216 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@112 | 217 fi |
pankso@140 | 218 |
pankso@140 | 219 # Run user.sh that plugins can provide to add content to a profile |
pankso@140 | 220 for script in $(ls $plugins/*/user.sh); do |
pankso@140 | 221 . ${script} |
pankso@140 | 222 done |
pankso@140 | 223 |
pankso@111 | 224 html_footer && exit 0 ;; |
pankso@111 | 225 |
pankso@111 | 226 *\ modprofile\ *) |
pankso@118 | 227 # Let user edit their profile |
pankso@111 | 228 if ! check_auth; then |
pankso@111 | 229 echo "ERROR" && exit 0 |
pankso@111 | 230 fi |
pankso@111 | 231 d="$user profile" |
pankso@111 | 232 path=${PEOPLE}/${user} |
pankso@111 | 233 header |
pankso@111 | 234 html_header |
pankso@111 | 235 user_box |
pankso@111 | 236 cat << EOT |
pankso@111 | 237 <h2>$(gettext "User:") $user</h2> |
pankso@111 | 238 <p>$(gettext "Modify your profile settings") |
pankso@111 | 239 <div id="edit"> |
pankso@111 | 240 |
pankso@111 | 241 <form method="get" action="$script" name="editor"> |
pankso@111 | 242 <input type="hidden" name="saveprofile" /> |
pankso@111 | 243 <h3>Name</h3> |
pankso@111 | 244 <input type="text" name="name" value="$NAME" /> |
pankso@111 | 245 <h3>Email</h3> |
pankso@111 | 246 <input type="text" name="mail" value="$MAIL" /> |
pankso@111 | 247 <h3>About you</h3> |
pankso@111 | 248 <textarea name="profile">$(cat "$path/profile.txt")</textarea> |
pankso@111 | 249 <input type="submit" value="$(gettext "Save profile")" /> |
pankso@111 | 250 </form> |
pankso@111 | 251 |
pankso@111 | 252 </div> |
pankso@111 | 253 EOT |
pankso@111 | 254 html_footer && exit 0 ;; |
pankso@111 | 255 |
pankso@111 | 256 *\ saveprofile\ *) |
pankso@111 | 257 # Save a user profile |
pankso@111 | 258 if check_auth; then |
pankso@111 | 259 path="$PEOPLE/$user" |
pankso@111 | 260 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf |
pankso@111 | 261 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf |
pankso@111 | 262 cp -f ${path}/profile.txt ${path}/profile.bak |
pankso@111 | 263 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT |
pankso@111 | 264 $(GET profile) |
pankso@111 | 265 EOT |
pankso@111 | 266 header "Location: $script?user=$user" |
pankso@111 | 267 fi && exit 0 ;; |
pankso@111 | 268 |
pankso@66 | 269 esac |