tazbug annotate web/plugins/users/users.cgi @ rev 111
Backport users plugins from TinyCM
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Feb 10 23:43:16 2017 +0100 (2017-02-10) |
parents | 1a43d9e16913 |
children | c9939a4ea74c |
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 # Display personal user profile |
pankso@111 | 10 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@111 | 11 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@111 | 12 fi |
pankso@111 | 13 } |
pankso@111 | 14 |
pankso@111 | 15 # Display authenticated user profile. TODO: change password |
pankso@111 | 16 auth_people() { |
pankso@111 | 17 cat << EOT |
pankso@111 | 18 Email : $MAIL |
pankso@111 | 19 </pre> |
pankso@111 | 20 EOT |
pankso@111 | 21 # Each user can have personal profile page |
pankso@111 | 22 if [ -f "$PEOPLE/$USER/profile.txt" ]; then |
pankso@111 | 23 cat $PEOPLE/$USER/profile.txt | wiki_parser |
pankso@111 | 24 cat << EOT |
pankso@111 | 25 <div id="tools"> |
pankso@111 | 26 <a href="$script?modprofile">$(gettext "Modify profile")</a> |
pankso@111 | 27 <a href="$script?dashboard">Dashboard</a> |
pankso@111 | 28 </div> |
pankso@111 | 29 EOT |
pankso@111 | 30 else |
pankso@111 | 31 cat << EOT |
pankso@111 | 32 <div id="tools"> |
pankso@111 | 33 <a href="$script?modprofile">$(gettext "Create a profile page")</a> |
pankso@111 | 34 <a href="$script?dashboard">Dashboard</a> |
pankso@111 | 35 </div> |
pankso@111 | 36 EOT |
pankso@111 | 37 fi |
pankso@111 | 38 } |
pankso@111 | 39 |
pankso@66 | 40 case " $(GET) " in |
pankso@66 | 41 *\ users\ *) |
pankso@66 | 42 d="Users" |
pankso@66 | 43 header |
pankso@66 | 44 html_header |
pankso@66 | 45 user_box |
pankso@66 | 46 if check_auth && ! admin_user; then |
pankso@66 | 47 gettext "You must be admin to manage users" |
pankso@66 | 48 exit 0 |
pankso@66 | 49 fi |
pankso@66 | 50 users=$(ls -1 $PEOPLE | wc -l) |
pankso@66 | 51 cat << EOT |
pankso@66 | 52 <h2>Users: $users</h2> |
pankso@66 | 53 <div id="tools"> |
pankso@66 | 54 <a href="$script?dashboard">Dashboard</a> |
pankso@72 | 55 <a href='?logged'>Logged users</a> |
pankso@66 | 56 </div> |
pankso@66 | 57 <pre> |
pankso@66 | 58 EOT |
pankso@66 | 59 for u in $(ls $PEOPLE) |
pankso@66 | 60 do |
pankso@93 | 61 # Skip corrupted accounts |
pankso@93 | 62 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then |
pankso@93 | 63 echo "${u} : Missing account.conf" |
pankso@93 | 64 continue |
pankso@93 | 65 fi |
pankso@66 | 66 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 67 cat << EOT |
pankso@66 | 68 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL |
pankso@66 | 69 EOT |
pankso@66 | 70 # deluser link |
pankso@66 | 71 #: <a href="?users&deluser=$USER">$(gettext "delete")</a> |
pankso@66 | 72 unset NAME USER |
pankso@66 | 73 done |
pankso@93 | 74 echo "</pre>" |
pankso@93 | 75 html_footer && exit 0 ;; |
pankso@66 | 76 |
pankso@69 | 77 *\ logged\ *) |
pankso@66 | 78 # Show online users based on sessions files. |
pankso@69 | 79 d="Logged users" |
pankso@66 | 80 header |
pankso@66 | 81 html_header |
pankso@66 | 82 user_box |
pankso@66 | 83 if ! check_auth; then |
paul@70 | 84 gettext "You must be logged in to view online users" |
pankso@66 | 85 exit 0 |
pankso@66 | 86 fi |
pankso@66 | 87 cat << EOT |
pankso@69 | 88 <h2>Logged users</h2> |
pankso@66 | 89 <div id="tools"> |
pankso@66 | 90 <a href="$script?dashboard">Dashboard</a> |
pankso@66 | 91 </div> |
pankso@66 | 92 <pre> |
pankso@66 | 93 EOT |
pankso@66 | 94 for u in $(ls $sessions) |
pankso@66 | 95 do |
pankso@66 | 96 . "${PEOPLE}/${u}/account.conf" |
pankso@66 | 97 cat << EOT |
pankso@66 | 98 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME |
pankso@66 | 99 EOT |
pankso@66 | 100 done |
pankso@66 | 101 echo "</pre>" |
pankso@66 | 102 html_footer && exit 0 ;; |
pankso@111 | 103 |
pankso@111 | 104 *\ user\ *) |
pankso@111 | 105 # User profile page |
pankso@111 | 106 d="$(GET user)" |
pankso@111 | 107 last="$(cat $PEOPLE/"$(GET user)"/last)" |
pankso@111 | 108 header |
pankso@111 | 109 html_header |
pankso@111 | 110 user_box |
pankso@111 | 111 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 112 cat << EOT |
pankso@111 | 113 <h2>$(get_gravatar $MAIL) $NAME</h2> |
pankso@111 | 114 |
pankso@111 | 115 <pre> |
pankso@111 | 116 $(gettext "User name :") $USER |
pankso@111 | 117 $(gettext "Last login :") $last |
pankso@111 | 118 EOT |
pankso@111 | 119 if check_auth && [ "$(GET user)" == "$user" ]; then |
pankso@111 | 120 auth_people |
pankso@111 | 121 else |
pankso@111 | 122 # check_auth will set VARS to current logged user: re-source |
pankso@111 | 123 . $PEOPLE/"$(GET user)"/account.conf |
pankso@111 | 124 public_people |
pankso@111 | 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 |