X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=handlers%2F10_page.sh;h=f8cbbafaae166c9f141af7d548c18f3a5cba47b5;hb=4bb6a2be511e608fa87fbb7b54d8ed275b844b30;hp=e010ab12c4e7bc7d797c3a9fe81c706d664a2f74;hpb=b86e88d2d6acd3eda7d9858539818a290db67d41;p=shellwiki diff --git a/handlers/10_page.sh b/handlers/10_page.sh index e010ab1..f8cbbaf 100755 --- a/handlers/10_page.sh +++ b/handlers/10_page.sh @@ -1,19 +1,11 @@ #!/bin/sh -CACHE_AGE=${CACHE_AGE:-1800} +. "$_EXEC/cgilite/file.sh" +. "$_EXEC/css.sh" + +CACHE_AGE=${CACHE_AGE:-300} export MD_MACROS="$_EXEC/macros" export MD_HTML="${MD_HTML:-false}" -export WIKI_THEME=${WIKI_THEME:-default} - -. "$_EXEC/themes/${WIKI_THEME}.sh" - -if [ "$(which awk)" ]; then - md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; } -elif [ "$(which busybox)" ]; then - md() { busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; } -else - md() { cat; } -fi wiki() { # Print content of a wiki page @@ -34,8 +26,8 @@ wiki() { mkdir -p -- "$_DATA/pages/$page/" # Macros expect to find page directory as working dir ( cd -- "$_DATA/pages/$page/"; - sed -E '1,20{ /^%[a-z]+/d; }' "$mdfile" \ - | md |tee -- "${cache}.$$" + md <"$mdfile" \ + | tee -- "${cache}.$$" ) grep -q '^%nocache' "$mdfile" \ && rm -- "${cache}.$$" \ @@ -45,31 +37,34 @@ wiki() { case "${PATH_INFO}" in /"[.]"/*) + # usually some file related to theme + # let file server handle errors FILE "${_EXEC}/${PATH_INFO#/\[.\]}" return 0 ;; - */\[*\]/*/) - return 1 - ;; - */"#"*/*) - export ERROR_MSG="This page name is not allowed" + *${BR}*) + export ERROR_MSG='Page names containing newline character are not allowed' theme_error 400 return 0 ;; - */"[login]") - theme_page "/[wiki]/login/" - return 0 - ;; - */"[register]") - theme_page "/[wiki]/register/" + */\#*) + export ERROR_MSG='Page names starting with "#" are not allowed' + theme_error 400 return 0 ;; - */"[invite]") - theme_page "/[wiki]/invite/" - return 0 + */\[*\]/*|*/\[*\]) + # looks like some kind of handler + return 1 ;; */) - theme_page "${PATH_INFO}" + if [ ! "$(mdfile "$PATH_INFO")" ]; then + theme_error 404 + elif ! acl_read "$PATH_INFO"; then + theme_error 403 + else + PAGE_CSS="$(css "${PATH_INFO}")" + theme_page "${PATH_INFO}" + fi return 0 ;; esac