From: paul Date: Sat, 6 Sep 2014 06:37:20 +0000 (+0000) Subject: initial commit X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=cc3eaa233f51324cdb20b594b6751468ba78aa4f;p=serve0 initial commit svn path=/trunk/; revision=1 --- cc3eaa233f51324cdb20b594b6751468ba78aa4f diff --git a/action.sh b/action.sh new file mode 100755 index 0000000..0077575 --- /dev/null +++ b/action.sh @@ -0,0 +1,24 @@ +#!/bin/zsh + +# Copyright 2014 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 . + +ACTION="$(echo "$_GET[\"action\"]" |egrep '^[a-zA-Z0-9_-]+$')" +ACTION="${_EXEC}/actions/${ACTION}.sh" +[ -x "$ACTION" ] || echo -n "Location: http://$HTTP_HOST/?page=error\n\n" + +. $ACTION diff --git a/cgi.sh b/cgi.sh new file mode 100755 index 0000000..49e68b4 --- /dev/null +++ b/cgi.sh @@ -0,0 +1,54 @@ +#!/bin/zsh + +# Copyright 2014 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 . + +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 new file mode 100755 index 0000000..84d7c7a --- /dev/null +++ b/constants.sh @@ -0,0 +1,20 @@ +#!/bin/zsh + +# Copyright 2014 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 . + +_GET['page']=videoview diff --git a/index.cgi b/index.cgi new file mode 100755 index 0000000..d17b4c3 --- /dev/null +++ b/index.cgi @@ -0,0 +1,70 @@ +#!/bin/zsh + +# Copyright 2014 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 . + +export LC_ALL=de_DE.UTF-8 + +# basic functions +die() { + echo "$*" >/dev/stderr + exit 1 +} +debug() { #change to false to disable debugging + #true && echo "$*" >>debug + true && [ -n "$*" ] && echo -E "$*" >>/dev/stderr + true && [ -z "$*" ] && tee /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 + +[ -w "$_DATA" ] && [ -d "$_DATA" ] || die "storage directory must be writable" + +# create directories for object storage +for each in "$_DATA"/{cache,meta,mp4,videos,thumbs,trash,by_length}; do + [ ! -e "$each" ] && mkdir "$each" + [ -w "$each" ] && [ -d "$each" ] || die "storage $each must be a writable directory" +done + +# 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/pages/videoview.sh b/pages/videoview.sh new file mode 100755 index 0000000..0229b36 --- /dev/null +++ b/pages/videoview.sh @@ -0,0 +1,147 @@ +#!/bin/zsh + +# Copyright 2014 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 . + +filterdiag() { + . ${_EXEC}/templates/filterdiag.html.sh +} + +tagger() { + n=foot + hideall="$(sed -rn "s;^([^:]+):.*$;hide_inline('${n}_\\1')\\;;p" <<<"$taglist" |sort -u)hide_inline('${n}_none');" + + . ${_EXEC}/templates/tagger.html.sh +} + +view() { + meta="${_DATA}/meta/$info.meta" + video="${_DATA}/videos/$info" + #reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )" + #[ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv" + tags="$(sed -n '2p' "$meta")" + description="$(sed -n '3,$p' "$meta")" + length=0; width=0; height=0; + eval $(mplayer -noconsolecontrols -input file=/dev/null -slave -really-quiet -identify -frames 0 -ao null -vo null "$video" 2>/dev/null |sed -rn 's:ID_VIDEO_WIDTH=(.*):width=\1:p;s:ID_VIDEO_HEIGHT=(.*):height=\1:p;s:ID_LENGTH=(.*)(\..*)$:length=\1:p;') + + taglist=$( + for each in ${_DATA}/meta/*.meta; do + sed -n '2s:|:\n:gp' "$each" + done |sort -u |grep -xv '') + + . ${_EXEC}/templates/view.html.sh +} + +_printVideo(){ + info="$1" + meta="${_DATA}/meta/$info.meta" + tags="$(sed -n 2p "$meta")" + thumb="${_DATA}/thumbs/$info.jpg" + head -n1 "$meta" |read length width height + [ -z "$length" ] && length=0 + [ -z "$width" ] && width=0 + [ -z "$height" ] && height=0 + + video="${_DATA}/videos/$info" +# reenc="vp8/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1:' <<<"$info" )" + mpfake="${_DATA}/mp4/$(sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:\1.mp4:' <<<"$info" )" +# [ -f "$reenc.mp4" ] && reenc="$reenc.mp4" || reenc="$reenc.mkv" + [ -r "$meta" ] || ./genmeta.sh "$video" "$meta" + [ -r "$thumb" ] || ./genthumb.sh "$video" "$thumb" + [ -L "$mpfake" ] || ln -s "../$video" "$mpfake" +# anchor=$(ls videos |grep -xA2 "$info" |tail -n1) + video="$(echo "$video" |sed 's/\?/\%6F/g')" + thumb="$(echo "$thumb" |sed 's/\?/%6F/g')" + mpfake="$(echo "$mpfake" |sed 's/\?/%6F/g')" + + [ "$(($length % 60))" -lt 10 ] &&\ + minutes="$(($length / 60)):0$(($length % 60))" ||\ + minutes="$(($length / 60)):$(($length % 60))" + + cat < + +
+ $info
+ + fake-mp4
+ + ${minutes}min + ${width}x${height}
+ + $(sed 's,|$,,;s,|, ,g' <<<"$tags") +
+ +VIDEOend +} + +_by_name(){ ls ${_DATA}/videos/ } +_by_date(){ ls -c ${_DATA}/videos/ } +_by_length(){ ls ${_DATA}/by_length/ |sed -r 's:[0-9]{5} - ::g' } + +thumblist() { + cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&p=${page}" + [ -f "$cache" ] && [ "$cache" -ot ${_DATA}/videos -o "$cache" -ot ${_DATA}/meta ] && rm "$cache" + if [ -r "$cache" ]; then + cat "$cache" + exit 0 + fi + + filterex="p" + for each in $(sed 's,\^, ,g' <<<"$filter"); do + if egrep -q '^!' <<<"$each"; then + this="$(sed 's,^!,,' <<<"$each")" + filterex="/${this}/q;{${filterex}}" + else + filterex="/${each}/{${filterex}}" + fi + done + + case "$order" in + Date) genlist="_by_date" + ;; + Length) genlist="_by_length" + ;; + *) genlist="_by_name" + ;; + esac + + $genlist |while read video; do + #video="$(basename "$each")" + if [ -n "$search" ] ; then + egrep -iq "$search" <<<"$video" <"${_DATA}/meta/$video.meta" && (echo "$video" || exit 0) + elif [ "$filterex" != p ]; then + [ -n "$(sed -rn "2{$filterex}" "${_DATA}/meta/$video.meta")" ] && (echo "$video" || exit 0) + else + echo "$video" || exit 0 + fi + done |sed -n $(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p | while read line; do + _printVideo "$line" + done |tee "$cache" +} + +case "$1" in + title) + echo "Videos" + ;; + css) + . ${_EXEC}/templates/videoview.css.sh + ;; + body) + . ${_EXEC}/templates/videoview.html.sh + ;; +esac diff --git a/templates/filterdiag.html.sh b/templates/filterdiag.html.sh new file mode 100755 index 0000000..f35e15e --- /dev/null +++ b/templates/filterdiag.html.sh @@ -0,0 +1,70 @@ +#!/bin/zsh + +cat < +
+ + Order by: + + Clear All + Advanced + + Page: << + $(($page + 1)) + >> + +
+ + + + +FilterEnd + +# vi:set filetype=html: + diff --git a/templates/frame.html.sh b/templates/frame.html.sh new file mode 100755 index 0000000..b6363d0 --- /dev/null +++ b/templates/frame.html.sh @@ -0,0 +1,53 @@ +# Copyright 2014 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 . + +cat < + + + + $($PAGE title) + + + + + $(. $PAGE body) + + +EOF + +# vi:set filetype=html: diff --git a/templates/tagger.html.sh b/templates/tagger.html.sh new file mode 100755 index 0000000..28fb1b8 --- /dev/null +++ b/templates/tagger.html.sh @@ -0,0 +1,47 @@ +#!/bin/zsh + +cat < + Add Tags + + Page: + << + $(($page + 1)) + >> + + + + + + +LOCATIONend + +# vi:set filetype=html: + diff --git a/templates/videoview.css.sh b/templates/videoview.css.sh new file mode 100755 index 0000000..bf22dc2 --- /dev/null +++ b/templates/videoview.css.sh @@ -0,0 +1,130 @@ +# Copyright 2014 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 . + +cat <. + +cat < +
$(thumblist)
+ $(tagger) + +EOF + +# vi:set filetype=html: diff --git a/templates/view.html.sh b/templates/view.html.sh new file mode 100755 index 0000000..c17284b --- /dev/null +++ b/templates/view.html.sh @@ -0,0 +1,54 @@ +#!/bin/zsh + +cat < + Dismiss +
+ Full
+ + +
+ +
+ $infoEdit
+ $(($length / 60)):$(($length % 60)) min + Width: $widthHeight: $height
+

Tags:$(sed 's,|$,,;s,|, ,g' <<<"$tags") +

$(_wiki <<<"$description") +
+ + + +viewEND + +# vi:set filetype=html: +