#!/usr/bin/perl -wT use strict; use warnings; use DBI; use CGI qw(:standard); use Date::Format; use HTML::Template; my (@keys,@values,@env_types,@servers,@loopdata); my %rowdata; my ($env_types); my $o_dbuser = "test"; my $o_dbpwd = "test"; my $cgi = CGI->new(); my $mode = $cgi->param('mode') || 'show'; my $dbh = DBI->connect("DBI:mysql:database=overall;host=10.10.10.10;port=3306", "$o_dbuser", "$o_dbpwd", {'RaiseError' => 1}); my $env_types = "SHOW TABLES FROM `overall` LIKE '%xen_env_%';"; my $sth = $dbh->prepare($env_types); $sth->execute() or die "could not execute", $sth->errstr; while (my $e = $sth->fetchrow_array) { push @env_types, $e; } $sth->finish(); my $get_servers = "SELECT `serverid` FROM `Servers`;"; my $sth0 = $dbh->prepare($get_servers); $sth0->execute(); while (my $s = $sth0->fetchrow_array()) { push @servers, $s; } $sth0->finish(); if ($mode eq 'servers') { my (@fields); my $get_summary = "SELECT * FROM `Servers`;"; my $sth0 = $dbh->prepare($get_summary); $sth0->execute(); @keys = @{$sth0->{NAME_lc}} or die "Can't get Field names due to:$!"; $sth0->finish(); push @fields, "flag\n"; push @fields, " \n"; for (@keys) { push @fields, "\n"; } for (@keys) { if ($_ eq "serverid") { push @values,"\"> \n"; push @values,"
\n"; } push @values, "\n"; } open (TMPL,">", "/tmp/servers.tmpl"); print TMPL <

@fields @values

SERVERS close(TMPL); foreach my $key (@keys) { $rowdata{$key} = $key; } push(@loopdata, \%rowdata); my $values; $get_summary = "SELECT * FROM `Servers`;"; $sth0 = $dbh->prepare($get_summary); $sth0->execute(); push @{$values}, $_ while $_ = $sth0->fetchrow_hashref(); $sth0->finish(); my $template = HTML::Template->new(filename => '/tmp/servers.tmpl', associate => $cgi,); $template->param( KEYS => \@loopdata); $template->param( VALUES => $values); print "Content-Type: text/html\n\n", $template->output; }