--- /dev/null
+.*.swo
+.*.swp
+*.html
--- /dev/null
+#!/bin/sh
+
+# Copyright 2017 - 2018 Paul Hänsch
+#
+# This is CGIlite.
+# A collection of posix shell functions for writing CGI scripts.
+#
+# CGIlite 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.
+#
+# CGIlite 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 CGIlite. If not, see <http://www.gnu.org/licenses/>.
+
+# ksh and zsh workaround
+# set -o posix # ksh, not portable
+setopt -o OCTAL_ZEROES 2>&-
+
+CR="\r"
+BR='
+'
+cgilite_timeout=2
+
+HEADER(){
+ # Read value of header line. Use this instead of
+ # referencing HTTP_* environment variables.
+ if [ -n "${cgilite_headers+x}" ]; then
+ printf %s "$cgilite_headers" \
+ | sed -En 's;^'"${1}"': ([^\r]+)\r?$;\1;i; tX; d; :X;p;q;'
+ else
+ eval "printf %s \"\$HTTP_$(printf %s "${1}" |tr a-z A-Z |tr -c A-Z _)\""
+ fi
+}
+
+HEX_DECODE='
+ s;\\;\\\\;g; :HEXDECODE_X; s;%([^0-9A-F]);\\045\1;g; tHEXDECODE_X;
+ # Hexadecimal { %00 - %FF } will be transformed to octal { \000 - \377 } for posix printf
+ s;%[0123].;&\\0;g; s;%[4567].;&\\1;g; s;%[89AB].;&\\2;g; s;%[CDEF].;&\\3;g;
+ s;%[048C][0-7]\\.;&0;g; s;%[048C][89A-F]\\.;&1;g; s;%[159D][0-7]\\.;&2;g; s;%[159D][89A-F]\\.;&3;g;
+ s;%[26AE][0-7]\\.;&4;g; s;%[26AE][89A-F]\\.;&5;g; s;%[37BF][0-7]\\.;&6;g; s;%[37BF][89A-F]\\.;&7;g;
+ s;%.[08](\\..);\10;g; s;%.[19](\\..);\11;g; s;%.[2A](\\..);\12;g; s;%.[3B](\\..);\13;g;
+ s;%.[4C](\\..);\14;g; s;%.[5D](\\..);\15;g; s;%.[6E](\\..);\16;g; s;%.[7F](\\..);\17;g;
+'
+
+HEX_DECODE(){
+ printf -- "$(printf %s "$1" |sed -E "$HEX_DECODE")"
+}
+
+if [ -z "$REQUEST_METHOD" ]; then
+ # no webserver variables means we are running via inetd / ncat
+ # so use builtin web server
+
+ # Use env from inetd as webserver variables
+ REMOTE_ADDR="${TCPREMOTEIP}"
+ SERVER_NAME="${TCPLOCALIP}"
+ SERVER_PORT="${TCPLOCALPORT}"
+
+ # Wait 2 seconds for request or kill connection through watchdog.
+ # Once Request is received the watchdog will be suspended (killed).
+ # At the end of the loop the watchdog will be restarted to enable
+ # timeout for the subsequent request.
+
+ (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!
+ while read REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL; do
+ kill $cgilite_watchdog
+ PATH_INFO="$(HEX_DECODE "${REQUEST_URI%\?*}")"
+ QUERY_STRING="${REQUEST_URI#*\?}"
+ cgilite_headers="$(while read -r hl; do [ "${hl%${CR}}" ] && printf '%s\n' "$hl" || break; done )"
+
+ HTTP_CONTENT_LENGTH="$(HEADER Content-Length |grep -xE '[0-9]+')"
+
+ export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \
+ PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH
+
+ # Try to serve multiple requests, provided that script serves a
+ # Content-Length header.
+ # Without Content-Length header, connection will terminate after
+ # script.
+
+ cgilite_status='200 OK'; cgilite_response=''; cgilite_cl="Connection: close${CR}";
+ . "$0" | while read -r l; do case $l in
+ Status:*) cgilite_status="${l#Status: }";;
+ Content-Length:*) cgilite_cl="${l}";;
+ $CR) printf '%s %s\r\n%s\n%s\n\r\n' \
+ 'HTTP/1.1' "${cgilite_status%${CR}}" \
+ "$cgilite_response" "${cgilite_cl}"
+ cat
+ [ "${cgilite_cl#Connection}" = "${cgilite_cl}" ]; exit;;
+ *) cgilite_response="${cgilite_response:+${cgilite_response}${BR}}${l}";;
+ esac; done || exit 0;
+ (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!
+ done
+fi
+
+if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=${CONTENT_LENGTH:=0}}" -gt 0 ]; then
+ cgilite_post="$(head -c "$HTTP_CONTENT_LENGTH")"
+fi
+
+[ -n "${DEBUG+x}" ] && env
+
+cgilite_count(){
+ printf %s "&$1" \
+ | grep -oE '&'"$2"'=[^&]*' \
+ | wc -l
+}
+
+cgilite_value(){
+ local str="&$1" name="$2" cnt="${3:-1}"
+ while [ $cnt -gt 0 ]; do
+ str=${str#*&${name}=}
+ cnt=$((cnt - 1))
+ done
+ printf -- "$(printf %s "${str%%&*}" |sed -E 's;\+; ;g;'"$HEX_DECODE")"
+}
+
+cgilite_keys(){
+ local str="&$1"
+ while [ "${str#*&}" != "${str}" ]; do
+ str="${str#*&}"
+ printf '%s\n' "${str%%=*}"
+ done \
+ | sort -u
+}
+
+GET(){ cgilite_value "${QUERY_STRING}" $@; }
+GET_COUNT(){ cgilite_count "${QUERY_STRING}" $1; }
+GET_KEYS(){ cgilite_keys "${QUERY_STRING}"; }
+
+POST(){ cgilite_value "${cgilite_post}" $@; }
+POST_COUNT(){ cgilite_count "${cgilite_post}" $1; }
+POST_KEYS(){ cgilite_keys "${cgilite_post}"; }
+
+REF(){ cgilite_value "${HTTP_REFERER#*\?}" $@; }
+REF_COUNT(){ cgilite_count "${HTTP_REFERER#*\?}" $1; }
+REF_KEYS(){ cgilite_keys "${HTTP_REFERER#*\?}"; }
+
+COOKIE(){
+ HEX_DECODE "$(
+ HEADER Cookie \
+ | grep -oE '(^|; ?)'"$1"'=[^;]*' \
+ | sed -En "${2:-1}"'{s;^[^=]+=;;; s;\+; ;g; p;}'
+ )"
+}
+
+HTML(){
+ # HTML Entity Coding
+ # Prints UTF-8 string as decimal Unicode Code Points
+ # Useful for escaping user input for use in HTML text and attributes
+ { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+ | hexdump -ve '/1 "%03o\n"' \
+ | while read n; do
+ case $n in
+ # bitbanging octal UTF-8 chains into singular 7 digit octal numbers
+ [01]??) printf '0000%s' $n;; # 7 bit ASCII character, nothing to do
+ 2??) printf '%s' ${n#2};; # tail fragment, append 6 bit
+ 3[0123]?) printf '000%s' ${n#3};; # 2 octet (11 bit) chain start
+ 34?) printf '00%s' ${n#34};; # 3 octet (16 bit) chain start
+ 35?) printf '01%s' ${n#35};; # 3 octet chain start, high
+ 36?) printf '%s' ${n#36};; # 4 octet (21 bit) chain start
+ esac
+ done \
+ | sed -E 's;.{7};&\n;g;' \
+ | while read n; do
+ printf '&#%d;' $((0$n))
+ done
+}
+
+URL(){
+ # Code every character in URL escape hex format
+ # except alphanumeric ascii
+
+ { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+ | hexdump -v -e '/1 ",%02X"' \
+ | sed 's;,;%;g; s;%2F;/;g;'
+}
+
+PATH(){
+ { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+ | sed -E 's;^.*$;/&/;; s;/+;/;g;
+ :X;
+ s;^/\.\./;/;; s;/\./;/;g;
+ tX;
+ s;/[^/]+/\.\./;/;;
+ tX;
+ s;^(/.*)/$;\1;'
+}
+
+
+SET_COOKIE(){
+ local expire cookie
+ case "$1" in
+ ''|0|session) expire='';;
+ [+-][0-9]*) expire="$(date -R -d @$(($(date +%s) + $1)))";;
+ *) expire="$(date -R -d "$1")";;
+ esac
+ cookie="$2"
+
+ printf 'Set-Cookie: %s' "$cookie"
+ [ -n "$expire" ] && printf '; Expires=%s' "${expire%+????}${expire:+GMT}"
+ [ $# -ge 3 ] && shift 2 && printf '; %s' "$@"
+ printf '\r\n'
+}
+
+REDIRECT(){
+ printf '%s: %s\r\n' \
+ Status "303 See Other" \
+ Content-Length 0 \
+ Location "$*"
+ printf '\r\n'
+ exit 0
+}
--- /dev/null
+#!/bin/sh
+
+# Copyright 2016 - 2018 Paul Hänsch
+#
+# This file is part of cgilite.
+#
+# cgilite 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.
+#
+# cgilite 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 cgilite. If not, see <http://www.gnu.org/licenses/>.
+
+[ -n "$include_fileserve" ] && return 0
+include_fileserve="$0"
+
+file_type(){
+ case ${1##*.} in
+ html|html) printf 'text/html';;
+ css) printf 'text/css';;
+ js) printf 'text/javascript';;
+ txt) printf 'text/plain';;
+ sh) printf 'text/shellscript';;
+ jpg|jpeg) printf 'image/jpeg';;
+ png) printf 'image/png';;
+ svg) printf 'image/svg+xml';;
+ gif) printf 'image/gif';;
+ webm) printf 'video/webm';;
+ mp4) printf 'video/mp4';;
+ ogg) printf 'audio/ogg';;
+ xml) printf 'application/xml';;
+ *) printf 'application/octet-stream';;
+ esac
+}
+
+FILE(){
+ local file file_size file_date http_date cachedate range mime
+ file="$1" mime="$2"
+
+ if ! [ -f "$file" ]; then
+ printf 'Content-Length: 0\r\nStatus: 404 Not Found\r\n\r\n'
+ exit 0
+ elif ! [ -r "$file" ]; then
+ printf 'Content-Length: 0\r\nStatus: 403 Forbidden\r\n\r\n'
+ exit 0
+ fi
+
+ file_size="$(stat -Lc %s "$file")"
+ file_date="$(stat -Lc %Y "$file")"
+ http_date="$(date -uRd @$file_date)"
+ http_date="${http_date%+0000}GMT"
+ cachedate="$(
+ # Parse the allowable date formats from Section 3.3.1 of
+ # https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
+ HEADER If-Modified-Since \
+ | sed -r 's;^[^ ]+, ([0-9]{2}) (...) ([0-9]{4}) (..:..:..) GMT$;\3-\2-\1 \4;;
+ s;^[^ ]+, ([0-9]{2})-(...)-([789][0-9]) (..:..:..) GMT$;19\3-\2-\1 \4;;
+ s;^[^ ]+, ([0-9]{2})-(...)-([0-6][0-9]) (..:..:..) GMT$;20\3-\2-\1 \4;;
+ s;^[^ ]+ (...) ([0-9]{2}) (..:..:..) ([0-9]{4})$;\4-\1-\2 \3;;
+ s;^[^ ]+ (...) ([0-9]) (..:..:..) ([0-9]{4})$;\4-\1-\2 \3;;
+ s;Jan;01;; s;Feb;02;; s;Mar;03;; s;Apr;04;; s;May;05;; s;Jun;06;;
+ s;Jul;07;; s;Aug;08;; s;Sep;09;; s;Oct;10;; s;Nov;11;; s;Dec;12;;' \
+ | xargs -r0 date +%s -ud 2>&-
+ )"
+
+ range="$(HEADER Range |sed -nr 's;^bytes=([0-9]+-[0-9]*|-[0-9]+)$;\1;p;q;')"
+ case "$range" in
+ *-) range="${range}$((file_size - 1))";;
+ -*) [ ${range#-} -le $file_size ] \
+ && range="$((file_size - ${range#-}))-$((file_size - 1))" \
+ || range="0-$((file_size - 1))";;
+ *-*) [ ${range#*-} -ge $file_size ] \
+ && range="${range%-*}-$((file_size - 1))";;
+ esac
+
+ if [ "$file_date" -lt "$cachedate" ] 2>&-; then
+ printf '%s: %s\r\n' \
+ Status '304 Not Modified' \
+ Content-Length 0 \
+ Last-Modified "$http_date"
+ printf '\r\n'
+
+ elif [ -z "$range" ]; then
+ printf '%s: %s\r\n' \
+ Status "200 OK" \
+ Accept-Ranges bytes \
+ Last-Modified "$http_date" \
+ Content-Type "${mime:-$(file_type "$file")}" \
+ Content-Length $file_size
+ printf '\r\n'
+
+ [ "$REQUEST_METHOD" != HEAD ] && cat "$file"
+
+ elif [ "${range%-*}" -le "${range#*-}" ]; then
+ printf '%s: %s\r\n' \
+ Status "206 Partial Content" \
+ Accept-Ranges bytes \
+ Last-Modified "$http_date" \
+ Content-Type "${mime:-$(file_type "$file")}" \
+ Content-Range "bytes ${range}/${file_size}" \
+ Content-Length "$((${range#*-} - ${range%-*} + 1))"
+ printf '\r\n'
+
+ [ "$REQUEST_METHOD" != HEAD ] \
+ && tail -c+$((${range%-*} + 1)) "$file" \
+ | head -c "$((${range#*-} - ${range%-*} + 1))"
+
+ elif [ "${range%-*}" -gt "${range#*-}" ]; then
+ printf '%s: %s\r\n' \
+ Status "216 Range Not Satisfiable" \
+ Content-Length 0 \
+ Content-Range \*/${file_size}
+ printf '\r\n'
+ fi
+}
--- /dev/null
+#!/bin/sed -nEf
+
+:Escapes
+s,\\\\,\\,g; s,\\&,\&,g;
+s,\\<,\<,g; s,\\>,\>,g;
+s,\\",\",g; s,\\',\',g;
+s,\\\[,\[,g; s,\\\],\],g;
+s,\\\.,\.,g; s,\\#,\#,g;
+s,\\,,g;
+
+:CommentHandle
+x; /^<\/!-->/{
+ x; /--]/{
+ H; s;^(.*)--].*$;\1-->;p;
+ g; s;^.*--]([^\n]*)$;\1;
+ x; s;^</!-->\n(.*)\n[^\n]*$;\1;; x;
+ bCommentEnd
+ }
+ p; b;
+}
+x;
+:CommentEnd
+
+:shortcuts
+s;\[hidden[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="hidden" name="\1" value="\2";g;
+s;\[checkbox[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="checkbox" name="\1" value="\2";g;
+s;\[radio[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="radio" name="\1" value="\2";g;
+s;\[submit[ \t]+"([^"]*)"[ \t]+"([^"]*)";[button type="submit" name="\1" value="\2";g;
+s;\[a[ \t]+"([^"]*)";[a href="\1";g;
+s;\[img[ \t]+"([^"]*)"[ \t]+"([^"]*)";[img src="\1" alt="\2";g;
+
+s;\[!([^]\[]*)\];<!\1>;g;
+s;\[!--([^]\[]*)--\];<!--\1-->;g;
+
+:tags
+s;\[([^]\[< \t]+)([^]\[]*)\];<\1>\2</\1>;g;
+t tags;
+
+G;
+:tagclose
+s;^([^]\n]*)\]([^\n]*)\n([^\n]+);\1\3\2;
+t tagclose;
+h; s;^([^\n]*)\n;;; x; s;\n.*$;;;
+
+:tagopen
+s;^([^\[\n]*)\[([^]\[< \t\n]+)([^\n]*);\1<\2>\3\n</\2>;
+t tagopen;
+G; h; s;^[^\n]*\n+;;; x; s;\n.*$;;;
+
+:attribs
+s;class="([^>]+)>[ \t]*\.([^< \t]+);class="\2 \1>;g; t attribs;
+s;(<[^/][^>]*)>[ \t]*\.([^< \t]+);\1 class="\2">;g;
+s;(<[^/][^>]*)>[ \t]*#([^< \t]+);\1 id="\2">;g;
+s;(<[^/][^>]*)>[ \t]*([^ \t=<]+=("[^"]*"|'[^']*'|[^< \t]*));\1 \2>;g;
+t attribs;
+s;(<input ([^>]+ )?type=(radio|"radio"|'radio')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
+s;(<input ([^>]+ )?type=(checkbox|"checkbox"|'checkbox')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
+s;(<option( [^>]+)?)>[ \t]*(checked|selected);\1 selected="selected">;g;
+s;(<select( [^>]+)?)>[ \t]*multiple;\1 multiple="multiple">;g;
+t attribs;
+
+s;(<[^/][^>]*>)[ \t]*;\1;g;
+# s;(<[^/][^>]*)>[ \t]*</[^>]+>;\1/>;g;
+s;(<(br|hr|img|input|link|meta|area|base|col|command|embed|keygen|param|source|track|wbr)[^>]*)>[ \t]*</\1>;\1>;g;
+
+s;<!-->;<!--;;
+
+p; ${g; s;\n+;;g; p;}
--- /dev/null
+#!/bin/sh
+
+# LOGLEVEL 1: Crash condition
+# LOGLEVEL 2: Unexpected condition
+# LOGLEVEL 3: Failed action (i.e. due to config error)
+# LOGLEVEL 4: Debug
+
+[ -n "$include_logging" ] && return 0
+include_logging="$0"
+
+LOGLEVEL="${LOGLEVEL:-3}"
+LOGFILE="${LOGFILE:-/dev/stderr}"
+
+logmsg(){
+ local ll="${1:-3}"
+ shift 1
+ if [ "$ll" -le "$LOGLEVEL" -a "$#" -gt 0 ]; then
+ printf %s\\n "$*" >>"${LOGFILE}"
+ elif [ "$ll" -le "$LOGLEVEL" ]; then
+ tee -a "${LOGFILE}"
+ elif [ ! "$#" -gt 0 ]; then
+ cat
+ fi
+}
+
+die(){
+ [ "$#" -gt 0 ] && logmsg 1 "$@"
+ exit 1
+}
+panic(){ logmsg 2 "$@"; }
+error(){ logmsg 3 "$@"; }
+debug(){ logmsg 4 "$@"; }
--- /dev/null
+#!/bin/sh
+
+[ -n "$include_session" ] && return 0
+include_session="$0"
+
+server_key(){
+ IDFILE="${IDFILE:-${_DATA:-.}/serverkey}"
+ if [ "$(stat -c %s "$IDFILE")" -ne 512 ] || ! cat "$IDFILE"; then
+ dd count=1 bs=512 if=/dev/urandom \
+ | tee "$IDFILE"
+ fi 2>&-
+}
+
+slopecode(){
+ # 6-Bit Code that retains sort order of input data, while beeing safe to use
+ # in ascii transmissions, unix file names, HTTP URLs, and HTML attributes
+
+ uuencode -m - | sed '
+ 1d;$d;
+ y;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/;0123456789:=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;
+ '
+}
+
+randomid(){
+ dd bs=12 count=1 if=/dev/urandom 2>&- \
+ | slopecode
+}
+
+timeid(){
+ d=$(($(date +%s) % 4294967296))
+ { printf "$(
+ printf \\%o \
+ $((d / 16777216 % 256)) \
+ $((d / 65536 % 256)) \
+ $((d / 256 % 256)) \
+ $((d % 256))
+ )"
+ dd bs=8 count=1 if=/dev/urandom 2>&-
+ } | slopecode
+}
+
+checkid(){ grep -m 1 -xE '[0-9a-zA-Z:=]{16}'; }
+
+update_session(){
+ local session sid time sig serverkey checksig
+
+ IFS=- read -r sid time sig <<-END
+ $(COOKIE session)
+ END
+ serverkey="$(server_key)"
+
+ checksig="$(printf %s "$sid" "$time" "$serverkey" | sha256sum)"
+ checksig="${checksig%% *}"
+ d=$(date +%s)
+
+ if [ "$checksig" != "$sig" \
+ -o "$time" -lt "$d" \
+ -o ! "$(printf %s "$sid" |checkid)" ] 2>&-
+ then
+ debug Setting up new session
+ sid="$(randomid)"
+ fi
+
+ time=$(( $(date +%s) + 7200 ))
+ sig="$(printf %s "$sid" "$time" "$serverkey" |sha256sum)"
+ sig="${sig%% *}"
+ printf %s\\n "${sid}-${time}-${sig}"
+}
+
+SESSION_ID="$(update_session)"
+SET_COOKIE 0 session="$SESSION_ID" Path=/ SameSite=Strict HttpOnly
+SESSION_ID="${SESSION_ID%%-*}"
--- /dev/null
+#!/bin/sh
+
+# Copyright 2018 Paul Hänsch
+#
+# This is a file format helper, part of CGIlite.
+#
+# CGIlite 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.
+#
+# CGIlite 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 CGIlite. If not, see <http://www.gnu.org/licenses/>.
+
+[ -n "$include_storage" ] && return 0
+include_storage="$0"
+
+LOCK(){
+ local lock timeout block
+ lock="${1}.lock"
+ timeout="${2-20}"
+ if [ \! -w "${lock%/*}" ] || [ -e "$lock" -a \! -d "$lock" ]; then
+ printf 'Impossible to get lock: %s\n' "$lock" >&2
+ return 1
+ fi
+
+ while ! mkdir "$lock" 2>&-; do
+ block="$(cat "$lock/pid" || printf 1)"
+ if ! { ps -eo pid |grep -qwF "$block"; }; then
+ printf 'Overriding stale lock: %s\n' "$lock" >&2
+ break
+ fi
+ if [ $timeout -le 0 ]; then
+ printf 'Timeout while trying to get lock: %s\n' "$lock" >&2
+ return 1
+ fi
+ timeout=$((timeout - 1))
+ sleep 1
+ done
+ printf '%i\n' $$ >"${lock}/pid"
+ return 0
+}
+
+RELEASE(){
+ local lock
+ lock="${1}.lock"
+ if [ "$(cat "$lock/pid")" = "$$" ]; then
+ rm "$lock/pid"
+ if ! rmdir "$lock"; then
+ printf 'Cannot remove tainted lock: %s\n' "$lock" >&2
+ printf '%i\n' $$ >"${lock}/pid"
+ return 1
+ fi
+ return 0
+ else
+ printf 'Refusing to release foreign lock: %s\n' "$lock" >&2
+ return 1
+ fi
+}
+
+STRING='
+ s;\\;\\\\;g;
+ s;\n;\\n;g;
+ s;\t;\\t;g;
+ s;\r;\\r;g;
+ s;\+;\\+;g;
+ s; ;+;g;
+'
+
+STRING(){
+ { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+ | sed -r ':X; $!{N;bX;}'"$STRING"
+}
+
+UNSTRING='
+ :UNSTRING_X
+ s;((^|[^\\])(\\\\)*)\\n;\1\n;g;
+ s;((^|[^\\])(\\\\)*)\\t;\1\t;g;
+ s;((^|[^\\])(\\\\)*)\\r;\1\r;g;
+ s;((^|[^\\])(\\\\)*)\+;\1 ;g;
+ tUNSTRING_X;
+ s;((^|[^\\])(\\\\)*)\\\+;\1+;g;
+ s;\\\\;\\;g;
+'
+UNSTRING(){
+ { [ $# -eq 0 ] && cat || printf %s "$*"; } \
+ | sed -r "$UNSTRING"
+}
--- /dev/null
+* {
+ box-sizing: border-box;
+ margin: 0; padding: 0;
+ background-position: center;
+ background-repeat: no-repeat;
+ background-size: cover;
+}
+
+/* min-height: 240px */ body { font-size: 9px; }
+@media(min-height: 320px) { body { font-size: 12px; } }
+@media(min-height: 480px) { body { font-size: 19px; } }
+@media(min-height: 720px) { body { font-size: 28px; } }
+@media(min-height: 768px) { body { font-size: 30px; } }
+@media(min-height: 800px) { body { font-size: 32px; } }
+@media(min-height: 960px) { body { font-size: 38px; } }
+@media(min-height: 1024px) { body { font-size: 41px; } }
+@media(min-height: 1080px) { body { font-size: 43px; } }
+@media(min-height: 2160px) { body { font-size: 86px; } }
+
+body {
+ font-family: sans-serif;
+ padding: 2em 1em 6em 1em;
+ background-color: #555;
+ text-align: center;
+ overflow-x: hidden;
+}
+body * {
+ text-align: left;
+ font-size: inherit;
+}
+
+body:after {
+ position: fixed;
+ bottom: 0; left: 0;
+ width: 100%;
+ background-color: #EEE;
+ height: 1.25em;
+ content: ' ';
+}
+
+a.previous, a.next ,a.toplevel {
+ text-decoration: none;
+}
+
+footer {
+ position: fixed;
+ bottom: 0; left: 0;
+ width: 100%;
+ font-size: .75em;
+ padding: .5em 4em .5em 12em;
+ text-align: center;
+ color: #888;
+ z-index: 4;
+}
+footer:before {
+ content: ' ';
+ position: absolute;
+ top: 0; left: 0;
+ bottom: 1.5em;
+ width: 100%;
+ background-color: #EEE;
+ z-index: -1;
+}
+
+body a.toplevel {
+ position: fixed;
+ bottom: 0; left: 8em;
+ width: 2ex; overflow: hidden;
+ font-size: .875em;
+ padding-bottom: .25em;
+ color: #EEE;
+ z-index: 5;
+}
+body a.toplevel:before {
+ color: #888;
+ content: '\2196';
+}
+
+body span.count {
+ position: fixed;
+ bottom: 0; left: 6.25em;
+ font-size: .875em;
+ padding-bottom: .125em;
+ color: #888;
+ z-index: 5;
+}
+
+/* ==== Overview Screen ==== */
+
+div.slide, a.nextslide {
+ font-size: .15625em;
+}
+
+div.slide {
+ position: relative;
+ display: inline-block;
+ overflow: hidden;
+ width: 48em; height: 30em;
+ margin-left: -48em;
+ border: 1px solid black;
+}
+
+div.slide:after { /* slide number */
+ position: absolute;
+ bottom: 0; left: 0;
+ font-size: 15em;
+ line-height: 1em;
+ text-align: left;
+ content: attr(count);
+ padding-left: .125em;
+ color: #DDD;
+}
+
+div.slide + a { display: none; }
+a.nextslide {
+ display: inline-block;
+ position: relative;
+ vertical-align: top;
+ width: 48em; line-height: 30em;
+ color: rgba(0, 0, 0, 0);
+ z-index: 2;
+}
+#div.slide:nth-of-type(1) { margin-right: .5em; }
+
+/* ==== Slide Appearance ==== */
+
+div.slide {
+ background: #FFF no-repeat center;
+ text-align: center;
+ line-height: 1.5em;
+}
+
+div.slide > * {
+ margin-top: 1em;
+ max-width: 85%;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+div.slide > *:first-child:last-child,
+div.slide > h2:first-child + :last-child {
+ margin-top: 20%;
+ transform: translate(0, -50%);
+}
+
+div.slide h1, div.slide h2 {
+ display: block;
+ background-color: #EEE;
+ text-align: center;
+ font-size: 1.5em;
+ margin-top: 0;
+ margin-bottom: 1em;
+ width: 100%; max-width: 100%;
+}
+
+div.slide h1,
+div.slide > h1:first-child:last-child {
+ margin-top: 25%;
+ margin-bottom: 0;
+ padding: .5em 2em;
+}
+
+div.slide h2 {
+ padding: .25em 1em;
+}
+
+div.slide > table {
+ width: 85%;
+}
+div.slide * table {
+ width: 100%;
+}
+
+div.slide ul li {
+ list-style-type: square;
+ margin-left: 2em;
+}
+
+div.slide ul ul, div.slide ul ol,
+div.slide ol ul, div.slide ol ol {
+ margin-left: -1em;
+}
+
+div.slide > ul,
+div.slide > ol {
+ width: fit-content;
+ margin: .25em auto;
+}
+
+div.slide pre {
+ background-color: rgba(192,192,192,128);
+ padding: 1ex;
+ text-align: left;
+ font-family: monospace;
+ overflow: hidden;
+}
+
+/* ==== Slide Display ==== */
+
+div.slide:target {
+ position: fixed;
+ z-index: 3;
+ top: 0; bottom: 0; left: 0; right: 0;
+ width: auto; height: 100%;
+ margin: 0;
+ border: none;
+ font-size: inherit;
+}
+
+/* slide number, footer bar*/
+div.slide:target:after {
+ position: absolute;
+ bottom: 0; left: 0;
+ width: 100%;
+ font-size: .875em;
+ line-height: 1.5em;
+ text-align: left;
+ content: attr(count) " /";
+ padding-left: 4em;
+ background-color: #EEE;
+ color: #888;
+}
+
+/* back and forth link buttons */
+div.slide:target + a,
+div.slide:target + a + a {
+ position: static;
+ display: block;
+ font-size: inherit;
+ line-height: 1em;
+ color: #888;
+}
+:target + a:before, :target + a + a:before {
+ display: block;
+ position: fixed;
+ bottom: 0;
+ color: #888;
+ padding: 0 1em .25em 1em;
+ z-index: 4;
+}
+:target + a:before { left: 0; }
+:target + a:before { content: '\22d8'; }
+:target + a + a:before { right: 0; }
+:target + a + a:before { content: '\22d9'; }
+
+.uncover[type="checkbox"] + * { opacity: .2; }
+.uncover[type="checkbox"]:checked + * { opacity: 1; }
+
+.uncover[type="checkbox"] {
+ position: fixed;
+ top: 0; bottom: 0; left: 0; right: 0;
+ width: 100%; height: 100%;
+ opacity: 0;
+ z-index: 1;
+}
+
+.uncover[type="checkbox"] + * + .uncover[type="checkbox"] { display: none; }
+.uncover[type="checkbox"]:checked + * + .uncover[type="checkbox"] { display: inline; }
+.uncover[type="checkbox"]:checked + * + .uncover[type="checkbox"]:checked,
+.uncover[type="checkbox"]:checked { display: none; }
+
--- /dev/null
+#!/bin/sh
+
+prev='' next='' idoff=0
+depth=0 ucdepth=-1
+
+base64() {
+ uuencode -m - <"$1" \
+ | sed '1d; :X;$!{N;bX;}; s;\n;;g; s;=\+;;g;'
+}
+
+{ "${0%/*}"/cgilite/html-sh.sed || cat; } \
+| {
+ line="$(line)"
+ while :; do
+ tag="${tag}${line%%>*}"
+
+ if [ "$line" = "${line%%>*}" ]; then
+ # $line did not contain ">" and thus was added to $tag entirely
+ if ! line="$(line)"; then
+ printf %s\\n "$tag"
+ break
+ fi
+ tag="${tag}
+ "
+ else
+ # $line is shortened by segment added to $tag
+ line="${line#*>}"
+ tag="${tag}>"
+ fi
+
+ ### Image embedding for Inline styles
+ while expr "$tag" : '.*<[^>]*style="[^"]*url("\?[^)]\+\.\(png\|jpg\|jpeg\|gif\|svg\)"\?)'; do
+ pre="${tag%%url(*)*}"
+ post="${tag#*url(*)}"
+ file="${tag#${pre}url(}" file="${file%)$post}"
+ file="${file#"}" file="${file%"}"
+ echo Inlining Background Image "$file" >&2
+ if [ -r "$file" ]; then
+ tag="${pre}url('data:image/${file##*.};base64,$(base64 "$file")')${post}"
+ fi
+ done >/dev/null
+
+ ### Image embedding for Image tags
+ while expr "$tag" : '.*<img [^>]*src="[^"]\+\.\(png\|jpg\|jpeg\|gif\|svg\)"'; do
+ pre="${tag%%src=\"*\"*}"
+ post="${tag#*src=\"*\"}"
+ file="${tag#${pre}src=\"}" file="${file%\"$post}"
+ echo Inlining Image "$file" >&2
+ if [ -r "$file" ]; then
+ tag="${pre}src=\"data:image/${file##*.};base64,$(base64 "${file}")\"${post}"
+ fi
+ done >/dev/null
+
+ ### Tag Processing
+ case $tag in
+ *\<head\>*|\*\<head\ *\>) # Inline styles into head
+ printf '%s<meta name="viewport" content="width=device-width">
+ <meta charset="UTF-8">
+ <style type="text/css"><!--\n' "${tag%${tag#*<head*>}}"
+ cat "${0%/*}/clickslide.css"
+ printf '\n--></style>%s' "${tag#*<head*>}"
+ tag='' depth=$((depth + 1))
+ ;;
+ *\<slide\ *id=\"?*\"*\>*) # Count slide id, insert "next" button
+ prev="$next"
+ next="${tag#*<slide }" next="${next#*id=\"}" next="${next%\"*}"
+ next="autoslide${idoff}"
+ idoff="$((idoff + 1))"
+ printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
+ "${tag%<slide *}" "$next" "$idoff" "$next" "${tag#*<slide }"
+ tag='' depth=$((depth + 1))
+ ;;
+ *\<slide\ *\>*|*\<slide\>*)
+ prev="$next"
+ next="autoslide${idoff}"
+ idoff="$((idoff + 1))"
+ printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
+ "${tag%<slide*}" "$next" "$idoff" "$next" "${tag#*<slide}"
+ tag='' depth=$((depth + 1))
+ ;;
+ *\</slide\>*) # Insert "previous" button
+ printf '%s</div><a class="prevslide" href="#%s">previous</a>%s' \
+ "${tag%</slide>*}" "$prev" "${tag#*</slide>}"
+ tag='' depth=$((depth - 1))
+ ;;
+ *\<body*\>*) # Insert toplevel link
+ printf '%s<a href="#" class="toplevel">overview</a>' "$tag"
+ tag='' depth=$((depth + 1))
+ ;;
+ *\</body*\>*) # Insert total slide count
+ printf '<span class="count">%i</span>%s' "$idoff" "$tag"
+ tag='' depth=$((depth - 1))
+ ;;
+ *\<*class=\"uncover\"*\>*) # Insert checkboxes in "uncover" lists
+ #printf '%s<li></li>' "$tag"
+ printf '%s' "$tag"
+ tag='' depth=$((depth + 1))
+ ucdepth=$depth
+ ;;
+ *\</*\>*)
+ printf %s "$tag"
+ tag='' depth=$((depth - 1))
+ [ $depth -lt $ucdepth ] && ucdepth=-1
+ ;;
+ *\<*\>*)
+ if [ $ucdepth = $depth ]; then
+ printf '%s<input type="checkbox" class="uncover"/><%s' "${tag%<*}" "${tag#*<}"
+ else
+ printf %s "$tag"
+ fi
+ [ "${tag}" = "${tag%/>}" ] && depth=$((depth + 1))
+ tag=''
+ ;;
+ *) :
+ ;;
+ esac
+ done
+}
--- /dev/null
+[!DOCTYPE HTML]
+[html [head
+ [title Demo]
+][body
+ [footer Paul Hänsch | Linux-Grundkurs | VHS Chemnitz]
+ [slide
+ [h1 Folie A]
+ [ul .uncover
+ [li Eins]
+ [li Zwei]
+ [li Drei]
+ [li Vier]
+ [li Fünf]
+ ]
+ ][slide
+ [h1 Folie B]
+ foo bar qua spam eggs bacon jam elephant
+ [ol .uncover [li x] [li y] [li z]]
+ giraffe sabertooth kitten vegetarian
+ ]
+ [slide [h1 Slide]] [slide [h1 Slide]] [slide [h1 Slide]] [slide [h1 Slide]]
+]]
--- /dev/null
+[html [head
+ [title ClickSlide Demo]
+] [body
+ [footer Clickslide Demo]
+
+ [slide
+ [h1 Clickslide]
+ a Compiler for Browser based Slideshows
+ ]
+ [slide
+ [ul
+ [li Why would I write another Slideshow system]
+ [li What's wrong with JavaScript?]
+ [li How do you simplify HTML?]
+ ]
+ ]
+ [slide
+ [h2 Why Write another Slideshow System?]
+ [ul .uncover
+ [li WYSIWYG Slideshow applications are annoying [ul
+ [li too much fiddling, not straight to point]
+ ]]
+ [li [em LaTeX] is not exactly casual]
+ [li Existing Browser Slideshows are [ul
+ [li based on JavaScript (see next slide)]
+ [li Either verbous HTML, or unflexible markup]
+ ]]
+ ]
+ ]
+ [slide
+ [h2 Why avoid JavaScript]
+ [ul .uncover
+ [li Nothing wrong with JS as a programming language, [strong but...]]
+ [li Freedom to [em Use], [em Study], [em Share], and [em Improve] can in practice not be applied to code served from another Computer (regardless of the license this code is under)]
+ [li Impossible to get Browser security straight for Turing complete programs [ul
+ [li → Massive security problems, which are fundamentally unresolvable]
+ [li HTML and CSS are not Turing complete (CSS is a [em regular] language)]
+ ]]
+ [li Performance killer in practice]
+ ]
+ ]
+ [slide [h2 Simplifying HTML]
+ Maintain the flexibility of plain HTML. Decrease verbosity of the code. [br]
+ [pre style="display: inline-block; width: 46%; background-image: url(exb0_light.jpg);"
+\<html\>
+ \<head\>
+ \<title\>Demo\</title\>
+ \</head\>
+ \<body id="frontpage"\>
+ \<h1 class="top"\>Headline\</h1\>
+ \</body\>
+\</html\>
+ ]
+ [pre style="display: inline-block; width: 46%; background-image: url(exb3_light.jpg);"
+\[html
+ \[head
+ \[title Demo\]
+ \]
+ \[body \#frontpage
+ \[h1 .top Headline\]
+ \]
+\]
+ ]
+ ]
+ [slide [h1 This is a \<h1\>]
+ [pre \[h1 This is a \\\<h1\\\>\]]
+ ]
+ [slide
+ [h2 This is a \<h2\>]
+ [pre
+ \[h2 This is a \\\<h2\\\>\]
+ \[ul .uncover
+ \[li This list ...\]
+ \[li ... gets uncovered ...\]
+ \[li ... item by item\]
+ \]
+ ]
+ [br]
+ [ul .uncover
+ [li This list ...]
+ [li ... gets uncovered ...]
+ [li ... item by item]
+ ]
+ ]
+]