]> git.plutz.net Git - lobster/blobdiff - index.cgi
Merge commit 'a27498203e5d589514f082a0fcdcca53e31c595e' into cgilite
[lobster] / index.cgi
index 0cfa8a312eeba1030ad327588297d2bf27322e0f..841917dad69a72b7e6b2328d611003782fe7fb75 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -3,27 +3,24 @@
 for n in "$@"; do case ${n%%=*} in
   data) _DATA="${n#data=}";;
   exec) _EXEC="${n#exec=}";;
-  noerr) exec 2>&-;;
+  base) _BASE="${n#base=}";;
+  debug) DEBUG="${n#debug=}";;
 esac; done
 
-[ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
-[ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
+[ ! "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
+[ ! "${_DATA%/}" ] && _DATA="${PWD%/}" || _DATA="${_DATA%/}"
+_BASE="${_BASE%/}"
+[ "$DEBUG" ] && exec 2>>"$DEBUG"
 
-debug() {
-  local dbg=/dev/stderr
-  if [ ! "$DEBUG" ]; then
-    [ "$#" -gt 0 ] && : || cat;
-  elif [ "$#" -gt 0 ]; then
-    printf '%s\n' "$@" >>"$dbg"
-  else
-    tee -a "$dbg"
-  fi
-}
+mkdir -p "${_DATA}/cache" "${_DATA}/mappings" "${_DATA}/export" "${_DATA}/lock" "${_DATA}/ical" "${_DATA}/vcard" "${_DATA}/therapies"
 
 . "$_EXEC/cgilite/cgilite.sh"
 . "$_EXEC/cgilite/session.sh"
 
+. "$_EXEC/l10n.sh"
+
 _PATH="$(PATH "/${PATH_INFO}")"
+_PATH="${_PATH#${_BASE}}"
 ACTION="$(GET a)"
 
 message="$(COOKIE message)"
@@ -45,18 +42,19 @@ yield_page() {
   printf 'Content-Type: text/html; charset=utf-8\r\n\r\n'
   { printf '
        [html [head
-          [title Confetti]
+         [title Lobster]
          [meta name="viewport" content="width=device-width"]
-         [link rel="stylesheet" type="text/css" href="/style.css"]
-    '
+         [link rel="stylesheet" type="text/css" href="%s/cgilite/common.css"]
+         [link rel="stylesheet" type="text/css" href="%s/style.css"]
+    ' "${_BASE}" "${_BASE}"
     [ -n "$style" ] && printf '
          [link rel="stylesheet" type="text/css" href="%s"]
     ' "$style"
     printf '
        ] [body #top class="%s"
     ' "$class"
-    cat
     [ "$message" ] && printf '[p #message\n%s\n]' "$(l10n "$message")"
+    cat
     printf '] ]'
   } \
   | "${_EXEC}/cgilite/html-sh.sed"
@@ -66,13 +64,7 @@ topdir="${_PATH#/}"
 topdir="/${topdir%%/*}"
 
 case ${_PATH} in
-  /) REDIRECT /cards/
-    ;;
-  /export/*.pdf) . "$_EXEC/cgilite/file.sh"
-    FILE "${_DATA}/${_PATH}" "application/pdf"
-    ;;
-  /export/*) . "$_EXEC/cgilite/file.sh"
-    FILE "${_DATA}/${_PATH}"
+  "/") REDIRECT "${_BASE}/cards/"
     ;;
   *)
     if   [ -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/index.cgi" ]; then