]> git.plutz.net Git - shellwiki/commitdiff
page selector layout
authorPaul Hänsch <paul@plutz.net>
Wed, 11 May 2022 18:40:57 +0000 (20:40 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 11 May 2022 18:40:57 +0000 (20:40 +0200)
attachment.sh
index.cgi
page_edit.sh
themes/default.sh

index 3b6e6c565aed8b3171895c8115dc65e65e4d7209..b88e4f47ceb4216df91745d4f646a5044112177b 100755 (executable)
@@ -78,7 +78,7 @@ if [ "${PATH_INFO%/\[attachment\]/}"  != "${PATH_INFO}" ]; then
       rm -- "$multipart_cachefile"
       printf 'Refresh: %i\r\n' 4
       theme_403
-      exit 0
+      return 0
     fi
 
     mkdir -p "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/"
@@ -93,16 +93,20 @@ if [ "${PATH_INFO%/\[attachment\]/}"  != "${PATH_INFO}" ]; then
     printf 'Refresh: %i\r\n' 4
     theme_403
     head -c $((CONTENT_LENGTH)) >/dev/null
+    return 0
   elif [ "$attachment_delete" -a "$SESSION_ID" = "$tsid" ]; then
     rm -- "$_DATA/pages/${PATH_INFO%/\[attachment\]/}/#attachments/$attachment_delete"
     REDIRECT "${_BASE}${PATH_INFO}"
   elif [ "$attachment_delete" ]; then
     printf 'Refresh: %i\r\n' 4
     theme_403
+    return 0
   elif acl_read "${PATH_INFO%\[attachment\]/}"; then
     theme_attachments "${PATH_INFO%\[attachment\]/}"
+    return 0
   else
     theme_404
+    return 0
   fi
 
 elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
@@ -110,12 +114,16 @@ elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
 
   if ! acl_read "${PATH_INFO%/\[attachment\]/*}"; then
     theme_403
+    return 0
   elif [ -f "$_DATA/pages/$attpath" ]; then
     FILE "$_DATA/pages/$attpath"
+    return 0
   elif [ -f "$_EXEC/pages/$attpath" ]; then
     FILE "$_EXEC/pages/$attpath"
+    return 0
   else
     theme_404
+    return 0
   fi
 #  exit 0;
   
@@ -124,13 +132,19 @@ elif [ "${PATH_INFO%/}" = "${PATH_INFO}" ]; then
 
   if ! acl_read "${PATH_INFO%/*}/"; then
     theme_403
+    return 0
   elif [ -f "$_DATA/pages/$attpath" ]; then
     FILE "$(attachment_convert "$_DATA/pages/$attpath")"
+    return 0
   elif [ -f "$_EXEC/pages/$attpath" ]; then
     FILE "$(attachment_convert "$_EXEC/pages/$attpath")"
+    return 0
   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
+    return 0
   fi
 fi
+
+return 1
index 465a98994140c6b1919090333297ca10e0320eca..bb9a914ca834ffaa9d9e2864ed7ca863ca71933a 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -74,20 +74,26 @@ case "${PATH_INFO}" in
   /"[.]"/*)
     FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
     ;;
+  */"#"*/*)
+    export ERROR_MSG="This page name is not allowed"
+    theme_400
+    ;;
   /|*[^]]/)
     theme_page "${PATH_INFO}"
     ;;
   */"[login]")
-    theme_login
+    theme_page "/[wiki]/login/"
     ;;
   */"[register]")
-    theme_register
+    theme_page "/[wiki]/register/"
     ;;
-  */"#"*)
-    :  # TODO: Invalid page name
+  */"[invite]")
+    theme_page "/[wiki]/invite/"
     ;;
   *)
-  . "$_EXEC/page_edit.sh"
-  . "$_EXEC/attachment.sh"
+    . "$_EXEC/page_edit.sh" \
+    || . "$_EXEC/attachment.sh" \
+    || theme_404
+    ;;
 esac
 
index ca70c676c505df342ad4c989dd1fc79524309c89..e029c8fb3061560c7c1b03544bc2b2e33e67a3c0 100755 (executable)
@@ -42,14 +42,19 @@ elif [ "$edit_action" = cancel ]; then
 
 elif ! acl_write "$edit_page"; then
   theme_403
+  return 0
 
 elif mkdir -p -- "${edit_file%/#page.md}" \
      && S_LOCK "$edit_file"; then
   theme_editor "$edit_page"
+  return 0
 
 else
   printf 'Refresh: %i; url=%s\r\n' 4 ../
   export ERROR_MSG="Unable to lock page for editing"
   theme_409
+  return 0
 
 fi
+
+return 1
index 36710dbd44e8194f6fd6fad0dba0dfc60e4ef4f9..8a73756030730af1e4cf7208fc4209d59a0eb21b 100755 (executable)
@@ -60,10 +60,7 @@ theme_editor(){
   local page="$1" title
   title="${page%/}"; title="${title##*/}"
 
-  if [ ! "$(mdfile "$page")" ]; then
-    theme_404
-    return 0
-  elif ! acl_write "$page"; then
+  if ! acl_write "$page"; then
     theme_403
     return 0
   fi
@@ -165,50 +162,26 @@ theme_attachments(){
   fi
 }
 
-theme_login(){
-  theme_page '/[wiki]/login/'
-}
-
-theme_register(){
-  theme_page '/[wiki]/register/'
-}
-
-theme_403(){
-  printf "%s\r\n" "Status: 403 Forbidden"
-
-  if [ "$(mdfile '/[wiki]/403/')" ]; then
-    theme_page '/[wiki]/403/'
-  else
-    printf "Content-Length: 0\r\n\r\n"
-  fi
-}
+theme_error(){
+  local errno="$1"
 
-theme_404(){
-  printf "%s\r\n" "Status: 404 Not Found"
+  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
 
-  if [ "$(mdfile '/[wiki]/404/')" ]; then
-    theme_page '/[wiki]/404/'
+  if [ "$(mdfile "/[wiki]/$errno/")" ]; then
+    theme_page "/[wiki]/$errno/"
   else
     printf "Content-Length: 0\r\n\r\n"
   fi
 }
 
-theme_409(){
-  printf "%s\r\n" "Status: 409 Conflict"
-
-  if [ "$(mdfile '/[wiki]/409/')" ]; then
-    theme_page '/[wiki]/409/'
-  else
-    printf "Content-Length: 0\r\n\r\n"
-  fi
-}
-
-theme_500(){
-  printf "%s\r\n" "Status: 500 Internal Server Error"
-
-  if [ "$(mdfile '/[wiki]/500/')" ]; then
-    theme_page '/[wiki]/500/'
-  else
-    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; }