3 # Copyright 2022 - 2023 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . "$_EXEC/session_lock.sh"
24 if [ "$(POST action)" != newpage ]; then
25 printf 'Refresh: %i; url=%s\r\n' 4 ./
26 export ERROR_MSG="Formdata invalid"
31 pattern="$(POST pattern)"
32 template="$(POST template)"
36 # either a page name has been entered
37 pattern="$(date +"$pattern")"
38 page="$(printf -- "$pattern" "$page")"
40 elif [ "${pattern%%"%%s"*}" = "${pattern}" ]; then
41 # or a page name is not part of the pattern
42 pattern="$(date +"$pattern")"
46 printf 'Refresh: %i; url=%s\r\n' 4 ./
47 export ERROR_MSG="Page name required"
52 page="$(page_abs "$page")"
54 && template="$(page_abs "$template")" \
57 if [ -f "$_DATA/pages/$page/#page.md" -o \
58 -f "$_EXEC/pages/$page/#page.md" ]; then
59 printf 'Refresh: %i; url=%s\r\n' 4 ./
60 export ERROR_MSG="Page exists already"
64 elif ! acl_write "$page"; then
65 printf 'Refresh: %i; url=%s\r\n' 4 ./
66 export ERROR_MSG="You don't have permission to write to this page"
70 elif mkdir -p -- "$_DATA/pages/${page}" \
71 && S_LOCK "$_DATA/pages/$page/#page.md"; then
72 theme_editor "$page" "$template"
76 printf 'Refresh: %i; url=%s\r\n' 4 ./
77 export ERROR_MSG="Unable to lock page for editing"