templates!

This commit is contained in:
Al Beano 2016-08-24 22:14:37 +01:00
parent 95e1e99be5
commit be0ec1c8d7
3 changed files with 33 additions and 4 deletions

View File

@ -6,8 +6,7 @@ chown www:www /var/www/run
install -o www -g www -m 0400 httpd.conf /etc/
echo "permit nopass root as www" >> /etc/doas.conf
curl -L https://cpanmin.us | perl - App::cpanminus
cpanm -l /var/www/perl5 FCGI Switch
perl -I /var/www/perl5/lib/perl5 -MFCGI -M5.010 -e 'say "it works"' # test perl installation
cpanm -l /var/www/perl5 FCGI Switch Template::Simple File::Slurp
install -o www -g www -m 0500 tormon/* /var/www/tormon/
echo 'echo "Starting tormon" && doas -u www /var/www/tormon/tormon.fcgi &' >> /etc/rc.local
sh /etc/rc.local # assuming tormon is the only thing in rc.local

View File

@ -4,6 +4,14 @@ use strict;
use warnings;
use FCGI;
use Switch;
use File::Slurp;
use Template::Simple;
use FindBin qw($Bin);
my $tmpl = new Template::Simple (
pre_delim => "<%",
post_delim => "%>",
);
my $sock = FCGI::OpenSocket(
"/var/www/run/tormon.sock",
@ -21,14 +29,24 @@ my $request = FCGI::Request(
while ($request->Accept() <= 0) {
print "Content-Type: text/html\n\n";
my $content;
switch ($ENV{"REQUEST_URI"}) {
case "/debug" {
use Data::Dumper;
print "<textarea>" . Dumper(\%ENV) . "</textarea>";
$content = "<textarea>" . Dumper(\%ENV) . "</textarea>";
}
case "/" {
print "Hello, world!";
$content = "Hello, world!";
}
}
my $tt = read_file("$Bin/wrapper.tt");
my $html = $tmpl->render(
$tt,
{
content => $content,
},
);
print ${$html};
}

12
tormon/wrapper.tt Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Tor Relay/Bridge Monitor</title>
<style>
body{margin:40px auto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:0 10px;font-family: serif}h1,h2,h3{line-height:1.2}
</style>
</head>
<body>
<% content %>
</body>
</html>