pdf export of course lists
[confetti] / index.cgi
index 5dc55be..0cfa8a3 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -65,17 +65,27 @@ yield_page() {
 topdir="${_PATH#/}"
 topdir="/${topdir%%/*}"
 
-if [ "${_PATH}" = / ]; then
-  REDIRECT /cards/
-elif   [   -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/index.cgi" ]; then
-  . "${_EXEC}/${_PATH}/index.cgi"
-elif [ ! -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
-  . "${_EXEC}/${_PATH}"
-elif [ ! -x "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
-  . "$_EXEC/cgilite/file.sh"
-  FILE "${_EXEC}/${_PATH}"
-elif   [   -d "${_EXEC}/${topdir}" -a -x "${_EXEC}/${topdir}/index.cgi" ]; then
-  . "${_EXEC}/${topdir}/index.cgi"
-else
-  printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n'
-fi
+case ${_PATH} in
+  /) REDIRECT /cards/
+    ;;
+  /export/*.pdf) . "$_EXEC/cgilite/file.sh"
+    FILE "${_DATA}/${_PATH}" "application/pdf"
+    ;;
+  /export/*) . "$_EXEC/cgilite/file.sh"
+    FILE "${_DATA}/${_PATH}"
+    ;;
+  *)
+    if   [ -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/index.cgi" ]; then
+      . "${_EXEC}/${_PATH}/index.cgi"
+    elif [ -f "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}" ]; then
+      . "${_EXEC}/${_PATH}"
+    elif [ -f "${_EXEC}/${_PATH}" -a -r "${_EXEC}/${_PATH}" ]; then
+      . "$_EXEC/cgilite/file.sh"
+      FILE "${_EXEC}/${_PATH}"
+    elif [ -d "${_EXEC}/${topdir}" -a -x "${_EXEC}/${topdir}/index.cgi" ]; then
+      . "${_EXEC}/${topdir}/index.cgi"
+    else
+      printf '%s\r\n' 'Status: 404 Not Found' 'Content-Length: 0' ''
+    fi
+    ;;
+esac