#!/bin/sh # Copyright 2022 - 2023 Paul Hänsch # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. export REV_PAGES=${REV_PAGES:-true} export REV_ATTACHMENTS=${REV_ATTACHMENTS:-false} export WIKI_THEME="${WIKI_THEME:-default}" export SEARCH_INDEX="${SEARCH_INDEX:-true}" export USER_AUTH="${USER_AUTH:-default}" . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh" . "${_EXEC}/cgilite/session.sh" . "${_EXEC}/auth/${USER_AUTH}.sh" . "${_EXEC}/tools.sh" . "${_EXEC}/acl.sh" . "${_EXEC}/themes/${WIKI_THEME}.sh" which git >/dev/null || REV_PAGES=false [ "$REV_PAGES" != true ] && REV_ATTACHMENTS=false # Renew session cookie, only if cookie already set [ "$(COOKIE session)" ] && SESSION_COOKIE wiki_text() { # Print source text of a wiki page # Get page from data or underlay dir local page="$(PATH "$1")" mdfile mdfile="$(mdfile "$page")" || return 4 acl_read "$page" || return 3 cat -- "$mdfile" } if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then cat >"$_DATA/.gitignore" <<-EOF users.db serverkey tags/ index/ **/#cache/ **/#page.md.lock **/#page.*.cache **/#page.*.cache.* **/#page:*.*.cache **/#page:*.*.cache.* **/#index.flag EOF [ "$REV_ATTACHMENTS" != true ] \ && printf '**/#attachments/\n' >>"$_DATA/.gitignore" git init "$_DATA" git -C "$_DATA" add .gitignore printf '%s\n' "" "[user]" \ "email = \"shellwiki@localhost\"" \ "name = \"Shellwiki\"" \ >>"$_DATA/.git/config" 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