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

users plugin: small change to use PROFILE_TOOLS
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 24 08:46:34 2017 +0100 (2017-02-24)
parents a82f38aff5ba
children 26809676b304
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 $PROFILE_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 # account.conf
180 if [ ! -f "$account_config" ]; then
181 echo "No user profile for: $(GET user)"
182 html_footer && exit 0
183 else
184 . ${account_config}
185 fi
186 # Init profile.conf
187 if [ -f "${profile_config}" ]; then
188 . ${profile_config}
189 else
190 cat > $PEOPLE/$user/profile.conf << EOT
191 # User profile
192 WEBSITE="$website"
193 FACEBOOK="$facebook"
194 TWITTER="$twitter"
195 EOT
196 chmod 0600 $PEOPLE/$user/profile.conf
197 fi
198 cat << EOT
199 <h2>$(get_gravatar $MAIL) $NAME</h2>
201 <pre>
202 $(gettext "User name :") $USER
203 $(gettext "Last login :") $last
204 EOT
205 if check_auth && [ "$(GET user)" == "$user" ]; then
206 auth_people
207 else
208 # check_auth will set VARS to current logged user: re-source
209 . $PEOPLE/"$(GET user)"/account.conf
210 public_people
211 fi
213 # Display personal user profile
214 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
215 echo "<h2>$(gettext "About me")</h2>"
216 cat $PEOPLE/$USER/profile.txt | wiki_parser
217 fi
219 # Run user.sh that plugins can provide to add content to a profile
220 for script in $(ls $plugins/*/user.sh); do
221 . ${script}
222 done
224 html_footer && exit 0 ;;
226 *\ modprofile\ *)
227 # Let user edit their profile
228 if ! check_auth; then
229 echo "ERROR" && exit 0
230 fi
231 d="$user profile"
232 path=${PEOPLE}/${user}
233 header
234 html_header
235 user_box
236 cat << EOT
237 <h2>$(gettext "User:") $user</h2>
238 <p>$(gettext "Modify your profile settings")
239 <div id="edit">
241 <form method="get" action="$script" name="editor">
242 <input type="hidden" name="saveprofile" />
243 <h3>Name</h3>
244 <input type="text" name="name" value="$NAME" />
245 <h3>Email</h3>
246 <input type="text" name="mail" value="$MAIL" />
247 <h3>About you</h3>
248 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
249 <input type="submit" value="$(gettext "Save profile")" />
250 </form>
252 </div>
253 EOT
254 html_footer && exit 0 ;;
256 *\ saveprofile\ *)
257 # Save a user profile
258 if check_auth; then
259 path="$PEOPLE/$user"
260 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
261 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
262 cp -f ${path}/profile.txt ${path}/profile.bak
263 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
264 $(GET profile)
265 EOT
266 header "Location: $script?user=$user"
267 fi && exit 0 ;;
269 esac