Merge pull request #255 from ClusterLabs/anvil-tools-dev

* Updated System->check_ram_use() to set the maximum RAM based on the…
main
Digimer 2 years ago committed by GitHub
commit 753ea7518f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Anvil/Tools.pm
  2. 23
      Anvil/Tools/System.pm
  3. 92
      share/words.xml
  4. 4
      tools/Makefile.am
  5. 728
      tools/anvil-manage-alerts

@ -906,6 +906,11 @@ sub _set_defaults
privacy => { privacy => {
strong => 0, strong => 0,
}, },
ram_limits => {
striker => 3221225472, # 3 GiB
node => 1073741824, # 1 GiB
dr => 2147483648, # 2 GiB
},
# On actual RHEL systems, this will be used to ensure that given repos are enabled on given # On actual RHEL systems, this will be used to ensure that given repos are enabled on given
# machines types. Obviously, this requires that the host has been subscribed. # machines types. Obviously, this requires that the host has been subscribed.
rhel => { rhel => {

@ -684,12 +684,33 @@ sub check_ram_use
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->check_ram_use()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->check_ram_use()" }});
my $program = defined $parameter->{program} ? $parameter->{program} : ""; my $program = defined $parameter->{program} ? $parameter->{program} : "";
my $max_ram = defined $parameter->{max_ram} ? $parameter->{max_ram} : 1073741824; my $max_ram = defined $parameter->{max_ram} ? $parameter->{max_ram} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
program => $program, program => $program,
max_ram => $max_ram, max_ram => $max_ram,
}}); }});
# If we weren't told what the max RAM is, set it from defaults
if (not $max_ram)
{
my $host_type = $anvil->Get->host_type({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_type => $host_type }});
# We'll set '1073741824' (1 GiB) as max default. Then adjust if we have a device type.
$max_ram = 1073741824;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
max_ram => $anvil->Convert->add_commas({number => $max_ram})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_ram}).")",
}});
if (exists $anvil->data->{sys}{ram_limits}{$host_type})
{
$max_ram = $anvil->data->{sys}{ram_limits}{$host_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
max_ram => $anvil->Convert->add_commas({number => $max_ram})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_ram}).")",
}});
}
}
# Find the PID(s) of the program. # Find the PID(s) of the program.
my $problem = 0; my $problem = 0;
my $ram_used = 0; my $ram_used = 0;

