]> git.plutz.net Git - busy/blob - index.cgi
state project name in page title
[busy] / index.cgi
1 #!/bin/zsh
2
3 # Copyright 2011 Paul Haensch
4 # This file is part of Busy
5 #
6 # Busy is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Busy is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
18
19 umask=002
20 alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
21 . auth/acl.sh
22
23 page=$(egrep -o '(^|&)p=[a-zA-Z0-9/_-]+(&|$)' <<<"${QUERY_STRING}" |sed 's,&,,g;s,p=,,')
24
25 [ -z "$LOGIN" ] && LOGIN=false
26 [ -z "$page" ] && page=Home
27
28 if (! $LOGIN && egrep -qx "https?://${HTTP_HOST}/(session.cgi\?|write/).*" <<<"${HTTP_REFERER}"); then
29   echo -n "Location: https://${HTTP_HOST}/session.cgi?${QUERY_STRING}\n\n"
30   exit 0
31 fi
32
33 echo -n "Content-type: text/html\n\n"
34
35 cat <<END_index.cgi
36 <!DOCTYPE HTML>
37 <!-- DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" -->
38
39 <html>
40   <head>
41     <title>$(sed -rn 's:^name=(.*)$:\1:p' project.meta) - Busy</title>
42     <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
43     <link rel="stylesheet" type="text/css" href="busy.css">
44     <link rel="stylesheet" type="text/css" href="wikitext.css">
45     $([ -r "${page}.css" ] && echo '<link rel="stylesheet" type="text/css" href="'"$page"'.css">')
46     <style type="text/css"><!-- --></style>
47     <script type="text/javascript">
48     <!--
49 function show_screen(id){
50   document.getElementById(id).style.display = "inline";
51 }
52 function hide_screen(id){
53   document.getElementById(id).style.display = "none";
54 }
55     -->
56     </script>
57   </head>
58   <body onload="init();">
59     <div id="TITLE">
60       <h1 id="NAME">$(egrep '^name=.*$' project.meta |cut -d= -f2-)</h1>
61       <span id="SLOGAN">$(egrep '^slogan=.*$' project.meta |cut -d= -f2-)</span>
62     </div>
63     <div id="USERMENU">
64 $( $LOGIN || echo '<form action="https://'${HTTP_HOST}'/login.cgi?'${QUERY_STRING:gs/&/&amp;/}'" method="post" accept-charset="UTF-8">
65                      Login:<br>
66                      <input type="text" name="user" value placeholder="Username"><br>
67                      <input type="password" name="pass" value placeholder="Password"><br>
68                      <input type="submit" value="Go!">
69                    </form>')
70     </div>
71     <div id="ACCOUNTING">
72     </div>
73     <div id="MENU">
74       <a href='/?p=Home'>Home</a>
75       <a href='/?p=Wiki'>Wiki</a>
76       <a href='/?p=Subversion'>Code</a>
77       <a href='/?p=Tasks'>Tasks</a>
78     </div>
79       $(if [ -r "./${page}.page" ]; then
80         . "./${page}.page"
81         else
82         echo '<h2>Page not found or nevermore</h2>'
83         echo 'Quoth the Raven: 404'
84         fi
85       )
86   </body>
87 </html>
88 END_index.cgi
89