]> git.plutz.net Git - confetti/commitdiff
allow running from sub directory of base location
authorPaul Hänsch <paul@plutz.net>
Wed, 28 Apr 2021 10:57:03 +0000 (12:57 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 28 Apr 2021 10:57:03 +0000 (12:57 +0200)
17 files changed:
cards/edit_card.sh
cards/filter_card.sh
cards/index.cgi
cards/list.sh
cards/new_card.sh
cards/update_card.sh
cards/widgets.sh
categories/edit_categories.sh
categories/update_categories.sh
courses/edit_course.sh
courses/export_pdf.sh
courses/index.cgi
courses/list.sh
courses/new_course.sh
courses/update_course.sh
index.cgi
style.css

index 4239cc5968c03b5e58d11a96d0e0ae22f68de41f..897bcc28df0109af1bf7a969d5d6506dba464f6f 100755 (executable)
@@ -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
index aacacbb2b42033b4fded4f9da2a807107cdc7402..504fb08e5b78d0cb44c9c092732dfebf77aae1f5 100755 (executable)
@@ -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
index 934c19ac3bf2499b3aee9adf0440188739a6e3f2..2c9f267e1f6e0345164df1c674fac6b36338c724 100755 (executable)
@@ -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
index 0ed8af46297cc72abe6ae1202869e21db1501c3c..2f2e767a9dad082aed283da405e01c1eda6bf8fb 100755 (executable)
@@ -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
index 424f242904f027d46787a0e033cd488662bb71e7..69f89c662f87dfa6fb3a35cc5a3520d0ac446f10 100755 (executable)
@@ -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
index d942e9abdbc527aa5ff803bc8c0b4dd501355778..2b87632aea3208def628e80226996b32e1eb171b 100755 (executable)
@@ -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
index 09956a70559ac8f788b6da14e6f5cea2901addbb..eb9d0fde95cb88f6bba42282e4b7738467f74047 100755 (executable)
@@ -51,7 +51,7 @@ cat <<EOF
                  "$(printf %s "$cat" |grep -qxEe "$2" && printf checked )" \
                  "$(HTML "$cat")"
       done)
-      [a href="/categories/" $(l10n edit_categories)]
+      [a href="${_BASE}/categories/" $(l10n edit_categories)]
     ]
     [fieldset .tab .courses
       $(list_courses | while IFS=/ read course coursename; do
@@ -67,7 +67,7 @@ EOF
 
 w_filter_diag(){
   cat <<EOF
-  [form .filter action="/cards/filter_card.sh" method="POST"
+  [form .filter action="${_BASE}/cards/filter_card.sh" method="POST"
     [h1 $(l10n filter_label)]
     [input type="hidden" name="page" value="cards"]
   
index 7ee6f36edffe91bb9d2c48feff824bccf90ebdb1..2eef152ad851126578dd73a85e0d4be689ae3653 100755 (executable)
@@ -32,4 +32,4 @@ elif [ "$remove" ]; then
   sed -E -i '/^'"${remove}"'$/d' "$catfile"
 fi
 
-REDIRECT "/categories/"
+REDIRECT "${_BASE}/categories/"
index 108c5d55f20859f8ae9fad66e363fd2da49faaa5..a26f93d3818359875df92066edc90ffec3af64d0 100755 (executable)
@@ -38,4 +38,4 @@ for card in "${_DATA}"/vcard/*.vcf; do
   fi
 done
 
-REDIRECT /categories/
+REDIRECT "${_BASE}/categories/"
index 3c0c54fc9dee25db23b6eb5fe0a4d5075865099e..e8ce0c6914e8331690708c62d5bc6e64301a3e9f 100755 (executable)
@@ -24,11 +24,11 @@ course="$(GET course |PATH)"
 coursefile="$_DATA/ical/${course##*/}"
 
 if tempfile="$(SLOCK "$coursefile" "$locktimeout")"; then
-  REDIRECT "/courses/?e=${course}"
+  REDIRECT "${_BASE}/courses/?e=${course}"
 elif [ -f "$tempfile" ]; then
   SET_COOKIE session message="SESSLOCK"
-  REDIRECT "/courses/#${course}"
+  REDIRECT "${_BASE}/courses/#${course}"
 else
   SET_COOKIE session message="EDITLOCK"
-  REDIRECT "/courses/#${course}"
+  REDIRECT "${_BASE}/courses/#${course}"
 fi
index 62bb69e50f6c00e3c36bcdacc2c84f9f86a0e5ed..92e10c5f900626b0805da4224f3b5599bcbec039 100755 (executable)
@@ -7,11 +7,11 @@ coursefile="${_DATA}/ical/$(GET course)"
 
 if [ ! -r "$coursefile" ]; then
   SET_COOKIE 0 message="Cannot read course file"
-  REDIRECT /courses/
+  REDIRECT "${_BASE}/courses/"
   return 0
 elif ! mkdir -p "$_DATA/export"; then
   SET_COOKIE 0 message="Cannot create export directory"
-  REDIRECT /courses/
+  REDIRECT "${_BASE}/courses/"
   return 0
 fi
 
@@ -123,10 +123,10 @@ style_td='style="border: 1pt solid; padding: 1mm 2mm; vertical-align: top;"'
 ]]
 EOF
 
-export            HOME="$_DATA"
+export            HOME="$_DATA/"
 export XDG_CONFIG_HOME="$_DATA/xdg_config"
 export  XDG_CACHE_HOME="$_DATA/xdg_cache"
 export   XDG_DATA_HOME="$_DATA/xdg_local"
 
 lowriter --convert-to pdf --outdir "$_DATA/export/" "$htmlfile" >/dev/null
-REDIRECT "$(URL "/export/${pdffile##*/}")"
+REDIRECT "$(URL "${_BASE}/export/${pdffile##*/}")"
index 7ff426f2d2a80b2bbed50ca1e32ee1f895a542f8..f860247ad02939df4ecba48916916a7906ea8a7b 100755 (executable)
@@ -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'
index 97356db9b6180c0c9e2f6b9f47b75a11eec1e498..cc0deae382f77cd2a22c016c1a5af10c28e40a45 100755 (executable)
@@ -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)]
       ]
     ]
index 362752dbb2a70cdd8deb1ec87cac38c1524374fd..36de913dcf290b93fd802a7e7ba99a9dc31e53d4 100755 (executable)
@@ -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
index 4abdbe7034054523637772ff2ab233f9b7380308..aa9632ce5c20342d4088861663bc2ecfdb6d3f6d 100755 (executable)
@@ -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
index 1c4e7175ddf83f25dae4d7dc84ef7dd125734433..276965f66dcab5ff0846aedf81afe68b4f560a09 100755 (executable)
--- 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}"
     ;;
   *)
index 04b133675f3483ce0967b84ebfe04e1f8e721ba4..298ae3d614903a785fdcb45091ed4bebb91e534f 100644 (file)
--- 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;