tazbug view web/plugins/users/users.cgi @ rev 134

Tiny edits
author Paul Issott <paul@slitaz.org>
date Tue Feb 21 19:12:22 2017 +0000 (2017-02-21)
parents 039c90c60494
children 49fa101e75f5
line source
1 #!/bin/sh
2 #
3 # TinyCM/TazBug Plugin - Users profile and admin
4 #
6 # Display user public profile.
7 public_people() {
8 echo "</pre>"
9 }
11 # Display authenticated user profile. TODO: change password
12 auth_people() {
13 cat << EOT
14 Email : $MAIL
15 </pre>
17 <div id="tools">
18 $PLUGINS_TOOLS
19 <a href="$script?modprofile">$(gettext "Modify profile")</a>
20 </div>
21 EOT
22 }
24 # List last active users. Usage: last_users NB
25 list_last_users() {
26 count=${1}
27 echo "<h3>Last $count active users</h3>"
28 echo "<pre>"
29 find ${PEOPLE} -name "last" | xargs ls -1t | head -n ${count} | while read last;
30 do
31 dir="$(dirname $last)"
32 date="$(cat $last)"
33 u=$(basename $dir)
34 . "${PEOPLE}/${u}/account.conf"
35 cat << EOT
36 $(get_gravatar $MAIL 24) $date : <a href="?user=$u">$u</a> | $NAME
37 EOT
38 done
39 echo "</pre>"
40 }
42 case " $(GET) " in
43 *\ users\ *)
44 d="Users"
45 header
46 html_header
47 user_box
48 # Admin only
49 if admin_user; then
50 tools="<a href='$script?userslist'>Users list</a>"
51 fi
52 # Logged users
53 if check_auth; then
54 cat << EOT
55 <div id="tools">
56 <a href="$script?dashboard">Dashboard</a>
57 <a href='$script?lastusers'>Last users</a>
58 $tools
59 </div>
60 <h2>${d}</h2>
61 <pre>
62 User accounts : $(ls -1 $PEOPLE | wc -l)
63 Logged users : $(ls $sessions | wc -l)
64 </pre>
65 EOT
66 list_last_users 5
68 # Admin only
69 if admin_user; then
70 cat << EOT
71 <h3>Config paths</h3>
72 <pre>
73 People DB : $PEOPLE
74 Authfile : $AUTH_FILE
75 Admin users : $ADMIN_USERS
76 </pre>
77 EOT
78 # Get the list of administrators
79 echo "<h3>Admin users</h3>"
80 echo "<pre>"
81 for u in $(cat $ADMIN_USERS)
82 do
83 . ${PEOPLE}/${u}/account.conf
84 echo "<a href='?user=$u'>$u</a> - $NAME"
85 done
86 echo "</pre>"
87 fi
89 else
90 gettext "You must be logged in to check on admin users"
91 fi
92 html_footer && exit 0 ;;
94 *\ userslist\ *)
95 # List all users
96 d="Users"
97 header
98 html_header
99 user_box
100 if check_auth && ! admin_user; then
101 gettext "You must be admin to manage users"
102 exit 0
103 fi
104 users=$(ls -1 $PEOPLE | wc -l)
105 cat << EOT
106 <div id="tools">
107 <a href="$script?dashboard">Dashboard</a>
108 <a href="$script?users">Users</a>
109 <a href='$script?lastusers'>Last users</a>
110 </div>
111 <h2>Users: $users</h2>
112 <div id="users">
113 <table>
114 <thead>
115 <td>$(gettext "Username")</td>
116 <td>$(gettext "Action")</td>
117 </thead>
118 EOT
119 for u in $(ls $PEOPLE)
120 do
121 # Skip corrupted accounts
122 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then
123 echo "${u} : Missing account.conf"
124 continue
125 fi
126 cat << EOT
127 <tr>
128 <td><a href="$script?user=$u">$u</a></td>
129 <td>TODO</td>
130 </tr>
131 EOT
132 # deluser link --> use 'tazu' on SliTaz
133 #: <a href="?users&amp;deluser=$USER">$(gettext "delete")</a>
134 unset NAME USER
135 done
136 echo "</table></div>"
137 html_footer && exit 0 ;;
139 *\ lastusers\ *)
140 # Show online users based on sessions files.
141 d="Last users"
142 header
143 html_header
144 user_box
145 if ! check_auth; then
146 gettext "You must be logged in to view online users"
147 exit 0
148 fi
149 cat << EOT
150 <div id="tools">
151 <a href="$script?dashboard">Dashboard</a>
152 <a href="$script?users">Users</a>
153 </div>
154 EOT
155 list_last_users 15
157 # Active cookies
158 echo "<h3>Session cookies: $(ls $sessions | wc -l)</h3>"
159 echo "<pre>"
160 for u in $(ls $sessions)
161 do
162 . "${PEOPLE}/${u}/account.conf"
163 cat << EOT
164 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME
165 EOT
166 done
167 echo "</pre>"
168 html_footer && exit 0 ;;
170 *\ user\ *)
171 # User profile page
172 d="$(GET user)"
173 last="$(cat $PEOPLE/"$(GET user)"/last)"
174 header
175 html_header
176 user_box
177 account_config="$PEOPLE/$(GET user)/account.conf"
178 profile_config="$PEOPLE/$(GET user)/profile.conf"
179 if [ ! -f "$account_config" ]; then
180 echo "No user profile for: $(GET user)"
181 html_footer && exit 0
182 else
183 . ${account_config}
184 fi
185 [ -f "$profile_config" ] && . ${profile_config}
186 cat << EOT
187 <h2>$(get_gravatar $MAIL) $NAME</h2>
189 <pre>
190 $(gettext "User name :") $USER
191 $(gettext "Last login :") $last
192 EOT
193 if check_auth && [ "$(GET user)" == "$user" ]; then
194 auth_people
195 else
196 # check_auth will set VARS to current logged user: re-source
197 . $PEOPLE/"$(GET user)"/account.conf
198 public_people
199 fi
201 # Messages plugin integration
202 if [ -x "$plugins/messages/messages.cgi" ]; then
203 if check_auth && [ "$(GET user)" != "$user" ]; then
204 cat << EOT
205 <div id="tools">
206 <a href="$script?messages&amp;to=$(GET user)">$(gettext "Send message")</a>
207 </div>
208 EOT
209 fi
210 fi
212 # Display personal user profile
213 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
214 echo "<h2>$(gettext "About me")</h2>"
215 cat $PEOPLE/$USER/profile.txt | wiki_parser
216 fi
217 html_footer && exit 0 ;;
219 *\ modprofile\ *)
220 # Let user edit their profile
221 if ! check_auth; then
222 echo "ERROR" && exit 0
223 fi
224 d="$user profile"
225 path=${PEOPLE}/${user}
226 header
227 html_header
228 user_box
229 cat << EOT
230 <h2>$(gettext "User:") $user</h2>
231 <p>$(gettext "Modify your profile settings")
232 <div id="edit">
234 <form method="get" action="$script" name="editor">
235 <input type="hidden" name="saveprofile" />
236 <h3>Name</h3>
237 <input type="text" name="name" value="$NAME" />
238 <h3>Email</h3>
239 <input type="text" name="mail" value="$MAIL" />
240 <h3>About you</h3>
241 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
242 <input type="submit" value="$(gettext "Save profile")" />
243 </form>
245 </div>
246 EOT
247 html_footer && exit 0 ;;
249 *\ saveprofile\ *)
250 # Save a user profile
251 if check_auth; then
252 path="$PEOPLE/$user"
253 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
254 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
255 cp -f ${path}/profile.txt ${path}/profile.bak
256 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
257 $(GET profile)
258 EOT
259 header "Location: $script?user=$user"
260 fi && exit 0 ;;
262 esac