tazbug annotate web/plugins/users/users.cgi @ rev 112
Small fixes
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Feb 11 00:00:17 2017 +0100 (2017-02-11) |
parents | 0dfc02021c92 |
children | b19dbd851223 |
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@66 | 42 gettext "You must be admin to manage users" |
pankso@66 | 43 exit 0 |
pankso@66 | 44 fi |
pankso@66 | 45 users=$(ls -1 $PEOPLE | wc -l) |
pankso@66 | 46 cat << EOT |
pankso@66 | 47 <h2>Users: $users</h2> |
pankso@66 | 48 <div id="tools"> |
pankso@66 | 49 <a href="$script?dashboard">Dashboard</a> |
pankso@72 | 50 <a href='?logged'>Logged users</a> |
pankso@66 | 51 </div> |
pankso@66 | 52 <pre> |
pankso@66 | 53 EOT |
pankso@66 | 54 for u in $(ls $PEOPLE) |
pankso@66 | 55 do |
pankso@93 | 56 # Skip corrupted accounts |
pankso@93 | 57 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then |
pankso@93 | 58 echo "${u} : Missing account.conf" |
pankso@93 | 59 continue |
pankso@93 | 60 fi |
pankso@66 | 61 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 62 cat << EOT |
pankso@66 | 63 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL |
pankso@66 | 64 EOT |
pankso@66 | 65 # deluser link |
pankso@66 | 66 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> |
pankso@66 | 67 unset NAME USER |
pankso@66 | 68 done |
pankso@93 | 69 echo "</pre>" |
pankso@93 | 70 html_footer && exit 0 ;; |
pankso@66 | 71 |
pankso@69 | 72 *\ logged\ *) |
pankso@66 | 73 # Show online users based on sessions files. |
pankso@69 | 74 d="Logged users" |
pankso@66 | 75 header |
pankso@66 | 76 html_header |
pankso@66 | 77 user_box |
pankso@66 | 78 if ! check_auth; then |
paul@70 | 79 gettext "You must be logged in to view online users" |
pankso@66 | 80 exit 0 |
pankso@66 | 81 fi |
pankso@66 | 82 cat << EOT |
pankso@69 | 83 <h2>Logged users</h2> |
pankso@66 | 84 <div id="tools"> |
pankso@66 | 85 <a href="$script?dashboard">Dashboard</a> |
pankso@66 | 86 </div> |
pankso@66 | 87 <pre> |
pankso@66 | 88 EOT |
pankso@66 | 89 for u in $(ls $sessions) |
pankso@66 | 90 do |
pankso@66 | 91 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 92 cat << EOT |
pankso@66 | 93 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME |
pankso@66 | 94 EOT |
pankso@66 | 95 done |
pankso@66 | 96 echo "</pre>" |
pankso@66 | 97 html_footer && exit 0 ;; |
pankso@111 | 98 |
pankso@111 | 99 *\ user\ *) |
pankso@111 | 100 # User profile page |
pankso@111 | 101 d="$(GET user)" |
pankso@111 | 102 last="$(cat $PEOPLE/"$(GET user)"/last)" |
pankso@111 | 103 header |
pankso@111 | 104 html_header |
pankso@111 | 105 user_box |
pankso@111 | 106 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 107 cat << EOT |
pankso@111 | 108 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@111 | 109 |
pankso@111 | 110 <pre> |
pankso@111 | 111 $(gettext "User name :") $USER |
pankso@111 | 112 $(gettext "Last login :") $last |
pankso@111 | 113 EOT |
pankso@111 | 114 if check_auth && [ "$(GET user)" == "$user" ]; then |
pankso@111 | 115 auth_people |
pankso@111 | 116 else |
pankso@111 | 117 # check_auth will set VARS to current logged user: re-source |
pankso@111 | 118 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 119 public_people |
pankso@111 | 120 fi |
pankso@112 | 121 # Display personal user profile |
pankso@112 | 122 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@112 | 123 echo "<h2>$(gettext "About me")</h2>" |
pankso@112 | 124 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@112 | 125 fi |
pankso@111 | 126 html_footer && exit 0 ;; |
pankso@111 | 127 |
pankso@111 | 128 *\ modprofile\ *) |
pankso@111 | 129 # Let user edit there profile |
pankso@111 | 130 if ! check_auth; then |
pankso@111 | 131 echo "ERROR" && exit 0 |
pankso@111 | 132 fi |
pankso@111 | 133 d="$user profile" |
pankso@111 | 134 path=${PEOPLE}/${user} |
pankso@111 | 135 header |
pankso@111 | 136 html_header |
pankso@111 | 137 user_box |
pankso@111 | 138 cat << EOT |
pankso@111 | 139 <h2>$(gettext "User:") $user</h2> |
pankso@111 | 140 <p>$(gettext "Modify your profile settings") |
pankso@111 | 141 <div id="edit"> |
pankso@111 | 142 |
pankso@111 | 143 <form method="get" action="$script" name="editor"> |
pankso@111 | 144 <input type="hidden" name="saveprofile" /> |
pankso@111 | 145 <h3>Name</h3> |
pankso@111 | 146 <input type="text" name="name" value="$NAME" /> |
pankso@111 | 147 <h3>Email</h3> |
pankso@111 | 148 <input type="text" name="mail" value="$MAIL" /> |
pankso@111 | 149 <h3>About you</h3> |
pankso@111 | 150 <textarea name="profile">$(cat "$path/profile.txt")</textarea> |
pankso@111 | 151 <input type="submit" value="$(gettext "Save profile")" /> |
pankso@111 | 152 </form> |
pankso@111 | 153 |
pankso@111 | 154 </div> |
pankso@111 | 155 EOT |
pankso@111 | 156 html_footer && exit 0 ;; |
pankso@111 | 157 |
pankso@111 | 158 *\ saveprofile\ *) |
pankso@111 | 159 # Save a user profile |
pankso@111 | 160 if check_auth; then |
pankso@111 | 161 path="$PEOPLE/$user" |
pankso@111 | 162 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf |
pankso@111 | 163 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf |
pankso@111 | 164 cp -f ${path}/profile.txt ${path}/profile.bak |
pankso@111 | 165 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT |
pankso@111 | 166 $(GET profile) |
pankso@111 | 167 EOT |
pankso@111 | 168 header "Location: $script?user=$user" |
pankso@111 | 169 fi && exit 0 ;; |
pankso@111 | 170 |
pankso@66 | 171 esac |