tinycm annotate plugins/users/users.cgi @ rev 121
Remove ashism ==
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Feb 26 12:26:25 2019 +0100 (2019-02-26) |
parents | 26809676b304 |
children |
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@113 | 18 $PROFILE_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@102 | 74 Authfile : $AUTH_FILE |
pankso@102 | 75 Admin users : $ADMIN_USERS |
pankso@100 | 76 </pre> |
pankso@82 | 77 EOT |
pankso@100 | 78 # Get the list of administrators |
pankso@100 | 79 echo "<h3>Admin users</h3>" |
pankso@102 | 80 echo "<pre>" |
pankso@102 | 81 for u in $(cat $ADMIN_USERS) |
pankso@100 | 82 do |
pankso@102 | 83 . ${PEOPLE}/${u}/account.conf |
pankso@103 | 84 echo "<a href='?user=$u'>$u</a> - $NAME" |
pankso@100 | 85 done |
pankso@102 | 86 echo "</pre>" |
pankso@100 | 87 fi |
pankso@100 | 88 |
pankso@100 | 89 else |
paul@105 | 90 gettext "You must be logged in to check on admin users" |
pankso@100 | 91 fi |
pankso@82 | 92 html_footer && exit 0 ;; |
pankso@82 | 93 |
pankso@82 | 94 *\ userslist\ *) |
pankso@101 | 95 # List all users |
pankso@82 | 96 d="Users" |
pankso@82 | 97 header |
pankso@82 | 98 html_header |
pankso@82 | 99 user_box |
pankso@82 | 100 if check_auth && ! admin_user; then |
pankso@75 | 101 gettext "You must be admin to manage users" |
pankso@75 | 102 exit 0 |
pankso@75 | 103 fi |
pankso@75 | 104 users=$(ls -1 $PEOPLE | wc -l) |
pankso@75 | 105 cat << EOT |
pankso@75 | 106 <div id="tools"> |
pankso@75 | 107 <a href="$script?dashboard">Dashboard</a> |
pankso@101 | 108 <a href="$script?users">Users</a> |
pankso@101 | 109 <a href='$script?lastusers'>Last users</a> |
pankso@75 | 110 </div> |
pankso@100 | 111 <h2>Users: $users</h2> |
pankso@101 | 112 <div id="users"> |
pankso@101 | 113 <table> |
pankso@101 | 114 <thead> |
pankso@101 | 115 <td>$(gettext "Username")</td> |
pankso@101 | 116 <td>$(gettext "Action")</td> |
pankso@101 | 117 </thead> |
pankso@75 | 118 EOT |
pankso@75 | 119 for u in $(ls $PEOPLE) |
pankso@75 | 120 do |
pankso@75 | 121 # Skip corrupted accounts |
pankso@75 | 122 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then |
pankso@75 | 123 echo "${u} : Missing account.conf" |
pankso@75 | 124 continue |
pankso@75 | 125 fi |
pankso@75 | 126 cat << EOT |
pankso@101 | 127 <tr> |
pankso@103 | 128 <td><a href="$script?user=$u">$u</a></td> |
pankso@101 | 129 <td>TODO</td> |
pankso@101 | 130 </tr> |
pankso@75 | 131 EOT |
pankso@82 | 132 # deluser link --> use 'tazu' on SliTaz |
pankso@75 | 133 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> |
pankso@75 | 134 unset NAME USER |
pankso@75 | 135 done |
pankso@101 | 136 echo "</table></div>" |
pankso@75 | 137 html_footer && exit 0 ;; |
pankso@75 | 138 |
pankso@101 | 139 *\ lastusers\ *) |
pankso@75 | 140 # Show online users based on sessions files. |
pankso@101 | 141 d="Last users" |
pankso@75 | 142 header |
pankso@75 | 143 html_header |
pankso@75 | 144 user_box |
pankso@75 | 145 if ! check_auth; then |
pankso@75 | 146 gettext "You must be logged in to view online users" |
pankso@75 | 147 exit 0 |
pankso@75 | 148 fi |
pankso@75 | 149 cat << EOT |
pankso@75 | 150 <div id="tools"> |
pankso@75 | 151 <a href="$script?dashboard">Dashboard</a> |
pankso@100 | 152 <a href="$script?users">Users</a> |
pankso@75 | 153 </div> |
pankso@75 | 154 EOT |
pankso@101 | 155 list_last_users 15 |
pankso@101 | 156 |
pankso@101 | 157 # Active cookies |
pankso@101 | 158 echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>" |
pankso@101 | 159 echo "<pre>" |
pankso@75 | 160 for u in $(ls $sessions) |
pankso@75 | 161 do |
pankso@75 | 162 . "${PEOPLE}/${u}/account.conf" |
pankso@75 | 163 cat << EOT |
pankso@75 | 164 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME |
pankso@75 | 165 EOT |
pankso@75 | 166 done |
pankso@75 | 167 echo "</pre>" |
pankso@75 | 168 html_footer && exit 0 ;; |
pankso@76 | 169 |
pankso@76 | 170 *\ user\ *) |
pankso@76 | 171 # User profile page |
pankso@76 | 172 d="$(GET user)" |
pankso@76 | 173 last="$(cat $PEOPLE/"$(GET user)"/last)" |
pankso@76 | 174 header |
pankso@76 | 175 html_header |
pankso@76 | 176 user_box |
pankso@104 | 177 account_config="$PEOPLE/$(GET user)/account.conf" |
pankso@104 | 178 profile_config="$PEOPLE/$(GET user)/profile.conf" |
pankso@116 | 179 |
pankso@107 | 180 # account.conf |
pankso@104 | 181 if [ ! -f "$account_config" ]; then |
pankso@104 | 182 echo "No user profile for: $(GET user)" |
pankso@104 | 183 html_footer && exit 0 |
pankso@104 | 184 else |
pankso@104 | 185 . ${account_config} |
pankso@104 | 186 fi |
pankso@116 | 187 |
pankso@116 | 188 # profile.conf |
pankso@116 | 189 if [ -f "$profile_config" ]; then |
pankso@106 | 190 . ${profile_config} |
pankso@106 | 191 fi |
pankso@116 | 192 |
pankso@106 | 193 cat << EOT |
pankso@76 | 194 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@76 | 195 |
pankso@76 | 196 <pre> |
pankso@76 | 197 $(gettext "User name :") $USER |
pankso@76 | 198 $(gettext "Last login :") $last |
pankso@76 | 199 EOT |
pascal@121 | 200 if check_auth && [ "$(GET user)" = "$user" ]; then |
pankso@76 | 201 auth_people |
pankso@76 | 202 else |
pankso@76 | 203 # check_auth will set VARS to current logged user: re-source |
pankso@76 | 204 . $PEOPLE/"$(GET user)"/account.conf |
pankso@76 | 205 public_people |
pankso@76 | 206 fi |
pankso@99 | 207 |
pankso@79 | 208 # Display personal user profile |
pankso@79 | 209 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@79 | 210 echo "<h2>$(gettext "About me")</h2>" |
pankso@79 | 211 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@79 | 212 fi |
pankso@107 | 213 |
pankso@113 | 214 # Run user.sh that plugins can provide to add content to a profile |
pankso@107 | 215 for script in $(ls $plugins/*/user.sh); do |
pankso@107 | 216 . ${script} |
pankso@107 | 217 done |
pankso@107 | 218 |
pankso@76 | 219 html_footer && exit 0 ;; |
pankso@76 | 220 |
pankso@77 | 221 *\ modprofile\ *) |
paul@80 | 222 # Let user edit their profile |
pankso@76 | 223 if ! check_auth; then |
pankso@76 | 224 echo "ERROR" && exit 0 |
pankso@76 | 225 fi |
pankso@76 | 226 d="$user profile" |
pankso@76 | 227 path=${PEOPLE}/${user} |
pankso@76 | 228 header |
pankso@76 | 229 html_header |
pankso@76 | 230 user_box |
pankso@76 | 231 cat << EOT |
pankso@77 | 232 <h2>$(gettext "User:") $user</h2> |
pankso@77 | 233 <p>$(gettext "Modify your profile settings") |
pankso@76 | 234 <div id="edit"> |
pankso@76 | 235 |
pankso@76 | 236 <form method="get" action="$script" name="editor"> |
pankso@78 | 237 <input type="hidden" name="saveprofile" /> |
pankso@76 | 238 <h3>Name</h3> |
pankso@76 | 239 <input type="text" name="name" value="$NAME" /> |
pankso@76 | 240 <h3>Email</h3> |
pankso@76 | 241 <input type="text" name="mail" value="$MAIL" /> |
pankso@76 | 242 <h3>About you</h3> |
pankso@76 | 243 <textarea name="profile">$(cat "$path/profile.txt")</textarea> |
pankso@76 | 244 <input type="submit" value="$(gettext "Save profile")" /> |
pankso@76 | 245 </form> |
pankso@76 | 246 |
pankso@76 | 247 </div> |
pankso@76 | 248 EOT |
pankso@76 | 249 html_footer && exit 0 ;; |
pankso@76 | 250 |
pankso@78 | 251 *\ saveprofile\ *) |
pankso@76 | 252 # Save a user profile |
pankso@76 | 253 if check_auth; then |
pankso@76 | 254 path="$PEOPLE/$user" |
pankso@76 | 255 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf |
pankso@76 | 256 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf |
pankso@76 | 257 cp -f ${path}/profile.txt ${path}/profile.bak |
pankso@76 | 258 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT |
pankso@76 | 259 $(GET profile) |
pankso@76 | 260 EOT |
pankso@76 | 261 header "Location: $script?user=$user" |
pankso@76 | 262 fi && exit 0 ;; |
pankso@76 | 263 |
pankso@75 | 264 esac |