tinycm view index.cgi @ rev 55

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