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

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 12:26:25 2019 +0100 (2019-02-26)
parents 26809676b304
children
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"
180 # account.conf
181 if [ ! -f "$account_config" ]; then
182 echo "No user profile for: $(GET user)"
183 html_footer && exit 0
184 else
185 . ${account_config}
186 fi
188 # profile.conf
189 if [ -f "$profile_config" ]; then
190 . ${profile_config}
191 fi
193 cat << EOT
194 <h2>$(get_gravatar $MAIL) $NAME</h2>
196 <pre>
197 $(gettext "User name :") $USER
198 $(gettext "Last login :") $last
199 EOT
200 if check_auth && [ "$(GET user)" = "$user" ]; then
201 auth_people
202 else
203 # check_auth will set VARS to current logged user: re-source
204 . $PEOPLE/"$(GET user)"/account.conf
205 public_people
206 fi
208 # Display personal user profile
209 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
210 echo "<h2>$(gettext "About me")</h2>"
211 cat $PEOPLE/$USER/profile.txt | wiki_parser
212 fi
214 # Run user.sh that plugins can provide to add content to a profile
215 for script in $(ls $plugins/*/user.sh); do
216 . ${script}
217 done
219 html_footer && exit 0 ;;
221 *\ modprofile\ *)
222 # Let user edit their profile
223 if ! check_auth; then
224 echo "ERROR" && exit 0
225 fi
226 d="$user profile"
227 path=${PEOPLE}/${user}
228 header
229 html_header
230 user_box
231 cat << EOT
232 <h2>$(gettext "User:") $user</h2>
233 <p>$(gettext "Modify your profile settings")
234 <div id="edit">
236 <form method="get" action="$script" name="editor">
237 <input type="hidden" name="saveprofile" />
238 <h3>Name</h3>
239 <input type="text" name="name" value="$NAME" />
240 <h3>Email</h3>
241 <input type="text" name="mail" value="$MAIL" />
242 <h3>About you</h3>
243 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
244 <input type="submit" value="$(gettext "Save profile")" />
245 </form>
247 </div>
248 EOT
249 html_footer && exit 0 ;;
251 *\ saveprofile\ *)
252 # Save a user profile
253 if check_auth; then
254 path="$PEOPLE/$user"
255 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
256 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
257 cp -f ${path}/profile.txt ${path}/profile.bak
258 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
259 $(GET profile)
260 EOT
261 header "Location: $script?user=$user"
262 fi && exit 0 ;;
264 esac