tinycm view plugins/users/users.cgi @ rev 77
Small change to user plugins
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Feb 10 23:17:21 2017 +0100 (2017-02-10) |
parents | e3cba575c564 |
children | 4b58d8ca918a |
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 # Display personal user profile
10 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
11 cat $PEOPLE/$USER/profile.txt | wiki_parser
12 fi
13 }
15 # Display authenticated user profile. TODO: change password
16 auth_people() {
17 cat << EOT
18 Email : $MAIL
19 </pre>
20 EOT
21 # Each user can have personal profile page
22 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
23 cat $PEOPLE/$USER/profile.txt | wiki_parser
24 cat << EOT
25 <div id="tools">
26 <a href="$script?modprofile">$(gettext "Modify profile")</a>
27 <a href="$script?dashboard">Dashboard</a>
28 </div>
29 EOT
30 else
31 cat << EOT
32 <div id="tools">
33 <a href="$script?modprofile">$(gettext "Create a profile page")</a>
34 <a href="$script?dashboard">Dashboard</a>
35 </div>
36 EOT
37 fi
38 }
40 case " $(GET) " in
41 *\ users\ *)
42 d="Users"
43 header
44 html_header
45 user_box
46 if check_auth && ! admin_user; then
47 gettext "You must be admin to manage users"
48 exit 0
49 fi
50 users=$(ls -1 $PEOPLE | wc -l)
51 cat << EOT
52 <h2>Users: $users</h2>
53 <div id="tools">
54 <a href="$script?dashboard">Dashboard</a>
55 <a href='?logged'>Logged users</a>
56 </div>
57 <pre>
58 EOT
59 for u in $(ls $PEOPLE)
60 do
61 # Skip corrupted accounts
62 if ! [ -f "${PEOPLE}/${u}/account.conf" ]; then
63 echo "${u} : Missing account.conf"
64 continue
65 fi
66 . "${PEOPLE}/${u}/account.conf"
67 cat << EOT
68 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME | $MAIL
69 EOT
70 # deluser link
71 #: <a href="?users&deluser=$USER">$(gettext "delete")</a>
72 unset NAME USER
73 done
74 echo "</pre>"
75 html_footer && exit 0 ;;
77 *\ logged\ *)
78 # Show online users based on sessions files.
79 d="Logged users"
80 header
81 html_header
82 user_box
83 if ! check_auth; then
84 gettext "You must be logged in to view online users"
85 exit 0
86 fi
87 cat << EOT
88 <h2>Logged users</h2>
89 <div id="tools">
90 <a href="$script?dashboard">Dashboard</a>
91 </div>
92 <pre>
93 EOT
94 for u in $(ls $sessions)
95 do
96 . "${PEOPLE}/${u}/account.conf"
97 cat << EOT
98 $(get_gravatar $MAIL 24) <a href="?user=$USER">$USER</a> | $NAME
99 EOT
100 done
101 echo "</pre>"
102 html_footer && exit 0 ;;
104 *\ user\ *)
105 # User profile page
106 d="$(GET user)"
107 last="$(cat $PEOPLE/"$(GET user)"/last)"
108 header
109 html_header
110 user_box
111 . $PEOPLE/"$(GET user)"/account.conf
112 cat << EOT
113 <h2>$(get_gravatar $MAIL) $NAME</h2>
115 <pre>
116 $(gettext "User name :") $USER
117 $(gettext "Last login :") $last
118 EOT
119 if check_auth && [ "$(GET user)" == "$user" ]; then
120 auth_people
121 else
122 # check_auth will set VARS to current logged user: re-source
123 . $PEOPLE/"$(GET user)"/account.conf
124 public_people
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="save-profile" />
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 *\ save-profile\ *)
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