From a6a6efcbdceb69ef4b70e88447901375aa30d093 Mon Sep 17 00:00:00 2001 From: Marius Halden Date: Sat, 14 Feb 2015 17:22:36 +0100 Subject: Added basic support for templates for the web interface --- sitesummary-makewebreport | 84 ++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) (limited to 'sitesummary-makewebreport') diff --git a/sitesummary-makewebreport b/sitesummary-makewebreport index bedad22..dfbcb41 100755 --- a/sitesummary-makewebreport +++ b/sitesummary-makewebreport @@ -1,44 +1,40 @@ -#!/bin/sh -# -# Make simple web page with summary information. This should be rewritten -# to use some template system and be more flexible. -# - -( -cat < - - -sitesummary report - - -

sitesummary report

-EOF - -for f in site-summary \ - hostclass-summary \ - kernelversion-summary \ - agesinceseen-summary \ - hardware-model-summary \ - debian_edu-summary ; do - echo "

$f

" - echo "
"
-    /usr/lib/sitesummary/$f
-    echo "
" - echo -done - -# Add last updated string -echo "
" -echo -n "

Last updated: " -date -echo "

" - -cat < - -EOF -) > /var/lib/sitesummary/www/index.html - -exit 0 +#!/usr/bin/env perl + +use strict; +use warnings; +use Template; +use POSIX qw(strftime); + +my $outfile = "/var/lib/sitesummary/www/index.html"; +my $tplfile = "/usr/share/sitesummary/www/default.html"; + +my $tpl = Template->new(); + +my @cmds = qw( + site-summary + hostclass-summary + kernelversion-summary + agesinceseen-summary + hardware-model-summary + debian_edu-version + ); + +my $vars = {}; + +for my $cmd (@cmds) { + $vars->{'results'}->{$cmd} = `/usr/lib/sitesummary/$cmd`; +} + +$vars->{'last_updated'} = strftime("%a %b %d %H:%M:%S %Z %Y", localtime); + +$tpl->process($tplfile, $vars, \&write_out); + +exit 0; + +sub write_out { + my $output = shift; + + open FH, ">$outfile"; + print FH "$output"; + close FH; +} -- cgit v1.2.3