X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=acl.sh;h=1017c6e7188018dd50d864052785f627670d8bce;hb=19dff502e8d78c56a1a8a09e9b9d27f304839a6e;hp=0ba66631d40c6709e1b59ee2e41f6dfde4167cc0;hpb=1b8f9a660793917c33769e345500814f5b5cdd60;p=shellwiki diff --git a/acl.sh b/acl.sh index 0ba6663..1017c6e 100755 --- a/acl.sh +++ b/acl.sh @@ -10,25 +10,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 @@ -51,7 +45,6 @@ acl_collect(){ ' <"$pagefile")" printf %s\\n "${acl}" - acl_collection="${acl_collection}${acl}${BR}" done printf '%s\n' "$ACL_DEFAULT" @@ -61,6 +54,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) @@ -83,8 +81,8 @@ acl_read(){ "+All:read") return 0;; "-All:read") return 1;; esac - done <<-EOF - $(acl_collect "$page") + done <<-EOF + ${acl_collection} EOF return 1 } @@ -93,6 +91,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) @@ -116,7 +119,7 @@ acl_write(){ "-All:write") return 1;; esac done <<-EOF - $(acl_collect "$page") + ${acl_collection} EOF return 1 }