From bc1a27bcfb4baef96e53eb30396588b310c6851f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 10 Jan 2021 23:51:05 +0100 Subject: [PATCH] bug fix using tempfile, allow +-Buttons for add field --- courses/update_course.sh | 43 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/courses/update_course.sh b/courses/update_course.sh index 3ddcc73..f2b4e18 100755 --- a/courses/update_course.sh +++ b/courses/update_course.sh @@ -27,14 +27,6 @@ course="$(POST course |PATH)"; course="${course##*/}" coursefile="$_DATA/ical/$course" attfile="$_DATA/mappings/attendance" -action="$(POST action)" -newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')" - -if printf '%s\n' "$action" |grep -qxE 'addfield [A-Z][A-Z0-9]*'; then - newfield="${action##* }" - action=addfield -fi - if ! tempfile="$(CHECK_SLOCK "$coursefile")"; then SET_COOKIE 0 message="NO VALID FILE LOCK" REDIRECT "/courses/?e=${course}" @@ -53,12 +45,12 @@ vcf_escape(){ | sed -E ':X;$!{N;bX}; s;\n;\;;g' } -course="$(pdi_load "$coursefile")" +ics="$(pdi_load "$coursefile")" tzid=$(cat /etc/timezone) -course="$(pdi_update_attrib "$course" DTSTAMP 1 "TZID=${tzid}")" -course="$(pdi_update_value "$course" DTSTAMP 1 "$(TZ="$tzid" date +%Y%m%dT%H%M%S)")" +ics="$(pdi_update_attrib "$ics" DTSTAMP 1 "TZID=${tzid}")" +ics="$(pdi_update_value "$ics" DTSTAMP 1 "$(TZ="$tzid" date +%Y%m%dT%H%M%S)")" dts_year="$( POST DTS_YEAR |grep -m1 -xE '[0-9]{4}' || date +%Y)" dts_month="$( POST DTS_MONTH |grep -m1 -xE '0[1-9]|1[012]' || date +%m)" @@ -69,8 +61,8 @@ dts_minute="$(POST DTS_MINUTE |grep -m1 -xE '[0-9]|[1-5][0-9]' || date +%M)" [ ${#dts_minute} -eq 1 ] && dts_minute="0$dts_minute" DTSTART="${dts_year}${dts_month}${dts_day}T${dts_hour}${dts_minute}00" -course="$(pdi_update_attrib "$course" DTSTART 1 "TZID=${tzid}")" -course="$(pdi_update_value "$course" DTSTART 1 "$DTSTART")" +ics="$(pdi_update_attrib "$ics" DTSTART 1 "TZID=${tzid}")" +ics="$(pdi_update_value "$ics" DTSTART 1 "$DTSTART")" rr_int=$( POST RRULE_INTERVAL |grep -m1 -xE '[0-9]+' || printf 1) rr_count=$(POST RRULE_COUNT |grep -m1 -xE '[0-9]+' || printf 1) @@ -87,13 +79,13 @@ case $(POST RRULE_LIMIT) in ETERN|*) RRULE="FREQ=$rr_freq;INTERVAL=$rr_int";; esac -course="$(pdi_update_value "$course" RRULE 1 "$RRULE")" +ics="$(pdi_update_value "$ics" RRULE 1 "$RRULE")" for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do for cnt in $(seq 1 $(POST_COUNT "$field")); do case "$field" in *) - course="$(pdi_update_value "$course" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")" + ics="$(pdi_update_value "$ics" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")" ;; esac done; done @@ -104,14 +96,21 @@ done; done delete_key="$(randomid)" for delete in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*_delete_[0-9]+'); do f="${delete%%_*}"; c="${delete##*_}"; - [ "$(POST "$delete")" = "true" ] && course="$(pdi_update_value "$course" "$f" "$c" "delete=${delete_key}")" + [ "$(POST "$delete")" = "true" ] && ics="$(pdi_update_value "$ics" "$f" "$c" "delete=${delete_key}")" done -course="$(printf '%s\n' "$course" |sed -E "/^[^:]+:delete=${delete_key}\$/d")" +ics="$(printf '%s\n' "$ics" |sed -E "/^[^:]+:delete=${delete_key}\$/d")" case "$(POST action)" in addfield) - course="$(pdi_update_value "$course" "$newfield" $(( $(pdi_count "$course" "$newfield") + 1 )) '')" - printf '%s' "$course" |grep -vx '' >"$tempfile" + 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}" + ;; + addfield\ [A-Z]*) + newfield="$(POST action |sed -rn '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}" ;; update) @@ -131,7 +130,7 @@ case "$(POST action)" in SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS" fi - printf '%s' "$course" |grep -vx '' >"${tempfile}.cp" + printf '%s' "$ics" |grep -vx '' >"${tempfile}.cp" mv "${tempfile}.cp" "$coursefile" RELEASE_SLOCK "$coursefile" REDIRECT "/courses/#${course}" @@ -147,4 +146,8 @@ case "$(POST action)" in RELEASE_SLOCK "$coursefile" REDIRECT "/courses/" ;; + *) + printf '%s' "$ics" |grep -vx '' >"$tempfile" + REDIRECT "/courses/?e=${course}" + ;; esac -- 2.39.2