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

Small fixes
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 11 00:00:17 2017 +0100 (2017-02-11)
parents 0dfc02021c92
children b19dbd851223
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"
43 exit 0
44 fi
45 users=$(ls -1 $PEOPLE | wc -l)
46 cat << EOT
47 <h2>Users: $users</h2>
48 <div id="tools">
49 <a href="$script?dashboard">Dashboard</a>
50 <a href='?logged'>Logged users</a>
51 </div>
52 <pre>
53 EOT
54 for u in $(ls $PEOPLE)
55 do
56 # Skip corrupted accounts
57 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then
58 echo "${u} : Missing account.conf"
59 continue
60 fi
61 . "${PEOPLE}/${u}/account.conf"
62 cat << EOT
63 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL
64 EOT
65 # deluser link
66 #: <a href="?users&amp;deluser=$USER">$(gettext "delete")</a>
67 unset NAME USER
68 done
69 echo "</pre>"
70 html_footer && exit 0 ;;
72 *\ logged\ *)
73 # Show online users based on sessions files.
74 d="Logged users"
75 header
76 html_header
77 user_box
78 if ! check_auth; then
79 gettext "You must be logged in to view online users"
80 exit 0
81 fi
82 cat << EOT
83 <h2>Logged users</h2>
84 <div id="tools">
85 <a href="$script?dashboard">Dashboard</a>
86 </div>
87 <pre>
88 EOT
89 for u in $(ls $sessions)
90 do
91 . "${PEOPLE}/${u}/account.conf"
92 cat << EOT
93 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME
94 EOT
95 done
96 echo "</pre>"
97 html_footer && exit 0 ;;
99 *\ user\ *)
100 # User profile page
101 d="$(GET user)"
102 last="$(cat $PEOPLE/"$(GET user)"/last)"
103 header
104 html_header
105 user_box
106 . $PEOPLE/"$(GET user)"/account.conf
107 cat << EOT
108 <h2>$(get_gravatar $MAIL) $NAME</h2>
110 <pre>
111 $(gettext "User name :") $USER
112 $(gettext "Last login :") $last
113 EOT
114 if check_auth && [ "$(GET user)" == "$user" ]; then
115 auth_people
116 else
117 # check_auth will set VARS to current logged user: re-source
118 . $PEOPLE/"$(GET user)"/account.conf
119 public_people
120 fi
121 # Display personal user profile
122 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
123 echo "<h2>$(gettext "About me")</h2>"
124 cat $PEOPLE/$USER/profile.txt | wiki_parser
125 fi
126 html_footer && exit 0 ;;
128 *\ modprofile\ *)
129 # Let user edit there profile
130 if ! check_auth; then
131 echo "ERROR" && exit 0
132 fi
133 d="$user profile"
134 path=${PEOPLE}/${user}
135 header
136 html_header
137 user_box
138 cat << EOT
139 <h2>$(gettext "User:") $user</h2>
140 <p>$(gettext "Modify your profile settings")
141 <div id="edit">
143 <form method="get" action="$script" name="editor">
144 <input type="hidden" name="saveprofile" />
145 <h3>Name</h3>
146 <input type="text" name="name" value="$NAME" />
147 <h3>Email</h3>
148 <input type="text" name="mail" value="$MAIL" />
149 <h3>About you</h3>
150 <textarea name="profile">$(cat "$path/profile.txt")</textarea>
151 <input type="submit" value="$(gettext "Save profile")" />
152 </form>
154 </div>
155 EOT
156 html_footer && exit 0 ;;
158 *\ saveprofile\ *)
159 # Save a user profile
160 if check_auth; then
161 path="$PEOPLE/$user"
162 sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
163 sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
164 cp -f ${path}/profile.txt ${path}/profile.bak
165 sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
166 $(GET profile)
167 EOT
168 header "Location: $script?user=$user"
169 fi && exit 0 ;;
171 esac