From 07454834f9d0291be5e652eef5f62c889331d695 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 28 Apr 2021 12:57:03 +0200 Subject: [PATCH] allow running from sub directory of base location --- cards/edit_card.sh | 6 +++--- cards/filter_card.sh | 8 ++++---- cards/index.cgi | 4 ++-- cards/list.sh | 10 +++++----- cards/new_card.sh | 4 ++-- cards/update_card.sh | 14 +++++++------- cards/widgets.sh | 4 ++-- categories/edit_categories.sh | 2 +- categories/update_categories.sh | 2 +- courses/edit_course.sh | 6 +++--- courses/export_pdf.sh | 8 ++++---- courses/index.cgi | 4 ++-- courses/list.sh | 12 ++++++------ courses/new_course.sh | 4 ++-- courses/update_course.sh | 18 +++++++++--------- index.cgi | 19 +++++++++++-------- style.css | 4 ++-- 17 files changed, 66 insertions(+), 63 deletions(-) diff --git a/cards/edit_card.sh b/cards/edit_card.sh index 4239cc5..897bcc2 100755 --- a/cards/edit_card.sh +++ b/cards/edit_card.sh @@ -26,11 +26,11 @@ filter="$(REF f)" order="$(REF o)" if tempfile="$(SLOCK "$cardfile" "$locktimeout")"; then - REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}&e=${card}" elif [ -f "$tempfile" ]; then SET_COOKIE session message="SESSLOCK" - REDIRECT "/cards/?o=${order}&f=${filter}#${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}#${card}" else SET_COOKIE session message="EDITLOCK" - REDIRECT "/cards/?o=${order}&f=${filter}#${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}#${card}" fi diff --git a/cards/filter_card.sh b/cards/filter_card.sh index aacacbb..504fb08 100755 --- a/cards/filter_card.sh +++ b/cards/filter_card.sh @@ -44,15 +44,15 @@ filter="$( case $(POST choice) in filter) - REDIRECT "/cards/?o=$(POST order)&f=${filter}" + REDIRECT "${_BASE}/cards/?o=$(POST order)&f=${filter}" ;; new_filter) - REDIRECT "/cards/?o=$(POST order)&f=${filter}&newfilter=yes" + REDIRECT "${_BASE}/cards/?o=$(POST order)&f=${filter}&newfilter=yes" ;; export_csv) - REDIRECT "/cards/export_csv.sh?o=$(POST order)&f=${filter}" + REDIRECT "${_BASE}/cards/export_csv.sh?o=$(POST order)&f=${filter}" ;; *) - REDIRECT '/cards/' + REDIRECT "${_BASE}/cards/" ;; esac diff --git a/cards/index.cgi b/cards/index.cgi index 934c19a..2c9f267 100755 --- a/cards/index.cgi +++ b/cards/index.cgi @@ -16,10 +16,10 @@ edit="${edit##*/}" { w_filter_diag printf ' - [form class="newcard" action="/cards/new_card.sh" method="POST" + [form class="newcard" action="%s/cards/new_card.sh" method="POST" [button type="submit" %s] [input name="seed" placeholder="%s"] - ]' "$(l10n newcard)" "$(l10n vcf_seed_label)" + ]' "${_BASE}" "$(l10n newcard)" "$(l10n vcf_seed_label)" [ "$edit" ] && edit_card "$edit" list_cards } | yield_page cards #/cards/cards.css diff --git a/cards/list.sh b/cards/list.sh index 0ed8af4..2f2e767 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -13,7 +13,7 @@ edit_card(){ else card="$(pdi_load "$tempfile")" cat <<-EOF - [form .card #${cardfile##*/} action="/cards/update_card.sh" method="POST" + [form .card #${cardfile##*/} action="${_BASE}/cards/update_card.sh" method="POST" [input type="hidden" name="tid" value="$(transid ${tempfile})"] [div .section .basic $( edit_item "$card" N GENDER @@ -94,15 +94,15 @@ print_card(){ [div .section .note . $(card_item "$card" NOTE)] [div .section .attendance [h3 $(l10n course_attendance) ] [ul $(grep -F " ${cardfile##*/}" "$_DATA/mappings/attendance" |while read each discard; do - printf '[li [a .item .attendance href="/courses#%s" . %s]]' \ - "$each" \ + printf '[li [a .item .attendance href="%s/courses#%s" . %s]]' \ + "${_BASE}" "$each" \ "$(pdi_value "$(pdi_load "$_DATA/ical/$each")" SUMMARY || l10n "(unnamed course)" |unescape |HTML)" done |sort -k7)] $(card_item "$card" CATEGORIES) ] [div .control - [a .button .item href="/cards/edit_card.sh?card=${cardfile##*/}" $(l10n edit)] - [a .button .item href="/cards/export_card.sh?card=${cardfile##*/}" $(l10n vcf_export)] + [a .button .item href="${_BASE}/cards/edit_card.sh?card=${cardfile##*/}" $(l10n edit)] + [a .button .item href="${_BASE}/cards/export_card.sh?card=${cardfile##*/}" $(l10n vcf_export)] ] ] EOF diff --git a/cards/new_card.sh b/cards/new_card.sh index 424f242..69f89c6 100755 --- a/cards/new_card.sh +++ b/cards/new_card.sh @@ -68,8 +68,8 @@ if mkdir "$lockdir"; then UID:${uid} END:VCARD EOF - REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}&e=${card}" else SET_COOKIE session message="EDITLOCK" - REDIRECT "/cards/?o=${order}&f=${filter}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}" fi diff --git a/cards/update_card.sh b/cards/update_card.sh index d942e9a..2b87632 100755 --- a/cards/update_card.sh +++ b/cards/update_card.sh @@ -42,11 +42,11 @@ fi if ! tempfile=$(CHECK_SLOCK "$cardfile"); then SET_COOKIE 0 message="NO VALID FILE LOCK" - REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}&e=${card}" exit 0 elif [ "$(POST tid)" != "$(transid "$tempfile")" ]; then SET_COOKIE 0 message="INVALID TRANSACTION ID" - REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}&e=${card}" exit 0 fi @@ -105,7 +105,7 @@ printf '%s' "$vcf" |grep -vx '' >"$tempfile" case "$action" in addfield) - REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}&e=${card}" ;; update) if LOCK "$attfile"; then @@ -126,13 +126,13 @@ case "$action" in cp "$tempfile" "$cardfile" RELEASE_SLOCK "$cardfile" - REDIRECT "/cards/?o=${order}&f=${filter}#${card}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}#${card}" ;; cancel) RELEASE_SLOCK "$cardfile" [ -f "$cardfile" ] \ - && REDIRECT "/cards/?o=${order}&f=${filter}#${card}" \ - || REDIRECT "/cards/?o=${order}&f=${filter}" + && REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}#${card}" \ + || REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}" ;; delete) rm "$cardfile" @@ -146,6 +146,6 @@ case "$action" in else SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS" fi - REDIRECT "/cards/?o=${order}&f=${filter}" + REDIRECT "${_BASE}/cards/?o=${order}&f=${filter}" ;; esac diff --git a/cards/widgets.sh b/cards/widgets.sh index 09956a7..eb9d0fd 100755 --- a/cards/widgets.sh +++ b/cards/widgets.sh @@ -51,7 +51,7 @@ cat </dev/null -REDIRECT "$(URL "/export/${pdffile##*/}")" +REDIRECT "$(URL "${_BASE}/export/${pdffile##*/}")" diff --git a/courses/index.cgi b/courses/index.cgi index 7ff426f..f860247 100755 --- a/courses/index.cgi +++ b/courses/index.cgi @@ -15,9 +15,9 @@ edit="${edit##*/}" { w_sort_courses printf ' - [form .newcourses action="/courses/new_course.sh" method="POST" + [form .newcourses action="%s/courses/new_course.sh" method="POST" [button type="submit" %s] - ]' "$(l10n newcourse)" + ]' "${_BASE}" "$(l10n newcourse)" [ "$edit" ] && edit_course "$edit" printf '[div .courselist\n' diff --git a/courses/list.sh b/courses/list.sh index 97356db..cc0deae 100755 --- a/courses/list.sh +++ b/courses/list.sh @@ -15,7 +15,7 @@ edit_course(){ else course="$(pdi_load "$tempfile")" cat <<-EOF - [form .course #${coursefile##*/} action="/courses/update_course.sh" method="POST" + [form .course #${coursefile##*/} action="${_BASE}/courses/update_course.sh" method="POST" [input type="hidden" name="course" value="${coursefile##*/}"] [input type="hidden" name="tid" value="$(transid ${tempfile})"] [div .section .basic . $( @@ -60,15 +60,15 @@ print_course(){ [div .section .COMMENT . $(cal_item "$course" COMMENT)] [div .section .attendance [h3 $(l10n course_attendance) ] [ul . $(grep -F "${coursefile##*/} " "$_DATA/mappings/attendance" |while read discard each; do - printf '[li [a .item .attendance href="/cards/#%s" . %s]]\n' \ - "$each" \ + printf '[li [a .item .attendance href="%s/cards/#%s" . %s]]\n' \ + "${_BASE}" "$each" \ "$(pdi_value "$(pdi_load "$_DATA/vcard/$each")" FN |unescape |HTML)" done |sort -k7)] ] [div .control - [a .button .item href="/courses/edit_course.sh?course=${coursefile##*/}" $(l10n edit)] - [a .button .item href="/courses/export_pdf.sh?course=${coursefile##*/}" target="blank" $(l10n courselist)] - [a .button .item href="/courses/export_ical.sh?course=${coursefile##*/}" $(l10n ics_export)] + [a .button .item href="${_BASE}/courses/edit_course.sh?course=${coursefile##*/}" $(l10n edit)] + [a .button .item href="${_BASE}/courses/export_pdf.sh?course=${coursefile##*/}" target="blank" $(l10n courselist)] + [a .button .item href="${_BASE}/courses/export_ical.sh?course=${coursefile##*/}" $(l10n ics_export)] [a .button .item href="mailto:zack@vuesch.org?bcc=$(course_mail "${coursefile##*/}" |HTML)" $(l10n course_mail)] ] ] diff --git a/courses/new_course.sh b/courses/new_course.sh index 362752d..36de913 100755 --- a/courses/new_course.sh +++ b/courses/new_course.sh @@ -44,8 +44,8 @@ if tempfile="$(SLOCK "$coursefile")"; then END:VEVENT END:VCARD EOF - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" else SET_COOKIE session message="EDITLOCK" - REDIRECT "/courses/" + REDIRECT "${_BASE}/courses/" fi diff --git a/courses/update_course.sh b/courses/update_course.sh index 4abdbe7..aa9632c 100755 --- a/courses/update_course.sh +++ b/courses/update_course.sh @@ -29,11 +29,11 @@ attfile="$_DATA/mappings/attendance" if ! tempfile="$(CHECK_SLOCK "$coursefile")"; then SET_COOKIE 0 message="NO VALID FILE LOCK" - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" exit 0 elif [ "$(POST tid)" != "$(transid "$tempfile")" ]; then SET_COOKIE 0 message="INVALID TRANSACTION ID" - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" exit 0 fi @@ -105,13 +105,13 @@ case "$(POST action)" in newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')" ics="$(pdi_update_value "$ics" "$newfield" $(( $(pdi_count "$ics" "$newfield") + 1 )) '')" printf '%s' "$ics" |grep -vx '' >"$tempfile" - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" ;; addfield\ [A-Z]*) newfield="$(POST action |sed -nE '1s;^addfield ([A-Z][A-Z0-9-]*)$;\1;p')" ics="$(pdi_update_value "$ics" "$newfield" $(( $(pdi_count "$ics" "$newfield") + 1 )) '')" printf '%s' "$ics" |grep -vx '' >"$tempfile" - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" ;; update) if LOCK "$attfile"; then @@ -133,21 +133,21 @@ case "$(POST action)" in printf '%s' "$ics" |grep -vx '' >"${tempfile}.cp" mv "${tempfile}.cp" "$coursefile" RELEASE_SLOCK "$coursefile" - REDIRECT "/courses/#${course}" + REDIRECT "${_BASE}/courses/#${course}" ;; cancel) RELEASE_SLOCK "$coursefile" [ -f "$coursefile" ] \ - && REDIRECT "/courses/#${course}" \ - || REDIRECT "/courses/" + && REDIRECT "${_BASE}/courses/#${course}" \ + || REDIRECT "${_BASE}/courses/" ;; delete) rm "$coursefile" RELEASE_SLOCK "$coursefile" - REDIRECT "/courses/" + REDIRECT "${_BASE}/courses/" ;; *) printf '%s' "$ics" |grep -vx '' >"$tempfile" - REDIRECT "/courses/?e=${course}" + REDIRECT "${_BASE}/courses/?e=${course}" ;; esac diff --git a/index.cgi b/index.cgi index 1c4e717..276965f 100755 --- a/index.cgi +++ b/index.cgi @@ -3,11 +3,13 @@ for n in "$@"; do case ${n%%=*} in data) _DATA="${n#data=}";; exec) _EXEC="${n#exec=}";; + base) _BASE="${n#base=}";; debug) DEBUG="${n#debug=}";; esac; done [ ! "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}" -[ ! "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}" +[ ! "${_DATA%/}" ] && _DATA="${PWD%/}" || _DATA="${_DATA%/}" +_BASE="${_BASE%/}" [ "$DEBUG" ] && exec 2>>"$DEBUG" mkdir -p "${_DATA}/cache" "${_DATA}/mappings" "${_DATA}/export" "${_DATA}/lock" "${_DATA}/ical" "${_DATA}/vcard" @@ -29,6 +31,7 @@ debug() { . "$_EXEC/l10n.sh" _PATH="$(PATH "/${PATH_INFO}")" +_PATH="${_PATH#${_BASE}}" ACTION="$(GET a)" message="$(COOKIE message)" @@ -52,16 +55,16 @@ yield_page() { [html [head [title Confetti] [meta name="viewport" content="width=device-width"] - [link rel="stylesheet" type="text/css" href="/cgilite/common.css"] - [link rel="stylesheet" type="text/css" href="/style.css"] - ' + [link rel="stylesheet" type="text/css" href="%s/cgilite/common.css"] + [link rel="stylesheet" type="text/css" href="%s/style.css"] + ' "${_BASE}" "${_BASE}" [ -n "$style" ] && printf ' [link rel="stylesheet" type="text/css" href="%s"] ' "$style" printf ' ] [body #top class="%s" ' "$class" - printf '[ul .menu [li [a "/cards/" . %s]][li [a "/courses/" . %s]]]' "$(l10n cards)" "$(l10n courses)" + printf '[ul .menu [li [a "%s/cards/" . %s]][li [a "%s/courses/" . %s]]]' "${_BASE}" "$(l10n cards)" "${_BASE}" "$(l10n courses)" [ "$message" ] && printf '[p #message\n%s\n]' "$(l10n "$message")" cat printf '] ]' @@ -73,12 +76,12 @@ topdir="${_PATH#/}" topdir="/${topdir%%/*}" case ${_PATH} in - /) REDIRECT /cards/ + "/") REDIRECT "${_BASE}/cards/" ;; - /export/*.pdf) . "$_EXEC/cgilite/file.sh" + "/export"/*.pdf) . "$_EXEC/cgilite/file.sh" FILE "${_DATA}/${_PATH}" "application/pdf" ;; - /export/*) . "$_EXEC/cgilite/file.sh" + "/export"/*) . "$_EXEC/cgilite/file.sh" FILE "${_DATA}/${_PATH}" ;; *) diff --git a/style.css b/style.css index 04b1336..298ae3d 100644 --- a/style.css +++ b/style.css @@ -25,8 +25,8 @@ body > .menu a { padding: .5em 3em; box-shadow: inset 0 0 .5em #000; } -body.cards > .menu a[href="/cards/"], -body.courses > .menu a[href="/courses/"] { +body.cards > .menu a[href$="/cards/"], +body.courses > .menu a[href$="/courses/"] { color: #000; background-color: #FFF; box-shadow: none; -- 2.39.2