From 16deeb30487a64daff6475da5a008a061f581f92 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 13 Jun 2015 16:46:06 +0000 Subject: [PATCH] externalise cgi engine svn path=/trunk/; revision=62 --- actions/edit_attendee.sh | 2 +- actions/edit_course.sh | 2 +- action.sh => actions/export_ical.sh | 10 ++-- export.sh => actions/export_vcard.sh | 17 ++---- actions/filter_attendee.sh | 4 +- actions/new_attendee.sh | 2 +- actions/new_course.sh | 2 +- actions/update_attendee.sh | 10 ++-- actions/update_course.sh | 12 ++--- cgi.sh | 54 ------------------- constants.sh | 5 +- index.cgi | 81 ---------------------------- local.opts | 8 --- page.sh | 34 ------------ templates/view_attendee.sh | 4 +- templates/view_course.sh | 4 +- 16 files changed, 33 insertions(+), 218 deletions(-) rename action.sh => actions/export_ical.sh (77%) rename export.sh => actions/export_vcard.sh (68%) delete mode 100755 cgi.sh delete mode 100755 index.cgi delete mode 100644 local.opts delete mode 100755 page.sh diff --git a/actions/edit_attendee.sh b/actions/edit_attendee.sh index a36a3d6..766031c 100644 --- a/actions/edit_attendee.sh +++ b/actions/edit_attendee.sh @@ -24,4 +24,4 @@ filter="&filter=$_REF[\"filter\"]" filtertype="&filtertype=$_REF[\"filtertype\"]" order="&order=$_REF[\"order\"]" -echo -n "Location: ?page=attendees${filter}${filtertype}${order}&edit=$card\n\n" +echo -n "Location: ?p=attendees${filter}${filtertype}${order}&edit=$card\n\n" diff --git a/actions/edit_course.sh b/actions/edit_course.sh index abeae20..ecf5bc6 100644 --- a/actions/edit_course.sh +++ b/actions/edit_course.sh @@ -19,4 +19,4 @@ course="$_GET[\"course\"]" -echo -n "Location: ?page=courses&edit=$course\n\n" +echo -n "Location: ?p=courses&edit=$course\n\n" diff --git a/action.sh b/actions/export_ical.sh similarity index 77% rename from action.sh rename to actions/export_ical.sh index a0240d9..715f4d2 100755 --- a/action.sh +++ b/actions/export_ical.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014,2015 Paul Hänsch # # This file is part of Confetti. # @@ -17,8 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -ACTION="$(echo "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')" -ACTION="${_EXEC}/actions/${ACTION}.sh" -[ -x "$ACTION" ] || echo -n "Location: ?page=error\n\n" - -. $ACTION +echo -n "Content-Type: text/calendar;charset=utf-8\n\n" +course="$_GET[\"course\"]" +cat "$_DATA/ical/$course" diff --git a/export.sh b/actions/export_vcard.sh similarity index 68% rename from export.sh rename to actions/export_vcard.sh index 96c2bf5..4c78411 100755 --- a/export.sh +++ b/actions/export_vcard.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014,2015 Paul Hänsch # # This file is part of Confetti. # @@ -17,15 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -case "$_GET[\"export\"]" in - vcard) - echo -n "Content-Type: text/vcard;charset=utf-8\n\n" - card="$_GET[\"card\"]" - cat "$_DATA/vcard/$card" - ;; - ical) - echo -n "Content-Type: text/calendar;charset=utf-8\n\n" - course="$_GET[\"course\"]" - cat "$_DATA/ical/$course" - ;; -esac +echo -n "Content-Type: text/vcard;charset=utf-8\n\n" +card="$_GET[\"card\"]" +cat "$_DATA/vcard/$card" diff --git a/actions/filter_attendee.sh b/actions/filter_attendee.sh index a18c1eb..fcdf8d1 100755 --- a/actions/filter_attendee.sh +++ b/actions/filter_attendee.sh @@ -24,9 +24,9 @@ case "$_POST[\"choice\"]"; in filter="$_POST[\"filter\"]" filtertype="$_POST[\"filtertype\"]" order="$_POST[\"order\"]" - echo -n "Location: ?page=attendees&filter=$filter&filtertype=$filtertype&order=$order\n\n" + echo -n "Location: ?p=attendees&filter=$filter&filtertype=$filtertype&order=$order\n\n" ;; *) - echo -n "Location: ?page=attendees\n\n" + echo -n "Location: ?p=attendees\n\n" ;; esac diff --git a/actions/new_attendee.sh b/actions/new_attendee.sh index 72581a7..b998d1d 100644 --- a/actions/new_attendee.sh +++ b/actions/new_attendee.sh @@ -42,4 +42,4 @@ UID:$uid END:VCARD EOF -echo -n "Location: ?page=attendees${filter}${filtertype}${order}&edit=$card\n\n" +echo -n "Location: ?p=attendees${filter}${filtertype}${order}&edit=$card\n\n" diff --git a/actions/new_course.sh b/actions/new_course.sh index e33f681..4f97d4a 100644 --- a/actions/new_course.sh +++ b/actions/new_course.sh @@ -43,4 +43,4 @@ END:VEVENT END:VCARD EOF -echo -n "Location: ?page=courses&edit=$course\n\n" +echo -n "Location: ?p=courses&edit=$course\n\n" diff --git a/actions/update_attendee.sh b/actions/update_attendee.sh index b6c38bc..6125b2f 100644 --- a/actions/update_attendee.sh +++ b/actions/update_attendee.sh @@ -54,7 +54,7 @@ case "$_POST[\"action\"]" in addfield) echo "$_POST[\"newfield\"]:\r" >>"$tempfile" echo "END:VCARD\r" >>"$tempfile" - echo -n "Location: ?page=attendees${filter}${filtertype}${order}&edit=$card\n\n" + echo -n "Location: ?p=attendees${filter}${filtertype}${order}&edit=$card\n\n" ;; update) attendance=() @@ -74,16 +74,16 @@ case "$_POST[\"action\"]" in echo "END:VCARD\r" >>"$tempfile" mv "$tempfile" "$cardfile" - echo -n "Location: ?page=attendees${filter}${filtertype}${order}#$card\n\n" + echo -n "Location: ?p=attendees${filter}${filtertype}${order}#$card\n\n" ;; cancel) rm "$tempfile" [ -f "$cardfile" ] \ - && echo -n "Location: ?page=attendees${filter}${filtertype}${order}#$card\n\n" \ - || echo -n "Location: ?page=attendees${filter}${filtertype}${order}\n\n" + && echo -n "Location: ?p=attendees${filter}${filtertype}${order}#$card\n\n" \ + || echo -n "Location: ?p=attendees${filter}${filtertype}${order}\n\n" ;; delete) rm "$tempfile" "$cardfile" - echo -n "Location: ?page=attendees${filter}${filtertype}${order}\n\n" + echo -n "Location: ?p=attendees${filter}${filtertype}${order}\n\n" ;; esac diff --git a/actions/update_course.sh b/actions/update_course.sh index 0e1ee24..d95d062 100644 --- a/actions/update_course.sh +++ b/actions/update_course.sh @@ -88,27 +88,27 @@ case "$_POST[\"action\"]" in echo "$_POST[\"newfield\"]:\r" >>"$tempfile" echo "END:VEVENT\r" >>"$tempfile" echo "END:VCALENDAR\r" >>"$tempfile" - echo -n "Location: ?page=courses&edit=$course\n\n" + echo -n "Location: ?p=courses&edit=$course\n\n" ;; update) echo "END:VEVENT\r" >>"$tempfile" echo "END:VCALENDAR\r" >>"$tempfile" mv "$tempfile" "$coursefile" - echo -n "Location: ?page=courses#$course\n\n" + echo -n "Location: ?p=courses#$course\n\n" ;; cancel) rm "$tempfile" [ -f "$coursefile" ] \ - && echo -n "Location: ?page=courses#$course\n\n" \ - || echo -n "Location: ?page=courses\n\n" + && echo -n "Location: ?p=courses#$course\n\n" \ + || echo -n "Location: ?p=courses\n\n" ;; delete) rm "$tempfile" "$coursefile" - echo -n "Location: ?page=courses\n\n" + echo -n "Location: ?p=courses\n\n" ;; *) echo "END:VEVENT\r" >>"$tempfile" echo "END:VCALENDAR\r" >>"$tempfile" - echo -n "Location: ?page=courses&edit=$course\n\n" + echo -n "Location: ?p=courses&edit=$course\n\n" ;; esac diff --git a/cgi.sh b/cgi.sh deleted file mode 100755 index b840770..0000000 --- a/cgi.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/zsh - -# Copyright 2014 Paul Hänsch -# -# This file is part of Confetti. -# -# Confetti is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Confetti is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Confetti. If not, see . - -declare -A _GET -declare -A _POST -declare -A _REF - -cgi_get() { # parse HTTP GET string - echo "$QUERY_STRING" |tr '&' '\n' |while read query; do - key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')" - val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')" - _GET["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")" - done -} - -cgi_post() { # parse HTTP POST string - sed -u 1q |tr '&' '\n' |while read query; do - key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')" - val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')" - value="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")" - if [ -n "$_POST[\"$key\"]" ]; then - n=0 - while [ -n "$_POST[\"$key$n\"]" ]; do n=$(($n + 1)); done - _POST["$key$n"]="$value" - else - _POST["$key"]="$value" - fi - #debug "_POST[$key] => $value" - done -} - -cgi_refdata() { # Parse GET data from referer - echo "$HTTP_REFERER" |cut -d'?' -f2- |tr '&' '\n' |while read query; do - key="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\1:')" - val="$(echo "$query" |sed -r 's:^([a-zA-Z0-9_-]*)=(.*)$:\2:')" - _REF["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")" - done -} diff --git a/constants.sh b/constants.sh index 3d4e648..c526da4 100644 --- a/constants.sh +++ b/constants.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014,2015 Paul Hänsch # # This file is part of Confetti. # @@ -17,6 +17,9 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . +export LC_ALL=de_DE.UTF-8 +data_dirs vcard ical cache temp mappings + VCF_FIELDS=(PHOTO LOGO FN NICKNAME SOUND GENDER KIND TITLE ROLE ORG MEMBER CATEGORIES ANNIVERSARY BDAY EMAIL TEL IMPP ADR URL LANG NOTE RELATED X-ZACK-JOINDATE X-ZACK-LEAVEDATE) uuidgenerator(){ diff --git a/index.cgi b/index.cgi deleted file mode 100755 index c908d7b..0000000 --- a/index.cgi +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/zsh - -# Copyright 2014 Paul Hänsch -# -# This file is part of Confetti. -# -# Confetti is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Confetti is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Confetti. If not, see . - -export LC_ALL=de_DE.UTF-8 -DBG_ENABLED=false -DBG_FILE=/dev/stderr - -# this program is supposed to be symlinked into a http root directory -# we will use the http root as object storage (data directory) and call sub -# programs from the directory in which the real executable resides -# therefore we need to identify the code and data directories _EXEC and _DATA -call="$0" -real="$(readlink -f $call)" -_EXEC="$(dirname "$real")" #execution directory -_DATA="$(dirname "$call")" #storage directory - -# put debug options in the local.opts file -[ -r "$_DATA/local.opts" ] && . "$_DATA/local.opts" - -# basic functions -debug() { #change to false to disable debugging - if [ "$DBG_ENABLED" = true -a -n "$*" ]; then - echo -E "$*" >>"$DBG_FILE" - elif [ "$DBG_ENABLED" = true -a -z "$*" ]; then - tee -a "$DBG_FILE" - elif [ -z "$*" ]; then - cat - fi -} - -die() { - debug "$*" - echo -E "$*" >>/dev/stderr - exit 1 -} - -# create directories for object storage -[ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" - -for each in "$_DATA"/{vcard,ical,cache,temp,mappings}; do - [ ! -e "$each" ] && mkdir "$each" - [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory" -done -touch "$_DATA/mappings/attendance" - -# create htaccess file -[ -f .htaccess ] || cat >.htaccess <. - -echo -n "Content-Type: text/html;charset=utf-8\n\n" - -PAGE="$(echo "$_GET[\"page\"]" |egrep '^[a-zA-Z0-9_-]+$')" -PAGE="${_EXEC}/pages/${PAGE}.sh" -[ -x "$PAGE" ] || PAGE="${_EXEC}/pages/error.sh" - -NAVIGATION() { - for each in "${_EXEC}"/pages/*.sh; do - link="$(echo "$each" |sed -r "s:^.*/([^/]*)\.sh$:\1:")" - title="$($each title)" - [ -n "$title" ] && echo "?page=$link $title" - done -} - -. ${_EXEC}/templates/frame.html.sh diff --git a/templates/view_attendee.sh b/templates/view_attendee.sh index 4d14e75..0265a80 100755 --- a/templates/view_attendee.sh +++ b/templates/view_attendee.sh @@ -85,12 +85,12 @@ echo '
' echo ' '$(l10n course_attendance)'' sed -rn 's:(.*)\t'$id'$:\1:p' "$_DATA/mappings/attendance" |while read each; do cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")" - echo ' '$cname'' + echo ' '$cname'' done echo '
' echo '' echo '
' echo ' '$(l10n edit)'' -echo ' '$(l10n vcf_export)'' +echo ' '$(l10n vcf_export)'' echo '
' echo '' diff --git a/templates/view_course.sh b/templates/view_course.sh index 9ebe377..ab93e02 100755 --- a/templates/view_course.sh +++ b/templates/view_course.sh @@ -87,13 +87,13 @@ echo ' ' echo '
' echo ' '$(l10n course_attendance)'' -list_attendance "$id" |sort -k 2 |sed -r 's:^([^ ]+) (.*)$:\2:' +list_attendance "$id" |sort -k 2 |sed -r 's:^([^ ]+) (.*)$:\2:' echo '
' echo ' ' echo '' -- 2.39.2