X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=themes%2Fdefault.sh;h=0d60fb34a4144846925a50dbc54ebd716381e602;hb=38202c7e5f15596fd2cb2a82f0e635cf63495f60;hp=56b57aed24eb505669d742cca13fde2f9660ae3f;hpb=5188614dbad08cce02ab53910d9252b0007f228f;p=shellwiki diff --git a/themes/default.sh b/themes/default.sh index 56b57ae..0d60fb3 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -1,9 +1,12 @@ #!/bin/sh +. "$_EXEC/tools.sh" + theme_head(){ printf ' + ' "$_BASE" } @@ -19,7 +22,15 @@ theme_page(){ local page="$1" title title="${page%/}"; title="${title##*/}" - # Important! Web Server response including newline newline + if [ ! "$(mdfile "$page")" ]; then + theme_error 404 + return 0 + elif ! acl_read "$page"; then + theme_error 403 + return 0 + fi + + # Important! Web Server response including newline printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" cat <<-EOF @@ -29,7 +40,17 @@ theme_page(){ $(HTML "${title}") $(theme_header) -
$(wiki "$page" || printf 'Page not found')
+
+ $(acl_write "$page" && printf %s \ + '' + ) +
+ $(wiki "$page" || printf 'Error while loading page
function "wiki" of index.sh returned with an error.') +
+
$(theme_footer) EOF @@ -39,7 +60,12 @@ theme_editor(){ local page="$1" title title="${page%/}"; title="${title##*/}" - # Important! Web Server response including newline newline + if ! acl_write "$page"; then + theme_error 403 + return 0 + fi + + # Important! Web Server response including newline printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" cat <<-EOF @@ -50,25 +76,106 @@ theme_editor(){ $(theme_header)
- - - + + + +
$(theme_footer) EOF } -theme_login(){ - theme_page '[wiki]/login/' -} +theme_attachments(){ + local page="$1" title + title="${page%/}"; title="${title##*/}" + + if [ ! "$(mdfile "$page")" ]; then + theme_error 404 + return 0 + elif ! acl_read "$page"; then + theme_error 403 + return 0 + fi -theme_register(){ - theme_page '[wiki]/register/' + # Important! Web Server response including newline + printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" + + if acl_write "$page"; then + cat <<-EOF + + + $(theme_head) + Attachments $(HTML "${title}") + + $(theme_header) +
+
+ + + +
+ +
+
+ $(theme_footer) + + EOF + else + cat <<-EOF + + + $(theme_head) + Attachments $(HTML "${title}") + + $(theme_header) +
+ +
+ $(theme_footer) + + EOF + fi } -theme_404(){ - printf "%s\r\n" "Status: 404 Not Found" +theme_error(){ + local errno="$1" + + case $errno in + 400) printf "%s\r\n" "Status: 400 Bad Request";; + 403) printf "%s\r\n" "Status: 403 Forbidden";; + 404) printf "%s\r\n" "Status: 404 Not Found";; + 409) printf "%s\r\n" "Status: 409 Conflict";; + 500) printf "%s\r\n" "Status: 500 Internal Server Error";; + esac - theme_page '[wiki]/404/' + if [ "$(mdfile "/[wiki]/$errno/")" ]; then + theme_page "/[wiki]/$errno/" + else + printf "Content-Length: 0\r\n\r\n" + fi }