* Added binary uploading to Get->cgi and moved the variable store to 'cgi::<variable>::value'. Also added "pretty" variable logging for passed-in CGI variables.

* Added fields for domain and sequence to config_step1 in 'home' CGI script.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent c962a9ac79
commit 3ac52e1724
  1. 101
      AN/Tools/Get.pm
  2. 36
      cgi-bin/home
  3. 10
      cgi-bin/words.xml
  4. 12
      html/skins/alteeve/main.html

@ -91,6 +91,8 @@ 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.
If the variable 'file' is passed, it will be treated as a binary stream containing an uploaded file.
=cut
sub cgi
{
@ -110,7 +112,7 @@ sub cgi
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 }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cgi_list => $cgi_list }});
foreach my $variable (split/,/, $cgi_list)
{
@ -132,24 +134,105 @@ sub cgi
# 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->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable => $variable }});
$an->data->{cgi}{$variable} = "";
$an->data->{cgi}{$variable}{value} = "";
$an->data->{cgi}{$variable}{mimetype} = "string";
$an->data->{cgi}{$variable}{filehandle} = "";
if ($variable eq "file")
{
if (not $cgi->upload($variable))
{
# Empty file passed, looks like the user forgot to select a file to upload.
#$an->Log->entry({log_level => 3, message_key => "log_0016", file => $THIS_FILE, line => __LINE__});
}
else
{
$an->data->{cgi}{$variable}{filehandle} = $cgi->upload($variable);
my $file = $an->data->{cgi}{$variable}{filehandle};
$an->data->{cgi}{$variable}{mimetype} = $cgi->uploadInfo($file)->{'Content-Type'};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
variable => $variable,
"cgi::${variable}::filehandle" => $an->data->{cgi}{$variable}{filehandle},
"cgi::${variable}::mimetype" => $an->data->{cgi}{$variable}{mimetype},
}});
}
}
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 (Encode::is_utf8($cgi->param($variable)))
{
$an->data->{cgi}{$variable}{value} = $cgi->param($variable);
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "cgi::${variable}::value" => $an->data->{cgi}{$variable}{value} }});
}
else
{
$an->data->{cgi}{$variable}{value} = Encode::decode_utf8($cgi->param($variable));
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "cgi::${variable}::value" => $an->data->{cgi}{$variable}{value} }});
}
# Append to 'sys::cgi_string'
$an->data->{sys}{cgi_string} .= "$variable=".$an->data->{cgi}{$variable}{value}."&";
}
}
# This is a pretty way of displaying the passed-in CGI variables. It loops through all we've got and
# sorts out the longest variable name. Then it loops again, appending '.' to shorter ones so that
# everything is lined up in the logs.
my $debug = 2;
if ($an->Log->level >= $debug)
{
my $longest_variable = 0;
foreach my $variable (sort {$a cmp $b} keys %{$an->data->{cgi}})
{
next if $an->data->{cgi}{$variable} eq "";
if (length($variable) > $longest_variable)
{
$longest_variable = length($variable);
}
}
# Make this UTF8 if it isn't already.
if (not Encode::is_utf8($an->data->{cgi}{$variable}))
# Now loop again in the order that the variables were passed is 'cgi_list'.
foreach my $variable (@{$cgis})
{
$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} }});
next if $an->data->{cgi}{$variable} eq "";
my $difference = $longest_variable - length($variable);
my $say_value = "value";
if ($difference == 0)
{
# Do nothing
}
elsif ($difference == 1)
{
$say_value .= " ";
}
elsif ($difference == 2)
{
$say_value .= " ";
}
else
{
my $dots = $difference - 2;
$say_value .= " ";
for (1 .. $dots)
{
$say_value .= ".";
}
$say_value .= " ";
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cgi::${variable}::$say_value" => $an->data->{cgi}{$variable}{value},
}});
}
}
# Clear the last &
$an->data->{sys}{cgi_string} =~ s/&$//;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::cgi_string" => $an->data->{sys}{cgi_string} }});
return(0);
}

