aboutsummaryrefslogtreecommitdiffstats
path: root/sitesummary-makewebreport
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2015-02-14 17:22:36 +0100
committerMarius Halden <marius.h@lden.org>2015-02-14 17:22:36 +0100
commita6a6efcbdceb69ef4b70e88447901375aa30d093 (patch)
treeef6d9f2566d7f1edaa0a912241c420dd0773e5c4 /sitesummary-makewebreport
parent139bdcdf9718ae0e3bfd65fb8627b21e358e0f78 (diff)
downloadsitesummary-web-template.tar.gz
sitesummary-web-template.tar.bz2
sitesummary-web-template.tar.xz
Added basic support for templates for the web interfaceweb-template
Diffstat (limited to 'sitesummary-makewebreport')
-rwxr-xr-xsitesummary-makewebreport84
1 files changed, 40 insertions, 44 deletions
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;
+}