diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | default.html | 20 | ||||
-rwxr-xr-x | sitesummary-makewebreport | 84 |
3 files changed, 64 insertions, 44 deletions
@@ -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 @@ +<!DOCTYPE html> +<html> +<head> +<title>SiteSummary report</title> +</head> +<body> +<h1>SiteSummary report</h1> + +[% FOREACH key IN results.keys %] +<h2>[% key %]</h2> +<pre> +[% results.$key %] +</pre> +[% END %] + +<hr /> +<p><b>Last updated:</b> [% last_updated %]</p> + +</body> +</html> 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 <<EOF -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" -"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> -<head> -<title>sitesummary report</title> -</head> -<body> -<h1>sitesummary report</h1> -EOF - -for f in site-summary \ - hostclass-summary \ - kernelversion-summary \ - agesinceseen-summary \ - hardware-model-summary \ - debian_edu-summary ; do - echo "<h2>$f</h2>" - echo "<pre>" - /usr/lib/sitesummary/$f - echo "</pre>" - echo -done - -# Add last updated string -echo "<hr>" -echo -n "<p><b>Last updated</b>: " -date -echo "</p>" - -cat <<EOF -</body> -</html> -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; +} |