]> git.plutz.net Git - busy/blob - index.cgi
implemented bitcoin donations and advertisement (via http://bitcoinadvertisers.com)
[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/permissions.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
48     <script type="text/javascript">
49     <!--
50       function show_screen(id){
51         document.getElementById(id).style.display = "inline";
52       }
53       function hide_screen(id){
54         document.getElementById(id).style.display = "none";
55       }
56     -->
57     </script>
58     
59     <!-- Script for Flattr Button -->
60     <script type="text/javascript">
61     /* <![CDATA[ */
62         (function() {
63             var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
64             s.type = 'text/javascript';
65             s.async = true;
66             s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
67             t.parentNode.insertBefore(s, t);
68         })();
69     /* ]]> */</script>
70
71   </head>
72   <body onload="init();">
73     <div id="TITLE">
74       <h1 id="NAME">$(egrep '^name=.*$' project.meta |cut -d= -f2-)</h1>
75       <span id="SLOGAN">$(egrep '^slogan=.*$' project.meta |cut -d= -f2-)</span>
76     </div>
77     <div id="USERMENU">
78 $( $LOGIN || echo '<form action="https://'${HTTP_HOST}'/login.cgi?'${QUERY_STRING:gs/&/&amp;/}'" method="post" accept-charset="UTF-8">
79                      Login:<br>
80                      <input type="text" name="user" value placeholder="Username"><br>
81                      <input type="password" name="pass" value placeholder="Password"><br>
82                      <input type="submit" value="Go!">
83                    </form>')
84 $( $LOGIN && echo "You are loggeed in as <b>${REMOTE_USER}</b><br>")
85 $( $LOGIN && $ACL_ADMIN && echo '<a href="?p=Admin">Admin</a><br>')
86 $( $LOGIN && echo '<a href="?p=Settings">My Settings</a><br>')
87     </div>
88     <div id="ACCOUNTING">
89       $(btcAddress="$(sed -rn 's:^btcAddress=(.*)$:\1:p' project.meta)"
90         flattrThingURL=$(sed -rn 's:^flattrThingURL=(.*)$:\1:p' project.meta)
91
92         grep -q 'useBitcoin=yes' project.meta && [ \! -f "QRcodes/bitcoin:${btcAddress}.png" ] &&\
93           qrencode -o "QRcodes/bitcoin:${btcAddress}.png" "bitcoin:$btcAddress"
94         grep -q 'useBitcoin=yes' project.meta && echo '
95         <a href="#" onclick="javascript:show_screen('\'btcqr\'')"><img src="http://bitcoin.it/img/bc_logo_135.png" height="60"></a>
96         <div id='btcqr' style="display:none;">
97           <a href="#" onclick="javascript:hide_screen('\'btcqr\'')">close</a><br>
98           <img src="QRcodes/bitcoin:'$btcAddress'.png"><br>
99           Address:<br><a href="bitcoin:'$btcAddress'">'$btcAddress'</a>
100         </div>
101         '
102         grep -q 'useFlattr=yes' project.meta && echo '
103         <a class="FlattrButton" style="display:none;" href="http://'${HTTP_HOST}'"></a>
104         <noscript> <a href="'$flattrThingURL'" target="_blank">
105           <img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" />
106         </a></noscript>
107       ')
108     </div>
109     <div id="MENU">
110       <a href='/?p=Home'>Home</a>
111       <a href='/?p=Wiki'>Wiki</a>
112       <a href='/?p=Subversion'>Code</a>
113       <a href='/?p=Tasks'>Tasks</a>
114     </div>
115       $(if [ -r "./${page}.page" ]; then
116         . "./${page}.page"
117         else
118         echo '<h2>Page not found or nevermore</h2>'
119         echo 'Quoth the Raven: 404'
120         fi
121       )
122   </body>
123 </html>
124 END_index.cgi
125