local page="$1" title
title="${page%/}"; title="${title##*/}"
+ if [ ! "$(mdfile "$page")" ]; then
+ theme_404
+ return 0
+ elif ! acl_read "$page"; then
+ theme_403
+ return 0
+ fi
+
# Important! Web Server response including newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
- cat <<-EOF
+ if acl_write "$page"; then
+ cat <<-EOF
<!DOCTYPE HTML>
<html><head>
$(theme_head)
<button type=submit name=action value=upload>Upload</button>
</form>
+ <form method=POST><ul class="attachment list">
+ $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
+ [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
+ -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
+ stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
+ size="${stat% *}" date="${stat#* }"
+
+ printf '<li><button type=submit name=delete value="%s">Delete</button><a class=name href="%s">%s</a>
+ <span class=size>%s</span><span class=date>%s</span></li>' \
+ "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
+ "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+ done)
+ </ul></form>
+ </main>
+ $(theme_footer)
+ </body></html>
+ EOF
+ else
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <html><head>
+ $(theme_head)
+ <title>Attachments $(HTML "${title}")</title>
+ </head><body id="$(HTML "$page")[attachment]/">
+ $(theme_header)
+ <main>
<ul class="attachment list">
$(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
[ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
size="${stat% *}" date="${stat#* }"
- printf '<li><span class=name>%s</span>
+ printf '<li><a class=name href="%s">%s</a>
<span class=size>%s</span><span class=date>%s</span></li>' \
- "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+ "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
done)
</ul>
</main>
$(theme_footer)
</body></html>
EOF
+ fi
}
theme_login(){