X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=index.cgi;h=db4d749b7c179efde9b4fec43a5158c5e4dd4d21;hb=b0ccec5d3d972350accfc64149bf724c29bf577a;hp=465a98994140c6b1919090333297ca10e0320eca;hpb=dd1dff2be02329bf557a5af4653976b115d88ba2;p=shellwiki diff --git a/index.cgi b/index.cgi index 465a989..db4d749 100755 --- a/index.cgi +++ b/index.cgi @@ -2,35 +2,16 @@ . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh" . "${_EXEC}/cgilite/session.sh" -. "${_EXEC}/cgilite/file.sh" . "${_EXEC}/cgilite/users.sh" +. "${_EXEC}/tools.sh" . "${_EXEC}/acl.sh" -. "${_EXEC}/themes/default.sh" +REV_ATTACHMENTS=${REV_ATTACHMENTS:-false} +WIKI_THEME="${WIKI_THEME:-default}" +. "${_EXEC}/themes/${WIKI_THEME}.sh" -CACHE_AGE=${CACHE_AGE:-1800} -export MD_MACROS="$_EXEC/macros" -export MD_HTML="${MD_HTML:-false}" - -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 - -mdfile(){ - local page="$(PATH "$1")" - - if [ -f "$_DATA/pages/$page/#page.md" ]; then - printf %s\\n "$_DATA/pages/$page/#page.md" - elif [ -f "$_EXEC/pages/$page/#page.md" ]; then - printf %s\\n "$_EXEC/pages/$page/#page.md" - else - return 1 - fi -} +# Renew session cookie, only if cookie already set +[ "$(COOKIE session)" ] && SESSION_COOKIE wiki_text() { # Print source text of a wiki page @@ -42,52 +23,26 @@ wiki_text() { cat -- "$mdfile" } -wiki() { - # Print content of a wiki page - # Get page from data or underlay dir, handle caching - local page="$(PATH "$1")" mdfile cache cachetime - - cache="$_DATA/pages/$page/#page.${USER_ID}.cache" - - mdfile="$(mdfile "$page")" || return 4 - acl_read "$page" || return 3 - - cachetime="$(stat -c %Y -- "$mdfile" "$cache" 2>/dev/null)" - - if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \ - -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then - cat "${cache}" - else - 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}.$$" - ) - grep -q '^%nocache' "$mdfile" \ - && rm -- "${cache}.$$" \ - || mv -- "${cache}.$$" "${cache}" - fi -} - -case "${PATH_INFO}" in - /"[.]"/*) - FILE "${_EXEC}/${PATH_INFO#/\[.\]}" - ;; - /|*[^]]/) - theme_page "${PATH_INFO}" - ;; - */"[login]") - theme_login - ;; - */"[register]") - theme_register - ;; - */"#"*) - : # TODO: Invalid page name - ;; - *) - . "$_EXEC/page_edit.sh" - . "$_EXEC/attachment.sh" -esac - +if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then + cat >"$_DATA/.gitignore" <<-EOF + users.db + serverkey + $([ "$REV_ATTACHMENTS" = true ] || printf %s "**/#attachments/") + **/#cache/ + **/#page.lock + **/#page.*.cache + **/#page.*.cache.* + EOF + git init "$_DATA" + git -C "$_DATA" add .gitignore + git -C "$_DATA" commit -m 'initialization' -- .gitignore +fi 1>&2 + +for handler in "$_EXEC"/handlers/*; do + . "$handler" && break +done + +if [ $? != 0 ]; then + export ERROR_MSG="The presented URL schema cannot be handled" + theme_error 400 +fi