slitaz-dev-tools view tazwikiss/rootfs/var/www/wiki/index.sh @ rev 225

tazwikiss: log plugins error messages (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 28 11:32:38 2014 +0000 (2014-03-28)
parents 4ef87cdc7d28
children 6a4c256a83ad
line source
1 #!/bin/sh
2 #
3 # TazWikiss - A tiny Wiki for busybox/httpd
4 # Licence GNU/GPLv2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
5 # Copyright (C) Pascal Bellard
6 # Based on WiKiss - http://wikiss.tuxfamily.org/
8 . /usr/lib/slitaz/httphelper.sh
10 cd $(dirname $0)
11 CONFIG=config-${HTTP_ACCEPT_LANGUAGE%%,*}.sh
12 [ -x "$CONFIG" ] || CONFIG=config.sh
13 . ./$CONFIG
15 WIKI_VERSION="Based on WiKiss 0.3"
17 # Initialisations
18 toc='' # Table Of Content
19 CONTENT='' # contenu de la page
20 HISTORY='' # lien vers l'historique
21 plugins_dir="plugins/" # repertoire ou stocker les plugins
22 template="template.html" # Fichier template
23 PAGE_TITLE_link=true # y-a-t-il un lien sur le titre de la page ?
24 editable=true # la page est editable
25 urlbase="$SCRIPT_NAME"
26 #urlbase="./"
28 die()
29 {
30 echo $@
31 exit
32 }
34 redirect()
35 {
36 awk '{ printf "%s\r\n",$0 }' <<EOT
37 HTTP/1.0 302 Found
38 location: $1
40 EOT
41 exit
42 }
44 cache_auth()
45 {
46 local tmp
47 tmp="$(echo $1$(date +%d) | md5sum | cut -c1-8)"
48 [ "$(POST sc)" == "$1" ] && AUTH=$tmp || [ "$AUTH" == "$tmp" ]
49 }
51 authentified()
52 {
53 [ -n "$PASSWORDS" ] && for i in $PASSWORDS ; do
54 cache_auth "$i" && return
55 done
56 cache_auth "$PASSWORD"
57 }
59 plugin_call_method()
60 {
61 local status
62 local name
63 name=$1
64 shift
65 [ -d "$plugins_dir" ] || return
66 status=false
67 for i in $plugins_dir/*.sh ; do
68 [ -x $i ] || continue
69 grep -q "^$name()" $i || continue
70 . $i
71 eval $name "$@"
72 [ $? == 0 ] && status=true
73 done 3>&1 1>&2 2>&3 | logger -t "httpd/wiki/plugin"
74 $status
75 }
77 curdate()
78 {
79 date '+%Y-%m-%d %H:%M'
80 }
82 filedate()
83 {
84 stat -c %y $1 | sed -e 's|-|/|g' -e 's/\(:..\):.*/\1/'
85 }
87 AUTH=$(GET auth)
88 [ -n "$AUTH" ] || AUTH=$(POST auth)
89 PAGE_TITLE="$(GET page)"
90 [ -n "$PAGE_TITLE" ] || PAGE_TITLE="$(POST page)"
91 if [ -z "$PAGE_TITLE" ]; then
92 PAGE_TITLE="$START_PAGE"
93 case "$(GET action)" in
94 recent) PAGE_TITLE="$RECENT_CHANGES" ;;
95 search) PAGE_TITLE="$LIST"
96 [ -n "$(GET query)" ] && PAGE_TITLE="$SEARCH_RESULTS $(GET query)"
97 esac
98 fi
99 case "$PAGE_TITLE" in
100 */*|*\&*) PAGE_TITLE="$START_PAGE" ;;
101 esac
102 gtime=$(GET time)
103 case "$gtime" in
104 */*|*\&*) gtime="" ;;
105 esac
106 action=$(GET action)
107 datew="$(curdate)"
108 content="$(POST content)"
110 # Ecrire les modifications, s'il y a lieu
111 PAGE_txt="$PAGES_DIR$PAGE_TITLE.txt"
112 plugin_call_method "init" $PAGE_txt
113 if [ -n "$content" ]; then # content => page
114 if authentified; then
115 CR="$(echo -en '\r')"
116 sed 's/</\&lt;/g;s/'$CR' /'$CR'\n/g' > $PAGE_txt <<EOT
117 $POST_content_1
118 EOT
119 if [ -n "$BACKUP_DIR" ]; then
120 complete_dir_s="$BACKUP_DIR$PAGE_TITLE/"
121 if [ ! -d "$complete_dir_s" ]; then
122 mkdir -p $complete_dir_s
123 chmod 777 $complete_dir_s
124 fi
125 cat >> "$complete_dir_s$(curdate).bak" <<EOT
127 // $datew / $REMOTE_ADDR
128 $(cat $PAGE_txt)
129 EOT
130 fi
131 plugin_call_method "writedPage" $PAGE_txt
132 PAGE_TITLE="$PAGE_TITLE&auth=$AUTH"
133 else
134 PAGE_TITLE="$PAGE_TITLE&action=edit&error=1"
135 fi
136 redirect "$urlbase?page=$PAGE_TITLE"
137 fi
139 if [ -r "$PAGE_txt" -o -n "$action" ]; then
140 CONTENT=""
141 if [ -e "$PAGE_txt" ]; then
142 TIME=$(filedate $PAGE_txt)
143 CONTENT="$(cat $PAGE_txt)"
144 fi
145 # Restaurer une page
146 [ -n "$(GET page)" -a -n "$gtime" -a "$(GET restore)" == 1 ] &&
147 [ -r "$BACKUP_DIR$PAGE_TITLE/$gtime" ] &&
148 CONTENT="$(cat $BACKUP_DIR$PAGE_TITLE/$gtime)"
149 CONTENT="$(sed -e 's/\$/\&#036;/g' -e 's/\\/\&#092;/g' <<EOT
150 $CONTENT
151 EOT
152 )"
153 else
154 CONTENT="$(sed -e "s#%page%#$PAGE_TITLE#" <<EOT
155 $DEFAULT_CONTENT
156 EOT
157 )"
158 fi
160 htmldiff()
161 {
162 local files
163 local old
164 local new
165 old="$BACKUP_DIR$(GET page)/$1"
166 new="$BACKUP_DIR$(GET page)/$2"
167 [ -s "$old" ] || old=/dev/null
168 [ -n "$2" -a "$2" != "none" ] || new=$PAGES_DIR$(GET page).txt
169 files="$old $new"
170 [ "$old" -nt "$new" -a "$old" != "/dev/null" ] && files="$new $old"
171 diff -aU 99999 $files | sed -e '1,3d' -e '/^\\/d' -e 's|$|<br/>|' \
172 -e 's|^-\(.*\)$|<font color=red>\1</font>|' \
173 -e 's|^+\(.*\)$|<font color=green>\1</font>|'
174 }
176 # Actions speciales du Wiki
177 case "$action" in
178 edit)
179 editable=false
180 HISTORY="<a href=\"$urlbase?page=$(urlencode $PAGE_TITLE)\&amp;action=history\" accesskey=\"6\" rel=\"nofollow\">$HISTORY_BUTTON</a><br />"
181 CONTENT="$(sed 's/%/\&#37;/g' <<EOT
182 $CONTENT
183 EOT
184 )"
185 CONTENT="<form method=\"post\" action=\"$urlbase\">
186 <textarea name=\"content\" cols=\"83\" rows=\"30\" style=\"width: 100%;\">
187 $CONTENT
188 </textarea>
189 <input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br />
190 <p align=\"right\">"
191 if authentified; then
192 CONTENT="$CONTENT<input type=\"hidden\" value=\"$(POST password)\""
193 else
194 CONTENT="$CONTENT$MDP : <input type=\"password\""
195 fi
196 CONTENT="$CONTENT name=\"sc\" /> <input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></p></form>"
197 ;;
198 history)
199 complete_dir="$BACKUP_DIR$PAGE_TITLE/"
200 if [ -n "$gtime" ]; then
201 HISTORY="<a href=\"$urlbase?page=$PAGE_TITLE\&amp;action=history\" rel=\"nofollow\">$HISTORY_BUTTON</a>"
202 if [ -r "$complete_dir$gtime" ]; then
203 HISTORY="$HISTORY <a href=\"$urlbase?page=$PAGE_TITLE\&amp;action=edit\&amp;time=$gtime&amp;restore=1\" rel=\"nofollow\">$RESTORE</a>"
204 CONTENT="$(cat $complete_dir$gtime | sed -e s/$(echo -ne '\r')//g -e 's|$|<br/>|g')"
205 else
206 HISTORY="$HISTORY -"
207 fi
208 else
209 HISTORY="$HISTORY_BUTTON"
210 CONTENT="$NO_HISTORY"
211 if [ -d $complete_dir ]; then
212 CONTENT="<form method=\"GET\" action=\"$urlbase\">\n<input type=hidden name=action value=diff><input type=hidden name=page value=\"$PAGE_TITLE\">"
213 for file in $(ls $complete_dir | sort -r); do
214 CONTENT="$CONTENT
215 <input type=radio name=f1 value=$file><input type=radio name=f2 value=$file />
216 <a href=\"$urlbase?page=$PAGE_TITLE&amp;action=history&amp;time=$file\">$file</a><br />
217 "
218 done
219 CONTENT="$CONTENT<input type=submit value=diff></form>"
220 fi
221 fi ;;
222 diff)
223 if [ -n "$(GET f1)" ]; then
224 HISTORY="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&amp;action=history\">$HISTORY_BUTTON</a>"
225 CONTENT="$(htmldiff "$(GET f1)" "$(GET f2)" )"
226 else
227 # diff auto entre les 2 dernières versions
228 ls "$BACKUP_DIR$PAGE_TITLE/" | ( sort -r ; echo none ; echo ) | head -n 2 | while read f1 f2; do
229 redirect "$urlbase?page=$(urlencode "$PAGE_TITLE")&action=$action&f1=$f1&f2=$f2"
230 done
231 fi ;;
232 search)
233 PAGE_TITLE_link=false
234 editable=false
235 query="$(GET query)"
236 n=0
237 for file in $(ls $PAGES_DIR/*.txt 2> /dev/null | sort) ; do
238 [ -e $file ] || continue
239 echo $file | grep -qs "$query" $file /dev/stdin || continue
240 file=$(basename $file ".txt")
241 CONTENT="$CONTENT<a href=\"$urlbase?page=$file\">$file</a><br />
242 "
243 n=$(($n + 1))
244 done
245 PAGE_TITLE="$PAGE_TITLE ($n)" ;;
246 recent)
247 PAGE_TITLE_link=false
248 editable=false
249 n=0
250 for file in $(ls -l $PAGES_DIR/*.txt 2> /dev/null | awk '{ print $9 }' | tail -n 10) ; do
251 filename=$(basename $file ".txt")
252 timestamp=$(filedate $file)
253 CONTENT="$CONTENT<a href=\"$urlbase?page=$filename\">$filename</a> ($timestamp - <a href=\"$urlbase?page=$filename&amp;action=diff\">diff</a>)<br />
254 "
255 done ;;
256 '') ;;
257 *)
258 plugin_call_method "action" $action || action="" ;;
259 esac
260 if [ -z "$action" ]; then
261 if echo "$CONTENT" | grep -q '%html%\s'; then
262 CONTENT="$(sed 's/%html%\s//' <<EOT
263 $CONTENT
264 EOT
265 )"
266 else
267 tmpdir=/tmp/tazwiki$$
268 mkdir $tmpdir
269 unesc="$(echo "$CONTENT" | sed 's/\^\(.\)/\n^\1\n/g' | grep '\^' |\
270 sort | uniq | grep -v "['[!]" | hexdump -e '"" 3/1 "%d " "\n"' |\
271 awk '{ printf "-e '\''s/\\^%c/\\&#%d;/g'\'' ",$2,$2}') \
272 -e 's/\\^'\\''/\\&#39;/g' -e 's/\^\!/\&#33;/g' \
273 -e 's/\^\[/\&#91;/g'"
274 CONTENT="$(eval sed $unesc <<EOT | \
275 sed -e 's/&/\&amp;/g' -e s/$(echo -ne '\r')//g \
276 -e 's/&amp;lt;/\&lt;/g' -e 's/&amp;#\([0-9]\)/\&#\1/g' | \
277 awk -v tmpdir=$tmpdir 'BEGIN { n=1; state=0 } {
278 s=$0
279 while (1) {
280 if (state == 0) {
281 if (match(s,/\{\{/)) {
282 printf "%s<pre><code>{{CODE%s}}</code></pre>",substr(s,1,RSTART-1),n
283 s=substr(s,RSTART+RLENGTH)
284 state=1
285 }
286 else {
287 print s
288 break
289 }
290 }
291 if (state == 1) {
292 if (match(s,/\}\}/)) {
293 printf "%s",substr(s,1,RSTART-1) >> tmpdir "/CODE" n
294 s=substr(s,RSTART+RLENGTH)
295 n++
296 state=0
297 }
298 else {
299 print s >> tmpdir "/CODE" n
300 break
301 }
302 }
303 }
304 }'
305 $CONTENT
306 EOT
307 )"
308 plugin_call_method formatBegin
309 CONTENT="$(sed -e 's/&lt;-->/\&harr;/g' -e 's/&lt;==>/\&hArr;/g'\
310 -e 's/-->/\&rarr;/g' -e 's/&lt;--/\&larr;/g' \
311 -e 's/==>/\&rArr;/g' -e 's/&lt;==/\&lArr;/g' \
312 -e 's/([eE])/\&euro;/g' -e 's/([pP])/\&pound;/g' \
313 -e 's/([yY])/\&yen;/g' -e 's/([tT][mM])/\&trade;/g' \
314 -e 's/([cC])/\&copy;/g' -e 's/([rR])/\&reg;/g' \
315 -e 's/([dD])/\&deg;/g' -e 's/(1\/2)/\&frac12;/g' \
316 -e 's/(1\/4)/\&frac14;/g' -e 's/(3\/4)/\&frac34;/g' \
317 -e 's/(&lt;=)/\&le;/g' -e 's/(>=)/\&ge;/g' \
318 -e 's/(!=)/\&ne;/g' -e 's/(+-)/\&plusmn;/g' <<EOT
319 $CONTENT
320 EOT
321 )"
322 rg_url="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*" # TODO: verif & / &amp;
323 rg_link_local="$rg_url"
324 rg_link_http="https\?://$rg_url"
325 rg_img_local="$rg_url\.jpe\?g\|$rg_url\.gif\|$rg_url\.png"
326 rg_img_http="$rg_link_http\.jpe\?g\|$rg_link_http\.gif\|$rg_link_http\.png"
328 # image, image link, link, wikipedia, email ...
329 CONTENT="$(sed \
330 -e "s#\[\($rg_img_http\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
331 -e "s#\[\($rg_img_local\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
332 -e "s#\[\($rg_img_http\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
333 -e "s#\[\($rg_img_local\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
334 -e "s#\[\($rg_img_http\)|\($rg_link_http\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
335 -e "s#\[\($rg_img_http\)|\($rg_link_local\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
336 -e "s#\[\($rg_img_local\)|\($rg_link_http\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
337 -e "s#\[\($rg_img_local\)|\($rg_link_local\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
338 -e "s#\[\([^]]*\)|\($rg_link_http\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
339 -e "s#\[\([^]]*\)|\($rg_link_local\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
340 -e "s#\[\($rg_link_http\)\]#<a href=\"\1\" class=\"url\">\1</a>#g" \
341 -e "s#\([^>\"]\)\($rg_link_http\)#\1<a href=\"\2\" class=\"url\">\2</a>#g" \
342 -e "s#\[?\([^]]*\)\]#<a href=\"http://$LANG.wikipedia.org/wiki/\1\" class=\"url\" title=\"Wikipedia\">\1</a>#g" \
343 -e "s#\[\([^]]*\)\]#<a href=\"$urlbase?page=\1\">\1</a>#g" \
344 -e 's#\([0-9a-zA-Z\./~\-\_][0-9a-zA-Z\./~\-\_]*@[0-9a-zA-Z\./~\-\_][0-9a-zA-Z\./~\-\_]*\)#<a href=\"mailto:\1\">\1</a>#g' \
345 -e 's#^\*\*\*\(.*\)#<ul><ul><ul><li>\1</li></ul></ul></ul>#g' \
346 -e 's#^\*\*\(.*\)#<ul><ul><li>\1</li></ul></ul>#g' \
347 -e 's#^\*\(.*\)#<ul><li>\1</li></ul>#g' \
348 -e 's,^\#\#\#\(.*\),<ol><ol><ol><li>\1</li></ol></ol></ol>,g' \
349 -e 's,^\#\#\(.*\),<ol><ol><li>\1</li></ol></ol>,g' \
350 -e 's,^\#\(.*\),<ol><li>\1</li></ol>,g' \
351 -e "s/$(printf '\r')//" <<EOT | sed \
352 -e ':x;/<\/ol>$/{N;s/\n//;$P;$D;bx;}' | sed \
353 -e ':x;/<\/ul>$/{N;s/\n//;$P;$D;bx;}' | sed \
354 -e ':x;s/<\/ul><ul>//g;tx' -e ':x;s/<\/ol><ol>//g;tx' \
355 -e 's|----*$|<hr />|' -e 's|$|<br />|' \
356 -e 's|</ul>|&\n|g' -e 's|</ol>|&\n|g' \
357 -e 's#</li>#&\n#g' -e 's#\(</h[123456]>\)<br />#\1#g' \
358 -e "s#'--\([^']*\)--'#<del>\1</del>#g" \
359 -e "s#'__\([^']*\)__'#<u>\1</u>#g" \
360 -e "s#'''''\([^']*\)'''''#<strong><em>\1</em></strong>#g" \
361 -e "s#'''\([^']*\)'''#<strong>\1</strong>#g" \
362 -e "s#''\([^']*\)''#<em>\1</em>#g"
363 $CONTENT
364 EOT
365 )"
366 while read link; do
367 [ -s $PAGES_DIR$link.txt ] && continue
368 CONTENT="$(sed "s|\\?page=$link\"|& class=\"pending\"|" <<EOT
369 $CONTENT
370 EOT
371 )"
372 done <<EOT
373 $(grep "$urlbase?page=" <<EOM | sed -e 's/^.*\?page=\([^"]*\).*$/\1/' -e 's/&.*//'
374 $CONTENT
375 EOM
376 )
377 EOT
378 while echo "$CONTENT" | grep -q '^ ' ; do
379 CONTENT="$(sed 's/^\( *\) \([^ ]\)/\1\&nbsp;\&nbsp;\&nbsp;\&nbsp;\2/' <<EOT
380 $CONTENT
381 EOT
382 )"
383 done
384 read hastoc <<EOT
385 $CONTENT
386 EOT
387 CONTENT="$(sed -e 's/^ /\&nbsp;\&nbsp;\&nbsp;\&nbsp;/' -e '1s/^TOC//' <<EOT
388 $CONTENT
389 EOT
390 )"
391 toc='<div id="toc">'
392 i=1
393 for pat in '^![^!]' '^!![^!]' '^!!![^!]' '^!!!![^!]' '^!!!!!' ; do
394 while read line; do
395 [ -n "$line" ] || continue
396 label="$(echo $line | sed 's/[^\dA-Za-z]/_/g')"
397 toc="$(cat <<EOT
398 $toc
399 <h$i><a href="#$label">$line</a></h$i>
400 EOT
401 )"
402 CONTENT="$(sed "s#^!!* *$line\$#<h$i><a name=\"$label\">$line</a></h$i>#" <<EOT
403 $CONTENT
404 EOT
405 )"
406 done <<EOT
407 $(grep "$pat" <<EOM | sed -e 's/^!!*//' -e 's/#/\#/g' -e 's/&/\\\&/g'
408 $CONTENT
409 EOM
410 )
411 EOT
412 i=$(( $i + 1 ))
413 done
414 toc="$(cat <<EOT
415 $toc
416 </div>
417 EOT
418 )"
419 case "$hastoc" in
420 TOC*) ;;
421 *) toc='';;
422 esac
423 CONTENT="$(awk -v tmpdir=$tmpdir '{
424 s=$0
425 while (1) {
426 if (match(s,/\{\{CODE[0-9]+\}\}/)) {
427 printf "%s" substr(s,1,RSTART-1)
428 system("cat " tmpdir "/" substr(s,RSTART+2,RLENGTH-4))
429 s=substr(s,RSTART+RLENGTH)
430 }
431 else {
432 print s
433 break
434 }
435 }
436 }' <<EOT
437 $CONTENT
438 EOT
439 )"
440 rm -rf $tmpdir
441 plugin_call_method formatEnd
442 fi
443 fi
445 # Remplacement dans le template
446 RECENT="<a href=\"$urlbase?action=recent\" accesskey=\"3\">$RECENT_CHANGES</a>"
447 [ "$action" == "recent" ] && RECENT=$RECENT_CHANGES
448 HOME="<a href=\"$urlbase?page=$START_PAGE\" accesskey=\"1\">$HOME_BUTTON</a>"
449 [ "$PAGE_TITLE" == "$START_PAGE" -a "$action" != "search" ] && HOME=$HOME_BUTTON
450 HELP="\1<a href=\"$urlbase?page=$HELP_BUTTON\" accesskey=\"2\" rel=\"nofollow\">$HELP_BUTTON</a>\2"
451 [ "$action" != "edit" ] && HELP=""
453 [ -r "$template" ] || die "'$template' is missing!"
454 html="$(sed -e "s#{\([^}]*\)RECENT_CHANGES\([^}]*\)}#\1$RECENT\2#" \
455 -e "s#{\([^}]*\)HOME\([^}]*\)}#\1$HOME\2#" \
456 -e "s#{\([^}]*\)HELP\([^}]*\)}#$HELP#" \
457 -e "s#{SEARCH}#<form method=\"get\" action=\"$urlbase?page=$(urlencode "$PAGE_TITLE" | sed 's/#/\\#/g')\"><div><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$(htmlentities $(GET query) )\" tabindex=\"1\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" accesskey=\"q\" /></div></form>#" \
458 < $template )"
459 [ "$action" != "" -a "$action" != "edit" -o ! -e "$PAGE_txt" ] && TIME="-"
460 plugin_call_method template
461 [ -n "$(GET error)" ] || ERROR=""
462 [ -n "$HISTORY" ] && HISTORY="\1$HISTORY\2"
463 PAGE_TITLE_str="$(htmlentities "$PAGE_TITLE")"
464 $PAGE_TITLE_link &&
465 PAGE_TITLE_str="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\">$PAGE_TITLE_str</a>"
466 EDIT="$EDIT_BUTTON"
467 if $editable ; then
468 EDIT="$PROTECTED_BUTTON"
469 [ -w "$PAGE_txt" -o ! -e "$PAGE_txt" ] &&
470 EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&amp;action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>"
471 fi
472 [ -n "$toc" ] && toc="\1$toc\2"
473 AUTH_GET=""
474 AUTH_POST=""
475 if authentified; then
476 AUTH_GET="auth=$AUTH\&"
477 AUTH_POST="\n<input type=\"hidden\" name=\"auth\" value=\"$AUTH\" />"
478 fi
480 header "Content-type: text/html"
481 sed -e "s#{ERROR}#$ERROR#" -e "s#{WIKI_TITLE}#$WIKI_TITLE#" \
482 -e "s#{\([^}]*\)HISTORY\([^}]*\)}#$HISTORY#" \
483 -e "s#{PAGE_TITLE}#$PAGE_TITLE_str#" \
484 -e "s#{\([^}]*\)EDIT\([^}]*\)}#\1$EDIT\2#" \
485 -e "s|{\([^}]*\)TOC\([^}]*\)}|$(awk '{ printf "%s\\n" $0 }' <<EOT | \
486 sed -e 's/&/\\\&/g' -e 's/|/\\|/g'
487 $toc
488 EOT
489 )|" \
490 -e "s#{PAGE_TITLE_BRUT}#$(htmlentities "$PAGE_TITLE")#" \
491 -e "s#{LAST_CHANGE}#$LAST_CHANGES :#" \
492 -e "s#{CONTENT}#$(awk '{ printf "%s\\n" $0 }' <<EOT | \
493 sed -e 's/&/\\\&/g' -e 's/#/\\#/g'
494 $CONTENT
495 EOT
496 )#" \
497 -e "s#{LANG}#$LANG#" -e "s#href=\"?#href=\"$urlbase?#g" \
498 -e "s#$urlbase?#&$AUTH_GET#g" -e "s#action=\"$urlbase\">#&$AUTH_POST#g" \
499 -e "s#{WIKI_VERSION}#$WIKI_VERSION#" \
500 -e "s#{TIME}#$TIME#" -e "s#{DATE}#$datew#" \
501 -e "s#{IP}#$REMOTE_ADDR#" -e "s#{COOKIE}##" <<EOT
502 $html
503 EOT