tazbug annotate web/plugins/users/users.cgi @ rev 159

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