#!/bin/sh # T2 CGI glue (C) 2004-2025 René Rebe # disable filename globbing set -f . $DOCUMENT_ROOT/webcore.conf [ "$DOCUMENT_ROOT" ] && base="$DOCUMENT_ROOT/webcore" || base="$PWD/webcore" new_date () { ls -l --time-style=long-iso "$1" | sed "s, *, ,g" | cut -d ' ' -f 6-7 } datefunc=new_date # which file to process x="$QUERY_STRING" [ "$x" ] || x=index.html [ -d "$x" ] && x="${x}index.html" dir="${x%/*}" # if sub-dir and has index.cgi, run it for dyn content, ... if [ "$dir" -a -e "$dir/index.cgi" ]; then dyn=1 y=`mktemp` if /usr/bin/time -f '%e' -o "$y.time" \ $PWD/$dir/index.cgi "$x" > "$y" then dt="Generated: in `cat "$y.time"`s" else rm $y ; # if error -> not found -> 404 fi x="$y" rm "$y.time" else dyn=0 x="${x%.html}.tmpl" dt="Last modified: `$datefunc "$x"`" fi if [[ "$x" = rss.xml* ]]; then # TODO: move to a rss.xml.cgi, ... echo "Content-type: application/rss+xml; charset=utf-8" echo echo ' T2 SDE https://t2sde.org/ en-us https://t2sde.org/t2-logo-medium.png https://t2sde.org/ ' echo "$(date -R)" wcbase="https://t2sde.org" grep 'h2\|datetime\|newslinkid\|,\n,' -e 's,<\/article,<\/item,' \ -e 's,.*

\(.*\)<\/h2>.*, \1<\/title>,' \ -e 's,.*newslinkid\" href="\(.*\)">, <link>\1<\/link>,' \ -e 's,.*<time datetime=\"\(.*\)\">.*<\/time>, <pubDate>\1<\/pubDate>,' echo '</channel> </rss>' exit elif [ ! -e "$x" ]; then echo "Status: 404 Not Found" x=404.tmpl fi echo "Content-type: text/html; charset=utf-8" echo # very ugly include file hackery ,-) sed -nf $base/webcore/include.sed "$x" | sed 'N;N;s/\n//' | sed -f - "$x" | sed -f $base/webcore/convert.sed \ -e "s,WCDEFAULTMENU,$wcdefaultmenu," \ -e "s,WCCUSTOMHEADER,$wccustomheader," \ -e "s,WCCOPYRIGHT,$wccopyright," \ -e "s,WCBASE,$wcbase,g" -e "s/WCDATE/$dt/" || true # remove temp file (we only need due to the sed include hack) [ $dyn = 1 ] && rm $x