# at most 4 segments, 64 bytes per segment, 128 bytes total; no segment starts
# with '.' or '-'; no '.', '..' or empty segment; the name cgi-bin (and the
# other reserved names) is refused; no leading/trailing slash.
docroot_valid(){
localLC_ALL=C s=$1 g seg
[ -z "$s"]&&return0
# Whole-string charset first: `read` below only sees the first line, so a
# newline (config injection) must be refused before the per-segment checks.
[[$s=~ ^[A-Za-z0-9._/-]+$ ]]||return1
[${#s} -le 128]||return1
[[$s != /* &&$s != */ ]]||return1
local -a segs
IFS=/ read -r -a segs <<<"$s"
[${#segs[@]} -le 4]||return1
for seg in "${segs[@]}";do
[ -n "$seg"]||return1
[${#seg} -le 64]||return1
[[$seg=~ ^[A-Za-z0-9._-]+$ ]]||return1
[[$seg != .* &&$seg != -* ]]||return1
g=${seg,,}
case"$g" in .git|.well-known|.whp|.site-builder|.svn|.hg|.bzr|.env|.htaccess|cgi-bin)return1;;esac
done
return0
}
docroot="/home/$user/public_html"
parent_block=''
if[ -n "${DOCROOT_SUBDIR:-}"];then
if ! docroot_valid "$DOCROOT_SUBDIR";then
echo"FATAL: invalid DOCROOT_SUBDIR '$DOCROOT_SUBDIR': use up to 4 folders of ASCII letters, digits, '.', '_' and '-' (e.g. public or web/public); no segment may start with '.' or '-', and '.', '..' and cgi-bin are not allowed." >&2
exit1
fi
docroot="/home/$user/public_html/$DOCROOT_SUBDIR"
# Same shape as WHP's shared-tier render: public_html itself stops being a web
# root (no symlinks followed, public_html/.htaccess never read, nothing served).