remove-user.sh: improve robustness
[girocco.git] / cgi / html.cgi
blob2c108f1e62a8eae4125fe2c9c219691446d02cb2
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;
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 # /@@ifmob@@...@@end@@/ remove unless mob defined
19 # /@@ifssh@@...@@end@@/ remove unless pushurl defined
20 # /@@ifhttps@@...@@end@@/ remove unless httpspushurl defined
22 my $pathinfo = $ENV{PATH_INFO};
23 $pathinfo =~ s,^/,,;
24 unless ($pathinfo) {
25 my $gcgi = Girocco::CGI->new('HTML Templater');
26 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
27 exit;
30 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
31 my $gcgi = Girocco::CGI->new('HTML Templater');
32 print "<p>Invalid template name.</p>\n";
33 exit;
36 if ($pathinfo =~ /\.png$/) {
37 print "Content-type: image/png\n\n";
38 print while (<TEMPLATE>);
39 exit;
42 my ($gcgi, $section, $heading);
44 my $template=join('', <TEMPLATE>);
45 close TEMPLATE;
46 $template =~ s/@\@ifmob@\@(.*?)@\@end@\@/$Girocco::Config::mob?$1:''/ges;
47 $template =~ s/@\@ifssh@\@(.*?)@\@end@\@/$Girocco::Config::pushurl?$1:''/ges;
48 $template =~ s/@\@ifhttps@\@(.*?)@\@end@\@/$Girocco::Config::httpspushurl?$1:''/ges;
50 foreach (split(/\n/, $template)) {
51 chomp;
52 if (s/^\@section=//) {
53 $section = $_;
54 next;
55 } elsif (s/^\@heading=//) {
56 $heading = $_;
57 next;
58 } elsif (s/^\@header//) {
59 $gcgi = Girocco::CGI->new($heading, $section);
60 next;
61 } else {
62 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
63 print "$_\n";
67 $gcgi and $gcgi->srcname("html/$pathinfo");