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 --- Makefile | 4 +++ default.html | 20 +++++++++++ sitesummary-makewebreport | 84 ++++++++++++++++++++++------------------------- 3 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 default.html diff --git a/Makefile b/Makefile index 6d8d789..fb5093f 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,9 @@ SUMMARYSCRIPTS = \ kernelversion-summary \ debian_edu-summary +TEMPLATES = \ + default.html + all: install: install-server install-client @@ -47,6 +50,7 @@ install-server: $(INSTALL) -d $(DESTDIR)$(pkgdir) $(INSTALL_DATA) SiteSummary.pm $(DESTDIR)$(perldir) $(INSTALL) $(SUMMARYSCRIPTS) $(DESTDIR)$(pkgdir)/ + $(INSTALL_DATA) $(TEMPLATES) $(DESTDIR) $(pkgdatadir)/www/ $(INSTALL) expire-entry $(DESTDIR)$(pkgdir)/ diff --git a/default.html b/default.html new file mode 100644 index 0000000..fdc3b96 --- /dev/null +++ b/default.html @@ -0,0 +1,20 @@ + + + +SiteSummary report + + +

SiteSummary report

+ +[% FOREACH key IN results.keys %] +

[% key %]

+
+[% results.$key %]
+
+[% END %] + +
+

Last updated: [% last_updated %]

+ + + 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