diff --git a/AN/Tools.pm b/AN/Tools.pm index d227c400..d609df63 100755 --- a/AN/Tools.pm +++ b/AN/Tools.pm @@ -35,6 +35,7 @@ use AN::Tools::Alert; use AN::Tools::Get; use AN::Tools::Log; use AN::Tools::Storage; +use AN::Tools::Template; use AN::Tools::Words; use AN::Tools::Validate; @@ -105,6 +106,7 @@ sub new GET => AN::Tools::Get->new(), LOG => AN::Tools::Log->new(), STORAGE => AN::Tools::Storage->new(), + TEMPLATE => AN::Tools::Template->new(), WORDS => AN::Tools::Words->new(), VALIDATE => AN::Tools::Validate->new(), }, @@ -129,6 +131,7 @@ sub new $an->Get->parent($an); $an->Log->parent($an); $an->Storage->parent($an); + $an->Template->parent($an); $an->Words->parent($an); $an->Validate->parent($an); @@ -314,6 +317,18 @@ sub Storage return ($self->{HANDLE}{STORAGE}); } +=head2 Template + +Access the C methods via 'C<< $an->Template->method >>'. + +=cut +sub Template +{ + my $self = shift; + + return ($self->{HANDLE}{TEMPLATE}); +} + =head2 Words Access the C methods via 'C<< $an->Words->method >>'. @@ -481,6 +496,9 @@ sub _set_defaults server => "", tag => "an-tools", }, + template => { + html => "alteeve", + }, }; return(0); @@ -503,6 +521,9 @@ sub _set_paths hostname => "/bin/hostname", logger => "/usr/bin/logger", }, + source => { + skins => "/var/www/html/skins", + }, words => { 'an-tools.xml' => "/usr/share/perl5/AN/an-tools.xml", }, @@ -533,7 +554,7 @@ sub _set_paths } } } - } + }; return(0); } diff --git a/AN/Tools/Template.pm b/AN/Tools/Template.pm new file mode 100755 index 00000000..a08332e1 --- /dev/null +++ b/AN/Tools/Template.pm @@ -0,0 +1,236 @@ +package AN::Tools::Template; +# +# This module contains methods used to handle templates. +# + +use strict; +use warnings; +use Data::Dumper; + +our $VERSION = "3.0.0"; +my $THIS_FILE = "Template.pm"; + +### Methods; +# get + +=pod + +=encoding utf8 + +=head1 NAME + +AN::Tools::Template + +Provides all methods related to template handling. + +=head1 SYNOPSIS + + use AN::Tools; + + # Template a common object handle on all AN::Tools modules. + my $an = AN::Tools->new(); + + # Access to methods using '$an->Template->X'. + # + # Example using '()'; + + +=head1 METHODS + +Methods in this module; + +=cut +sub new +{ + my $class = shift; + my $self = { + SKIN => { + HTML => "", + }, + }; + + bless $self, $class; + + return ($self); +} + +# Get a handle on the AN::Tools object. I know that technically that is a sibling module, but it makes more +# sense in this case to think of it as a parent. +sub parent +{ + my $self = shift; + my $parent = shift; + + $self->{HANDLE}{TOOLS} = $parent if $parent; + + return ($self->{HANDLE}{TOOLS}); +} + + +############################################################################################################# +# Public methods # +############################################################################################################# + +=head2 get + +This method takes a template file name and a template section name and returns that body template. + + my $body = $an->Template->get({file => "foo.html", name => "bar"})) + +=head2 Parameters; + +=head3 file (required) + +This is the name of the template file containing the template section you want to read. + +=head3 name (required) + +This is the name of the template section, bounded by 'C<< >>' and 'C<< >>' to read in from the file. + +=head3 skin (optional) + +By default, the + +=cut +sub get +{ + my $self = shift; + my $parameter = shift; + my $an = $self->parent; + + my $file = defined $parameter->{file} ? $parameter->{file} : ""; + my $name = defined $parameter->{name} ? $parameter->{name} : ""; + my $skin = defined $parameter->{skin} ? $parameter->{skin} : ""; + my $template = ""; + my $source = ""; + + my $error = 0; + if (not $file) + { + print $THIS_FILE." ".__LINE__."; [ Error ] - No template file passed to Template->get().\n"; + $error = 1; + } + else + { + # Make sure the file exists. + if ($skin) + { + $source = $an->data->{path}{source}{skins}."/".$skin."/".$file; + print $THIS_FILE." ".__LINE__."; [ Debug ] - source: [$source]\n"; + } + else + { + $source = $an->Template->skin."/".$file; + print $THIS_FILE." ".__LINE__."; [ Debug ] - source: [$source]\n"; + } + if (not -e $source) + { + print $THIS_FILE." ".__LINE__."; [ Error ] - No requested template file: [".$source."] does not exist. Is it missing in the active skin?\n"; + $error = 1; + } + elsif (not -r $source) + { + my $user_name = getpwuid($<); + $user_name = $< if not $user_name; + print $THIS_FILE." ".__LINE__."; [ Error ] - The requested template file: [".$source."] is not readable. Please check that it is readable by the webserver user: [$user_name]\n"; + $error = 1; + } + } + if (not $name) + { + print $THIS_FILE." ".__LINE__."; [ Error ] - No template file passed to Template->get().\n"; + $error = 1; + } + + if (not $error) + { + my $in_template = 0; + my $shell_call = $source; + open(my $file_handle, "<$shell_call") or warn $THIS_FILE." ".__LINE__."; Failed to read: [$shell_call], error was: $!\n"; + while(<$file_handle>) + { + chomp; + my $line = $_; + if ($line =~ /^/) + { + $in_template = 1; + } + if ($in_template) + { + if ($line =~ /^/) + { + $in_template = 0; + last; + } + else + { + $template .= $line."\n"; + } + } + } + close $file_handle; + } + + return($template); +} + + +=head2 skin + +This sets or returns the active skin used when rendering web output. + +The default skin is set via 'C<< defaults::template::html >>' and it must be the same as the directory name under 'C<< /var/www/html/skins/ >>'. + +Get the active skin; + + my $skin = $an->Template->skin; + +Set the active skin to 'C<< foo >>'. + + $an->Template->skin({set => "foo"}); + +Disable sensitive log entry recording. + + $an->Log->secure(0); + +=cut +sub skin +{ + my $self = shift; + my $parameter = shift; + my $an = $self->parent; + + my $set = defined $parameter->{skin} ? $parameter->{skin} : ""; + + if ($set) + { + my $skin_directory = $an->data->{path}{source}{skins}."/".$set; + if (-d $skin_directory) + { + $self->{SKIN}{HTML} = $skin_directory + } + else + { + print $THIS_FILE." ".__LINE__."; [ Warning ] - Asked to set the skin: [$set], but the source directory: [$skin_directory] doesn't exist. Ignoring.\n"; + } + } + + if (not $self->{SKIN}{HTML}) + { + $self->{SKIN}{HTML} = $an->data->{path}{source}{skins}."/".$an->data->{defaults}{template}{html}; + } + + return($self->{SKIN}{HTML}); +} + +# =head3 +# +# Private Functions; +# +# =cut + +############################################################################################################# +# Private functions # +############################################################################################################# + +1; diff --git a/AN/tools.conf b/AN/tools.conf index 1573f752..722e04e0 100644 --- a/AN/tools.conf +++ b/AN/tools.conf @@ -33,3 +33,9 @@ # This sets the default log tag used when logging an entry. Most programs will likely override this. #defaults::log::tag = an-tools + + +### Templates +# This sets the default template used when rendering HTML pages. It must be the same as the directory name +# under /var/www/html/skins/ +#defaults::template::html = alteeve diff --git a/cgi-bin/home b/cgi-bin/home new file mode 100755 index 00000000..04a63e13 --- /dev/null +++ b/cgi-bin/home @@ -0,0 +1,18 @@ +#!/usr/bin/perl +# +use strict; +use warnings; +use AN::Tools; + +my $an = AN::Tools->new(); + +my $THIS_FILE = "home"; + +# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. +$| = 1; + +print "Content-type: text/html; charset=utf-8\n\n"; +print "hello.\n"; + + +exit(0); diff --git a/html/favicon.ico b/html/favicon.ico new file mode 100644 index 00000000..9fa22e1c Binary files /dev/null and b/html/favicon.ico differ diff --git a/html/index.html b/html/index.html new file mode 100644 index 00000000..bb5d5fd6 --- /dev/null +++ b/html/index.html @@ -0,0 +1,8 @@ + + + Striker + + + + Hi, I'll be right with you... + diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html new file mode 100644 index 00000000..697b9e63 --- /dev/null +++ b/html/skins/alteeve/main.html @@ -0,0 +1,38 @@ + +#!replace!header!# + + + + + + + + + + + + + + + +
+ #!replace!left_top_bar!# + + #!replace!center_top_bar!# + + #!replace!right_top_bar!# +
+ #!replace!center_body!# +
+ #!replace!left_bottom_bar!# + + #!replace!center_bottom_bar!# + + #!replace!right_bottom_bar!# +
+ +#!replace!footer!# + + + +