From: Paul Hänsch Date: Wed, 11 May 2022 18:46:41 +0000 (+0200) Subject: generalized error pages X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=e7342f9c967cce37a40d37f84e9e182c6f4e02a5;p=shellwiki generalized error pages --- diff --git a/attachment.sh b/attachment.sh index b88e4f4..0e9757e 100755 --- a/attachment.sh +++ b/attachment.sh @@ -77,7 +77,7 @@ if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then if [ "$USER_NAME" -a "$(multipart session_id)" != "$SESSION_ID" ]; then rm -- "$multipart_cachefile" printf 'Refresh: %i\r\n' 4 - theme_403 + theme_error 403 return 0 fi @@ -91,7 +91,7 @@ if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then REDIRECT "${_BASE}${PATH_INFO}" elif [ "${CONTENT_TYPE%%;*}" = "multipart/form-data" ]; then printf 'Refresh: %i\r\n' 4 - theme_403 + theme_error 403 head -c $((CONTENT_LENGTH)) >/dev/null return 0 elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then @@ -99,13 +99,13 @@ if [ "${PATH_INFO%/\[attachment\]/}" != "${PATH_INFO}" ]; then REDIRECT "${_BASE}${PATH_INFO}" elif [ "$attachment_delete" ]; then printf 'Refresh: %i\r\n' 4 - theme_403 + theme_error 403 return 0 elif acl_read "${PATH_INFO%\[attachment\]/}"; then theme_attachments "${PATH_INFO%\[attachment\]/}" return 0 else - theme_404 + theme_error 404 return 0 fi @@ -113,7 +113,7 @@ elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}" if ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then - theme_403 + theme_error 403 return 0 elif [ -f "$_DATA/pages/$attpath" ]; then FILE "$_DATA/pages/$attpath" @@ -122,7 +122,7 @@ elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then FILE "$_EXEC/pages/$attpath" return 0 else - theme_404 + theme_error 404 return 0 fi # exit 0; @@ -131,7 +131,7 @@ elif [ "${PATH_INFO%/}" = "${PATH_INFO}" ]; then attpath="${PATH_INFO%/*}/#attachments/${PATH_INFO##*/}" if ! acl_read "${PATH_INFO%/*}/"; then - theme_403 + theme_error 403 return 0 elif [ -f "$_DATA/pages/$attpath" ]; then FILE "$(attachment_convert "$_DATA/pages/$attpath")" @@ -142,7 +142,7 @@ elif [ "${PATH_INFO%/}" = "${PATH_INFO}" ]; then elif [ -d "$_DATA/pages/${PATH_INFO}" -o -d "$_EXEC/pages/${PATH_INFO}" ]; then REDIRECT "${_BASE}${PATH_INFO}/" elif [ "${PATH_INFO%\[*\]}" = "${PATH_INFO}" ]; then - theme_404 + theme_error 404 return 0 fi fi diff --git a/index.cgi b/index.cgi index bb9a914..9b9bb5f 100755 --- a/index.cgi +++ b/index.cgi @@ -76,7 +76,7 @@ case "${PATH_INFO}" in ;; */"#"*/*) export ERROR_MSG="This page name is not allowed" - theme_400 + theme_error 400 ;; /|*[^]]/) theme_page "${PATH_INFO}" @@ -93,7 +93,7 @@ case "${PATH_INFO}" in *) . "$_EXEC/page_edit.sh" \ || . "$_EXEC/attachment.sh" \ - || theme_404 + || theme_error 404 ;; esac diff --git a/page_edit.sh b/page_edit.sh index e029c8f..60b1b25 100755 --- a/page_edit.sh +++ b/page_edit.sh @@ -41,7 +41,7 @@ elif [ "$edit_action" = cancel ]; then REDIRECT "${_BASE}${PATH_INFO%\[edit\]}" elif ! acl_write "$edit_page"; then - theme_403 + theme_error 403 return 0 elif mkdir -p -- "${edit_file%/#page.md}" \ @@ -52,7 +52,7 @@ elif mkdir -p -- "${edit_file%/#page.md}" \ else printf 'Refresh: %i; url=%s\r\n' 4 ../ export ERROR_MSG="Unable to lock page for editing" - theme_409 + theme_error 409 return 0 fi diff --git a/themes/default.sh b/themes/default.sh index 8a73756..0d60fb3 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -23,10 +23,10 @@ theme_page(){ title="${page%/}"; title="${title##*/}" if [ ! "$(mdfile "$page")" ]; then - theme_404 + theme_error 404 return 0 elif ! acl_read "$page"; then - theme_403 + theme_error 403 return 0 fi @@ -61,7 +61,7 @@ theme_editor(){ title="${page%/}"; title="${title##*/}" if ! acl_write "$page"; then - theme_403 + theme_error 403 return 0 fi @@ -91,10 +91,10 @@ theme_attachments(){ title="${page%/}"; title="${title##*/}" if [ ! "$(mdfile "$page")" ]; then - theme_404 + theme_error 404 return 0 elif ! acl_read "$page"; then - theme_403 + theme_error 403 return 0 fi @@ -179,9 +179,3 @@ theme_error(){ printf "Content-Length: 0\r\n\r\n" fi } - -theme_400(){ theme_error 400; } -theme_403(){ theme_error 403; } -theme_404(){ theme_error 404; } -theme_409(){ theme_error 409; } -theme_500(){ theme_error 500; }