From: Paul Hänsch Date: Thu, 4 Apr 2019 14:06:44 +0000 (+0200) Subject: modular design X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=e6309da8eba1d1474b98aa2d4723a10747d808b0;p=lobster modular design --- diff --git a/index.cgi b/index.cgi index cf70a45..12f59b2 100755 --- a/index.cgi +++ b/index.cgi @@ -11,21 +11,36 @@ esac; done . "$_EXEC/cgilite/cgilite.sh" -FILTER="$(GET filter)" -ORDER="$(GET o |grep -m1 -axE 'firstname|lastname|bdate' || printf firstname)" -# LISTSIZE="$(COOKIE pagesize |grep -m1 -axE '[1-9][0-9]*' || printf 50)" -ITEM="$(PATH "${PATH_INFO#/}")"; ITEM="${ITEM#/}" +_PATH="$(PATH "/${PATH_INFO}")" ACTION="$(GET a)" -if [ -d "${_EXEC}/${ITEM%%/*}" -a -x "${_EXEC}/${ITEM%%/*}/main.cgi" ]; then - . "${_EXEC}/${ITEM%%/*}/main.cgi" -elif [ "$ITEM" = "style.css" ]; then +yield_page() { + local class="$1" style="$2" + printf 'Content-Type: text/html; charset=utf-8\r\n\r\n' + { printf ' + [html [head + [meta name="viewport" content="width=device-width"] + [link rel="stylesheet" type="text/css" href="/style.css"] + ' + [ -n "$style" ] && printf ' + [link rel="stylesheet" type="text/css" href="%s"] + ' "$style" + printf ' + ] [body class="%s" + ' "$class" + cat + printf '] ]' + } \ + | "${_EXEC}/cgilite/html-sh.sed" +} + +if [ -d "${_EXEC}/${_PATH}" -a -x "${_EXEC}/${_PATH}/main.cgi" ]; then + . "${_EXEC}/${_PATH}/main.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" - [ -r "$_DATA/$ITEM" ] && FILE "$_DATA/$ITEM" \ - || FILE "$_EXEC/style.css" -# elif [ -d "${_EXEC}/${ITEM%%/*}" -a ! -x "${_EXEC}/$ITEM" ]; then -# . "$_EXEC/cgilite/file.sh" -# FILE "${_EXEC}/$ITEM" + FILE "${_EXEC}/${_PATH}" else printf 'Status: 404 Not Found\r\nContent-Length: 0\r\n\r\n' fi