From 6b08e359a06ed38d25c1756e5600096c77417a9c Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 22 Jan 2016 15:29:53 +0000 Subject: [PATCH] added licence headers, coding style improvements svn path=/trunk/; revision=100 --- actions/filter.sh | 20 +++++++++++++++++-- actions/meta.sh | 38 +++++++++++++++++++++++++------------ actions/multitag.sh | 30 +++++++++++++++++++++++------ actions/transcode.sh | 19 +++++++++++++++++-- helpers/genall.sh | 26 ++++++++++++++++++++----- helpers/genmeta.sh | 18 +++++++++++++++++- helpers/genthumb.sh | 20 +++++++++++++++++-- pages/common.sh | 10 +++++----- pages/list.sh | 17 ++++++++++------- pages/view.sh | 4 ++-- templates/advfilter.html.sh | 12 ++++++------ templates/view.html.sh | 4 ++-- 12 files changed, 166 insertions(+), 52 deletions(-) diff --git a/actions/filter.sh b/actions/filter.sh index c7f4d87..6f64a97 100755 --- a/actions/filter.sh +++ b/actions/filter.sh @@ -1,4 +1,20 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . cgi_post order=$(validate "${_POST[o]}" 'Name|Length|Date' Name) @@ -22,5 +38,5 @@ for fn in {0..9}; do done done -echo "?o=${order}&f=${filters}" >>${_DATA}/meta/recent -echo -n "Location: ?o=${order}&f=${filters}\n\n" +printf %s "?o=${order}&f=${filters}" >>${_DATA}/meta/recent +redirect "?o=${order}&f=${filters}" diff --git a/actions/meta.sh b/actions/meta.sh index 034befa..894743e 100755 --- a/actions/meta.sh +++ b/actions/meta.sh @@ -1,4 +1,20 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . cgi_refdata @@ -16,14 +32,11 @@ height="${_POST[height]}" trash="${_POST[trash]}" cancel="${_POST[cancel]}" tagacc="${_POST[tag]}" -tags="$(echo "${_POST[tags]}" \ - | sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g' -)" -description="$(echo -e "${_POST[description]}" \ - |sed 's/\r//g;s/\\/\\\\/g;s//\>\;/g' -)" +tags="$(htmlsafe "${_POST[tags]}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;' |tr '\n' '|')" +description="$(htmlsafe "${_POST[description]}")" + n=0; while [ -n "${_POST[tag$n]}" ]; do - tagacc="${_POST[tag$n]}|$tagacc" + tagacc="$(htmlsafe ${_POST[tag$n]} |sed -r '2,$d;s:\t| :_:g;s:^!|\r|\$|\^::g;')|$tagacc" n=$(($n + 1)) done @@ -33,13 +46,14 @@ done rm "${_DATA}/cache/$info.cache" 2>/dev/null rm ${_DATA}/cache/\?* 2>/dev/null else - echo -e "$length\t$width\t$height\t$info" > "$file" - echo -e "${tagacc}|${tags}" |tr '\n' '|' >> "$file" - echo >>"$file" - echo -e "${description}" >> "$file" + cat >$file </dev/null rm ${_DATA}/cache/*[0-9]\?* 2>/dev/null rm ${_DATA}/cache/taglist 2>/dev/null fi -echo -n "Location: ?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n" +redirect "?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#${info}" diff --git a/actions/multitag.sh b/actions/multitag.sh index db106f5..5691b4f 100755 --- a/actions/multitag.sh +++ b/actions/multitag.sh @@ -1,9 +1,25 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . filter="${_GET[f]}" search="${_GET[s]}" -order=$(echo "${_GET[o]}" |egrep '^(Name|Date|Length)$') -page=$(echo "${_GET[pn]}" |egrep '^[0-9]+$') +order=$(validate "${_GET[o]}" 'Name|Date|Length' Name) +page=$(validate "${_GET[pn]}" '[0-9]+' 1) addtag(){ meta="$1" @@ -31,11 +47,13 @@ while [ -n "${_POST[tagsel$n]}" ]; do tagsel="${_POST[tagsel$n]}" ( t='' while [ -n "${_POST[ctag$t]}" ]; do - echo "${_POST[ctag$t]}" + htmlsafe "${_POST[ctag$t]}" + printf \\n [ -z "$t" ] && t=0 || t=$(($t + 1)) done - echo "${_POST[tags]}" - ) |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s//\>\;/g' \ + htmlsafe "${_POST[tags]}" + printf \\n + ) |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;' \ | while read tag; do addtag "${_DATA}/meta/$tagsel.meta" "$tag" done @@ -47,4 +65,4 @@ done rm "${_DATA}"/cache/*[0-9]\?* 2>/dev/null [ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist 2>/dev/null -echo -n "Location: ?o=$order&s=$search&f=$filter&pn=$page\n\n" +redirect "?o=$order&s=$search&f=$filter&pn=$page" diff --git a/actions/transcode.sh b/actions/transcode.sh index 427c154..35ff8f4 100755 --- a/actions/transcode.sh +++ b/actions/transcode.sh @@ -1,4 +1,20 @@ #!/bin/zsh +# Copyright 2015 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . info="${_GET[i]}" target="${_GET[t]}" @@ -15,5 +31,4 @@ if ! [ -f "$trans" ]; then [ "$target" -gt 240 ] && nohup avconv -i "$video" -s "${twidth}x${target}" -threads auto "$trans" & fi -echo "Location: /transcoded/${info}.${target}p.webm" -echo +redirect "/transcoded/${info}.${target}p.webm" diff --git a/helpers/genall.sh b/helpers/genall.sh index 950a490..78e0794 100755 --- a/helpers/genall.sh +++ b/helpers/genall.sh @@ -1,4 +1,20 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . dir="$(dirname $0)" genmeta="$dir/genmeta.sh" @@ -18,7 +34,7 @@ addtag(){ egrep -q "(^|.*\|)$tag(\|.*|$)" <<<"$tags" || tags="$tag|$tags" - cat <"$meta" + cat >"$meta" </dev/null 2>/dev/null - echo -n ' Meta ...' + printf %s ' Meta ...' $genmeta "$each" "${each}.meta" >/dev/null 2>/dev/null - echo -n ' Tags ...' + printf %s ' Tags ...' for tag in $*; do addtag "${each}.meta" "$tag" done - echo ' Done!' + printf 'Done!\n' fi; done diff --git a/helpers/genmeta.sh b/helpers/genmeta.sh index ceeebe3..ca0fe7f 100755 --- a/helpers/genmeta.sh +++ b/helpers/genmeta.sh @@ -1,4 +1,20 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . video="$1" meta="$2" @@ -8,7 +24,7 @@ if [ -r "$meta" ]; then description="$(sed -n '3,$p' "$meta")" fi -echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \ +printf '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \ | sort \ | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p; s:ID_VIDEO_HEIGHT=(.*):\1:p; diff --git a/helpers/genthumb.sh b/helpers/genthumb.sh index 78f53c1..9a0c64a 100755 --- a/helpers/genthumb.sh +++ b/helpers/genthumb.sh @@ -1,10 +1,26 @@ #!/bin/zsh +# Copyright 2014 - 2016 Paul Hänsch +# +# This file is part of Serve0 +# +# Serve0 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. +# +# Serve0 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 Serve0 If not, see . video="$1" thumb="$2" if [ -e "$video" -a \! -e "$thumb" ]; then - echo '' |mplayer -input nodefault-bindings -nosound -vo null -frames 0 -identify "$video" \ + printf '' |mplayer -input nodefault-bindings -nosound -vo null -frames 0 -identify "$video" \ | sort \ | sed -rn 's:^.*ID_LENGTH=(.*)(\..*)$:\1:p; s:^.*ID_VIDEO_HEIGHT=(.*)$:\1:p; @@ -19,7 +35,7 @@ if [ -e "$video" -a \! -e "$thumb" ]; then tmp="$(mktemp -d)" for cnt in 1 2 3 4; do - echo '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \ + printf '' |mplayer -input nodefault-bindings -nosound -vo jpeg:outdir="$tmp" -frames 1 \ -benchmark -vf framestep=I,scale="$width":-2 -ss "$(($cnt*$chunk))" "$video" >/dev/null 2>/dev/null mv "$tmp/00000001.jpg" "${tmp}/_${cnt}.jpg" done diff --git a/pages/common.sh b/pages/common.sh index ecf16c2..4242aab 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014, 2015 Paul Hänsch +# Copyright 2014 - 2016 Paul Hänsch # # This file is part of Serve0. # @@ -28,7 +28,7 @@ page_link='' [ -n "$order" ] && page_link="${page_link}o=${order}&" [ -n "$search" ] && page_link="${page_link}s=${search}&" [ -n "$filter" ] && page_link="${page_link}f=${filter}&" -page_prev="${page_link}pn=$([ "$page" -le "$pagesize" ] && echo 1 || echo $(($page - $pagesize)) )" +[ "$page" -le "$pagesize" ] && page_prev="${page_link}pn=1" || page_prev="${page_link}pn=$(($page - $pagesize))" page_next="${page_link}pn=$(($page + $pagesize))" page_this="${page_link}pn=$page" @@ -42,7 +42,7 @@ else sed -n '2s:|:\n:gp' "$each" done \ | sort - echo + printf \\n ) | (while read tag; do if [ "$tag" = "$lasttag" ]; then tagcount=$(( ${tagcount:-0} + 1 )) @@ -53,7 +53,7 @@ else lasttag="$tag" done \ | sort -rn - echo + printf \\n ) | while read x tag; do topcnt=$(grep "${tag%%:*}" ${_DATA}/cache/taglist |wc -l) [ $topcnt -lt 10 ] \ @@ -68,7 +68,7 @@ fi ) list_categories(){ - echo none + printf none\\n printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u } diff --git a/pages/list.sh b/pages/list.sh index 2d3cbf3..0870961 100755 --- a/pages/list.sh +++ b/pages/list.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014, 2015 Paul Hänsch +# Copyright 2014 - 2016 Paul Hänsch # # This file is part of Serve0. # @@ -19,16 +19,19 @@ . $_EXEC/pages/common.sh +LF=' +' filters="${_GET[f]}" debug "FILTERS: $filters" quicklinks(){ output='' - tac ${_DATA}/meta/recent |while [ "$(echo "$output" |wc -l)" -lt 10 ] && read line; do + tac ${_DATA}/meta/recent \ + | while [ "$(printf %s "$output" |wc -l)" -lt 10 ] && read line; do line="$line" - echo "$output" |grep -qF "$line" || output="$output$line\n" + printf %s "$output" |grep -qF "$line" || output="$output$line$LF" done - echo $output + printf %s\\n "$output" } category_selected(){ @@ -56,9 +59,9 @@ _printVideo(){ [ -r "$meta" ] || genmeta "$videofile" "$meta" head -n1 "$meta" |read length width height filename - [ -z "$length" ] && length=0 - [ -z "$width" ] && width=0 - [ -z "$height" ] && height=0 + length=$(validate "$length" '[0-9]+' 0) + width=$(validate "$width" '[0-9]+' 0) + height=$(validate "$height" '[0-9]+' 0) tags="$(sed -n 2p "$meta")" video="$(urlsafe "videos/$info")" diff --git a/pages/view.sh b/pages/view.sh index 689d6c1..ec873bd 100755 --- a/pages/view.sh +++ b/pages/view.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 - 2016 Paul Hänsch +# Copyright 2014 2016 Paul Hänsch # # This file is part of Serve0. # @@ -31,7 +31,7 @@ description="$(sed -n '3,$p' "$meta")" length=0; width=0; height=0; debug "Analysing video: $video" -echo '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \ +printf '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \ | sort \ | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p; s:ID_VIDEO_HEIGHT=(.*):\1:p; diff --git a/templates/advfilter.html.sh b/templates/advfilter.html.sh index ec2e5e7..7fac882 100755 --- a/templates/advfilter.html.sh +++ b/templates/advfilter.html.sh @@ -1,4 +1,4 @@ -# Copyright 2014,2015 Paul Hänsch +# Copyright 2014 - 2016 Paul Hänsch # # This file is part of Serve0 # @@ -19,7 +19,7 @@ category_tabs(){ for cat in "$@"; do cat < - + +
@@ -68,9 +68,9 @@ cat <

diff --git a/templates/view.html.sh b/templates/view.html.sh index 85f3e9a..3c0e3a5 100755 --- a/templates/view.html.sh +++ b/templates/view.html.sh @@ -51,8 +51,8 @@ cat <Height: $height
- $(echo "$tags" |sed -r 's:\|*([^|]+)\|*:\1:g') - ${description:+$(echo -E "$description" |_wiki)} + $(printf %s\\n "$tags" |sed -r 's:\|*([^|]+)\|*:\1:g') + ${description:+$(printf %s "$description" |_wiki)}
-- 2.39.2