#!/bin/zsh
# Copyright 2011 Paul Haensch
# This file is part of Busy
#
# Busy 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.
#
# Busy 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 Busy. If not, see .
umask=002
alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
. auth/permissions.sh
page=$(egrep -o '(^|&)p=[a-zA-Z0-9/_-]+(&|$)' <<<"${QUERY_STRING}" |sed 's,&,,g;s,p=,,')
[ -z "$LOGIN" ] && LOGIN=false
[ -z "$page" ] && page=Home
if (! $LOGIN && egrep -qx "https?://${HTTP_HOST}/(session.cgi\?|write/).*" <<<"${HTTP_REFERER}"); then
echo -n "Location: https://${HTTP_HOST}/session.cgi?${QUERY_STRING}\n\n"
exit 0
fi
echo -n "Content-type: text/html\n\n"
cat <$(sed -rn 's:^name=(.*)$:\1:p' project.meta) - Busy
$([ -r "${page}.css" ] && echo '')