* Added the loading of the CGI module when the environment is set to 'html'.

* Added a check to Database->archive_database() to return immediately if the check_tables array is empty.
* Created the new Get->cgi() method that reads in CGI variables (as set by the special 'cgi_list' variable).
* Got more work done on the config_step1 funtions.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent fdc8850dfe
commit c962a9ac79
  1. 12
      AN/Tools.pm
  2. 10
      AN/Tools/Database.pm
  3. 70
      AN/Tools/Get.pm
  4. 2
      AN/Tools/Template.pm
  5. 1
      AN/an-tools.xml
  6. 77
      cgi-bin/home
  7. 8
      cgi-bin/words.xml
  8. 24
      html/skins/alteeve/main.css
  9. 43
      html/skins/alteeve/main.html

@ -282,9 +282,17 @@ sub environment
my ($an) = shift; my ($an) = shift;
weaken($an); weaken($an);
# Pick up the passed in delimiter, if any. # 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}); return ($an->{ENV_VALUES}{ENVIRONMENT});
} }

@ -108,6 +108,12 @@ sub archive_database
my $an = $self->parent; my $an = $self->parent;
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0125", variables => { method => "Database->archive_database()" }}); $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' # 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. # 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}})) foreach my $table (reverse(@{$an->data->{sys}{database}{check_tables}}))
@ -2888,8 +2894,10 @@ sub write
reenter => $reenter, reenter => $reenter,
}}); }});
print $THIS_FILE." ".__LINE__."; ID: [$id], query: [$query]\n";
# Make logging code a little cleaner # 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"; #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. # We don't check if ID is set here because not being set simply means to write to all available DBs.

@ -7,11 +7,13 @@ use strict;
use warnings; use warnings;
use Scalar::Util qw(weaken isweak); use Scalar::Util qw(weaken isweak);
use Data::Dumper; use Data::Dumper;
use Encode;
our $VERSION = "3.0.0"; our $VERSION = "3.0.0";
my $THIS_FILE = "Get.pm"; my $THIS_FILE = "Get.pm";
### Methods; ### Methods;
# cgi
# date_and_time # date_and_time
# host_uuid # host_uuid
# network_details # network_details
@ -83,6 +85,74 @@ sub parent
# Public methods # # 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 =head2 date_and_time
This method returns the date and/or time using either the current time, or a specified unix time. This method returns the date and/or time using either the current time, or a specified unix time.

@ -116,7 +116,7 @@ sub get
my $parameter = shift; my $parameter = shift;
my $an = $self->parent; my $an = $self->parent;
my $debug = 1; my $debug = 3;
my $file = defined $parameter->{file} ? $parameter->{file} : ""; my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $language = defined $parameter->{language} ? $parameter->{language} : $an->Words->language; my $language = defined $parameter->{language} ? $parameter->{language} : $an->Words->language;
my $name = defined $parameter->{name} ? $parameter->{name} : ""; my $name = defined $parameter->{name} ? $parameter->{name} : "";

@ -197,6 +197,7 @@ The database connection error was:
<key name="log_0126">Exiting method: [#!variable!method!#]</key> <key name="log_0126">Exiting method: [#!variable!method!#]</key>
<key name="log_0127">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').</key> <key name="log_0127">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').</key>
<key name="log_0128">Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it.</key> <key name="log_0128">Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it.</key>
<key name="log_0129">all</key> <!-- Used when logging DB writes to all DBs -->
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. --> <!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key> <key name="t_0000">Test</key>

