tazbug view web/plugins/users/users.cgi @ rev 119
Tiny edit
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Sun Feb 12 09:09:36 2017 +0000 (2017-02-12) |
parents | b19dbd851223 |
children | 039c90c60494 |
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>
16 EOT
17 # Each user can have personal profile page
18 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
19 cat << EOT
20 <div id="tools">
21 <a href="$script?modprofile">$(gettext "Modify profile")</a>
22 <a href="$script?dashboard">Dashboard</a>
23 </div>
24 EOT
25 else
26 cat << EOT
27 <div id="tools">
28 <a href="$script?modprofile">$(gettext "Create a profile page")</a>
29 <a href="$script?dashboard">Dashboard</a>
30 </div>
31 EOT
32 fi
33 }
35 case " $(GET) " in
36 *\ users\ *)
37 d="Users"
38 header
39 html_header
40 user_box
41 if check_auth && ! admin_user; then
42 gettext "You must be admin to manage users" && exit 0
43 fi
44 cat << EOT
45 <h2>Users admin</h2>
46 <div id="tools">
47 <a href="$script?dashboard">Dashboard</a>
48 <a href='$script?loggedusers'>Logged users</a>
49 <a href='$script?userslist'>Users list</a>
50 </div>
51 <pre>
52 User accounts : $(ls -1 $PEOPLE | wc -l)
53 Logged users : $(ls $sessions | wc -l)
54 People DB : $PEOPLE
55 Auth file : $AUTH_FILE
56 EOT
58 echo "</pre>"
59 html_footer && exit 0 ;;
61 *\ userslist\ *)
62 # List all users (slow if a lot a of accounts)
63 d="Users"
64 header
65 html_header
66 user_box
67 if check_auth && ! admin_user; then
68 gettext "You must be admin to manage users"
69 exit 0
70 fi
71 users=$(ls -1 $PEOPLE | wc -l)
72 cat << EOT
73 <h2>Users: $users</h2>
74 <div id="tools">
75 <a href="$script?dashboard">Dashboard</a>
76 <a href="$script?users">Users admin</a>
77 <a href='$script?loggedusers'>Logged users</a>
78 </div>
79 <pre>
80 EOT
81 for u in $(ls $PEOPLE)
82 do
83 # Skip corrupted accounts
84 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then
85 echo "${u} : Missing account.conf"
86 continue
87 fi
88 . "${PEOPLE}/${u}/account.conf"
89 cat << EOT
90 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL
91 EOT
92 # deluser link --> use 'tazu' on SliTaz
93 #: <a href="?users&deluser=$USER">$(gettext "delete")</a>
94 unset NAME USER
95 done
96 echo "</pre>"
97 html_footer && exit 0 ;;
99 *\ loggedusers\ *)
100 # Show online users based on sessions files.
101 d="Logged users"
102 header
103 html_header
104 user_box
105 if ! check_auth; then
106 gettext "You must be logged in to view online users"
107 exit 0
108 fi
109 logged="$(ls $sessions | wc -l)"
110 cat << EOT
111 <h2>Logged users: $logged</h2>
112 <div id="tools">
113 <a href="$script?dashboard">Dashboard</a>
114 <a href="$script?users">Users admin</a>
115 </div>
116 <pre>
117 EOT
118 for u in $(ls $sessions)
119 do
120 . "${PEOPLE}/${u}/account.conf"
121 cat << EOT
122 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME
123 EOT
124 done
125 echo "</pre>"
126 html_footer && exit 0 ;;
128 *\ user\ *)
129 # User profile page
130 d="$(GET user)"
131 last="$(cat $PEOPLE/"$(GET user)"/last)"
132 header
133 html_header
134 user_box
135 . $PEOPLE/"$(GET user)"/account.conf
136 cat << EOT
137 <h2>$(get_gravatar $MAIL) $NAME</h2>
139 <pre>
140 $(gettext "User name :") $USER
141 $(gettext "Last login :") $last
142 EOT
143 if check_auth && [ "$(GET user)" == "$user" ]; then
144 auth_people
145 else
146 # check_auth will set VARS to current logged user: re-source
147 . $PEOPLE/"$(GET user)"/account.conf
148 public_people
149 fi
150 # Display personal user profile
151 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
152 echo "<h2>$(gettext "About me")</h2>"
153 cat $PEOPLE/$USER/profile.txt | wiki_parser
154 fi
155 html_footer && exit 0 ;;
157 *\ modprofile\ *)
158 # Let user edit their profile
159 if ! check_auth; then
160 echo "ERROR" && exit 0
161 fi
162 d="$user profile"
163 path=${PEOPLE}/${user}
164 header
165 html_header
166 user_box
167 cat << EOT
168 <h2>$(gettext "User:") $user</h2>
169 <p>$(gettext "Modify your profile settings")
170 <div id="edit">
172 <form method="get" action="$script" name="editor">
173 <input type="hidden" name="saveprofile" />
174 <h3>Name</h3>
175 <input type="text" name="name" value="$NAME" />
176 <h3>Email</h3>
177 <input type="text" name="mail" value="$MAIL" />
178 <h3>About you</h3>
179 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
180 <input type="submit" value="$(gettext "Save profile")" />
181 </form>
183 </div>
184 EOT
185 html_footer && exit 0 ;;
187 *\ saveprofile\ *)
188 # Save a user profile
189 if check_auth; then
190 path="$PEOPLE/$user"
191 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
192 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
193 cp -f ${path}/profile.txt ${path}/profile.bak
194 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
195 $(GET profile)
196 EOT
197 header "Location: $script?user=$user"
198 fi && exit 0 ;;
200 esac