rev |
line source |
pankso@5
|
1 #!/bin/sh
|
pankso@5
|
2 #
|
pankso@5
|
3 # TinyCM - Small, fast and elegent CGI/SHell Content Manager
|
pankso@5
|
4 #
|
pankso@15
|
5 # Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
|
pankso@5
|
6 #
|
pankso@5
|
7 . /usr/lib/slitaz/httphelper
|
pankso@5
|
8
|
paul@8
|
9 # Let's have a peer site config file with a .cgi extension so content
|
pankso@5
|
10 # is secure even if left in a web server directory.
|
pankso@5
|
11 . config.cgi
|
pankso@5
|
12
|
pankso@5
|
13 tiny="$PWD"
|
pankso@5
|
14 po="en fr"
|
pankso@5
|
15 content="content"
|
pankso@5
|
16 wiki="$content/wiki"
|
pankso@5
|
17 index="index"
|
pankso@5
|
18 cache="cache"
|
pankso@5
|
19 plugins="plugins"
|
pankso@5
|
20 tmp="/tmp/tinycm"
|
pankso@5
|
21 sessions="$tmp/sessions"
|
pankso@15
|
22 script="$SCRIPT_NAME"
|
pankso@28
|
23 activity="$cache/log/activity.log"
|
pankso@5
|
24
|
pankso@5
|
25 # Content negotiation for Gettext
|
pankso@5
|
26 IFS=","
|
pankso@5
|
27 for lang in $HTTP_ACCEPT_LANGUAGE
|
pankso@5
|
28 do
|
pankso@5
|
29 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
|
pankso@5
|
30 if echo "$po" | fgrep -q "$lang"; then
|
pankso@5
|
31 break
|
pankso@5
|
32 fi
|
pankso@5
|
33 case "$lang" in
|
pankso@5
|
34 en) lang="C" ;;
|
pankso@5
|
35 fr) lang="fr_FR" ;;
|
pankso@5
|
36 pt) lang="pt_BR" ;;
|
pankso@5
|
37 ru) lang="ru_RU" ;;
|
pankso@5
|
38 esac
|
pankso@5
|
39 done
|
pankso@5
|
40 unset IFS
|
pankso@5
|
41 export LANG=$lang LC_ALL=$lang
|
pankso@5
|
42
|
pankso@5
|
43 #
|
pankso@5
|
44 # Functions
|
pankso@5
|
45 #
|
pankso@5
|
46
|
paul@8
|
47 # Used by edit to display language name and the language box. This is
|
pankso@5
|
48 # for CM content not gettext support.
|
pankso@5
|
49 get_lang() {
|
pankso@5
|
50 lang=$(echo $d | cut -d "/" -f 1)
|
pankso@5
|
51 doc=${d#$lang/}
|
pankso@5
|
52 echo '<div id="lang">'
|
pankso@5
|
53 for l in $LANGUAGES
|
pankso@5
|
54 do
|
pankso@5
|
55 case $lang in
|
pankso@5
|
56 en) i18n="English" ;;
|
pankso@5
|
57 fr) i18n="Français" ;;
|
pankso@5
|
58 pt) i18n="Português" ;;
|
pankso@5
|
59 ru) i18n="Русский" ;;
|
pankso@5
|
60 *) i18n="*" ;;
|
pankso@5
|
61 esac
|
pankso@5
|
62 echo "<a href='?d=$l/$doc'>$l</a>"
|
pankso@5
|
63 done
|
pankso@5
|
64 echo '</div>'
|
pankso@5
|
65 }
|
pankso@5
|
66
|
pankso@5
|
67 # HTML 5 header.
|
pankso@5
|
68 html_header() {
|
pankso@5
|
69 if [ -f "$tiny/lib/header.html" ]; then
|
pankso@5
|
70 cat $tiny/lib/header.html | sed -e s!'%TITLE%'!"$TITLE - $d"!g
|
pankso@5
|
71 else
|
pankso@5
|
72 cat << EOT
|
pankso@5
|
73 <!DOCTYPE html>
|
pankso@5
|
74 <html xmlns="http://www.w3.org/1999/xhtml">
|
pankso@5
|
75 <head>
|
pankso@5
|
76 <title>$TITLE</title>
|
pankso@5
|
77 <meta charset="utf-8" />
|
pankso@5
|
78 <style type="text/css">body { margin: 40px 120px; }</style>
|
pankso@5
|
79 </head>
|
pankso@5
|
80 <body>
|
pankso@5
|
81 <!-- Content -->
|
pankso@5
|
82 <div id="content">
|
pankso@5
|
83 EOT
|
pankso@5
|
84 fi
|
pankso@5
|
85 }
|
pankso@5
|
86
|
pankso@5
|
87 # HTML 5 footer.
|
pankso@5
|
88 html_footer() {
|
pankso@5
|
89 if [ -f "$tiny/lib/footer.html" ]; then
|
pankso@5
|
90 cat $tiny/lib/footer.html
|
pankso@5
|
91 else
|
pankso@5
|
92 cat << EOT
|
pankso@5
|
93
|
pankso@5
|
94 <!-- End content -->
|
pankso@5
|
95 </div>
|
pankso@5
|
96
|
pankso@5
|
97 <div id="footer">♥</div>
|
pankso@5
|
98
|
pankso@5
|
99 </body>
|
pankso@5
|
100 </html>
|
pankso@5
|
101 EOT
|
pankso@5
|
102 fi
|
pankso@5
|
103 }
|
pankso@5
|
104
|
pankso@5
|
105 # Default index if missing
|
pankso@5
|
106 default_index() {
|
pankso@11
|
107 mkdir -p "$wiki"
|
pankso@5
|
108 cat > $wiki/$index.txt << EOT
|
pankso@5
|
109 ==== Welcome ====
|
pankso@5
|
110
|
pankso@36
|
111 <p>
|
pankso@32
|
112 This is the default index page of your TinyCM, you can login then start to
|
pankso@32
|
113 edit and adding some content. You can read the help about text formating
|
pankso@32
|
114 and functions: <a href='?d=en/help'>Help page</a>
|
pankso@36
|
115 </p>
|
pankso@5
|
116
|
pankso@5
|
117 EOT
|
pankso@5
|
118 }
|
pankso@5
|
119
|
pankso@28
|
120 # Log main activity.
|
pankso@28
|
121 log_activity() {
|
pankso@28
|
122 [ -d "$cache/log" ] || mkdir -p ${cache}/log
|
pankso@28
|
123 #gravatar="$(get_gravatar $MAIL 24)"
|
pankso@28
|
124 grep ^[A-Z] | \
|
pankso@28
|
125 sed s"#^[A-Z]\([^']*\)#$user|$(date '+%Y-%m-%d')|\0#" \
|
pankso@28
|
126 >> $cache/log/activity.log
|
pankso@28
|
127 }
|
pankso@28
|
128
|
pankso@5
|
129 # Log documents activity.
|
pankso@5
|
130 log() {
|
pankso@5
|
131 grep ^[A-Z] | \
|
pankso@5
|
132 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" \
|
pankso@5
|
133 >> $cache/$d/activity.log
|
pankso@5
|
134 }
|
pankso@5
|
135
|
pankso@5
|
136 # Check if user is auth
|
pankso@5
|
137 check_auth() {
|
pankso@5
|
138 auth="$(COOKIE auth)"
|
pankso@5
|
139 user="$(echo $auth | cut -d ":" -f 1)"
|
pankso@5
|
140 md5cookie="$(echo $auth | cut -d ":" -f 2)"
|
pankso@5
|
141 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
|
pankso@5
|
142 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
|
pankso@5
|
143 . $PEOPLE/$user/account.conf
|
pankso@5
|
144 return 0
|
pankso@5
|
145 else
|
pankso@5
|
146 return 1
|
pankso@5
|
147 fi
|
pankso@5
|
148 }
|
pankso@5
|
149
|
pankso@28
|
150 # Check if user is admin
|
pankso@28
|
151 admin_user() {
|
pankso@28
|
152 fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf
|
pankso@28
|
153 }
|
pankso@28
|
154
|
pankso@5
|
155 # Authentified or not
|
pankso@5
|
156 user_box() {
|
pankso@5
|
157 if check_auth; then
|
pankso@5
|
158 cat << EOT
|
pankso@5
|
159
|
pankso@5
|
160 <div id="user">
|
pankso@5
|
161 <a href="$script?user=$user">$(get_gravatar $MAIL 20)</a>
|
pankso@5
|
162 <a href="$script?logout">Logout</a>
|
pankso@5
|
163 </div>
|
pankso@5
|
164
|
pankso@5
|
165 EOT
|
pankso@5
|
166 else
|
pankso@5
|
167 cat << EOT
|
pankso@5
|
168
|
pankso@5
|
169 <div id="user">
|
pankso@5
|
170 <a href="$script?login"><img src="images/avatar.png" alt="[ User ]" /></a>
|
pankso@5
|
171 <a href="$script?login">Login</a>
|
pankso@5
|
172 </div>
|
pankso@5
|
173
|
pankso@5
|
174 EOT
|
pankso@5
|
175 fi
|
pankso@5
|
176 cat << EOT
|
pankso@5
|
177 <!--
|
pankso@5
|
178 <div id="search">
|
pankso@5
|
179 <form method="get" action="$script">
|
pankso@5
|
180 <input type="text" name="search" placeholder="$(gettext "Search")" />
|
pankso@5
|
181 </form>
|
pankso@5
|
182 </div>
|
pankso@5
|
183 -->
|
pankso@5
|
184 EOT
|
pankso@5
|
185 }
|
pankso@5
|
186
|
pankso@5
|
187 # Link for online signup if enabled.
|
pankso@5
|
188 online_signup() {
|
pankso@5
|
189 if [ "$ONLINE_SIGNUP" == "yes" ]; then
|
pankso@5
|
190 echo -n "<p><a href='$script?signup'>"
|
pankso@5
|
191 gettext "Create a new account"
|
pankso@5
|
192 echo '</a></p>'
|
pankso@5
|
193 fi
|
pankso@5
|
194 }
|
pankso@5
|
195
|
pankso@5
|
196 # Login page
|
pankso@5
|
197 login_page() {
|
pankso@5
|
198 cat << EOT
|
pankso@5
|
199 <h2>$(gettext "Login")</h2>
|
pankso@5
|
200
|
pankso@5
|
201 <div id="account-info">
|
paul@8
|
202 $(gettext "No account yet or trouble with you account? Please send
|
pankso@5
|
203 a request to $ADMIN_MAIL with your real name, user name, mail and password.")
|
pankso@5
|
204 $(online_signup)
|
pankso@5
|
205 </div>
|
pankso@5
|
206
|
pankso@5
|
207 <div id="login">
|
pankso@5
|
208 <form method="post" action="$script">
|
pankso@5
|
209 <input type="text" name="auth" placeholder="$(gettext "User name")" />
|
pankso@5
|
210 <input type="password" name="pass" placeholder="$(gettext "Password")" />
|
pankso@5
|
211 <div>
|
pankso@5
|
212 <input type="submit" value="Login" /> $error
|
pankso@5
|
213 </div>
|
pankso@5
|
214 </form>
|
pankso@5
|
215 </div>
|
pankso@5
|
216
|
pankso@5
|
217 <div style="clear: both;"></div>
|
pankso@5
|
218 EOT
|
pankso@5
|
219 }
|
pankso@5
|
220
|
pankso@5
|
221 # Signup page
|
pankso@5
|
222 signup_page() {
|
pankso@5
|
223 cat << EOT
|
pankso@5
|
224
|
pankso@5
|
225 <div id="signup">
|
pankso@5
|
226 <form method="post" name="signup" action="$script" onsubmit="return checkSignup();">
|
pankso@5
|
227 <input type="hidden" name="signup" value="new" />
|
pankso@5
|
228 <input type="text" name="name" placeholder="$(gettext "Real name")" />
|
pankso@5
|
229 <input type="text" name="user" placeholder="$(gettext "User name")" />
|
pankso@5
|
230 <input type="text" name="mail" placeholder="$(gettext "Email")" />
|
pankso@5
|
231 <input type="password" name="pass" placeholder="$(gettext "Password")" />
|
pankso@5
|
232 <div>
|
pankso@5
|
233 <input type="submit" value="$(gettext "Create new account")" />
|
pankso@5
|
234 </div>
|
pankso@5
|
235 </form>
|
pankso@5
|
236 </div>
|
pankso@5
|
237
|
pankso@5
|
238 EOT
|
pankso@5
|
239 }
|
pankso@5
|
240
|
pankso@5
|
241 # Create a new user in AUTH_FILE and PEOPLE
|
pankso@5
|
242 new_user_config() {
|
pankso@20
|
243 if [ ! -f "$AUTH_FILE" ];then
|
pankso@20
|
244 touch $(DESTDIR)$(LOGIN)/auth/people
|
pankso@20
|
245 chmod 0600 $(DESTDIR)$(LOGIN)/auth/people
|
pankso@20
|
246 fi
|
pankso@5
|
247 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
|
pankso@5
|
248 echo "$user:$pass" >> $AUTH_FILE
|
pankso@5
|
249 mkdir -p $PEOPLE/$user/
|
pankso@5
|
250 cat > $PEOPLE/$user/account.conf << EOT
|
pankso@5
|
251 # SliTaz user configuration
|
pankso@5
|
252 #
|
pankso@5
|
253
|
pankso@5
|
254 NAME="$name"
|
pankso@5
|
255 USER="$user"
|
pankso@5
|
256 MAIL="$mail"
|
pankso@5
|
257 KEY="$key"
|
pankso@5
|
258
|
pankso@5
|
259 EOT
|
pankso@5
|
260 chmod 0600 $PEOPLE/$user/account.conf
|
pankso@28
|
261 # First created user is admin
|
pankso@28
|
262 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
|
pankso@28
|
263 echo 'ADMIN_USER="yes"' >> $PEOPLE/$user/account.conf
|
pankso@28
|
264 fi
|
pankso@5
|
265 }
|
pankso@5
|
266
|
pankso@5
|
267 # Display user public profile.
|
pankso@5
|
268 public_people() {
|
pankso@36
|
269 echo "</pre>"
|
pankso@23
|
270 # Display personnal user profile
|
pankso@23
|
271 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
|
pankso@23
|
272 cat $PEOPLE/$USER/profile.txt | wiki_parser
|
pankso@23
|
273 fi
|
pankso@5
|
274 }
|
pankso@5
|
275
|
pankso@5
|
276 # Display authentified user profile. TODO: change password
|
pankso@5
|
277 auth_people() {
|
pankso@5
|
278 cat << EOT
|
pankso@5
|
279 Email : $MAIL
|
pankso@5
|
280 Secure key : $KEY
|
pankso@5
|
281 </pre>
|
pankso@5
|
282 EOT
|
pankso@23
|
283 # Each user can have personal profile page
|
pankso@23
|
284 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
|
pankso@23
|
285 cat $PEOPLE/$USER/profile.txt | wiki_parser
|
pankso@23
|
286 cat << EOT
|
pankso@23
|
287 <div id="tools">
|
pankso@23
|
288 <a href="$script?edit=profile">$(gettext "Edit profile")</a>
|
pankso@23
|
289 </div>
|
pankso@23
|
290 EOT
|
pankso@23
|
291 else
|
pankso@23
|
292 cat << EOT
|
pankso@23
|
293 <div id="tools">
|
pankso@23
|
294 <a href="$script?edit=profile">$(gettext "Create a profile page")</a>
|
pankso@23
|
295 </div>
|
pankso@23
|
296 EOT
|
pankso@23
|
297 fi
|
pankso@5
|
298 }
|
pankso@5
|
299
|
paul@8
|
300 # The CM style parser. Just a title, simple text formating and internal
|
paul@8
|
301 # links, as well as images and use HTML for other stuff. Keep it fast!
|
pankso@5
|
302 # To make TinyCM as easy as possible we have a small HTML editor/helper
|
pankso@5
|
303 # written in Javascript
|
pankso@5
|
304 wiki_parser() {
|
pankso@5
|
305 doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
|
pankso@5
|
306 sed \
|
pankso@5
|
307 -e s"#====\([^']*\)====#<h2>\1</h2>#"g \
|
pankso@5
|
308 -e s"#===\([^']*\)===#<h3>\1</h3>#"g \
|
pankso@5
|
309 -e s"#==\([^']*\)==#<h4>\1</h4>#"g \
|
pankso@13
|
310 -e s"#\*\*\([^']*\)\*\*#<b>\1</b>#"g \
|
pankso@5
|
311 -e s"#''\([^']*\)''#<em>\1</em>#"g \
|
pankso@5
|
312 -e s"#__\([^']*\)__#<u>\1</u>#"g \
|
pankso@5
|
313 -e s"#\[\([^]]*\)|\($doc\)\]#<a href='$script?d=\2'>\1</a>#"g \
|
pankso@17
|
314 -e s"#\[\([^]]*\)!\($doc\)\]#<a href='\2'>\1</a>#"g \
|
pankso@17
|
315 -e s"#\[\(http://*[^]]*.png\)\]#<img src='\1' />#"g \
|
pankso@17
|
316 -e s"#\[\([^]]*.png\)\]#<img src='content/cloud/\1' />#"g
|
pankso@5
|
317 }
|
pankso@5
|
318
|
pankso@5
|
319 link_user() {
|
pankso@15
|
320 echo "<a href='$(basename $script)?user=$user'>$user</a>"
|
pankso@5
|
321 }
|
pankso@5
|
322
|
pankso@5
|
323 # Save a document. Do we need more than 1 backup and diff ?
|
pankso@5
|
324 save_document() {
|
pankso@5
|
325 mkdir -p $cache/$d $(dirname $wiki/$d)
|
pankso@5
|
326 # May be a new page.
|
pankso@5
|
327 if [ ! -f "$wiki/$d.txt" ]; then
|
pankso@5
|
328 new=0
|
pankso@5
|
329 touch $wiki/$d.txt
|
pankso@5
|
330 fi
|
pankso@5
|
331 cp $wiki/$d.txt $cache/$d/last.bak
|
pankso@5
|
332 sed "s/$(echo -en '\r') /\n/g" > $wiki/$d.txt << EOT
|
pankso@5
|
333 $(GET content)
|
pankso@5
|
334 EOT
|
pankso@5
|
335 diff $cache/$d/last.bak $wiki/$d.txt > $cache/$d/last.diff
|
pankso@5
|
336 # Log
|
pankso@5
|
337 if [ "$new" ]; then
|
pankso@5
|
338 echo "Page created by: $(link_user)" | log
|
pankso@31
|
339 echo "New document: <a href='$script?d=$d'>$d</a>" | log_activity
|
pankso@5
|
340 if [ "$HG" == "yes" ]; then
|
pankso@5
|
341 cd $content && hg -q add
|
pankso@5
|
342 hg commit -q -u "$NAME <$MAIL>" -m "Created new document: $d"
|
pankso@5
|
343 cd $tiny
|
pankso@5
|
344 fi
|
pankso@5
|
345 else
|
pankso@28
|
346 # Here we may clean log: cat && tail -n 40
|
pankso@5
|
347 echo "Page edited by: $(link_user)" | log
|
pankso@5
|
348 if [ "$HG" == "yes" ]; then
|
pankso@5
|
349 cd $content && hg commit -q -u "$NAME <$MAIL>" \
|
pankso@5
|
350 -m "Edited document: $d"
|
pankso@5
|
351 cd $tiny
|
pankso@5
|
352 fi
|
pankso@5
|
353 fi
|
pankso@5
|
354 }
|
pankso@5
|
355
|
pankso@23
|
356 # Save a user profile.
|
pankso@23
|
357 save_profile() {
|
pankso@23
|
358 path="$PEOPLE/$user"
|
pankso@23
|
359 cp -f ${path}/${d}.txt ${path}/${d}.bak
|
pankso@23
|
360 sed "s/$(echo -en '\r') /\n/g" > ${path}/${d}.txt << EOT
|
pankso@23
|
361 $(GET content)
|
pankso@23
|
362 EOT
|
pankso@23
|
363 }
|
pankso@23
|
364
|
pankso@5
|
365 # CM tools (edit, diff, etc).
|
pankso@5
|
366 wiki_tools() {
|
pankso@5
|
367 cat << EOT
|
pankso@5
|
368 <div id="tools">
|
pankso@5
|
369 <a href="$script?edit=$d">$(gettext "Edit document")</a>
|
pankso@5
|
370 <a href="$script?diff=$d">$(gettext "Last diff")</a>
|
pankso@31
|
371 <a href="$script?log=$d">$(gettext "File log")</a>
|
pankso@31
|
372 <a href="$script?dashboard">$(gettext "Dashboard")</a>
|
pankso@5
|
373 $([ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>")
|
pankso@5
|
374 </div>
|
pankso@5
|
375 EOT
|
pankso@5
|
376 }
|
pankso@5
|
377
|
pankso@5
|
378 # Get and display Gravatar image: get_gravatar email size
|
pankso@5
|
379 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
|
pankso@5
|
380 get_gravatar() {
|
pankso@5
|
381 email=$1
|
pankso@5
|
382 size=$2
|
pankso@5
|
383 [ "$size" ] || size=48
|
pankso@5
|
384 url="http://www.gravatar.com/avatar"
|
pankso@5
|
385 md5=$(md5crypt $email)
|
pankso@5
|
386 echo "<img src='$url/$md5?d=identicon&s=$size' alt='∗' />"
|
pankso@5
|
387 }
|
pankso@5
|
388
|
pankso@5
|
389 # List hg logs
|
pankso@5
|
390 hg_log() {
|
pankso@5
|
391 cd $content
|
pankso@5
|
392 cat << EOT
|
pankso@5
|
393 <table>
|
pankso@5
|
394 <thead>
|
pankso@5
|
395 <td>$(gettext "User")</td>
|
pankso@5
|
396 <td>$(gettext "Description")</td>
|
pankso@5
|
397 <td>$(gettext "Revision")</td>
|
pankso@5
|
398 </thead>
|
pankso@5
|
399 EOT
|
pankso@5
|
400 hg log --template "<tr><td>{author}</td><td>{desc}</td><td>{rev}</td></tr>\n"
|
pankso@5
|
401 echo '</table>'
|
pankso@5
|
402 }
|
pankso@5
|
403
|
pankso@5
|
404 #
|
pankso@5
|
405 # POST actions
|
pankso@5
|
406 #
|
pankso@5
|
407
|
pankso@5
|
408 case " $(POST) " in
|
pankso@5
|
409 *\ auth\ *)
|
pankso@5
|
410 # Authenticate user. Create a session file in $sessions to be used
|
pankso@5
|
411 # by check_auth. We have the user login name and a peer session
|
pankso@5
|
412 # md5 string in the COOKIE.
|
pankso@5
|
413 user="$(POST auth)"
|
pankso@5
|
414 pass="$(md5crypt "$(POST pass)")"
|
pankso@5
|
415 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
|
pankso@5
|
416 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
|
pankso@5
|
417 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
|
pankso@5
|
418 [ -d $sessions ] || mkdir -p $sessions
|
pankso@36
|
419 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
|
pankso@5
|
420 echo "$md5session" > $sessions/$user
|
pankso@5
|
421 header "Location: $script" \
|
pankso@5
|
422 "Set-Cookie: auth=$user:$md5session; HttpOnly"
|
pankso@5
|
423 else
|
pankso@5
|
424 header "Location: $script?login&error"
|
pankso@5
|
425 fi ;;
|
pankso@5
|
426 *\ signup\ *)
|
pankso@5
|
427 # POST action for signup
|
pankso@5
|
428 name="$(POST name)"
|
pankso@5
|
429 user="$(POST user)"
|
pankso@5
|
430 mail="$(POST mail)"
|
pankso@5
|
431 pass="$(md5crypt "$(POST pass)")"
|
pankso@5
|
432 if ! grep "^${user}:" $AUTH_FILE; then
|
pankso@5
|
433 new_user_config
|
pankso@5
|
434 header "Location: $script?login"
|
pankso@5
|
435 else
|
pankso@5
|
436 header
|
pankso@5
|
437 html_header
|
pankso@5
|
438 user_box
|
paul@8
|
439 echo "<h2>gettext "User already exists: $user"</h2>"
|
pankso@5
|
440 html_footer
|
pankso@5
|
441 fi ;;
|
pankso@5
|
442 esac
|
pankso@5
|
443
|
pankso@5
|
444 #
|
pankso@5
|
445 # Plugins
|
pankso@5
|
446 #
|
pankso@5
|
447 for p in $(ls -1 $plugins)
|
pankso@5
|
448 do
|
pankso@5
|
449 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
|
pankso@5
|
450 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
|
pankso@5
|
451 done
|
pankso@5
|
452
|
pankso@5
|
453 #
|
pankso@5
|
454 # GET actions
|
pankso@5
|
455 #
|
pankso@5
|
456
|
pankso@5
|
457 case " $(GET) " in
|
pankso@5
|
458 *\ edit\ *)
|
pankso@5
|
459 d="$(GET edit)"
|
pankso@5
|
460 header
|
pankso@5
|
461 html_header
|
pankso@5
|
462 user_box
|
pankso@5
|
463 get_lang
|
pankso@5
|
464 if check_auth; then
|
pankso@23
|
465 if [ "$doc" == "profile" ]; then
|
pankso@23
|
466 wiki="$PEOPLE/$user"
|
pankso@23
|
467 fi
|
pankso@5
|
468 cat << EOT
|
pankso@5
|
469 <h2>$(gettext "Edit $doc [ $i18n ]")</h2>
|
pankso@5
|
470
|
pankso@5
|
471 <div id="edit">
|
pankso@5
|
472
|
pankso@5
|
473 <form method="get" action="$script" name="editor">
|
pankso@5
|
474 <input type="hidden" name="save" value="$d" />
|
pankso@5
|
475 <textarea name="content">$(cat "$wiki/$d.txt")</textarea>
|
pankso@5
|
476 <input type="submit" value="$(gettext "Save document")" />
|
pankso@5
|
477 $(gettext "Code Helper:")
|
pankso@5
|
478 $(cat lib/jseditor.html)
|
pankso@5
|
479 </form>
|
pankso@5
|
480
|
pankso@5
|
481 </div>
|
pankso@5
|
482 EOT
|
pankso@5
|
483 else
|
paul@8
|
484 gettext "You must be logged in to edit pages"
|
pankso@5
|
485 fi
|
pankso@5
|
486 html_footer ;;
|
pankso@15
|
487
|
pankso@5
|
488 *\ save\ *)
|
pankso@5
|
489 d="$(GET save)"
|
pankso@5
|
490 if check_auth; then
|
pankso@23
|
491 # User profile
|
pankso@23
|
492 if [ "$d" == "profile" ]; then
|
pankso@23
|
493 save_profile
|
pankso@23
|
494 header "Location: $script?user=$user"
|
pankso@23
|
495 else
|
pankso@23
|
496 save_document
|
pankso@23
|
497 fi
|
pankso@5
|
498 fi
|
pankso@5
|
499 header "Location: $script?d=$d" ;;
|
pankso@15
|
500
|
pankso@5
|
501 *\ log\ *)
|
pankso@5
|
502 d="$(GET log)"
|
pankso@5
|
503 header
|
pankso@5
|
504 html_header
|
pankso@5
|
505 user_box
|
pankso@28
|
506 # Main activity
|
pankso@28
|
507 if [ "$d" == "log" ]; then
|
pankso@28
|
508 echo "<h2>$(gettext "Activity")</h2>"
|
pankso@28
|
509 if check_auth; then
|
pankso@28
|
510 echo "<div id='tools'>"
|
pankso@28
|
511 echo "<a href='$script?dashboard'>Dashboard</a>"
|
pankso@28
|
512 echo "</div>"
|
pankso@28
|
513 fi
|
pankso@28
|
514 echo '<pre>'
|
pankso@28
|
515 if [ -f "$cache/log/activity.log" ]; then
|
pankso@28
|
516 IFS="|"
|
pankso@28
|
517 tac $cache/log/activity.log | while read USER DATE LOG
|
pankso@28
|
518 do
|
pankso@28
|
519 . ${PEOPLE}/${USER}/account.conf
|
pankso@28
|
520 cat << EOT
|
pankso@28
|
521 <a href='$script?user=$USER'>$(get_gravatar $MAIL 24)</a>\
|
pankso@28
|
522 <span class='date'>$DATE -</span> $LOG
|
pankso@28
|
523 EOT
|
pankso@28
|
524 done
|
pankso@28
|
525 unset IFS
|
pankso@28
|
526 else
|
pankso@28
|
527 gettext "No activity log yet"; echo
|
pankso@28
|
528 fi
|
pankso@28
|
529 echo '</pre>'
|
pankso@28
|
530 html_footer && exit 0
|
pankso@28
|
531 fi
|
pankso@5
|
532 get_lang
|
pankso@5
|
533 echo "<h2>$(gettext "Activity for:") <a href='$script?d=$d'>$d</a></h2>"
|
pankso@5
|
534 echo '<pre>'
|
pankso@5
|
535 if [ -f "$cache/$d/activity.log" ]; then
|
pankso@5
|
536 tac $cache/$d/activity.log
|
pankso@5
|
537 else
|
pankso@5
|
538 gettext "No log for: $d"; echo
|
pankso@5
|
539 fi
|
pankso@5
|
540 echo '</pre>'
|
pankso@5
|
541 if check_auth; then
|
pankso@5
|
542 wiki_tools
|
pankso@5
|
543 fi
|
pankso@5
|
544 html_footer ;;
|
pankso@28
|
545
|
pankso@28
|
546 *\ ls\ *)
|
pankso@28
|
547 d="Document list"
|
pankso@28
|
548 header
|
pankso@28
|
549 html_header
|
pankso@28
|
550 user_box
|
pankso@28
|
551 echo "<h2>$(gettext "Document list")</h2>"
|
pankso@28
|
552 if check_auth; then
|
pankso@28
|
553 echo "<div id='tools'>"
|
pankso@28
|
554 echo "<a href='$script?dashboard'>Dashboard</a>"
|
pankso@28
|
555 echo "</div>"
|
pankso@28
|
556 fi
|
pankso@28
|
557 echo '<pre>'
|
pankso@28
|
558 cd ${wiki}
|
pankso@28
|
559 for d in $(find . -type f | sed s'/.\///')
|
pankso@28
|
560 do
|
pankso@28
|
561 echo "<a href='$script?d=${d%.txt}'>${d%.txt}</a>"
|
pankso@28
|
562 done
|
pankso@28
|
563 echo '</pre>'
|
pankso@28
|
564 html_footer ;;
|
pankso@15
|
565
|
pankso@5
|
566 *\ diff\ *)
|
pankso@5
|
567 d="$(GET diff)"
|
pankso@5
|
568 date="last"
|
pankso@5
|
569 header
|
pankso@5
|
570 html_header
|
pankso@5
|
571 user_box
|
pankso@5
|
572 get_lang
|
pankso@5
|
573 echo "<h2>$(gettext "Diff for:") <a href='$script?d=$d'>$d</a></h2>"
|
pankso@5
|
574 echo '<pre>'
|
pankso@5
|
575 if [ -f "$cache/$d/$date.diff" ]; then
|
pankso@5
|
576 cat $cache/$d/$date.diff | sed \
|
pankso@5
|
577 -e 's|&|\&|g' -e 's|<|\<|g' -e 's|>|\>|g' \
|
pankso@5
|
578 -e s"#^-\([^']*\).#<span style='color: red;'>\0</span>#"g \
|
pankso@5
|
579 -e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \
|
pankso@5
|
580 -e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g
|
pankso@5
|
581 else
|
pankso@5
|
582 gettext "No diff for: $d"; echo
|
pankso@5
|
583 fi
|
pankso@5
|
584 echo '</pre>'
|
pankso@5
|
585 if check_auth; then
|
pankso@5
|
586 wiki_tools
|
pankso@5
|
587 fi
|
pankso@5
|
588 html_footer ;;
|
pankso@15
|
589
|
pankso@5
|
590 *\ login\ *)
|
pankso@5
|
591 # The login page
|
pankso@5
|
592 d="Login"
|
pankso@5
|
593 [ "$(GET error)" ] && \
|
pankso@5
|
594 error="<p class="error">$(gettext "Bad login or pass")</p>"
|
pankso@5
|
595 header
|
pankso@5
|
596 html_header
|
pankso@5
|
597 user_box
|
pankso@5
|
598 login_page
|
pankso@5
|
599 html_footer ;;
|
pankso@15
|
600
|
pankso@5
|
601 *\ signup\ *)
|
pankso@5
|
602 # The login page
|
pankso@5
|
603 d="$(gettext "Sign Up")"
|
pankso@5
|
604 header
|
pankso@5
|
605 html_header
|
pankso@5
|
606 user_box
|
pankso@5
|
607 echo "<h2>$d</h2>"
|
pankso@5
|
608 if [ "$ONLINE_SIGNUP" == "yes" ]; then
|
pankso@5
|
609 signup_page
|
pankso@5
|
610 else
|
paul@8
|
611 gettext "Online registration is disabled"
|
pankso@5
|
612 fi
|
pankso@5
|
613 html_footer ;;
|
pankso@15
|
614
|
pankso@5
|
615 *\ logout\ *)
|
pankso@5
|
616 # Set a Cookie in the past to logout.
|
pankso@5
|
617 expires="Expires=Wed, 01-Jan-1980 00:00:00 GMT"
|
pankso@5
|
618 if check_auth; then
|
pankso@5
|
619 rm -f "$sessions/$user"
|
pankso@5
|
620 header "Location: $script" "Set-Cookie: auth=none; $expires; HttpOnly"
|
pankso@5
|
621 fi ;;
|
pankso@15
|
622
|
pankso@5
|
623 *\ user\ *)
|
pankso@5
|
624 # User profile
|
pankso@15
|
625 d="$(GET user)"
|
pankso@36
|
626 last="$(cat $PEOPLE/"$(GET user)"/last)"
|
pankso@5
|
627 header
|
pankso@5
|
628 html_header
|
pankso@5
|
629 user_box
|
pankso@5
|
630 . $PEOPLE/"$(GET user)"/account.conf
|
pankso@36
|
631 cat << EOT
|
pankso@36
|
632 <h2>$(get_gravatar $MAIL) $NAME</h2>
|
pankso@36
|
633
|
pankso@36
|
634 <pre>
|
pankso@36
|
635 $(gettext "User name :") $USER
|
pankso@36
|
636 $(gettext "Last login :") $last
|
pankso@36
|
637 EOT
|
pankso@5
|
638 if check_auth && [ "$(GET user)" == "$user" ]; then
|
pankso@5
|
639 auth_people
|
pankso@5
|
640 else
|
pankso@28
|
641 # check_auth will set VARS to current logged user: re-source
|
pankso@28
|
642 . $PEOPLE/"$(GET user)"/account.conf
|
pankso@5
|
643 public_people
|
pankso@5
|
644 fi
|
pankso@5
|
645 html_footer ;;
|
pankso@15
|
646
|
pankso@5
|
647 *\ dashboard\ *)
|
pankso@5
|
648 # For now simply list plugins and users info. We could have a
|
pankso@5
|
649 # dashbord only for ADMINS found in the config file. The dashboard
|
pankso@5
|
650 # should also be a plugin.
|
pankso@5
|
651 d="Dashboard"
|
pankso@5
|
652 header
|
pankso@5
|
653 html_header
|
pankso@5
|
654 user_box
|
pankso@5
|
655 users=$(ls -1 $PEOPLE | wc -l)
|
pankso@5
|
656 docs=$(find $wiki -type f | wc -l)
|
pankso@17
|
657 wikisize="$(du -sh $wiki | awk '{print $1}')"
|
pankso@17
|
658 cachesize="$(du -sh $cache | awk '{print $1}')"
|
pankso@17
|
659 [ "$HG" != "yes" ] && hg=$(gettext "disabled")
|
pankso@17
|
660 [ "$HG" == "yes" ] && hg=$(gettext "enabled")
|
pankso@5
|
661 echo "<h2>$d</h2>"
|
pankso@5
|
662 if check_auth; then
|
pankso@17
|
663 cat << EOT
|
pankso@28
|
664 <div id="tools">
|
pankso@28
|
665 <a href='$script?log'>Activity log</a>
|
pankso@28
|
666 <a href='$script?ls'>List files</a>
|
pankso@28
|
667 </div>
|
pankso@28
|
668
|
pankso@17
|
669 <pre>
|
pankso@17
|
670 Users : $users
|
pankso@17
|
671 Wiki : $docs ($wikisize)
|
pankso@17
|
672 Cache : $cachesize
|
pankso@17
|
673 Mercurial : $hg
|
pankso@17
|
674 </pre>
|
pankso@28
|
675 <h3>Admin users</h3>
|
pankso@28
|
676 EOT
|
pankso@28
|
677 # Get the list of administrators
|
pankso@28
|
678 for u in $(ls $PEOPLE)
|
pankso@28
|
679 do
|
pankso@28
|
680 user=${u}
|
pankso@28
|
681 if admin_user; then
|
pankso@28
|
682 echo "<a href='?user=$u'>$u</a>"
|
pankso@28
|
683 fi
|
pankso@28
|
684 done
|
pankso@28
|
685 cat << EOT
|
pankso@17
|
686 <h3>$(gettext "Plugins")</h3>
|
pankso@17
|
687 <pre>
|
pankso@17
|
688 EOT
|
pankso@5
|
689 for p in $(ls -1 $plugins)
|
pankso@5
|
690 do
|
pankso@5
|
691 . $plugins/$p/$p.conf
|
pankso@5
|
692 echo "<a href='?$p'>$PLUGIN</a> - $SHORT_DESC"
|
pankso@5
|
693 done
|
pankso@5
|
694 echo '</pre>'
|
pankso@5
|
695 else
|
paul@8
|
696 gettext "You must be logged in to view the dashboard."
|
pankso@5
|
697 fi
|
pankso@5
|
698 html_footer ;;
|
pankso@15
|
699
|
pankso@5
|
700 *\ hg\ *)
|
pankso@5
|
701 header
|
pankso@5
|
702 [ "$HG" != "yes" ] && gettext "Hg is disabled" && exit 0
|
pankso@5
|
703 [ ! -x /usr/bin/hg ] && gettext "Hg is not installed" && exit 0
|
pankso@5
|
704 d="Hg Log"
|
pankso@5
|
705 html_header
|
pankso@5
|
706 user_box
|
pankso@5
|
707 echo "<h2>$d</h2>"
|
pankso@5
|
708 case " $(GET hg) " in
|
pankso@5
|
709 *\ init\ *)
|
pankso@5
|
710 if check_auth; then
|
pankso@5
|
711 [ -d "$content/.hg" ] && exit 0
|
pankso@5
|
712 echo '<pre>'
|
pankso@5
|
713 gettext "Executing: hg init"; echo
|
pankso@5
|
714 cd $content/ && hg init
|
pankso@5
|
715 echo '[hooks]' > .hg/hgrc
|
pankso@5
|
716 echo 'incoming = hg update' >> .hg/hgrc
|
paul@8
|
717 gettext "Adding current content and committing"; echo
|
pankso@5
|
718 [ ! -f "$wiki/index.txt" ] && touch $wiki/$index.txt
|
pankso@5
|
719 hg add && hg commit -u "$NAME <$MAIL>" \
|
paul@22
|
720 -m "Initial commit with current content"
|
pankso@5
|
721 echo '</pre>' && cd ..
|
pankso@5
|
722 fi ;;
|
pankso@5
|
723 esac
|
pankso@5
|
724 hg_log
|
pankso@5
|
725 html_footer ;;
|
pankso@15
|
726
|
pankso@5
|
727 *)
|
pankso@5
|
728 # Display requested page
|
pankso@5
|
729 d="$(GET d)"
|
pankso@5
|
730 [ "$d" ] || d=$index
|
pankso@5
|
731 header
|
pankso@5
|
732 html_header
|
pankso@5
|
733 user_box
|
pankso@5
|
734 get_lang
|
pankso@34
|
735 # Generate a default index on first run
|
pankso@11
|
736 if [ ! -f "$wiki/$index.txt" ]; then
|
pankso@34
|
737 if ! default_index; then
|
pankso@34
|
738 echo "<pre class='error'>Directory : content/ is not writable"
|
pankso@32
|
739 html_footer && exit 0
|
pankso@32
|
740 fi
|
pankso@11
|
741 fi
|
pankso@34
|
742 # Check cache dir
|
pankso@34
|
743 if [ ! -w "$cache" ]; then
|
pankso@34
|
744 echo "<pre class='error'>Directory : cache/ is not writable"
|
pankso@34
|
745 echo "Command : install -m 0777 -d $tiny/cache</pre>"
|
pankso@34
|
746 html_footer && exit 0
|
pankso@34
|
747 fi
|
pankso@34
|
748 # Wiki document
|
pankso@5
|
749 if [ ! -f "$wiki/$d.txt" ]; then
|
pankso@5
|
750 echo "<h2>$d</h2>"
|
pankso@5
|
751 gettext "The document does not exist. You can create it or read the"
|
pankso@13
|
752 echo " <a href='?d=en/help'>help</a>"
|
pankso@5
|
753 else
|
pankso@26
|
754 if fgrep -q [NOWIKI] $wiki/$d.txt; then
|
pankso@35
|
755 cat $wiki/$d.txt | sed '/\[NOWIKI\]/'d
|
pankso@5
|
756 else
|
pankso@5
|
757 cat $wiki/$d.txt | wiki_parser
|
pankso@5
|
758 fi
|
pankso@5
|
759 fi
|
pankso@5
|
760 if check_auth; then
|
pankso@5
|
761 wiki_tools
|
pankso@5
|
762 if [ "$HG" == "yes" ] && [ ! -d "$content/.hg" ]; then
|
pankso@5
|
763 echo '<p class="error box">'
|
pankso@5
|
764 gettext "Mercurial is enabled but no repository found"
|
pankso@5
|
765 echo ": <a href='?hg=init'>Hg init</a>"
|
pankso@5
|
766 echo '</p>'
|
pankso@5
|
767 fi
|
pankso@5
|
768 fi
|
pankso@5
|
769 html_footer ;;
|
pankso@5
|
770 esac
|
pankso@5
|
771
|
pankso@5
|
772 exit 0
|