X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=acl.sh;h=93cbf6471007428d68ae96ba7f443930ef278527;hb=e9bb2b8721a5a47baa5b41ddead1238ea2a23221;hp=d232ea0138d4f5614ef4c61fc7d97548c0e85d4b;hpb=78a94a774fa0f9317b469995a9389551e0501a75;p=shellwiki diff --git a/acl.sh b/acl.sh index d232ea0..93cbf64 100755 --- a/acl.sh +++ b/acl.sh @@ -1,5 +1,22 @@ #!/bin/sh +[ "$include_acl" ] && return 0 +include_acl="$0" + +# Copyright 2022 - 2023 Paul Hänsch +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + # ACL_OVERRIDE="${ACL_OVERRIDE:-Admin:read,write}" ACL_DEFAULT="${ACL_DEFAULT:-Known:read,write${BR}All:read}" @@ -7,25 +24,19 @@ acl_cachepath='' acl_collection='' acl_collect(){ - local path="${1:-${PATH_INFO}}" + local path="$1" # Get directory part of PATH_INFO local path="${path%/*}/./" local pagefile head acl - if [ "$acl_cachepath" = "$path" ]; then - printf '%s\n' "$ACL_OVERRIDE" "$acl_collection" "$ACL_DEFAULT" - return 0 - else - acl_cachepath="$path" - acl_collection='' - fi - printf '%s\n' "$ACL_OVERRIDE" while :; do [ "$path" = / ] && break path="${path%/*/}/" + # Do not use `mdfile` function here because of specialties + # in translation handler (`handlers/10_translations.sh`) if [ -f "$_DATA/pages/$path/#page.md" ]; then pagefile="$_DATA/pages/$path/#page.md" elif [ -f "$_EXEC/pages/$path/#page.md" ]; then @@ -48,7 +59,6 @@ acl_collect(){ ' <"$pagefile")" printf %s\\n "${acl}" - acl_collection="${acl_collection}${acl}${BR}" done printf '%s\n' "$ACL_DEFAULT" @@ -58,6 +68,11 @@ acl_read(){ local page="${1:-${PATH_INFO}}" local acl + if [ "$acl_cachepath" != "$page" ]; then + acl_cachepath="$page" + acl_collection="$(acl_collect "$page")" + fi + while read -r acl; do case ${acl##*:} in read|*,read,*|read,*|*,read) @@ -80,8 +95,8 @@ acl_read(){ "+All:read") return 0;; "-All:read") return 1;; esac - done <<-EOF - $(acl_collect "$page") + done <<-EOF + ${acl_collection} EOF return 1 } @@ -90,6 +105,11 @@ acl_write(){ local page="${1:-${PATH_INFO}}" local acl + if [ "$acl_cachepath" != "$page" ]; then + acl_cachepath="$page" + acl_collection="$(acl_collect "$page")" + fi + while read -r acl; do case ${acl##*:} in write|*,write,*|write,*|*,write) @@ -113,7 +133,7 @@ acl_write(){ "-All:write") return 1;; esac done <<-EOF - $(acl_collect "$page") + ${acl_collection} EOF return 1 }