diff --git a/AN/Tools.pm b/AN/Tools.pm index e9a99731..db86b2dc 100755 --- a/AN/Tools.pm +++ b/AN/Tools.pm @@ -282,9 +282,17 @@ sub environment my ($an) = shift; weaken($an); - # Pick up the passed in delimiter, if any. - $an->{ENV_VALUES}{ENVIRONMENT} = shift if $_[0]; + if ($_[0]) + { + $an->{ENV_VALUES}{ENVIRONMENT} = shift; + if ($an->{ENV_VALUES}{ENVIRONMENT} eq "html") + { + # Load the CGI stuff if we're in a browser + use CGI; + use CGI::Carp qw(fatalsToBrowser); + } + } return ($an->{ENV_VALUES}{ENVIRONMENT}); } diff --git a/AN/Tools/Database.pm b/AN/Tools/Database.pm index ab03137a..88481144 100755 --- a/AN/Tools/Database.pm +++ b/AN/Tools/Database.pm @@ -108,6 +108,12 @@ sub archive_database my $an = $self->parent; $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0125", variables => { method => "Database->archive_database()" }}); + # If we don't have an array of tables, we have nothing to do. + if ((not exists $an->data->{sys}{database}{check_tables}) or (ref(@{$an->data->{sys}{database}{check_tables}} ne "ARRAY"))) + { + return(0); + } + # We'll use the list of tables created for _find_behind_databases()'s 'sys::database::check_tables' # array, but in reverse so that tables with primary keys (first in the array) are archived last. foreach my $table (reverse(@{$an->data->{sys}{database}{check_tables}})) @@ -2888,8 +2894,10 @@ sub write reenter => $reenter, }}); + print $THIS_FILE." ".__LINE__."; ID: [$id], query: [$query]\n"; + # Make logging code a little cleaner - my $say_server = $an->data->{database}{$id}{host}.":".$an->data->{database}{$id}{port}." -> ".$an->data->{database}{$id}{name}; + my $say_server = $id eq "" ? "#!string!log_0129!#" : $an->data->{database}{$id}{host}.":".$an->data->{database}{$id}{port}." -> ".$an->data->{database}{$id}{name}; #print "id: [$id], say_server: [$say_server]\n"; # We don't check if ID is set here because not being set simply means to write to all available DBs. diff --git a/AN/Tools/Get.pm b/AN/Tools/Get.pm index 3ee38bd1..c98cb80c 100755 --- a/AN/Tools/Get.pm +++ b/AN/Tools/Get.pm @@ -7,11 +7,13 @@ use strict; use warnings; use Scalar::Util qw(weaken isweak); use Data::Dumper; +use Encode; our $VERSION = "3.0.0"; my $THIS_FILE = "Get.pm"; ### Methods; +# cgi # date_and_time # host_uuid # network_details @@ -83,6 +85,74 @@ sub parent # Public methods # ############################################################################################################# +=head2 cgi + +This reads in the CGI variables passed in by a form or URL. + +This will read the 'cgi_list' CGI variable for a comma-separated list of CGI variables to read in. So your form must set this in order for this method to work. + +=cut +sub cgi +{ + my $self = shift; + my $parameter = shift; + my $an = $self->parent; + + # This will store all of the CGI variables. + $an->data->{sys}{cgi_string} = "?"; + + # Needed to read in passed CGI variables + my $cgi = CGI->new(); + + # The list of CGI variables to try and read will always be in 'cgi_list'. + my $cgis = []; + my $cgi_count = 0; + if (defined $cgi->param("cgi_list")) + { + my $cgi_list = $cgi->param("cgi_list"); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { cgi_list => $cgi_list }}); + + foreach my $variable (split/,/, $cgi_list) + { + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable => $variable }}); + push @{$cgis}, $variable; + } + + $cgi_count = @{$cgis}; + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cgi_count => $cgi_count }}); + } + + # If we don't have at least one variable, we're done. + if ($cgi_count < 1) + { + return(0); + } + + # NOTE: Later, we will have another array for handling file uploads. + # Now read in the variables. + foreach my $variable (sort {$a cmp $b} @{$cgis}) + { + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable => $variable }}); + + $an->data->{cgi}{$variable} = ""; + + if (defined $cgi->param($variable)) + { + $an->data->{cgi}{$variable} = $cgi->param($variable); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::$variable" => $an->data->{cgi}{$variable} }}); + } + + # Make this UTF8 if it isn't already. + if (not Encode::is_utf8($an->data->{cgi}{$variable})) + { + $an->data->{cgi}{$variable} = Encode::decode_utf8( $an->data->{cgi}{$variable} ); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::$variable" => $an->data->{cgi}{$variable} }}); + } + } + + return(0); +} + =head2 date_and_time This method returns the date and/or time using either the current time, or a specified unix time. diff --git a/AN/Tools/Template.pm b/AN/Tools/Template.pm index 59ebafb8..737f521c 100755 --- a/AN/Tools/Template.pm +++ b/AN/Tools/Template.pm @@ -116,7 +116,7 @@ sub get my $parameter = shift; my $an = $self->parent; - my $debug = 1; + my $debug = 3; my $file = defined $parameter->{file} ? $parameter->{file} : ""; my $language = defined $parameter->{language} ? $parameter->{language} : $an->Words->language; my $name = defined $parameter->{name} ? $parameter->{name} : ""; diff --git a/AN/an-tools.xml b/AN/an-tools.xml index c3dad266..23124b91 100644 --- a/AN/an-tools.xml +++ b/AN/an-tools.xml @@ -197,6 +197,7 @@ The database connection error was: Exiting method: [#!variable!method!#] Firewalld was not running, re-enabling it. If you do not want this behaviour, please set 'sys::daemons::restart_firewalld = 0' in the configuration file for this program (or in 'tools.conf'). Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it. + all Test diff --git a/cgi-bin/home b/cgi-bin/home index a32c5446..63ad02cf 100755 --- a/cgi-bin/home +++ b/cgi-bin/home @@ -26,14 +26,32 @@ $an->Words->read({file => $an->data->{path}{directories}{'cgi-bin'}."/words.xml" # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. $| = 1; +# Read in any CGI variables, if needed. +$an->Get->cgi(); + $an->data->{skin}{url} = $an->data->{path}{urls}{skins}."/".$an->Template->skin; my $header = $an->Template->get({file => "main.html", name => "header", variables => { language => $an->Words->language }}); my $body = ""; # This will be true when the dashboard is unconfigured. -if (1) +if (not $an->data->{cgi}{step}) { $body = config_step1($an); } +elsif ($an->data->{cgi}{step} eq "step1") +{ + # Sanity check step1. + my $sane = sanity_check_step1($an); + if ($sane) + { + # No good + $body = config_step1($an); + } + else + { + # Step 1 was sanem show step 2. + $body = config_step2($an); + } +} else { $body = get_network_details($an); @@ -63,6 +81,27 @@ exit(0); # Functions # ############################################################################################################# +# This is step2 where the user maps their network. +sub config_step2 +{ + my ($an) = @_; + + # TODO... + + return(0); +} + +# This sanity-checks step 1 and returns '1' if there was a problem. +sub sanity_check_step1 +{ + my ($an) = @_; + + my $sane = 1; + # TODO... + + return($sane); +} + # This is step 1 in asking the user how to configure Striker. sub config_step1 { @@ -75,12 +114,44 @@ sub config_step1 { # Old config exists. Load the detail and present the option to reload. } + + my $say_organization = $an->Template->get({file => "main.html", name => "input_text_form", variables => { + name => "organization", + id => "organization", + field => "#!string!striker_0003!#", + description => "#!string!striker_0004!#", + value => defined $an->data->{cgi}{organization} ? $an->data->{cgi}{organization} : "", + extra => "", + }}); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_organization => $say_organization }}); + my $say_prefix = $an->Template->get({file => "main.html", name => "input_text_form", variables => { + name => "prefix", + id => "prefix", + field => "#!string!striker_0005!#", + description => "#!string!striker_0006!#", + value => defined $an->data->{cgi}{prefix} ? $an->data->{cgi}{prefix} : "", + extra => "maxlength=\"5\"", + }}); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_prefix => $say_prefix }}); + my $say_ifn_count = $an->Template->get({file => "main.html", name => "input_number_form", variables => { + name => "ifn_count", + id => "ifn_count", + field => "#!string!striker_0007!#", + description => "#!string!striker_0008!#", + value => defined $an->data->{cgi}{ifn_count} ? $an->data->{cgi}{ifn_count} : "", + extra => "maxlength=\"2\"", + }}); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_ifn_count => $say_ifn_count }}); + my $step1_body = $an->Template->get({file => "main.html", name => "config_step1", variables => { step1_welcome_title_id => "", step1_welcome_message_id => "", - reload_option => "", - question_form => "", + organization_form => $say_organization, + prefix_form => $say_prefix, + ifn_count_form => $say_ifn_count, + cgi_list => "organization,prefix,ifn_count", }}); + $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step1_body => $step1_body }}); return($step1_body); } diff --git a/cgi-bin/words.xml b/cgi-bin/words.xml index 193f9aae..6e93ecf1 100644 --- a/cgi-bin/words.xml +++ b/cgi-bin/words.xml @@ -18,6 +18,7 @@ This is the AN::Tools master 'words' file. Striker ScanCore Alteeve's Niche! Inc., Toronto, Ontario, Canada]]> + Anvil!]]> Network Interfaces MAC Address @@ -28,6 +29,13 @@ This is the AN::Tools master 'words' file. Welcome! Lets setup your #!string!brand_0003!# dashboard! We're going to ask you a few questions so that we can set things up for your environment. If you need help at any time, just click on the "[?]" icon in the top-right. Let's get started! + Organization name + This is the name of the company, organization or division that owns or maintains this #!string!brand_0006!#. This is a descriptive field and you can enter whatever makes most sense to you. + Prefix + This is a two to five character prefix used to identify this organization. It is used as the prefix for host names for dashboards, nodes and foundation pack equipment. You can use letters and numbers and set whatever makes sense to you. + Internet-Facing Network Count + NOTE: You must have a network interface for the back-channel network, plus one for each internal network. If you have two interfaces for each network, we will setup bonds for redundancy automatically.]]> + Next Up diff --git a/html/skins/alteeve/main.css b/html/skins/alteeve/main.css index f3714f1a..756ab0ae 100644 --- a/html/skins/alteeve/main.css +++ b/html/skins/alteeve/main.css @@ -10,6 +10,30 @@ Colours; - Footer text: #515151 */ +input[type=text] { + width: 100%; + padding: 6px 10px; + margin: 2px 0; + display: inline-block; + border: 1px solid #9ba0a5; + border-radius: 2px; + box-sizing: border-box; + background-color: #343434; + color: #f7f7f7; +} + +input[type=number] { + width: 100%; + padding: 6px 10px; + margin: 2px 0; + display: inline-block; + border: 1px solid #9ba0a5; + border-radius: 2px; + box-sizing: border-box; + background-color: #343434; + color: #f7f7f7; +} + body { font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif; background-image: url("/skins/alteeve/images/Texture.jpg"); diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index acf6e2b2..d398890e 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -19,6 +19,8 @@ +
+
+ + + + + + + + + + + + +
#!string!striker_0001!#
@@ -27,17 +29,54 @@
- #!variable!reload_option!# +
+  
- #!variable!question_form!# + #!variable!organization_form!#
+ #!variable!prefix_form!# +
+ #!variable!ifn_count_form!# +
+
+
+ +
+ + #!variable!description!#
+ #!variable!options!# + + + + #!variable!description!#
+ + + + + #!variable!description!#
+ + +