@ -534,18 +534,25 @@ The definition data passed in was:
<key name="error_0377">[ Error ] - The '--type' must be 'host' or 'dr'. Was given: [#!variable!type!#].</key> <key name="error_0377">[ Error ] - The '--type' must be 'host' or 'dr'. Was given: [#!variable!type!#].</key>
<key name="error_0378">[ Error ] - The UUID: [#!variable!uuid!#] is not a valid UUID.</key> <key name="error_0378">[ Error ] - The UUID: [#!variable!uuid!#] is not a valid UUID.</key>
<key name="error_0379">[ Error ] - Neither '--host-ip-address' or '--target' were used to define who we are trying to connect to.</key> <key name="error_0379">[ Error ] - Neither '--host-ip-address' or '--target' were used to define who we are trying to connect to.</key>
<key name="error_0380">[ Error ] - The UUID: [#!variable!uuid!#] passed in by the switch: [#!variable!switch!#] appears to be invalid.</key> <key name="error_0380">[ Error ] - The UUID: [#!variable!uuid!#] passed in by the switch: [--#!variable!switch!#] appears to be invalid.</key>
<key name="error_0381">[ Error ] - The domain or IP: [#!variable!name!#] passed in by the switch: [#!variable!switch!#] appears to be invalid.</key> <key name="error_0381">[ Error ] - The domain or IP: [#!variable!name!#] passed in by the switch: [--#!variable!switch!#] appears to be invalid.</key>
<key name="error_0382">[ Error ] - The alert level: [#!variable!level!#] passed in by the switch: [#!variable!switch!#] appears to be invalid. Valid values are '1', '2', '3' or '4'. These represent; <key name="error_0382">[ Error ] - The alert level: [#!variable!level!#] passed in by the switch: [--#!variable!switch!#] appears to be invalid. Valid values are '0', '1', '2', '3' or '4'. These represent;
1 = "critical" alerts only * 1 = "critical" alerts only
2 = "warning" and critical alerts * 2 = "warning" and critical alerts
3 = "notice", warning and critical alerts * 3 = "notice", warning and critical alerts
4 = "info"; All alerts. This generates almost constant alerts! * 4 = "info"; All alerts. This generates almost constant alerts!</key>
</key> <key name="error_0383">[ Error ] - The TCP port: [#!variable!port!#] passed in by the switch: [--#!variable!switch!#] appears to be invalid. TCP ports must be integers between 1 and 65535.</key>
<key name="error_0383">[ Error ] - The TCP port: [#!variable!port!#] passed in by the switch: [#!variable!switch!#] appears to be invalid. TCP ports must be integers between 1 and 65535.</key>
<key name="error_0384">[ Error ] - The mail server security: [#!variable!security!#] appears to be invalid. Valid options are 'none', 'starttls' or 'tls-ssl'.</key> <key name="error_0384">[ Error ] - The mail server security: [#!variable!security!#] appears to be invalid. Valid options are 'none', 'starttls' or 'tls-ssl'.</key>
<key name="error_0385">[ Error ] - The mail server authentication: [#!variable!auth!#] appears to be invalid. Valid options are 'none', 'plain-text', or 'encrypted'.</key> <key name="error_0385">[ Error ] - The mail server authentication: [#!variable!auth!#] appears to be invalid. Valid options are:
* none = Normal Password
* encrypted = Encrypted Password
* kerberos = Kerberos GSSAPI
* ntlm = NTLM
* tls = TLS
* oauth2 = oauth2</key>
<key name="error_0386">[ Error ] - The email address: [#!variable!email!#] appears to be invalid.</key> <key name="error_0386">[ Error ] - The email address: [#!variable!email!#] appears to be invalid.</key>
<key name="error_0387">[ Error ] - The switch: [--#!variable!switch!#] is required, but not provided.</key>
<key name="error_0388">[ Error ] - The mail server UUID: [#!variable!uuid!#] was not found.</key>
<!-- Files templates --> <!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable --> <!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -2689,6 +2696,71 @@ Available options;
# configuration option. It will be removed in a future release. # configuration option. It will be removed in a future release.
# Please consider disabling it now.</key> # Please consider disabling it now.</key>
<key name="message_0293">Migration Network</key> <key name="message_0293">Migration Network</key>
<key name="message_0294">Are you sure you want to create the new mail server:
* Address: ...... [#!variable!new_address!#]
* TCP port: ..... [#!variable!new_port!#]
* User name: .... [#!variable!new_username!#]
* Password: ..... [#!variable!new_password!#]
* Authentication: [#!variable!new_authentication!#]
* Security: ..... [#!variable!new_security!#]
* HELO domain: .. [#!variable!new_helo_domain!#]
Proceed? [y/N]
</key>
<key name="message_0295">Are you sure you want to change the mail server thusly:
* Address: ...... [#!variable!old_address!#] -> [#!variable!new_address!#]
* TCP port: ..... [#!variable!old_port!#] -> [#!variable!new_port!#]
* User name: .... [#!variable!old_username!#] -> [#!variable!new_username!#]
* Password: ..... [#!variable!old_password!#] -> [#!variable!new_password!#]
* Authentication: [#!variable!old_authentication!#] -> [#!variable!new_authentication!#]
* Security: ..... [#!variable!old_security!#] -> [#!variable!new_security!#]
* HELO domain: .. [#!variable!old_helo_domain!#] -> [#!variable!new_helo_domain!#]
Proceed? [y/N]
</key>
<key name="message_0296">Are you sure you want to delete the mail server:
* Address: ...... [#!variable!old_address!#]
* TCP port: ..... [#!variable!old_port!#]
* User name: .... [#!variable!old_username!#]
* Password: ..... [#!variable!old_password!#]
* Authentication: [#!variable!old_authentication!#]
* Security: ..... [#!variable!old_security!#]
* HELO domain: .. [#!variable!old_helo_domain!#]
Proceed? [y/N]
</key>
<key name="message_0297">The new mail server was created with the UUID: [#!variable!uuid!#].</key>
<key name="message_0298">The mail server has been updated.</key>
<key name="message_0299">The mail server has been deleted.</key>
<key name="message_0300">Are you sure you want to create the alert recipient:
* Name: ... [#!variable!new_name!#]
* E-Mail: . [#!variable!new_email!#]
* Language: [#!variable!new_language!#]
* Level: .. [#!variable!new_level!#]
Proceed? [y/N]
</key>
<key name="message_0301">Are you sure you want to change the alert recipient thusly:
* Name: ... [#!variable!old_name!#] -> [#!variable!new_name!#]
* E-Mail: . [#!variable!old_email!#] -> [#!variable!new_email!#]
* Language: [#!variable!old_language!#] -> [#!variable!new_language!#]
* Level: .. [#!variable!old_level!#] -> [#!variable!new_level!#]
Proceed? [y/N]
</key>
<key name="message_0302">Are you sure you want to delete the alert recipient:
* Name: ... [#!variable!old_name!#]
* E-Mail: . [#!variable!old_email!#]
* Language: [#!variable!old_language!#]
* Level: .. [#!variable!old_level!#]
Proceed? [y/N]
</key>
<!-- Translate names (protocols, etc) -->
<key name="name_0001">Normal Password</key> <!-- none in mail-server -->
<key name="name_0002">Enctrypted Password</key> <!-- encrypted in mail-server -->
<key name="name_0003">Kerberos GSSAPI</key> <!-- kerberos in mail-server -->
<key name="name_0004">NTLM</key> <!-- ntlm in mail-server -->
<key name="name_0005">TLS Certificate</key> <!-- tls in mail-server -->
<key name="name_0006">OAuth2</key> <!-- oauth2 in mail-server -->
<key name="name_0007">None</key> <!-- none in mail-server -->
<key name="name_0008">STARTTLS</key> <!-- starttls in mail-server -->
<key name="name_0009">TLS/SSL</key> <!-- tls-ssl in mail-server -->
<!-- Success messages shown to the user --> <!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>

@ -17,6 +17,7 @@ dist_sbin_SCRIPTS = \
anvil-get-server-screenshot \ anvil-get-server-screenshot \
anvil-join-anvil \ anvil-join-anvil \
anvil-maintenance-mode \ anvil-maintenance-mode \
anvil-manage-alerts \
anvil-manage-dr \ anvil-manage-dr \
anvil-manage-files \ anvil-manage-files \
anvil-manage-firewall \ anvil-manage-firewall \
@ -25,6 +26,7 @@ dist_sbin_SCRIPTS = \
anvil-manage-power \ anvil-manage-power \
anvil-manage-server \ anvil-manage-server \
anvil-migrate-server \ anvil-migrate-server \
anvil-network-profiler \
anvil-parse-fence-agents \ anvil-parse-fence-agents \
anvil-provision-server \ anvil-provision-server \
anvil-rename-server \ anvil-rename-server \
@ -70,3 +72,5 @@ dist_fence_SCRIPTS = \
sharedir = ${datarootdir}/anvil sharedir = ${datarootdir}/anvil
dist_share_DATA = striker-auto-initialize-all.example dist_share_DATA = striker-auto-initialize-all.example
# -rwxr-xr-x. 1 digimer digimer 34K Feb 1 2020 tool-fio-tester

@ -42,6 +42,8 @@ $anvil->Get->switches({list => [
"recipient-email", "recipient-email",
"recipient-language", "recipient-language",
"recipient-level", "recipient-level",
"y",
"yes",
]}); ]});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}});
@ -60,16 +62,34 @@ if ($anvil->data->{switches}{"mail-servers"})
{ {
handle_mail_servers($anvil); handle_mail_servers($anvil);
} }
elsif ($anvil->data->{switches}{"notifications"})
{
handle_notifications($anvil);
}
elsif ($anvil->data->{switches}{"recipients"}) elsif ($anvil->data->{switches}{"recipients"})
{ {
$anvil->data->{sys}{show}{recipients} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients},
}});
handle_recipients($anvil); handle_recipients($anvil);
} }
elsif ($anvil->data->{switches}{"notifications"})
{
$anvil->data->{sys}{show}{notifications} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::notifications' => $anvil->data->{sys}{show}{notifications},
}});
handle_notifications($anvil);
}
else else
{ {
$anvil->data->{sys}{show}{mail_servers} = 1;
$anvil->data->{sys}{show}{recipients} = 1;
$anvil->data->{sys}{show}{notifications} = 1;
$anvil->data->{sys}{show}{systems} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::mail_servers' => $anvil->data->{sys}{show}{mail_servers},
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients},
'sys::show::notifications' => $anvil->data->{sys}{show}{notifications},
'sys::show::systems' => $anvil->data->{sys}{show}{systems},
}});
show_existing($anvil); show_existing($anvil);
} }
@ -80,11 +100,199 @@ $anvil->nice_exit({exit_code => 0});
# Functions # # Functions #
############################################################################################################# #############################################################################################################
sub recipients sub handle_recipients
{ {
my ($anvil) = @_; my ($anvil) = @_;
### Are we adding, editing or deleting?
# If we're adding or editing, all fields are required.
my $confirm_needed = 0;
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
# Did the user confirm yet?
if ((not $anvil->data->{switches}{'y'}) and (not $anvil->data->{switches}{'yes'}))
{
$confirm_needed = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { confirm_needed => $confirm_needed }});
}
}
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}))
{
# Do we have what we need?
my $problem = 0;
foreach my $switch ("recipient-name", "recipient-email", "recipient-language", "recipient-level")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
switch => $switch,
"switches::$switch" => $anvil->data->{switches}{$switch},
}});
if (($anvil->data->{switches}{$switch} eq "") or ($anvil->data->{switches}{$switch} eq "#!SET!#"))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => $switch }});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
if ($problem)
{
$anvil->nice_exit({exit_code => 1});
}
}
# If we're editing or deleting, make sure we have a valid UUID.
my $recipient_uuid = $anvil->data->{switches}{"recipient-uuid"};
my $old_recipient_language = "";
my $old_recipient_level = "";
if (($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
if (not $recipient_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => "recipient-uuid" }});
$anvil->nice_exit({exit_code => 1});
}
if (not exists $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0388", variables => { uuid => $recipient_uuid }});
$anvil->nice_exit({exit_code => 1});
}
$old_recipient_language = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_language};
$old_recipient_level = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_level};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
old_recipient_language => $old_recipient_language,
old_recipient_level => $old_recipient_level,
}});
$anvil->data->{sys}{say_old_language} = $anvil->data->{sys}{languages}{$old_recipient_language};
# Get the translated log level name.
if ($old_recipient_level == 0)
{
# Ignore
$anvil->data->{sys}{say_old_level} = $anvil->Words->string({key => "unit_0023"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_level' => $anvil->data->{sys}{say_old_level},
}});
}
elsif ($old_recipient_level == 1)
{
# Critical
$anvil->data->{sys}{say_old_level} = $anvil->Words->string({key => "unit_0024"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_level' => $anvil->data->{sys}{say_old_level},
}});
}
elsif ($old_recipient_level == 2)
{
# Warning
$anvil->data->{sys}{say_old_level} = $anvil->Words->string({key => "unit_0025"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_level' => $anvil->data->{sys}{say_old_level},
}});
}
elsif ($old_recipient_level == 3)
{
# Notice
$anvil->data->{sys}{say_old_level} = $anvil->Words->string({key => "unit_0026"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_level' => $anvil->data->{sys}{say_old_level},
}});
}
elsif ($old_recipient_level == 4)
{
# Info
$anvil->data->{sys}{say_old_level} = $anvil->Words->string({key => "unit_0027"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_level' => $anvil->data->{sys}{say_old_level},
}});
}
}
if ($confirm_needed)
{
my $key = "";
if ($anvil->data->{switches}{add})
{
$key = "message_0300";
}
elsif ($anvil->data->{switches}{edit})
{
$key = "message_0301";
}
elsif ($anvil->data->{switches}{'delete'})
{
$key = "message_0302";
}
print $anvil->Words->string({key => $key, variables => {
new_name => $anvil->data->{switches}{"recipient-name"},
new_email => $anvil->data->{switches}{"recipient-email"},
new_language => $anvil->data->{sys}{say_new_language},
new_level => $anvil->data->{sys}{say_new_level},
old_name => $recipient_uuid ? $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_name} : "",
old_email => $recipient_uuid ? $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_email} : "",
old_language => $anvil->data->{sys}{say_old_language},
old_level => $anvil->data->{sys}{say_old_level},
}})."\n";
my $answer = <STDIN>;
chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (lc($answer) !~ /^y/)
{
print $anvil->Words->string({key => "message_0022"})."\n";
$anvil->nice_exit({exit_code => 0});
}
}
# Still alive?
if ($anvil->data->{switches}{add})
{
# Create the new entry.
my ($mail_server_uuid) = $anvil->Database->insert_or_update_recipients({
debug => 2,
recipient_name => $anvil->data->{switches}{"recipient-name"},
recipient_email => $anvil->data->{switches}{"recipient-email"},
recipient_language => $anvil->data->{switches}{"recipient-language"},
recipient_level => $anvil->data->{switches}{"recipient-level"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0297", variables => { uuid => $mail_server_uuid }})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{edit})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_recipients({
debug => 2,
recipient_uuid => $anvil->data->{switches}{"recipient-uuid"},
recipient_name => $anvil->data->{switches}{"recipient-name"},
recipient_email => $anvil->data->{switches}{"recipient-email"},
recipient_language => $anvil->data->{switches}{"recipient-language"},
recipient_level => $anvil->data->{switches}{"recipient-level"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0298"})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{'delete'})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_recipients({
debug => 2,
'delete' => 1,
recipient_uuid => $anvil->data->{switches}{"recipient-uuid"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0299"})."\n";
$anvil->nice_exit({exit_code => 0});
}
else
{
$anvil->data->{sys}{show}{mail_recipients} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients},
}});
show_existing($anvil);
}
return(0); return(0);
} }
@ -93,7 +301,155 @@ sub handle_mail_servers
{ {
my ($anvil) = @_; my ($anvil) = @_;
### Are we adding, editing or deleting?
# If we're adding or editing, all fields are required.
my $confirm_needed = 0;
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
# Did the user confirm yet?
if ((not $anvil->data->{switches}{'y'}) and (not $anvil->data->{switches}{'yes'}))
{
$confirm_needed = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { confirm_needed => $confirm_needed }});
}
}
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}))
{
# Do we have what we need?
my $problem = 0;
foreach my $switch ("mail-server-address", "mail-server-port", "mail-server-username", "mail-server-password", "mail-server-security", "mail-server-authentication", "mail-server-helo-domain")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
switch => $switch,
"switches::$switch" => $anvil->data->{switches}{$switch},
}});
if (not $anvil->data->{switches}{$switch})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => $switch }});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
if ($problem)
{
$anvil->nice_exit({exit_code => 1});
}
}
# If we're editing or deleting, make sure we have a valid UUID.
my $mail_server_uuid = $anvil->data->{switches}{"mail-server-uuid"};
if (($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
if (not $mail_server_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => "mail-server-uuid" }});
$anvil->nice_exit({exit_code => 1});
}
if (not exists $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0388", variables => { uuid => $mail_server_uuid }});
$anvil->nice_exit({exit_code => 1});
}
}
# Confirmed?
if ($confirm_needed)
{
my $key = "";
if ($anvil->data->{switches}{add})
{
$key = "message_0294";
}
elsif ($anvil->data->{switches}{edit})
{
$key = "message_0295";
}
elsif ($anvil->data->{switches}{'delete'})
{
$key = "message_0296";
}
print $anvil->Words->string({key => $key, variables => {
new_address => $anvil->data->{switches}{"mail-server-address"},
new_port => $anvil->data->{switches}{"mail-server-port"},
new_username => $anvil->data->{switches}{"mail-server-username"},
new_password => $anvil->data->{switches}{"mail-server-password"},
new_authentication => $anvil->Words->string({key => $anvil->data->{sys}{say_new_auth}}),
new_security => $anvil->Words->string({key => $anvil->data->{sys}{say_new_security}}),
new_helo_domain => $anvil->data->{switches}{"mail-server-helo-domain"},
old_address => $mail_server_uuid ? $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_address} : "",
old_port => $mail_server_uuid ? $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_port} : "",
old_username => $mail_server_uuid ? $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_username} : "",
old_password => $mail_server_uuid ? $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password} : "",
old_authentication => $mail_server_uuid ? $anvil->Words->string({key => $anvil->data->{sys}{say_old_auth}}) : "",
old_security => $mail_server_uuid ? $anvil->Words->string({key => $anvil->data->{sys}{say_old_security}}) : "",
old_helo_domain => $mail_server_uuid ? $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_helo_domain} : "",
}})."\n";
my $answer = <STDIN>;
chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (lc($answer) !~ /^y/)
{
print $anvil->Words->string({key => "message_0022"})."\n";
$anvil->nice_exit({exit_code => 0});
}
}
# Still alive?
if ($anvil->data->{switches}{add})
{
# Create the new entry.
my ($mail_server_uuid) = $anvil->Database->insert_or_update_mail_servers({
debug => 2,
mail_server_address => $anvil->data->{switches}{"mail-server-address"},
mail_server_port => $anvil->data->{switches}{"mail-server-port"},
mail_server_username => $anvil->data->{switches}{"mail-server-username"},
mail_server_password => $anvil->data->{switches}{"mail-server-password"},
mail_server_authentication => $anvil->data->{switches}{"mail-server-authentication"},
mail_server_security => $anvil->data->{switches}{"mail-server-security"},
mail_server_helo_domain => $anvil->data->{switches}{"mail-server-helo-domain"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0297", variables => { uuid => $mail_server_uuid }})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{edit})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_mail_servers({
debug => 2,
mail_server_uuid => $anvil->data->{switches}{"mail-server-uuid"},
mail_server_address => $anvil->data->{switches}{"mail-server-address"},
mail_server_port => $anvil->data->{switches}{"mail-server-port"},
mail_server_username => $anvil->data->{switches}{"mail-server-username"},
mail_server_password => $anvil->data->{switches}{"mail-server-password"},
mail_server_authentication => $anvil->data->{switches}{"mail-server-authentication"},
mail_server_security => $anvil->data->{switches}{"mail-server-security"},
mail_server_helo_domain => $anvil->data->{switches}{"mail-server-helo-domain"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0298"})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{'delete'})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_mail_servers({
debug => 2,
'delete' => 1,
mail_server_uuid => $anvil->data->{switches}{"mail-server-uuid"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0299"})."\n";
$anvil->nice_exit({exit_code => 0});
}
else
{
$anvil->data->{sys}{show}{mail_servers} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::mail_servers' => $anvil->data->{sys}{show}{mail_servers},
}});
show_existing($anvil);
}
return(0); return(0);
} }
@ -161,6 +517,9 @@ sub show_existing
's8:mail_server_helo_domain' => $mail_server_helo_domain, 's8:mail_server_helo_domain' => $mail_server_helo_domain,
}}); }});
# mail_server_helo_domain is 'DELETED' if, well, deleted.
next if $mail_server_helo_domain eq "DELETED";
if (length($mail_server_address) > $anvil->data->{longest}{mail_server_address}) if (length($mail_server_address) > $anvil->data->{longest}{mail_server_address})
{ {
$anvil->data->{longest}{mail_server_address} = length($mail_server_address); $anvil->data->{longest}{mail_server_address} = length($mail_server_address);
@ -291,7 +650,7 @@ sub show_existing
my $recipient_email = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_email}; my $recipient_email = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_email};
my $recipient_language = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_language}; my $recipient_language = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_language};
my $say_language = $anvil->data->{sys}{languages}{$recipient_language}; my $say_language = $anvil->data->{sys}{languages}{$recipient_language};
my $recipient_level = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_level}; my $recipient_level = say_recipient_level($anvil, $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_level});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:recipient_name" => $recipient_name, "s1:recipient_name" => $recipient_name,
"s2:recipient_uuid" => $recipient_uuid, "s2:recipient_uuid" => $recipient_uuid,
@ -325,9 +684,9 @@ sub show_existing
}}); }});
} }
if (length($anvil->data->{say_alert}{$recipient_level}) > $anvil->data->{longest}{recipient_alert_level}) if (length($recipient_level) > $anvil->data->{longest}{recipient_alert_level})
{ {
$anvil->data->{longest}{recipient_alert_level} = length($anvil->data->{say_alert}{$recipient_level}); $anvil->data->{longest}{recipient_alert_level} = length($recipient_level);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::recipient_alert_level' => $anvil->data->{longest}{recipient_alert_level}, 'longest::recipient_alert_level' => $anvil->data->{longest}{recipient_alert_level},
}}); }});
@ -335,6 +694,8 @@ sub show_existing
} }
# Now show the data. # Now show the data.
if ($anvil->data->{sys}{show}{mail_servers})
{
# my $break_line = "+-".sprintf("%0${longest_anvil_name}d", 0); # my $break_line = "+-".sprintf("%0${longest_anvil_name}d", 0);
# my $header_line = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." "; # my $header_line = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." ";
# my $blank_lead = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." "; # my $blank_lead = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." ";
@ -360,15 +721,20 @@ sub show_existing
's7:mail_server_authentication' => $mail_server_authentication, 's7:mail_server_authentication' => $mail_server_authentication,
's8:mail_server_helo_domain' => $mail_server_helo_domain, 's8:mail_server_helo_domain' => $mail_server_helo_domain,
}}); }});
next if $mail_server_helo_domain eq "DELETED";
print $mail_server_address.", ".$mail_server_port.", ".$mail_server_username.", ".$mail_server_password.", ".$mail_server_security.", ".$mail_server_authentication.", ".$mail_server_helo_domain.", ".$mail_server_uuid."\n"; print $mail_server_address.", ".$mail_server_port.", ".$mail_server_username.", ".$mail_server_password.", ".$mail_server_security.", ".$mail_server_authentication.", ".$mail_server_helo_domain.", ".$mail_server_uuid."\n";
$mail_servers++; $mail_servers++;
} }
if (not $mail_servers) if (not $mail_servers)
{ {
print "No mail servers configured yet!\n"; print "# No mail servers configured yet!\n";
} }
print "\n"; print "\n";
}
if ($anvil->data->{sys}{show}{recipients})
{
print "-=] Recipients;\n"; print "-=] Recipients;\n";
print "Name, Email, Alert Level, Language, Recipient UUID\n"; print "Name, Email, Alert Level, Language, Recipient UUID\n";
my $recipients = 0; my $recipients = 0;
@ -388,15 +754,21 @@ sub show_existing
"s6:recipient_level" => $recipient_level, "s6:recipient_level" => $recipient_level,
}}); }});
print $recipient_name.", ".$recipient_email.", ".$anvil->data->{say_alert}{$recipient_level}.", ".$say_language.", ".$recipient_uuid."\n"; # Get the translated log level name.
my $say_recipient_level = say_recipient_level($anvil, $recipient_level);
print $recipient_name.", ".$recipient_email.", ".$say_recipient_level.", ".$say_language.", ".$recipient_uuid."\n";
$recipients++; $recipients++;
} }
if (not $recipients) if (not $recipients)
{ {
print "No alert recipients added yet!\n"; print "# No alert recipients added yet!\n";
} }
print "\n"; print "\n";
}
if ($anvil->data->{sys}{show}{notifications})
{
print "-=] Notification Over-rides;\n"; print "-=] Notification Over-rides;\n";
print "Recipient, Host, Anvil!, Alert Level, Notification UUID\n"; print "Recipient, Host, Anvil!, Alert Level, Notification UUID\n";
my $notifications = 0; my $notifications = 0;
@ -420,11 +792,14 @@ sub show_existing
} }
if (not $notifications) if (not $notifications)
{ {
print "No notification over-rides found.\n"; print "# No notification over-rides found.\n";
}
print "\n";
} }
# Lastly, show machines. # Lastly, show machines.
print "\n"; if ($anvil->data->{sys}{show}{systems})
{
print "-=] Striker Dashboards;\n"; print "-=] Striker Dashboards;\n";
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}}) foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}})
{ {
@ -454,10 +829,50 @@ sub show_existing
print " - Node 2: .. [".$anvil->data->{hosts}{host_uuid}{$anvil_node2_host_uuid}{short_host_name}."], UUID: [".$anvil_node2_host_uuid."]\n"; print " - Node 2: .. [".$anvil->data->{hosts}{host_uuid}{$anvil_node2_host_uuid}{short_host_name}."], UUID: [".$anvil_node2_host_uuid."]\n";
print " - DR Host 1: [".$say_dr1_name."], UUID: [".$say_dr1_uuid."]\n"; print " - DR Host 1: [".$say_dr1_name."], UUID: [".$say_dr1_uuid."]\n";
} }
}
return(0); return(0);
} }
sub say_recipient_level
{
my ($anvil, $recipient_level) = @_;
my $say_recipient_level = $recipient_level;
if ($recipient_level == 0)
{
# Ignore
$say_recipient_level .= " (".$anvil->Words->string({key => "unit_0023"}).")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_recipient_level => $say_recipient_level }});
}
elsif ($recipient_level == 1)
{
# Critical
$say_recipient_level .= " (".$anvil->Words->string({key => "unit_0024"}).")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_recipient_level => $say_recipient_level }});
}
elsif ($recipient_level == 2)
{
# Warning
$say_recipient_level .= " (".$anvil->Words->string({key => "unit_0025"}).")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_recipient_level => $say_recipient_level }});
}
elsif ($recipient_level == 3)
{
# Notice
$say_recipient_level .= " (".$anvil->Words->string({key => "unit_0026"}).")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_recipient_level => $say_recipient_level }});
}
elsif ($recipient_level == 4)
{
# Info
$say_recipient_level .= " (".$anvil->Words->string({key => "unit_0027"}).")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_recipient_level => $say_recipient_level }});
}
return($say_recipient_level);
}
# This sanity checks input switches. By necessity, this also loads data from the database. # This sanity checks input switches. By necessity, this also loads data from the database.
sub check_switches sub check_switches
{ {
@ -474,6 +889,14 @@ sub check_switches
### Now sanity check ### Now sanity check
my $problem = 0; my $problem = 0;
# These will be used to limit the display of things, if/when appropriate
$anvil->data->{sys}{show}{mail_servers} = 0;
$anvil->data->{sys}{show}{recipients} = 0;
$anvil->data->{sys}{show}{notifications} = 0;
$anvil->data->{sys}{show}{systems} = 0;
$anvil->data->{sys}{say_old_security} = "";
$anvil->data->{sys}{say_old_auth} = "";
# Validate UUIDs. # Validate UUIDs.
foreach my $switch ("mail-server-uuid", "notification-uuid", "recipient-uuid", "notification-recipient-uuid", "notification-host-uuid") foreach my $switch ("mail-server-uuid", "notification-uuid", "recipient-uuid", "notification-recipient-uuid", "notification-host-uuid")
{ {
@ -481,14 +904,98 @@ sub check_switches
if (($anvil->data->{switches}{$switch}) && (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{$switch}}))) if (($anvil->data->{switches}{$switch}) && (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{$switch}})))
{ {
# Invalid UUID. # Invalid UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0380", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0380", variables => {
uuid => $anvil->data->{switches}{$switch}, uuid => $anvil->data->{switches}{$switch},
switch => "--".$switch, switch => $switch,
}}); }});
$problem = 1; $problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
} }
# If it's a Security or Authentication UUID, translate the strings.
if ((not $problem) && ($switch eq "mail-server-uuid") && ($anvil->data->{switches}{$switch}))
{
my $mail_server_uuid = $anvil->data->{switches}{$switch};
my $mail_server_security = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_security};
my $mail_server_authentication = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_authentication};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
mail_server_uuid => $mail_server_uuid,
mail_server_security => $mail_server_security,
mail_server_authentication => $mail_server_authentication,
}});
if ($mail_server_security eq "none")
{
$anvil->data->{sys}{say_old_security} = "name_0007";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_security" => $anvil->data->{sys}{say_old_security},
}});
}
elsif ($mail_server_security eq "starttls")
{
$anvil->data->{sys}{say_old_security} = "name_0008";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_security" => $anvil->data->{sys}{say_old_security},
}});
}
elsif ($mail_server_security eq "ssl_tls")
{
$anvil->data->{sys}{say_old_security} = "name_0009";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_security" => $anvil->data->{sys}{say_old_security},
}});
}
if ($mail_server_authentication eq "normal_password")
{
# normal_password
$anvil->data->{sys}{say_old_auth} = "name_0001";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
elsif ($mail_server_authentication eq "encrypted_password")
{
# encrypted_password
$anvil->data->{sys}{say_old_auth} = "name_0002";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
elsif ($mail_server_authentication eq "kerberos_gssapi")
{
# kerberos_gssapi
$anvil->data->{sys}{say_old_auth} = "name_0003";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
elsif ($mail_server_authentication eq "ntlm")
{
# ntlm, no need to translate
$anvil->data->{sys}{say_old_auth} = "name_0004";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
elsif ($mail_server_authentication eq "tls_certificate")
{
# tls_certificate
$anvil->data->{sys}{say_old_auth} = "name_0005";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
elsif ($mail_server_authentication eq "oauth2")
{
# oauth2, no need to translate
$anvil->data->{sys}{say_old_auth} = "name_0006";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_old_auth" => $anvil->data->{sys}{say_old_auth},
}});
}
}
} }
# Validate domain or IP data. # Validate domain or IP data.
@ -500,9 +1007,9 @@ sub check_switches
# Make sure it's a domain or IP address. # Make sure it's a domain or IP address.
if ((not $anvil->Validate->domain_name({name => $anvil->data->{switches}{$switch}})) && (not $anvil->Validate->ip({ip => $anvil->data->{switches}{$switch}}))) if ((not $anvil->Validate->domain_name({name => $anvil->data->{switches}{$switch}})) && (not $anvil->Validate->ip({ip => $anvil->data->{switches}{$switch}})))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0381", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0381", variables => {
name => $anvil->data->{switches}{$switch}, name => $anvil->data->{switches}{$switch},
switch => "--".$switch, switch => $switch,
}}); }});
$problem = 1; $problem = 1;
@ -515,13 +1022,19 @@ sub check_switches
foreach my $switch ("notification-alert-level", "recipient-level") foreach my $switch ("notification-alert-level", "recipient-level")
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }});
if ($anvil->data->{switches}{$switch}) if ($anvil->data->{switches}{$switch} ne "")
{ {
# If they used a level name, convert it to a number. # If they used a level name, convert it to a number.
# 0 = "ignore"
# 1 = "critical" alerts only # 1 = "critical" alerts only
# 2 = "warning" and critical alerts # 2 = "warning" and critical alerts
# 3 = "notice", warning and critical alerts # 3 = "notice", warning and critical alerts
# 4 = "info"; All alerts. This generates almost constant alerts! # 4 = "info"; All alerts. This generates almost constant alerts!
if ($anvil->data->{switches}{$switch} eq "ignore")
{
$anvil->data->{switches}{$switch} = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::".$switch => $anvil->data->{switches}{$switch} }});
}
if ($anvil->data->{switches}{$switch} eq "critical") if ($anvil->data->{switches}{$switch} eq "critical")
{ {
$anvil->data->{switches}{$switch} = 1; $anvil->data->{switches}{$switch} = 1;
@ -544,12 +1057,12 @@ sub check_switches
} }
if (($anvil->data->{switches}{$switch} =~ /\D/) or if (($anvil->data->{switches}{$switch} =~ /\D/) or
($anvil->data->{switches}{$switch} < 1) or ($anvil->data->{switches}{$switch} < 0) or
($anvil->data->{switches}{$switch} > 4)) ($anvil->data->{switches}{$switch} > 4))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0382", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0382", variables => {
level => $anvil->data->{switches}{$switch}, level => $anvil->data->{switches}{$switch},
switch => "--".$switch, switch => $switch,
}}); }});
$problem = 1; $problem = 1;
@ -566,7 +1079,7 @@ sub check_switches
($anvil->data->{switches}{"mail-server-port"} < 1) or ($anvil->data->{switches}{"mail-server-port"} < 1) or
($anvil->data->{switches}{"mail-server-port"} > 65535)) ($anvil->data->{switches}{"mail-server-port"} > 65535))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0383", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0383", variables => {
port => $anvil->data->{switches}{"mail-server-port"}, port => $anvil->data->{switches}{"mail-server-port"},
switch => "--mail-server-port", switch => "--mail-server-port",
}}); }});
@ -577,14 +1090,37 @@ sub check_switches
} }
# Make sure mail server security is correct. # Make sure mail server security is correct.
$anvil->data->{sys}{say_new_security} = "";
if ($anvil->data->{switches}{"mail-server-security"}) if ($anvil->data->{switches}{"mail-server-security"})
{ {
$anvil->data->{switches}{"mail-server-security"} = lc($anvil->data->{switches}{"mail-server-security"}); $anvil->data->{switches}{"mail-server-security"} = lc($anvil->data->{switches}{"mail-server-security"});
if (($anvil->data->{switches}{"mail-server-security"} ne "none") && $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
($anvil->data->{switches}{"mail-server-security"} ne "starttls") && "switches::mail-server-security" => $anvil->data->{switches}{"mail-server-security"},
($anvil->data->{switches}{"mail-server-security"} ne "tls-ssl")) }});
if ($anvil->data->{switches}{"mail-server-security"} eq "none")
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0384", variables => { $anvil->data->{sys}{say_new_security} = "name_0007";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_security" => $anvil->data->{sys}{say_new_security},
}});
}
elsif ($anvil->data->{switches}{"mail-server-security"} eq "starttls")
{
$anvil->data->{sys}{say_new_security} = "name_0008";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_security" => $anvil->data->{sys}{say_new_security},
}});
}
elsif ($anvil->data->{switches}{"mail-server-security"} eq "tls-ssl")
{
$anvil->data->{sys}{say_new_security} = "name_0009";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_security" => $anvil->data->{sys}{say_new_security},
}});
}
else
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0384", variables => {
security => $anvil->data->{switches}{"mail-server-security"}, security => $anvil->data->{switches}{"mail-server-security"},
}}); }});
@ -593,26 +1129,87 @@ sub check_switches
} }
} }
$anvil->data->{sys}{say_new_auth} = "";
if ($anvil->data->{switches}{"mail-server-authentication"}) if ($anvil->data->{switches}{"mail-server-authentication"})
{ {
$anvil->data->{switches}{"mail-server-authentication"} = lc($anvil->data->{switches}{"mail-server-authentication"}); $anvil->data->{switches}{"mail-server-authentication"} = lc($anvil->data->{switches}{"mail-server-authentication"});
if (($anvil->data->{switches}{"mail-server-authentication"} ne "none") && $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
($anvil->data->{switches}{"mail-server-authentication"} ne "plain-text") && "switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"},
($anvil->data->{switches}{"mail-server-authentication"} ne "encrypted")) }});
if ($anvil->data->{switches}{"mail-server-authentication"} eq "none")
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0385", variables => { # normal_password
auth => $anvil->data->{switches}{"mail-server-authentication"}, $anvil->data->{sys}{say_new_auth} = "name_0001";
$anvil->data->{switches}{"mail-server-authentication"} = "normal_password";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
"switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"},
}}); }});
}
elsif ($anvil->data->{switches}{"mail-server-authentication"} eq "encrypted")
{
# encrypted_password
$anvil->data->{sys}{say_new_auth} = "name_0002";
$anvil->data->{switches}{"mail-server-authentication"} = "encrypted_password";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
"switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"},
}});
}
elsif ($anvil->data->{switches}{"mail-server-authentication"} eq "kerberos")
{
# kerberos_gssapi
$anvil->data->{sys}{say_new_auth} = "name_0003";
$anvil->data->{switches}{"mail-server-authentication"} = "kerberos_gssapi";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
"switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"},
}});
}
elsif ($anvil->data->{switches}{"mail-server-authentication"} eq "ntlm")
{
# ntlm, no need to translate
$anvil->data->{sys}{say_new_auth} = "name_0004";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
}});
}
elsif ($anvil->data->{switches}{"mail-server-authentication"} eq "tls")
{
# tls_certificate
$anvil->data->{sys}{say_new_auth} = "name_0005";
$anvil->data->{switches}{"mail-server-authentication"} = "tls_certificate";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
"switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"},
}});
}
elsif ($anvil->data->{switches}{"mail-server-authentication"} eq "oauth2")
{
# oauth2, no need to translate
$anvil->data->{sys}{say_new_auth} = "name_0006";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::say_new_auth" => $anvil->data->{sys}{say_new_auth},
}});
}
else
{
# Not valid
$problem = 1; $problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0385", variables => {
auth => $anvil->data->{switches}{"mail-server-authentication"},
}});
} }
} }
$anvil->data->{sys}{say_new_language} = "";
$anvil->data->{sys}{say_new_level} = "";
if ($anvil->data->{switches}{"recipient-email"}) if ($anvil->data->{switches}{"recipient-email"})
{ {
if (not $anvil->Validate->email({email => $anvil->data->{switches}{"recipient-email"}})) if (not $anvil->Validate->email({email => $anvil->data->{switches}{"recipient-email"}}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "error_0386", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0386", variables => {
email => $anvil->data->{switches}{"recipient-email"}, email => $anvil->data->{switches}{"recipient-email"},
}}); }});
@ -620,10 +1217,73 @@ sub check_switches
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
} }
} }
if (($anvil->data->{switches}{"recipient-level"} ne "") and ($anvil->data->{switches}{"recipient-level"} ne "#!SET!#"))
{
if (($anvil->data->{switches}{"recipient-level"} =~ /\D/) or ($anvil->data->{switches}{"recipient-level"} < 0) or ($anvil->data->{switches}{"recipient-level"} > 4))
{
# Invalid.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0386", variables => {
email => $anvil->data->{switches}{"recipient-email"},
}});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
# Get the translated log level name.
if ($anvil->data->{switches}{"recipient-level"} == 0)
{
# Ignore
$anvil->data->{sys}{say_new_level} = $anvil->Words->string({key => "unit_0023"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_level' => $anvil->data->{sys}{say_new_level},
}});
}
elsif ($anvil->data->{switches}{"recipient-level"} == 1)
{
# Critical
$anvil->data->{sys}{say_new_level} = $anvil->Words->string({key => "unit_0024"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_level' => $anvil->data->{sys}{say_new_level},
}});
}
elsif ($anvil->data->{switches}{"recipient-level"} == 2)
{
# Warning
$anvil->data->{sys}{say_new_level} = $anvil->Words->string({key => "unit_0025"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_level' => $anvil->data->{sys}{say_new_level},
}});
}
elsif ($anvil->data->{switches}{"recipient-level"} == 3)
{
# Notice
$anvil->data->{sys}{say_new_level} = $anvil->Words->string({key => "unit_0026"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_level' => $anvil->data->{sys}{say_new_level},
}});
}
elsif ($anvil->data->{switches}{"recipient-level"} == 4)
{
# Info
$anvil->data->{sys}{say_new_level} = $anvil->Words->string({key => "unit_0027"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_level' => $anvil->data->{sys}{say_new_level},
}});
}
}
# Later, we'll need to parse the language file, for now, we always force 'en_CA'. # Later, we'll need to parse the language file, for now, we always force 'en_CA'.
$anvil->data->{switches}{"recipient-language"} = "en_CA"; $anvil->data->{switches}{"recipient-language"} = "en_CA";
# Get the name of the language.
my $recipient_language = $anvil->data->{switches}{"recipient-language"};
$anvil->data->{sys}{say_new_language} = $anvil->data->{sys}{languages}{$recipient_language};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
recipient_language => $recipient_language,
'sys::say_new_language' => $anvil->data->{sys}{say_new_language},
}});
# If there's a problem, exit now. # If there's a problem, exit now.
if ($problem) if ($problem)
{ {

Loading…
Cancel
Save