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