* Created Validate->is_email() to validate email addresses, using Mail::RFC822::Address.

* Finished (but not yet tested) the menu to manage alert recipients.
* Created Words->language_list() that creates a hash reference of available languages.

Signed-off-by: Digimer <digimer@alteeve.ca>
This commit is contained in:
Digimer 2019-12-31 23:43:52 -07:00
parent eb0481bcb0
commit 9e16cdf504
7 changed files with 608 additions and 22 deletions

View File

@ -7,6 +7,7 @@ use strict;
use warnings; use warnings;
use Data::Dumper; use Data::Dumper;
use Scalar::Util qw(weaken isweak); use Scalar::Util qw(weaken isweak);
use Mail::RFC822::Address qw(valid validlist);
our $VERSION = "3.0.0"; our $VERSION = "3.0.0";
my $THIS_FILE = "Validate.pm"; my $THIS_FILE = "Validate.pm";
@ -15,6 +16,8 @@ my $THIS_FILE = "Validate.pm";
# form_field # form_field
# is_alphanumeric # is_alphanumeric
# is_domain_name # is_domain_name
# is_email
# is_hex
# is_ipv4 # is_ipv4
# is_mac # is_mac
# is_positive_integer # is_positive_integer
@ -106,6 +109,8 @@ This is the type to be checked. Valid options are;
=head4 domain_name =head4 domain_name
=head4 email
=head4 ipv4 =head4 ipv4
=head4 mac =head4 mac
@ -118,6 +123,10 @@ If this type is used, you can use the C<< zero >> parameter which can be set to
=head4 uuid =head4 uuid
=head3 zero (optional, default '0')
See 'type -> positive_integer' above for usage.
=cut =cut
sub form_field sub form_field
{ {
@ -135,6 +144,7 @@ sub form_field
name => $name, name => $name,
type => $type, type => $type,
empty_ok => $empty_ok, empty_ok => $empty_ok,
zero => $zero,
}}); }});
if ((not $name) or (not $type)) if ((not $name) or (not $type))
@ -163,43 +173,49 @@ sub form_field
} }
elsif (($type eq "alphanumeric") && (not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "alphanumeric") && (not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "domain_name") && (not $anvil->Validate->is_domain_name({name => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "domain_name") && (not $anvil->Validate->is_domain_name({name => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "email") && (not $anvil->Validate->is_email({email => $anvil->data->{cgi}{$name}{value}})))
{
$valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "ipv4") && (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "ipv4") && (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "mac") && (not $anvil->Validate->is_mac({mac => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "mac") && (not $anvil->Validate->is_mac({mac => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "positive_integer") && (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{$name}{value}, zero => $zero}))) elsif (($type eq "positive_integer") && (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{$name}{value}, zero => $zero})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "subnet_mask") && (not $anvil->Validate->is_subnet_mask({subnet_mask => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "subnet_mask") && (not $anvil->Validate->is_subnet_mask({subnet_mask => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "uuid") && (not $anvil->Validate->is_uuid({uuid => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "uuid") && (not $anvil->Validate->is_uuid({uuid => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
@ -349,6 +365,46 @@ sub is_hex
return($valid); return($valid);
} }
=head2 is_email
Checks if the passed-in string is a valid address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$email = "test@example.com";
if ($anvil->Validate->is_email({email => $email}))
{
print "The email address: [$email] is valid!\n";
}
Parameters;
=head3 email (required)
This is the email address to verify.
=cut
sub is_email
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $email = defined $parameter->{email} ? $parameter->{email} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { email => $email }});
# Validating email ourself is madness... See (TODO: link to email validation email). So we use
# 'Mail::RFC822::Address'.
my $valid = 0;
if (valid($email))
{
$valid = 1;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_ipv4 =head2 is_ipv4
Checks if the passed-in string is an IPv4 address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. Checks if the passed-in string is an IPv4 address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.

View File

@ -21,6 +21,7 @@ my $THIS_FILE = "Words.pm";
# clean_spaces # clean_spaces
# key # key
# language # language
# language_list
# parse_banged_string # parse_banged_string
# read # read
# string # string
@ -231,6 +232,20 @@ Set the output langauge to Japanese;
$anvil->Words->language({set => "jp"}); $anvil->Words->language({set => "jp"});
Parameters;
=head3 iso (optional, default is active language)
If C<< long >> is set, this can be used to query the long language name of the ISO code set here. If C<< long >> isn't set, this is ignored.
=head3 long (optional, default '0')
If set to an ISO code, the active default language is changed to the given language. If the long language name is not found, an empty string is returned.
=head3 set (optional)
If set to C<< 1 >>, the long version of the active language is returned.
=cut =cut
sub language sub language
{ {
@ -239,7 +254,9 @@ sub language
my $anvil = $self->parent; my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $set = defined $parameter->{set} ? $parameter->{set} : ""; my $iso = defined $parameter->{iso} ? $parameter->{iso} : "";
my $long = defined $parameter->{long} ? $parameter->{long} : "";
my $set = defined $parameter->{set} ? $parameter->{set} : "";
if ($set) if ($set)
{ {
@ -251,7 +268,49 @@ sub language
$self->{WORDS}{LANGUAGE} = $anvil->data->{defaults}{language}{output}; $self->{WORDS}{LANGUAGE} = $anvil->data->{defaults}{language}{output};
} }
return($self->{WORDS}{LANGUAGE}); my $return = $self->{WORDS}{LANGUAGE};
if ($long)
{
my $name = "";
$iso = $self->{WORDS}{LANGUAGE} if not $iso;
foreach my $this_file (sort {$a cmp $b} keys %{$anvil->data->{words}})
{
if ((exists $anvil->data->{words}{$this_file}{language}{$iso}{long_name}) && ($anvil->data->{words}{$this_file}{language}{$iso}{long_name}))
{
$name = $anvil->data->{words}{$this_file}{language}{$iso}{long_name};
last;
}
}
return($name);
}
return($return);
}
=head2 language_list
This creates a hashed list if languages available on the system. The list is stored as C<< sys::languages::<ISO> = <long_name> >>.
=cut
sub language_list
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
foreach my $this_file (sort {$a cmp $b} keys %{$anvil->data->{words}})
{
foreach my $iso (sort {$a cmp $b} keys %{$anvil->data->{words}{$this_file}{language}})
{
if ((exists $anvil->data->{words}{$this_file}{language}{$iso}{long_name}) && ($anvil->data->{words}{$this_file}{language}{$iso}{long_name}))
{
$anvil->data->{sys}{languages}{$iso} = $anvil->data->{words}{$this_file}{language}{$iso}{long_name};
}
}
}
return(9);
} }
=head2 parse_banged_string =head2 parse_banged_string

View File

@ -408,9 +408,9 @@ sub process_email_recipient_page
my $recipient_uuid = defined $anvil->data->{cgi}{recipient_uuid}{value} ? $anvil->data->{cgi}{recipient_uuid}{value} : ""; my $recipient_uuid = defined $anvil->data->{cgi}{recipient_uuid}{value} ? $anvil->data->{cgi}{recipient_uuid}{value} : "";
my $recipient_name = defined $anvil->data->{cgi}{recipient_name}{value} ? $anvil->data->{cgi}{recipient_name}{value} : ""; my $recipient_name = defined $anvil->data->{cgi}{recipient_name}{value} ? $anvil->data->{cgi}{recipient_name}{value} : "";
my $recipient_email = defined $anvil->data->{cgi}{recipient_email}{value} ? $anvil->data->{cgi}{recipient_email}{value} : ""; my $recipient_email = defined $anvil->data->{cgi}{recipient_email}{value} ? $anvil->data->{cgi}{recipient_email}{value} : "";
my $recipient_language = defined $anvil->data->{cgi}{recipient_language}{value} ? $anvil->data->{cgi}{recipient_language}{value} : ""; my $recipient_language = defined $anvil->data->{cgi}{recipient_language}{value} ? $anvil->data->{cgi}{recipient_language}{value} : "en_CA";
my $recipient_units = defined $anvil->data->{cgi}{recipient_units}{value} ? $anvil->data->{cgi}{recipient_units}{value} : ""; my $recipient_units = defined $anvil->data->{cgi}{recipient_units}{value} ? $anvil->data->{cgi}{recipient_units}{value} : "metric";
my $recipient_new_level = defined $anvil->data->{cgi}{recipient_new_level}{value} ? $anvil->data->{cgi}{recipient_new_level}{value} : ""; my $recipient_new_level = defined $anvil->data->{cgi}{recipient_new_level}{value} ? $anvil->data->{cgi}{recipient_new_level}{value} : "2";
my $delete = defined $anvil->data->{cgi}{'delete'}{value} ? $anvil->data->{cgi}{'delete'}{value} : ""; my $delete = defined $anvil->data->{cgi}{'delete'}{value} ? $anvil->data->{cgi}{'delete'}{value} : "";
my $back = defined $anvil->data->{cgi}{back}{value} ? $anvil->data->{cgi}{back}{value} : ""; my $back = defined $anvil->data->{cgi}{back}{value} ? $anvil->data->{cgi}{back}{value} : "";
my $save = defined $anvil->data->{cgi}{save}{value} ? $anvil->data->{cgi}{save}{value} : ""; my $save = defined $anvil->data->{cgi}{save}{value} ? $anvil->data->{cgi}{save}{value} : "";
@ -498,9 +498,9 @@ WHERE
# Clear the form # Clear the form
$recipient_name = ""; $recipient_name = "";
$recipient_email = ""; $recipient_email = "";
$recipient_language = ""; $recipient_language = "en_CA";
$recipient_units = ""; $recipient_units = "metric";
$recipient_new_level = ""; $recipient_new_level = "2";
} }
else else
{ {
@ -510,9 +510,9 @@ WHERE
$anvil->data->{form}{back_link} =~ s/save=.*?$//; $anvil->data->{form}{back_link} =~ s/save=.*?$//;
$anvil->data->{form}{refresh_link} = ""; $anvil->data->{form}{refresh_link} = "";
$anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "recipient-delete-confirm", variables => { $anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "recipient-delete-confirm", variables => {
recipient_name => $recipient_name, recipient_name => $recipient_name,
recipient_email => $recipient_email recipient_email => $recipient_email,
mail_server_uuid => $mail_server_uuid, recipient_uuid => $recipient_uuid,
}}); }});
return(0); return(0);
} }
@ -520,20 +520,248 @@ WHERE
} }
} }
# Are we saving? # If we're saving, make sure we have a valid email address and a name.
if ($save)
{
# Did the user give both an email address and name?
if ((not $recipient_name) or (not $recipient_name))
{
# Which was missing?
if (not $recipient_name)
{
$anvil->data->{cgi}{recipient_name}{alert} = 1;
}
if (not $recipient_email)
{
$anvil->data->{cgi}{recipient_email}{alert} = 1;
}
$save = "";
$confirm = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
save => $save,
confirm => $confirm,
}});
}
# Verify that the mail server and ports are sane.
if (not $anvil->Validate->is_email({email => $recipient_email}))
{
# Bad domain
my $error_message = $anvil->Words->string({key => "warning_0026"});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $error_message }});
$anvil->data->{cgi}{recipient_email}{alert} = 1;
$save = "";
$confirm = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
error_message => $error_message,
"form::error_massage" => $anvil->data->{form}{error_massage},
"cgi::recipient_email::alert" => $anvil->data->{cgi}{recipient_email}{alert},
save => $save,
confirm => $confirm,
}});
}
}
# Are we still saving?
if ($save) if ($save)
{ {
# Have we confirmed? # Have we confirmed?
if ($confirm) if ($confirm)
{ {
# Save the changes. ($recipient_uuid) = $anvil->Database->insert_or_update_recipients({
debug => 2,
recipient_uuid => $recipient_uuid,
recipient_name => $recipient_name,
recipient_email => $recipient_email,
recipient_language => $recipient_language,
recipient_units => $recipient_units,
recipient_new_level => $recipient_new_level,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { recipient_uuid => $recipient_uuid }});
if ($recipient_uuid)
{
# Saved successfully.
my $ok_message = $anvil->Words->string({key => "ok_0004"});
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_message }});
# Clear the form
$recipient_uuid = "";
$recipient_name = "";
$recipient_email = "";
$recipient_language = "en_CA";
$recipient_units = "metric";
$recipient_new_level = "2";
}
else
{
# Something went wrong...
my $error_message = $anvil->Words->string({key => "warning_0027"});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $error_message }});
}
} }
else else
{ {
# Ask them to confirm my $say_recipient_units = "#!string!unit_0027!#";
if ($recipient_language eq "imperial")
{
$say_recipient_units = "#!string!unit_0028!#";
}
# Ignore
my $say_recipient_new_level = "#!string!unit_0023!#";
if ($recipient_new_level eq "1")
{
# Critical
$say_recipient_new_level = "#!string!unit_0024!#";
}
elsif ($recipient_new_level eq "2")
{
# Warning
$say_recipient_new_level = "#!string!unit_0025!#";
}
elsif ($recipient_new_level eq "3")
{
# Notice
$say_recipient_new_level = "#!string!unit_0026!#";
}
my $say_recipient_language = $anvil->Words->language({iso => $recipient_language, long => 1});
$say_recipient_language = "???" if not $say_recipient_language;
# Ask the user to confirm
$anvil->data->{form}{back_link} = $anvil->data->{sys}{cgi_string};
$anvil->data->{form}{back_link} =~ s/save=.*?&//;
$anvil->data->{form}{back_link} =~ s/save=.*?$//;
$anvil->data->{form}{refresh_link} = "";
$anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "recipient-confirm", variables => {
recipient_uuid => $recipient_uuid,
recipient_name => $recipient_name,
recipient_email => $recipient_email,
recipient_language => $recipient_language,
say_recipient_language => $say_recipient_language,
recipient_units => $recipient_units,
say_recipient_units => $say_recipient_units,
recipient_new_level => $recipient_new_level,
say_recipient_new_level => $say_recipient_new_level,
}});
return(0);
} }
} }
# Get a list of existing alert recipients.
my $query = "SELECT recipient_uuid, recipient_name, recipient_email FROM recipients WHERE recipient_name != 'DELETED' ORDER BY recipient_name ASC;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
my $recipients_form = "";
if ($count)
{
# Build the list of existing mail servers
$recipients_form .= $anvil->Template->get({file => "email.html", name => "recipient-entry-open"});;
foreach my $row (@{$results})
{
my $recipient_uuid = $row->[0];
my $recipient_name = $row->[1];
my $recipient_email = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
recipient_uuid => $recipient_uuid,
recipient_name => $recipient_name,
recipient_email => $recipient_email,
}});
$recipients_form .= $anvil->Template->get({file => "email.html", name => "recipient-entry", variables => {
name => $recipient_name." (".$recipient_email.")",
uuid => $recipient_uuid,
}});;
}
$recipients_form .= $anvil->Template->get({file => "email.html", name => "recipient-entry-close"});;
}
# Name
my $recipient_name_class = $anvil->data->{cgi}{recipient_name}{alert} ? "input_alert" : "input_clear";
my $recipient_name_form = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
name => "recipient_name",
id => "recipient_name",
field => "#!string!striker_0194!#",
description => "#!string!striker_0195!#",
value => $recipient_name,
default_value => "",
class => $recipient_name_class,
extra => "",
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { recipient_name_form => $recipient_name_form }});
# Email
my $recipient_email_class = $anvil->data->{cgi}{recipient_email}{alert} ? "input_alert" : "input_clear";
my $recipient_email_form = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
name => "recipient_email",
id => "recipient_email",
field => "#!string!striker_0196!#",
description => "#!string!striker_0197!#",
value => $recipient_email,
default_value => "",
class => $recipient_email_class,
extra => "",
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { recipient_email_form => $recipient_email_form }});
# Language (select)
$anvil->Words->language_list();
my $options = [];
foreach my $iso (sort {$a cmp $b} keys %{$anvil->data->{sys}{languages}})
{
push @{$options}, $iso."#!#".$anvil->data->{sys}{languages}{$iso};
}
my $recipient_language_select = $anvil->Template->select_form({
name => "recipient_language",
options => $options,
blank => 0,
selected => $recipient_language,
class => $anvil->data->{cgi}{recipient_language}{alert} ? "input_alert" : "input_clear",
});
# Units (select)
my $recipient_units_select = $anvil->Template->select_form({
name => "recipient_units",
options => [
"metric#!#".$anvil->Words->string({key => "unit_0027"}),
"imperial#!#".$anvil->Words->string({key => "unit_0028"}),
],
blank => 0,
selected => $recipient_units,
class => $anvil->data->{cgi}{recipient_units}{alert} ? "input_alert" : "input_clear",
});
# Log Level (select)
my $recipient_new_level_select = $anvil->Template->select_form({
name => "recipient_new_level",
options => [
"0#!#".$anvil->Words->string({key => "unit_0023"}),
"1#!#".$anvil->Words->string({key => "unit_0024"}),
"2#!#".$anvil->Words->string({key => "unit_0025"}),
"3#!#".$anvil->Words->string({key => "unit_0026"}),
],
blank => 0,
selected => $recipient_new_level,
class => $anvil->data->{cgi}{recipient_new_level}{alert} ? "input_alert" : "input_clear",
});
# Show the menu.
$anvil->data->{form}{back_link} = "?";
$anvil->data->{form}{refresh_link} = "?email=true&task=email_recipient";
$anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "recipient-menu", variables => {
recipients => $recipients_form,
recipient_name => $recipient_name_form,
recipient_email => $recipient_email_form,
language => $recipient_language_select,
units => $recipient_units_select,
new_level => $recipient_new_level_select,
recipient_uuid => $recipient_uuid,
}});
return(0); return(0);
} }
@ -641,6 +869,7 @@ WHERE
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_message }}); $anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_message }});
# Clear the form # Clear the form
$mail_server_uuid = "";
$outgoing_mail_server = ""; $outgoing_mail_server = "";
$login_name = ""; $login_name = "";
$login_password = ""; $login_password = "";
@ -696,6 +925,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { helo_domain => $helo_domain }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { helo_domain => $helo_domain }});
} }
# Sanity check our save
if ($save) if ($save)
{ {
# Did the user give an outgoing mail server? # Did the user give an outgoing mail server?
@ -772,6 +1002,7 @@ WHERE
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_message }}); $anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_message }});
# Clear the form # Clear the form
$mail_server_uuid = "";
$outgoing_mail_server = ""; $outgoing_mail_server = "";
$login_name = ""; $login_name = "";
$login_password = ""; $login_password = "";
@ -907,7 +1138,7 @@ WHERE
class => $anvil->data->{cgi}{authentication_method}{alert} ? "input_alert" : "input_clear", class => $anvil->data->{cgi}{authentication_method}{alert} ? "input_alert" : "input_clear",
}); });
# Still here, show the menu. # Show the menu.
$anvil->data->{form}{back_link} = "?"; $anvil->data->{form}{back_link} = "?";
$anvil->data->{form}{refresh_link} = "?email=true&task=email_server"; $anvil->data->{form}{refresh_link} = "?email=true&task=email_server";
$anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "mail-server-menu", variables => { $anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "mail-server-menu", variables => {

View File

@ -309,6 +309,100 @@
</table> </table>
<!-- end mail-server-delete-confirm --> <!-- end mail-server-delete-confirm -->
<!-- start recipient-confirm -->
<table align="center">
<form name="recipient" action="" method="post">
<div id="recipient">
<tr>
<td colspan="2" class="title">
#!string!message_0156!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
#!string!message_0157!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
<table align="center" class="data_table_nowrap">
<tr>
<td class="column_header">
#!string!striker_0190!#
</td>
<td class="column_row_value_fixed">
&nbsp; #!variable!recipient_name!# (#!variable!recipient_email!#)
<input type="hidden" name="recipient_name" id="recipient_name" value="#!variable!recipient_name!#"/>
<input type="hidden" name="recipient_email" id="recipient_email" value="#!variable!recipient_email!#"/>
<input type="hidden" name="recipient_uuid" id="recipient_uuid" value="#!variable!recipient_uuid!#"/>
</td>
</tr>
<tr>
<td class="column_header">
#!string!striker_0191!#
</td>
<td class="column_row_value_fixed">
&nbsp; #!variable!say_alert_level!#
<input type="hidden" name="recipient_new_level" id="recipient_new_level" value="#!variable!recipient_new_level!#"/>
</td>
</tr>
<tr>
<td class="column_header">
#!string!striker_0192!#
</td>
<td class="column_row_value_fixed">
&nbsp; #!variable!say_recipient_language!#
<input type="hidden" name="recipient_language" id="recipient_language" value="#!variable!recipient_language!#"/>
</td>
</tr>
<tr>
<td class="column_header">
#!string!striker_0193!#
</td>
<td class="column_row_value_fixed">
&nbsp; #!variable!say_recipient_units!#
<input type="hidden" name="recipient_units" id="recipient_units" value="#!variable!recipient_units!#"/>
</td>
</tr>
<tr>
<td colspan="2" class="close_top">
&nbsp;
</td>
</tr>
<tr>
<td class="no_border">
<input type="submit" name="back" id="back" class="button" value="#!string!striker_0098!#">
</td>
<td class="no_border_right">
<input type="submit" name="confirm" id="confirm" class="button" value="#!string!striker_0082!#">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
</div>
<input type="hidden" name="email" id="email" value="true" />
<input type="hidden" name="save" id="save" value="true" />
<input type="hidden" name="task" id="task" value="email_server" />
</form>
</table>
<!-- end recipient-confirm -->
<!-- start recipient-delete-confirm --> <!-- start recipient-delete-confirm -->
<table align="center"> <table align="center">
<form name="recipient" action="" method="post"> <form name="recipient" action="" method="post">
@ -363,3 +457,120 @@
</form> </form>
</table> </table>
<!-- end recipient-delete-confirm --> <!-- end recipient-delete-confirm -->
<!-- start recipient-entry-open -->
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2" style="text-align: left; padding-bottom: 0.3em;">
#!string!striker_0187!#
</td>
</tr>
<tr>
<td colspan="2" style="text-align: left;">
<table class="list">
<!-- end recipient-entry-open -->
<!-- start recipient-entry -->
<tr>
<td class="column_row_value_fixed">
<a href="?email=true&task=email_recipient&recipient_uuid=#!variable!uuid!#" class="fixed_link">#!variable!name!#</a>
</td>
<td>
&nbsp; <a href="?email=true&task=email_recipient&recipient_uuid=#!variable!uuid!#&delete=true"><img src="#!data!skin::url!#/images/delete.png" alt="#!string!striker_0068!#" style="height: .8em;"></a> &nbsp;
</td>
</tr>
<!-- end recipient-entry -->
<!-- start recipient-entry-close -->
</table>
</td>
</tr>
<!-- end recipient-entry-close -->
<!-- start recipient-menu -->
<table align="center">
<script type="text/javascript" src="#!data!skin::url!#/email.js"></script>
<form name="mail_server" action="" method="post">
<div id="mail_server">
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2" class="title">
#!string!message_0156!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
#!string!message_0157!#
</td>
</tr>
#!variable!recipients!#
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2" class="column_row_value_right">
<a href="?email=true&task=email_recipient">#!string!striker_0188!#</a>
</td>
</tr>
<tr>
<td colspan="2">
<!-- recipient name -->
#!variable!recipient_name!#
</td>
</tr>
<tr>
<td colspan="2">
<!-- recipient email -->
#!variable!recipient_email!#
</td>
</tr>
<tr>
<td colspan="2">
#!string!striker_0198!#<br />
#!variable!language!#
</td>
</tr>
<tr>
<td colspan="2">
#!string!striker_0199!#<br />
#!variable!units!#
</td>
</tr>
<tr>
<td colspan="2">
#!string!striker_0200!#<br />
#!variable!new_level!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="save" id="save" class="button" value="#!string!striker_0067!#">
</td>
</tr>
</div>
<input type="hidden" name="email" id="email" value="true" />
<input type="hidden" name="task" id="task" value="email_recipient" />
<input type="hidden" name="recipient_uuid" id="recipient_uuid" value="#!variable!recipient_uuid!#" />
</form>
</table>
<!-- end recipient-menu -->

View File

@ -50,6 +50,7 @@ Requires: perl-HTML-Strip
Requires: perl-IO-Tty Requires: perl-IO-Tty
Requires: perl-JSON Requires: perl-JSON
Requires: perl-Log-Journald Requires: perl-Log-Journald
Requires: perl-Mail-RFC822-Address
Requires: perl-Net-SSH2 Requires: perl-Net-SSH2
Requires: perl-Net-Netmask Requires: perl-Net-Netmask
Requires: perl-Net-OpenSSH Requires: perl-Net-OpenSSH
@ -354,6 +355,7 @@ fi
%changelog %changelog
* tbd Madison Kelly <mkelly@alteeve.ca> 3.0-31 * tbd Madison Kelly <mkelly@alteeve.ca> 3.0-31
- Added perl-Mail-RFC822-Address to core requirements.
- -
* Fri Dec 13 2019 Madison Kelly <mkelly@alteeve.ca> 3.0-30 * Fri Dec 13 2019 Madison Kelly <mkelly@alteeve.ca> 3.0-30

View File

@ -261,6 +261,7 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="message_0154">Mail Server Configuration</key> <key name="message_0154">Mail Server Configuration</key>
<key name="message_0155">When alert emails are sent, they are stored locally and then forwarded to a mail server. This is where you can configure the mail server that alerts are forwarded to for delivery to recipients.</key> <key name="message_0155">When alert emails are sent, they are stored locally and then forwarded to a mail server. This is where you can configure the mail server that alerts are forwarded to for delivery to recipients.</key>
<key name="message_0156">Alert recipient Configuration</key> <key name="message_0156">Alert recipient Configuration</key>
<key name="message_0157">When a system alert is recorded, any alert recipient interested in that alert will be notified by email. This is determined by the alert's level, and the recipients alert level interest. If the alert's level is equal to or higher than a given alert, an email will be crafted for them, in their chosen language and units.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>
@ -1049,6 +1050,17 @@ If you are comfortable that the target has changed for a known reason, you can s
<key name="striker_0187">Existing mail servers:</key> <key name="striker_0187">Existing mail servers:</key>
<key name="striker_0188">Clear the form</key> <key name="striker_0188">Clear the form</key>
<key name="striker_0189">Are you sure that you want to delete:</key> <key name="striker_0189">Are you sure that you want to delete:</key>
<key name="striker_0190">Alert Recipient</key>
<key name="striker_0191">Alert level for future Anvil! systems</key>
<key name="striker_0192">Language</key>
<key name="striker_0193">Units</key>
<key name="striker_0194">Recipient's Name</key>
<key name="striker_0195">This is the name that will be displayed when sending an email to this user.</key>
<key name="striker_0196">Recipient's Email</key>
<key name="striker_0197">The email that alerts are sent to.</key>
<key name="striker_0198">The language the user will receive alerts in.</key>
<key name="striker_0199">Does the user want imperial or metric units?</key>
<key name="striker_0200">The alert level used for new (and existing) Anvil! systems.</key>
<!-- These are generally units and appended to numbers --> <!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key> <key name="suffix_0001">#!variable!number!#/sec</key>
@ -1196,6 +1208,7 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>
<key name="ok_0002">The mail server: [#!variable!mail_server!#] has been deleted.</key> <key name="ok_0002">The mail server: [#!variable!mail_server!#] has been deleted.</key>
<key name="ok_0003">The alert recipient: [#!variable!recipient_email!#] has been deleted.</key> <key name="ok_0003">The alert recipient: [#!variable!recipient_email!#] has been deleted.</key>
<key name="ok_0004">Saved the alert recipient information successfully!</key>
<!-- Warnings --> <!-- Warnings -->
<key name="warning_0001">The IP address will change. You will need to reconnect after applying these changes.</key> <key name="warning_0001">The IP address will change. You will need to reconnect after applying these changes.</key>
@ -1223,6 +1236,8 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="warning_0023">The outgoing mail server appear to not be a valid domain name or IP address.</key> <key name="warning_0023">The outgoing mail server appear to not be a valid domain name or IP address.</key>
<key name="warning_0024">The outgoing mail server port is not valid. Must be 'mail_server:x' where x is 1 ~ 65535.</key> <key name="warning_0024">The outgoing mail server port is not valid. Must be 'mail_server:x' where x is 1 ~ 65535.</key>
<key name="warning_0025">There was a problem saving the mail server data. Please check the logs for more information.</key> <key name="warning_0025">There was a problem saving the mail server data. Please check the logs for more information.</key>
<key name="warning_0026">The recipient's email address appears to not be valid.</key>
<key name="warning_0027">There was a problem saving the alert recipient data. Please check the logs for more information.</key>
<!-- Errors --> <!-- Errors -->
<key name="error_0001">There are not enough network interfaces on this machine. You have: [#!variable!interface_count!#] interface(s), and you need at least: [#!variable!required_interfaces_for_single!#] interfaces to connect to the requested networks (one for Back-Channel and one for each Internet-Facing network).</key> <key name="error_0001">There are not enough network interfaces on this machine. You have: [#!variable!interface_count!#] interface(s), and you need at least: [#!variable!required_interfaces_for_single!#] interfaces to connect to the requested networks (one for Back-Channel and one for each Internet-Facing network).</key>
@ -1372,6 +1387,12 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp
<key name="unit_0020">STP Disabled</key> <!-- Bridge STP state disabled - See: https://github.com/mstpd/mstpd/issues/17#issuecomment-245395763 --> <key name="unit_0020">STP Disabled</key> <!-- Bridge STP state disabled - See: https://github.com/mstpd/mstpd/issues/17#issuecomment-245395763 -->
<key name="unit_0021">STP Enabled in Kernel</key> <!-- Bridge STP state kernel --> <key name="unit_0021">STP Enabled in Kernel</key> <!-- Bridge STP state kernel -->
<key name="unit_0022">STP Enabled in User land</key> <!-- Bridge STP state user --> <key name="unit_0022">STP Enabled in User land</key> <!-- Bridge STP state user -->
<key name="unit_0023">Ignore</key> <!-- Alert level for Anvil! systems added in the future -->
<key name="unit_0024">Critical</key> <!-- Alert level 1 -->
<key name="unit_0025">Warning</key> <!-- Alert level 2 -->
<key name="unit_0026">Notice</key> <!-- Alert level 3 -->
<key name="unit_0027">Metric</key>
<key name="unit_0028">Imperial</key>
<!-- TODO: Merge these into 'unit' --> <!-- TODO: Merge these into 'unit' -->
<!-- These are works and strings used by javascript/jqery --> <!-- These are works and strings used by javascript/jqery -->

View File

@ -31,3 +31,9 @@ print "DB Connections: [".$anvil->data->{sys}{database}{connections}."]\n";
#$anvil->Network->load_interfces({debug => 2}); #$anvil->Network->load_interfces({debug => 2});
#$anvil->System->generate_state_json({debug => 2}); #$anvil->System->generate_state_json({debug => 2});
$anvil->Words->language_list();
foreach my $iso (sort {$a cmp $b} keys %{$anvil->data->{sys}{languages}})
{
print "iso: [".$iso."] -> [".$anvil->data->{sys}{languages}{$iso}."]\n";
}