@ -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. # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1; $| = 1;
# Read in any CGI variables, if needed.
$an->Get->cgi();
$an->data->{skin}{url} = $an->data->{path}{urls}{skins}."/".$an->Template->skin; $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 $header = $an->Template->get({file => "main.html", name => "header", variables => { language => $an->Words->language }});
my $body = ""; my $body = "";
# This will be true when the dashboard is unconfigured. # This will be true when the dashboard is unconfigured.
if (1) if (not $an->data->{cgi}{step})
{ {
$body = config_step1($an); $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 else
{ {
$body = get_network_details($an); $body = get_network_details($an);
@ -63,6 +81,27 @@ exit(0);
# Functions # # 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. # This is step 1 in asking the user how to configure Striker.
sub config_step1 sub config_step1
{ {
@ -75,12 +114,44 @@ sub config_step1
{ {
# Old config exists. Load the detail and present the option to reload. # 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 => { my $step1_body = $an->Template->get({file => "main.html", name => "config_step1", variables => {
step1_welcome_title_id => "", step1_welcome_title_id => "",
step1_welcome_message_id => "", step1_welcome_message_id => "",
reload_option => "", organization_form => $say_organization,
question_form => "", 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); return($step1_body);
} }

@ -18,6 +18,7 @@ This is the AN::Tools master 'words' file.
<key name="brand_0003">Striker</key> <key name="brand_0003">Striker</key>
<key name="brand_0004">ScanCore</key> <key name="brand_0004">ScanCore</key>
<key name="brand_0005"><![CDATA[&copy; 2017 <a href="https://alteeve.com/" target="_new">Alteeve's Niche! Inc.</a>, Toronto, Ontario, Canada]]></key> <key name="brand_0005"><![CDATA[&copy; 2017 <a href="https://alteeve.com/" target="_new">Alteeve's Niche! Inc.</a>, Toronto, Ontario, Canada]]></key>
<key name="brand_0006"><![CDATA[<i>Anvil!</i>]]></key>
<key name="header_0001">Network Interfaces</key> <key name="header_0001">Network Interfaces</key>
<key name="header_0002">MAC Address</key> <key name="header_0002">MAC Address</key>
@ -28,6 +29,13 @@ This is the AN::Tools master 'words' file.
<!-- General strings shown in Striker --> <!-- General strings shown in Striker -->
<key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard!</key> <key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard!</key>
<key name="striker_0002">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!</key> <key name="striker_0002">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!</key>
<key name="striker_0003">Organization name</key>
<key name="striker_0004">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.</key>
<key name="striker_0005">Prefix</key>
<key name="striker_0006">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.</key>
<key name="striker_0007">Internet-Facing Network Count</key>
<key name="striker_0008"><![CDATA[How many internal networks will this dashboard have access to? In most cases, this is just '1'.<br /><b>NOTE</b>: 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.]]></key>
<key name="striker_0009">Next</key>
<!-- These are works and strings used by javascript/jqery --> <!-- These are works and strings used by javascript/jqery -->
<key name="js_0001">Up</key> <key name="js_0001">Up</key>

@ -10,6 +10,30 @@ Colours;
- Footer text: #515151 - 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 { body {
font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif; font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif;
background-image: url("/skins/alteeve/images/Texture.jpg"); background-image: url("/skins/alteeve/images/Texture.jpg");

@ -19,6 +19,8 @@
<!-- start config_step1 --> <!-- start config_step1 -->
<table> <table>
<div id="config_step1_div">
<form name="config_step1" action="">
<tr> <tr>
<td> <td>
<span name="#!variable!step1_welcome_title_id!#" id="#!variable!step1_welcome_title_id!#" class="config_header1">#!string!striker_0001!#</span><br /> <span name="#!variable!step1_welcome_title_id!#" id="#!variable!step1_welcome_title_id!#" class="config_header1">#!string!striker_0001!#</span><br />
@ -27,17 +29,54 @@
</tr> </tr>
<tr> <tr>
<td> <td>
#!variable!reload_option!# <hr>
&nbsp;
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
#!variable!question_form!# #!variable!organization_form!#
</td> </td>
</tr> </tr>
<tr>
<td>
#!variable!prefix_form!#
</td>
</tr>
<tr>
<td>
#!variable!ifn_count_form!#
</td>
</tr>
<tr>
<td>
<br />
<hr>
<input type="submit" name="next" id="next" value="#!string!striker_0009!#">
</td>
</tr>
<input type="hidden" name="step" id="step" value="step1">
<input type="hidden" name="cgi_list" id="cgi_list" value="next,step,#!variable!cgi_list!#">
</form>
</div>
</table> </table>
<!-- end config_step1 --> <!-- end config_step1 -->
<!-- start select_form -->
#!variable!description!#<br />
<input type="select" name="#!variable!name!#" id="#!variable!id!#" #!variable!extra!#>#!variable!options!#</select>
<!-- end select_form -->
<!-- start input_text_form -->
<span id="description_id">#!variable!description!#</span><br />
<input type="text" name="#!variable!name!#" id="#!variable!id!#" value="#!variable!value!#" placeholder="#!variable!field!#" #!variable!extra!#>
<!-- end input_text_form -->
<!-- start input_number_form -->
<span id="description_id">#!variable!description!#</span><br />
<input type="number" name="#!variable!name!#" id="#!variable!id!#" value="#!variable!value!#" placeholder="#!variable!field!#" #!variable!extra!#>
<!-- end input_number_form -->
<!-- start footer --> <!-- start footer -->
<div onload="show_status()" class="footer"> <div onload="show_status()" class="footer">
#!string!brand_0005!# #!string!brand_0005!#

Loading…
Cancel
Save