@ -33,11 +33,11 @@ $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 (not $an->data->{cgi}{step})
if (not $an->data->{cgi}{step}{value})
{
$body = config_step1($an);
}
elsif ($an->data->{cgi}{step} eq "step1")
elsif ($an->data->{cgi}{step}{value} eq "step1")
{
# Sanity check step1.
my $sane = sanity_check_step1($an);
@ -120,7 +120,7 @@ sub config_step1
id => "organization",
field => "#!string!striker_0003!#",
description => "#!string!striker_0004!#",
value => defined $an->data->{cgi}{organization} ? $an->data->{cgi}{organization} : "",
value => defined $an->data->{cgi}{organization}{value} ? $an->data->{cgi}{organization}{value} : "",
extra => "",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_organization => $say_organization }});
@ -129,16 +129,34 @@ sub config_step1
id => "prefix",
field => "#!string!striker_0005!#",
description => "#!string!striker_0006!#",
value => defined $an->data->{cgi}{prefix} ? $an->data->{cgi}{prefix} : "",
value => defined $an->data->{cgi}{prefix}{value} ? $an->data->{cgi}{prefix}{value} : "",
extra => "maxlength=\"5\"",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_prefix => $say_prefix }});
my $say_domain = $an->Template->get({file => "main.html", name => "input_text_form", variables => {
name => "domain",
id => "domain",
field => "#!string!striker_0007!#",
description => "#!string!striker_0008!#",
value => defined $an->data->{cgi}{domain}{value} ? $an->data->{cgi}{domain}{value} : "",
extra => "maxlength=\"255\"",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_domain => $say_domain }});
my $say_sequence = $an->Template->get({file => "main.html", name => "input_number_form", variables => {
name => "sequence",
id => "sequence",
field => "#!string!striker_0009!#",
description => "#!string!striker_0010!#",
value => defined $an->data->{cgi}{sequence}{value} ? $an->data->{cgi}{sequence}{value} : "",
extra => "maxlength=\"2\"",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_domain => $say_domain }});
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} : "",
field => "#!string!striker_0011!#",
description => "#!string!striker_0012!#",
value => defined $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : "",
extra => "maxlength=\"2\"",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_ifn_count => $say_ifn_count }});
@ -148,8 +166,10 @@ sub config_step1
step1_welcome_message_id => "",
organization_form => $say_organization,
prefix_form => $say_prefix,
domain_form => $say_domain,
sequence_form => $say_sequence,
ifn_count_form => $say_ifn_count,
cgi_list => "organization,prefix,ifn_count",
cgi_list => "organization,prefix,domain,sequence,ifn_count",
}});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step1_body => $step1_body }});

@ -33,9 +33,13 @@ This is the AN::Tools master 'words' file.
<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>
<key name="striker_0007">Domain Name</key>
<key name="striker_0008">This is the domain name you would like to use for this dashboard. This will also be used as the default domain used when creating new install manifests.</key>
<key name="striker_0009">Sequence Number</key>
<key name="striker_0010">If this is your first Striker, set this to '1'. If it is the second one, set '2'. If it is the third, '3' and so on.</key>
<key name="striker_0011">Internet-Facing Network Count</key>
<key name="striker_0012"><![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_0013">Next</key>
<!-- These are works and strings used by javascript/jqery -->
<key name="js_0001">Up</key>

@ -43,6 +43,16 @@
#!variable!prefix_form!#
</td>
</tr>
<tr>
<td>
#!variable!domain_form!#
</td>
</tr>
<tr>
<td>
#!variable!sequence_form!#
</td>
</tr>
<tr>
<td>
#!variable!ifn_count_form!#
@ -52,7 +62,7 @@
<td>
<br />
<hr>
<input type="submit" name="next" id="next" value="#!string!striker_0009!#">
<input type="submit" name="next" id="next" value="#!string!striker_0013!#">
</td>
</tr>
<input type="hidden" name="step" id="step" value="step1">

Loading…
Cancel
Save