Do not require /bin/bash
[girocco.git] / cgi / html.cgi
blob2103693a934a9525a0e92a438f0a3193b8f7b4d2
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Util;
13 # Ultra-trivial templating engine;
14 # /^@section=SECTION
15 # /^@heading=HEADING
16 # /^@header produces HTML header based on @section and @heading
17 # /@@gitweburl@@/ substitute for gitweburl configuration variable
18 # /@@base(gitweburl)@@/ substitute for base portion of gitweburl variable
19 # /@@path(gitweburl)@@/ substitute for path portion of gitweburl variable
20 # /@@server(gitweburl)@@/ replace scheme://host:port portion of gitweburl variable
21 # /@@ifmob@@...@@end@@/ remove unless mob defined
22 # /@@ifssh@@...@@end@@/ remove unless pushurl defined
23 # /@@ifhttps@@...@@end@@/ remove unless httpspushurl defined
25 my $pathinfo = $ENV{PATH_INFO} || '';
26 $pathinfo =~ s,^/,,;
27 unless ($pathinfo) {
28 my $gcgi = Girocco::CGI->new('HTML Templater');
29 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
30 exit;
33 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
34 my $gcgi = Girocco::CGI->new('HTML Templater');
35 print "<p>Invalid template name.</p>\n";
36 exit;
39 if ($pathinfo =~ /\.png$/) {
40 print "Content-type: image/png\n\n";
41 print while (<TEMPLATE>);
42 exit;
45 my ($gcgi, $section, $heading);
47 my $template=join('', <TEMPLATE>);
48 close TEMPLATE;
49 $template =~ s/@\@ifmob@\@(.*?)@\@end@\@/$Girocco::Config::mob?$1:''/ges;
50 $template =~ s/@\@ifssh@\@(.*?)@\@end@\@/$Girocco::Config::pushurl?$1:''/ges;
51 $template =~ s/@\@ifhttps@\@(.*?)@\@end@\@/$Girocco::Config::httpspushurl?$1:''/ges;
53 foreach (split(/\n/, $template)) {
54 chomp;
55 if (s/^\@section=//) {
56 $section = $_;
57 next;
58 } elsif (s/^\@heading=//) {
59 $heading = $_;
60 next;
61 } elsif (s/^\@header//) {
62 $gcgi = Girocco::CGI->new($heading, $section);
63 print "<div class=\"htmlcgi\">";
64 next;
65 } else {
66 s/@\@base\((\w+?)\)@@/url_base(${$Girocco::Config::{$1}})/ge;
67 s/@\@path\((\w+?)\)@@/url_path(${$Girocco::Config::{$1}})/ge;
68 s/@\@server\((\w+?)\)@@/url_server(${$Girocco::Config::{$1}})/ge;
69 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
70 print "$_\n";
73 print "</div>";
74 $gcgi and $gcgi->srcname("html/$pathinfo");