2 # Copyright 2011 Paul Haensch
3 # This file is part of Kinoserver
5 # Kinoserver is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Kinoserver is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with Kinoserver. If not, see <http://www.gnu.org/licenses/>.
18 page="$(egrep -o '(^|&)p=[a-zA-Z0-9]+(&|$)' <<<"${QUERY_STRING}" |sed 's:.*p=::;s:&::g')"
19 info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d 'i=&')"
20 [ -z "$page" ] && page="Locations"
21 [ -z "$info" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
23 if [ -z "${CONTENT_LENGTH}" -o "${CONTENT_LENGTH}" -le 0 ]; then
24 echo -n "Location: http://${HTTP_HOST}/?p=Error&r=tooSmall\n\n"
26 elif [ "${CONTENT_LENGTH}" -gt 33554432 ]; then
27 echo -n "Location: http://${HTTP_HOST}/?p=Error&r=tooBig\n\n"
32 Photographs) imgpath="../Photographs/${info}";;
33 Locations) imgpath="../Locations";;
35 basename="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
36 filename="$imgpath/${basename}_meta.upload"
40 (head -c "${CONTENT_LENGTH}") |while line="$(line)"; do
41 if [ -z "${delim}" ]; then
43 end="$(echo "${delim}" |sed 's;\r;--\r;')"
45 if [ "${line}" = "${delim}" ]; then
46 field=$(egrep -o 'name="[a-zA-Z0-9]+"' <<<$(line) |sed 's,name=",,;s,"$,,')
47 line="$(line)" #consume a newline
48 [ "$field" = "picture" ] && line="$(line)" #consume additional newline for file upload
49 if [ -n "$filename" ]; then #finish last uploaded file by removing trailing CR|LF
50 size=$(stat -c %s "$filename")
51 truncate -s $(($size - 2)) "$filename"
53 if [ "$field" = "picture" ]; then
54 if [ "$page" = "Locations" -a "$filename" = "${imgpath}/${basename}_meta.upload" ]; then
55 echo -e "${lat}\t${lon}\t${title}" > "$filename"
56 echo -e "${tags}" |tr '\n' '|' >> "$filename"
57 echo -e "\n${desc}" >> "$filename"
58 elif [ "$page" = "Photographs" -a "$filename" = "${imgpath}/${basename}_meta.upload" ]; then
59 echo -e "name=$name" > "$filename"
61 filename="${imgpath}/${basename}_$n.upload"
65 elif [ "${line}" = "${end}" ]; then
66 size=$(stat -c %s $filename)
67 truncate -s $(($size - 2)) $filename
70 picture) echo -E "$line" >>$filename
72 title) title="$(sed 's/\t/ /g;s/\r|\n//g;s/\\/\\\\/g' <<<"$line")"
74 name) name="$(sed 's/\t/ /g;s/\r|\n//g;s/\\/\\\\/g' <<<"$line")"
76 lat) lat="$(egrep '[.0-9]{1,8}' <<<"$line" |tr -d '\r')"
78 lon) lon="$(egrep '[.0-9]{1,8}' <<<"$line" |tr -d '\r')"
80 tags) tags="${tags}$(sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' <<<"$line")\n"
82 desc) desc="${desc}$(sed 's/\t/ /g;s/\r//g;s/\\/\\\\/g' <<<"$line")\n"
89 for each in ${imgpath}/${basename}_<0-9999>.upload; do
90 convert "$each" "${imgpath}/${basename}_$n.jpg"
92 if [ "$page" = "Locations" -a -f "${imgpath}/${basename}_$n.jpg" ]; then
94 cp "${imgpath}/${basename}_meta.upload" "${imgpath}/${basename}_${n}.meta"
98 [ "$page" = "Photographs" -a ! -f "${imgpath}.meta" ] && cp "${imgpath}/${basename}_meta.upload" "${imgpath}.meta"
99 rm "${imgpath}/${basename}_meta.upload"
101 if [ -z "$info" ]; then
102 echo -n "Location: http://${HTTP_HOST}/?p=Error&r=noPic\n\n"
104 echo -n "Location: http://${HTTP_HOST}/?p=${page}&i=$info#$info\n\n"