tazbug annotate web/plugins/users/users.cgi @ rev 118
Up plugins/users and small improvments to dashboard
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Feb 11 22:27:47 2017 +0100 (2017-02-11) |
parents | c9939a4ea74c |
children | 39a59a1271e5 |
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@111 | 16 EOT |
pankso@111 | 17 # Each user can have personal profile page |
pankso@111 | 18 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@111 | 19 cat << EOT |
pankso@111 | 20 <div id="tools"> |
pankso@111 | 21 <a href="$script?modprofile">$(gettext "Modify profile")</a> |
pankso@111 | 22 <a href="$script?dashboard">Dashboard</a> |
pankso@111 | 23 </div> |
pankso@111 | 24 EOT |
pankso@111 | 25 else |
pankso@111 | 26 cat << EOT |
pankso@111 | 27 <div id="tools"> |
pankso@111 | 28 <a href="$script?modprofile">$(gettext "Create a profile page")</a> |
pankso@111 | 29 <a href="$script?dashboard">Dashboard</a> |
pankso@111 | 30 </div> |
pankso@111 | 31 EOT |
pankso@111 | 32 fi |
pankso@111 | 33 } |
pankso@111 | 34 |
pankso@66 | 35 case " $(GET) " in |
pankso@66 | 36 *\ users\ *) |
pankso@66 | 37 d="Users" |
pankso@66 | 38 header |
pankso@66 | 39 html_header |
pankso@66 | 40 user_box |
pankso@66 | 41 if check_auth && ! admin_user; then |
pankso@118 | 42 gettext "You must be admin to manage users" && exit 0 |
pankso@118 | 43 fi |
pankso@118 | 44 cat << EOT |
pankso@118 | 45 <h2>Users admin</h2> |
pankso@118 | 46 <div id="tools"> |
pankso@118 | 47 <a href="$script?dashboard">Dashboard</a> |
pankso@118 | 48 <a href='$script?loggedusers'>Logged users</a> |
pankso@118 | 49 <a href='$script?userslist'>Users list</a> |
pankso@118 | 50 </div> |
pankso@118 | 51 <pre> |
pankso@118 | 52 User accounts : $(ls -1 $PEOPLE | wc -l) |
pankso@118 | 53 Logged users : $(ls $sessions | wc -l) |
pankso@118 | 54 People DB : $PEOPLE |
pankso@118 | 55 Auth file : $AUTH_FILE |
pankso@118 | 56 EOT |
pankso@118 | 57 |
pankso@118 | 58 echo "</pre>" |
pankso@118 | 59 html_footer && exit 0 ;; |
pankso@118 | 60 |
pankso@118 | 61 *\ userslist\ *) |
pankso@118 | 62 # List all users (slow if a llots a of accounts) |
pankso@118 | 63 d="Users" |
pankso@118 | 64 header |
pankso@118 | 65 html_header |
pankso@118 | 66 user_box |
pankso@118 | 67 if check_auth && ! admin_user; then |
pankso@66 | 68 gettext "You must be admin to manage users" |
pankso@66 | 69 exit 0 |
pankso@66 | 70 fi |
pankso@66 | 71 users=$(ls -1 $PEOPLE | wc -l) |
pankso@66 | 72 cat << EOT |
pankso@66 | 73 <h2>Users: $users</h2> |
pankso@66 | 74 <div id="tools"> |
pankso@66 | 75 <a href="$script?dashboard">Dashboard</a> |
pankso@118 | 76 <a href="$script?users">Users admin</a> |
pankso@118 | 77 <a href='$script?loggedusers'>Logged users</a> |
pankso@66 | 78 </div> |
pankso@66 | 79 <pre> |
pankso@66 | 80 EOT |
pankso@66 | 81 for u in $(ls $PEOPLE) |
pankso@66 | 82 do |
pankso@93 | 83 # Skip corrupted accounts |
pankso@93 | 84 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then |
pankso@93 | 85 echo "${u} : Missing account.conf" |
pankso@93 | 86 continue |
pankso@93 | 87 fi |
pankso@66 | 88 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 89 cat << EOT |
pankso@66 | 90 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL |
pankso@66 | 91 EOT |
pankso@118 | 92 # deluser link --> use 'tazu' on SliTaz |
pankso@66 | 93 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> |
pankso@66 | 94 unset NAME USER |
pankso@66 | 95 done |
pankso@93 | 96 echo "</pre>" |
pankso@93 | 97 html_footer && exit 0 ;; |
pankso@66 | 98 |
pankso@118 | 99 *\ loggedusers\ *) |
pankso@66 | 100 # Show online users based on sessions files. |
pankso@69 | 101 d="Logged users" |
pankso@66 | 102 header |
pankso@66 | 103 html_header |
pankso@66 | 104 user_box |
pankso@66 | 105 if ! check_auth; then |
paul@70 | 106 gettext "You must be logged in to view online users" |
pankso@66 | 107 exit 0 |
pankso@66 | 108 fi |
pankso@118 | 109 logged="$(ls $sessions | wc -l)" |
pankso@66 | 110 cat << EOT |
pankso@118 | 111 <h2>Logged users: $logged</h2> |
pankso@66 | 112 <div id="tools"> |
pankso@66 | 113 <a href="$script?dashboard">Dashboard</a> |
pankso@118 | 114 <a href="$script?users">Users admin</a> |
pankso@66 | 115 </div> |
pankso@66 | 116 <pre> |
pankso@66 | 117 EOT |
pankso@66 | 118 for u in $(ls $sessions) |
pankso@66 | 119 do |
pankso@66 | 120 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 121 cat << EOT |
pankso@66 | 122 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME |
pankso@66 | 123 EOT |
pankso@66 | 124 done |
pankso@66 | 125 echo "</pre>" |
pankso@66 | 126 html_footer && exit 0 ;; |
pankso@111 | 127 |
pankso@111 | 128 *\ user\ *) |
pankso@111 | 129 # User profile page |
pankso@111 | 130 d="$(GET user)" |
pankso@111 | 131 last="$(cat $PEOPLE/"$(GET user)"/last)" |
pankso@111 | 132 header |
pankso@111 | 133 html_header |
pankso@111 | 134 user_box |
pankso@111 | 135 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 136 cat << EOT |
pankso@111 | 137 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@111 | 138 |
pankso@111 | 139 <pre> |
pankso@111 | 140 $(gettext "User name :") $USER |
pankso@111 | 141 $(gettext "Last login :") $last |
pankso@111 | 142 EOT |
pankso@111 | 143 if check_auth && [ "$(GET user)" == "$user" ]; then |
pankso@111 | 144 auth_people |
pankso@111 | 145 else |
pankso@111 | 146 # check_auth will set VARS to current logged user: re-source |
pankso@111 | 147 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 148 public_people |
pankso@111 | 149 fi |
pankso@112 | 150 # Display personal user profile |
pankso@112 | 151 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@112 | 152 echo "<h2>$(gettext "About me")</h2>" |
pankso@112 | 153 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@112 | 154 fi |
pankso@111 | 155 html_footer && exit 0 ;; |
pankso@111 | 156 |
pankso@111 | 157 *\ modprofile\ *) |
pankso@118 | 158 # Let user edit their profile |
pankso@111 | 159 if ! check_auth; then |
pankso@111 | 160 echo "ERROR" && exit 0 |
pankso@111 | 161 fi |
pankso@111 | 162 d="$user profile" |
pankso@111 | 163 path=${PEOPLE}/${user} |
pankso@111 | 164 header |
pankso@111 | 165 html_header |
pankso@111 | 166 user_box |
pankso@111 | 167 cat << EOT |
pankso@111 | 168 <h2>$(gettext "User:") $user</h2> |
pankso@111 | 169 <p>$(gettext "Modify your profile settings") |
pankso@111 | 170 <div id="edit"> |
pankso@111 | 171 |
pankso@111 | 172 <form method="get" action="$script" name="editor"> |
pankso@111 | 173 <input type="hidden" name="saveprofile" /> |
pankso@111 | 174 <h3>Name</h3> |
pankso@111 | 175 <input type="text" name="name" value="$NAME" /> |
pankso@111 | 176 <h3>Email</h3> |
pankso@111 | 177 <input type="text" name="mail" value="$MAIL" /> |
pankso@111 | 178 <h3>About you</h3> |
pankso@111 | 179 <textarea name="profile">$(cat "$path/profile.txt")</textarea> |
pankso@111 | 180 <input type="submit" value="$(gettext "Save profile")" /> |
pankso@111 | 181 </form> |
pankso@111 | 182 |
pankso@111 | 183 </div> |
pankso@111 | 184 EOT |
pankso@111 | 185 html_footer && exit 0 ;; |
pankso@111 | 186 |
pankso@111 | 187 *\ saveprofile\ *) |
pankso@111 | 188 # Save a user profile |
pankso@111 | 189 if check_auth; then |
pankso@111 | 190 path="$PEOPLE/$user" |
pankso@111 | 191 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf |
pankso@111 | 192 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf |
pankso@111 | 193 cp -f ${path}/profile.txt ${path}/profile.bak |
pankso@111 | 194 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT |
pankso@111 | 195 $(GET profile) |
pankso@111 | 196 EOT |
pankso@111 | 197 header "Location: $script?user=$user" |
pankso@111 | 198 fi && exit 0 ;; |
pankso@111 | 199 |
pankso@66 | 200 esac |