tinycm view plugins/users/users.cgi @ rev 103

Small fixes
author Christophe Lincoln <pankso@slitaz.org>
date Mon Feb 20 18:29:02 2017 +0100 (2017-02-20)
parents 69214a677729
children 348289f0b48d
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 to check or 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 . $PEOPLE/"$(GET user)"/account.conf
178 cat << EOT
179 <h2>$(get_gravatar $MAIL) $NAME</h2>
181 <pre>
182 $(gettext "User name :") $USER
183 $(gettext "Last login :") $last
184 EOT
185 if check_auth && [ "$(GET user)" == "$user" ]; then
186 auth_people
187 else
188 # check_auth will set VARS to current logged user: re-source
189 . $PEOPLE/"$(GET user)"/account.conf
190 public_people
191 fi
193 # Messages plugin integration
194 if [ -x "$plugins/messages/messages.cgi" ]; then
195 if check_auth && [ "$(GET user)" != "$user" ]; then
196 cat << EOT
197 <div id="tools">
198 <a href="$script?messages&amp;to=$(GET user)">$(gettext "Send message")</a>
199 </div>
200 EOT
201 fi
202 fi
204 # Display personal user profile
205 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
206 echo "<h2>$(gettext "About me")</h2>"
207 cat $PEOPLE/$USER/profile.txt | wiki_parser
208 fi
209 html_footer && exit 0 ;;
211 *\ modprofile\ *)
212 # Let user edit their profile
213 if ! check_auth; then
214 echo "ERROR" && exit 0
215 fi
216 d="$user profile"
217 path=${PEOPLE}/${user}
218 header
219 html_header
220 user_box
221 cat << EOT
222 <h2>$(gettext "User:") $user</h2>
223 <p>$(gettext "Modify your profile settings")
224 <div id="edit">
226 <form method="get" action="$script" name="editor">
227 <input type="hidden" name="saveprofile" />
228 <h3>Name</h3>
229 <input type="text" name="name" value="$NAME" />
230 <h3>Email</h3>
231 <input type="text" name="mail" value="$MAIL" />
232 <h3>About you</h3>
233 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
234 <input type="submit" value="$(gettext "Save profile")" />
235 </form>
237 </div>
238 EOT
239 html_footer && exit 0 ;;
241 *\ saveprofile\ *)
242 # Save a user profile
243 if check_auth; then
244 path="$PEOPLE/$user"
245 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
246 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
247 cp -f ${path}/profile.txt ${path}/profile.bak
248 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
249 $(GET profile)
250 EOT
251 header "Location: $script?user=$user"
252 fi && exit 0 ;;
254 esac