You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1971 lines
91 KiB
1971 lines
91 KiB
#!/usr/bin/perl |
|
|
|
use strict; |
|
use warnings; |
|
use Anvil::Tools; |
|
use Data::Dumper; |
|
use Text::Diff; |
|
|
|
$| = 1; |
|
|
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
|
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
|
{ |
|
$running_directory =~ s/^\./$ENV{PWD}/; |
|
} |
|
|
|
my $anvil = Anvil::Tools->new(); |
|
|
|
# Get a list of all interfaces with IP addresses. |
|
$anvil->Get->switches({list => [ |
|
"add", |
|
"edit", |
|
"delete", |
|
"alert-overrides", |
|
"alert-override-uuid", |
|
"alert-override-recipient-uuid", |
|
"alert-override-host-uuid", |
|
"alert-override-alert-level", |
|
"level", |
|
"mail-servers", |
|
"mail-server-uuid", |
|
"mail-server-address", |
|
"mail-server-port", |
|
"mail-server-username", |
|
"mail-server-password", |
|
"mail-server-security", |
|
"mail-server-authentication", |
|
"mail-server-helo-domain", |
|
"recipients", |
|
"recipient-uuid", |
|
"recipient-name", |
|
"recipient-email", |
|
"recipient-language", |
|
"recipient-level", |
|
"test", |
|
"y", |
|
"yes", |
|
]}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}}); |
|
|
|
$anvil->Database->connect(); |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132" }); |
|
if (not $anvil->data->{sys}{database}{connections}) |
|
{ |
|
# No databases, exit. |
|
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003" }); |
|
$anvil->nice_exit({ exit_code => 1 }); |
|
} |
|
|
|
check_switches($anvil); |
|
|
|
if ($anvil->data->{switches}{"mail-servers"}) |
|
{ |
|
handle_mail_servers($anvil); |
|
} |
|
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); |
|
} |
|
elsif ($anvil->data->{switches}{"alert-overrides"}) |
|
{ |
|
$anvil->data->{sys}{show}{alert_overrides} = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::show::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides}, |
|
}}); |
|
handle_alert_overrides($anvil); |
|
} |
|
elsif ($anvil->data->{switches}{"test"}) |
|
{ |
|
handle_test_alert($anvil); |
|
} |
|
else |
|
{ |
|
$anvil->data->{sys}{show}{mail_servers} = 1; |
|
$anvil->data->{sys}{show}{recipients} = 1; |
|
$anvil->data->{sys}{show}{alert_overrides} = 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::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides}, |
|
'sys::show::systems' => $anvil->data->{sys}{show}{systems}, |
|
}}); |
|
show_existing($anvil); |
|
} |
|
|
|
$anvil->nice_exit({exit_code => 0}); |
|
|
|
|
|
############################################################################################################# |
|
# Functions # |
|
############################################################################################################# |
|
|
|
sub handle_test_alert |
|
{ |
|
my ($anvil) = @_; |
|
|
|
# * 1 or "critical" |
|
# * 2 or "warning" |
|
# * 3 or "notice" |
|
# * 4 or "info" |
|
my $level = ""; |
|
my $say_level = ""; |
|
if (($anvil->data->{switches}{level} eq "critical") or ($anvil->data->{switches}{level} eq "1")) |
|
{ |
|
$level = "critical"; |
|
$say_level = $anvil->Words->string({key => "unit_0024"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
level => $level, |
|
say_level => $say_level, |
|
}}); |
|
} |
|
elsif (($anvil->data->{switches}{level} eq "warning") or ($anvil->data->{switches}{level} eq "2")) |
|
{ |
|
$level = "warning"; |
|
$say_level = $anvil->Words->string({key => "unit_0025"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
level => $level, |
|
say_level => $say_level, |
|
}}); |
|
} |
|
elsif (($anvil->data->{switches}{level} eq "notice") or ($anvil->data->{switches}{level} eq "3")) |
|
{ |
|
$level = "notice"; |
|
$say_level = $anvil->Words->string({key => "unit_0026"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
level => $level, |
|
say_level => $say_level, |
|
}}); |
|
} |
|
elsif (($anvil->data->{switches}{level} eq "info") or ($anvil->data->{switches}{level} eq "4")) |
|
{ |
|
$level = "info"; |
|
$say_level = $anvil->Words->string({key => "unit_0027"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
level => $level, |
|
say_level => $say_level, |
|
}}); |
|
} |
|
|
|
my $alert_uuid = $anvil->Alert->register({debug => 2, alert_level => $level, message => "message_0306", variables => { level => $say_level }, set_by => $THIS_FILE, sort_position => 0}); |
|
if ($alert_uuid) |
|
{ |
|
print $anvil->Words->string({key => "message_0306", variables => { level => $say_level }})."\n"; |
|
$anvil->Email->send_alerts(); |
|
} |
|
else |
|
{ |
|
# No one is listening, or no mail servers are configured. |
|
print $anvil->Words->string({key => "message_0307", variables => { level => $say_level }})."\n"; |
|
} |
|
|
|
return(0); |
|
} |
|
|
|
sub handle_alert_overrides |
|
{ |
|
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 ("alert-override-recipient-uuid", "alert-override-host-uuid", "alert-override-alert-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}); |
|
} |
|
} |
|
|
|
# These will be filled out if we need the user to confirm. |
|
$anvil->data->{sys}{say_old_alert_override_level} = ""; |
|
$anvil->data->{sys}{say_old_alert_override_recipient} = ""; |
|
$anvil->data->{sys}{say_old_alert_override_host} = ""; |
|
$anvil->data->{sys}{say_new_alert_override_level} = ""; |
|
$anvil->data->{sys}{say_new_alert_override_recipient} = ""; |
|
$anvil->data->{sys}{say_new_alert_override_host} = ""; |
|
|
|
# Populate the new 'say' strings, if needed. |
|
my $alert_override_uuid = $anvil->data->{switches}{"alert-override-uuid"}; |
|
my $new_alert_override_alert_level = $anvil->data->{switches}{"alert-override-alert-level"}; |
|
my $new_alert_override_recipient_uuid = $anvil->data->{switches}{"alert-override-recipient-uuid"}; |
|
my $new_alert_override_host_uuid = $anvil->data->{switches}{"alert-override-host-uuid"}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
alert_override_uuid => $alert_override_uuid, |
|
new_alert_override_alert_level => $new_alert_override_alert_level, |
|
new_alert_override_recipient_uuid => $new_alert_override_recipient_uuid, |
|
new_alert_override_host_uuid => $new_alert_override_host_uuid, |
|
}}); |
|
if ($new_alert_override_recipient_uuid) |
|
{ |
|
$anvil->data->{sys}{say_new_alert_override_recipient} = $anvil->data->{recipients}{recipient_uuid}{$new_alert_override_recipient_uuid}{recipient_name}." (".$anvil->data->{recipients}{recipient_uuid}{$new_alert_override_recipient_uuid}{recipient_email}.")"; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_recipient' => $anvil->data->{sys}{say_new_alert_override_recipient}, |
|
}}); |
|
} |
|
if ($new_alert_override_host_uuid) |
|
{ |
|
$anvil->data->{sys}{say_new_alert_override_host} = $anvil->data->{hosts}{host_uuid}{$new_alert_override_host_uuid}{host_name}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_host' => $anvil->data->{sys}{say_new_alert_override_host}, |
|
}}); |
|
} |
|
|
|
if ($new_alert_override_alert_level =~ /\d/) |
|
{ |
|
if ($new_alert_override_alert_level == 0) |
|
{ |
|
# Ignore |
|
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0023"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($new_alert_override_alert_level == 1) |
|
{ |
|
# Critical |
|
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0024"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($new_alert_override_alert_level == 2) |
|
{ |
|
# Warning |
|
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0025"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($new_alert_override_alert_level == 3) |
|
{ |
|
# Notice |
|
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0026"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($new_alert_override_alert_level == 4) |
|
{ |
|
# Info |
|
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0027"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level}, |
|
}}); |
|
} |
|
} |
|
|
|
# If we're editing or deleting, make sure we have a valid UUID. |
|
my $old_alert_override_level = ""; |
|
my $old_alert_override_recipient_uuid = ""; |
|
my $old_alert_override_host_uuid = ""; |
|
if (($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'})) |
|
{ |
|
if (not $alert_override_uuid) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => "alert-override-uuid" }}); |
|
$anvil->nice_exit({exit_code => 1}); |
|
} |
|
if (not exists $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0388", variables => { uuid => $alert_override_uuid }}); |
|
$anvil->nice_exit({exit_code => 1}); |
|
} |
|
|
|
$old_alert_override_recipient_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid}; |
|
$old_alert_override_host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid}; |
|
$old_alert_override_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
old_alert_override_recipient_uuid => $old_alert_override_recipient_uuid, |
|
old_alert_override_host_uuid => $old_alert_override_host_uuid, |
|
old_alert_override_level => $old_alert_override_level, |
|
}}); |
|
|
|
# Get the translated log level name. |
|
if ($old_alert_override_level == 0) |
|
{ |
|
# Ignore |
|
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0023"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($old_alert_override_level == 1) |
|
{ |
|
# Critical |
|
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0024"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($old_alert_override_level == 2) |
|
{ |
|
# Warning |
|
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0025"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($old_alert_override_level == 3) |
|
{ |
|
# Notice |
|
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0026"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level}, |
|
}}); |
|
} |
|
elsif ($old_alert_override_level == 4) |
|
{ |
|
# Info |
|
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0027"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level}, |
|
}}); |
|
} |
|
|
|
# Get the name / email of the recipient and the host |
|
$anvil->data->{sys}{say_old_alert_override_recipient} = $anvil->data->{recipients}{recipient_uuid}{$old_alert_override_recipient_uuid}{recipient_name}." (".$anvil->data->{recipients}{recipient_uuid}{$old_alert_override_recipient_uuid}{recipient_email}.")"; |
|
$anvil->data->{sys}{say_old_alert_override_host} = $anvil->data->{hosts}{host_uuid}{$old_alert_override_host_uuid}{host_name}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::say_old_alert_override_recipient' => $anvil->data->{sys}{say_old_alert_override_recipient}, |
|
'sys::say_old_alert_override_host' => $anvil->data->{sys}{say_old_alert_override_host}, |
|
}}); |
|
} |
|
|
|
if ($confirm_needed) |
|
{ |
|
my $key = ""; |
|
if ($anvil->data->{switches}{add}) |
|
{ |
|
$key = "message_0303"; |
|
} |
|
elsif ($anvil->data->{switches}{edit}) |
|
{ |
|
$key = "message_0304"; |
|
} |
|
elsif ($anvil->data->{switches}{'delete'}) |
|
{ |
|
$key = "message_0305"; |
|
} |
|
print $anvil->Words->string({key => $key, variables => { |
|
new_level => $anvil->data->{sys}{say_new_alert_override_level}, |
|
new_recipient => $anvil->data->{sys}{say_new_alert_override_recipient}, |
|
new_host => $anvil->data->{sys}{say_new_alert_override_host}, |
|
old_level => $anvil->data->{sys}{say_old_alert_override_level}, |
|
old_recipient => $anvil->data->{sys}{say_old_alert_override_recipient}, |
|
old_host => $anvil->data->{sys}{say_old_alert_override_host}, |
|
}})."\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_alert_overrides({ |
|
debug => 2, |
|
alert_override_recipient_uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"}, |
|
alert_override_host_uuid => $anvil->data->{switches}{"alert-override-host-uuid"}, |
|
alert_override_alert_level => $anvil->data->{switches}{"alert-override-alert-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_alert_overrides({ |
|
debug => 2, |
|
alert_override_uuid => $anvil->data->{switches}{"alert-override-uuid"}, |
|
alert_override_recipient_uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"}, |
|
alert_override_host_uuid => $anvil->data->{switches}{"alert-override-host-uuid"}, |
|
alert_override_alert_level => $anvil->data->{switches}{"alert-override-alert-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_alert_overrides({ |
|
debug => 2, |
|
'delete' => 1, |
|
alert_override_uuid => $anvil->data->{switches}{"alert-override-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}{alert_overrides} = 1; |
|
$anvil->data->{sys}{show}{recipients} = 1; |
|
$anvil->data->{sys}{show}{systems} = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'sys::show::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides}, |
|
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients}, |
|
'sys::show::systems' => $anvil->data->{sys}{show}{systems}, |
|
}}); |
|
show_existing($anvil); |
|
} |
|
|
|
return(0); |
|
} |
|
|
|
sub handle_recipients |
|
{ |
|
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); |
|
} |
|
|
|
sub handle_mail_servers |
|
{ |
|
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); |
|
} |
|
|
|
# Show existing mail servers. |
|
sub show_existing |
|
{ |
|
my ($anvil) = @_; |
|
|
|
# Show mail servers |
|
$anvil->data->{longest}{mail_server_address} = length($anvil->Words->string({key => "header_0086"})); |
|
$anvil->data->{longest}{mail_server_port} = length($anvil->Words->string({key => "header_0087"})); |
|
$anvil->data->{longest}{mail_server_username} = length($anvil->Words->string({key => "header_0088"})); |
|
$anvil->data->{longest}{mail_server_password} = length($anvil->Words->string({key => "header_0089"})); |
|
$anvil->data->{longest}{mail_server_security} = length($anvil->Words->string({key => "header_0090"})); |
|
$anvil->data->{longest}{mail_server_authentication} = length($anvil->Words->string({key => "header_0091"})); |
|
$anvil->data->{longest}{mail_server_helo_domain} = length($anvil->Words->string({key => "header_0092"})); |
|
$anvil->data->{longest}{mail_server_uuid} = length($anvil->Words->string({key => "header_0093"})); |
|
$anvil->data->{longest}{recipient_name} = length($anvil->Words->string({key => "header_0003"})); |
|
$anvil->data->{longest}{recipient_email} = length($anvil->Words->string({key => "header_0095"})); |
|
$anvil->data->{longest}{recipient_alert_level} = length($anvil->Words->string({key => "header_0096"})); |
|
$anvil->data->{longest}{recipient_language} = length($anvil->Words->string({key => "header_0097"})); |
|
$anvil->data->{longest}{recipient_uuid} = length($anvil->Words->string({key => "header_0098"})); |
|
$anvil->data->{longest}{alert_override_recipient_name} = length($anvil->Words->string({key => "header_0100"})); |
|
$anvil->data->{longest}{alert_override_host_name} = length($anvil->Words->string({key => "header_0026"})); |
|
$anvil->data->{longest}{alert_override_anvil_name} = length($anvil->Words->string({key => "header_0081"})); |
|
$anvil->data->{longest}{alert_override_alert_level} = length($anvil->Words->string({key => "header_0096"})); |
|
$anvil->data->{longest}{alert_override_uuid} = length($anvil->Words->string({key => "header_0102"})); |
|
$anvil->data->{longest}{host_name} = length($anvil->Words->string({key => "header_0026"})); |
|
$anvil->data->{longest}{host_type} = length($anvil->Words->string({key => "header_0103"})); |
|
$anvil->data->{longest}{host_anvil_name} = length($anvil->Words->string({key => "header_0081"})); |
|
$anvil->data->{longest}{host_uuid} = length($anvil->Words->string({key => "header_0104"})); |
|
|
|
$anvil->data->{say_alert}{1} = "1 (".$anvil->Words->string({key => "unit_0024"}).")"; |
|
$anvil->data->{say_alert}{2} = "2 (".$anvil->Words->string({key => "unit_0025"}).")"; |
|
$anvil->data->{say_alert}{3} = "3 (".$anvil->Words->string({key => "unit_0026"}).")"; |
|
$anvil->data->{say_alert}{4} = "4 (".$anvil->Words->string({key => "unit_0027"}).")"; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'say_alert::1' => $anvil->data->{say_alert}{1}, |
|
'say_alert::2' => $anvil->data->{say_alert}{2}, |
|
'say_alert::3' => $anvil->data->{say_alert}{3}, |
|
'say_alert::4' => $anvil->data->{say_alert}{4}, |
|
}}); |
|
|
|
# Get longest counts. |
|
foreach my $mail_server_address (sort {$a cmp $b} keys %{$anvil->data->{mail_servers}{address_to_uuid}}) |
|
{ |
|
my $mail_server_uuid = $anvil->data->{mail_servers}{address_to_uuid}{$mail_server_address}; |
|
my $mail_server_port = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_port}; |
|
my $mail_server_username = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_username}; |
|
my $mail_server_password = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password}; |
|
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}; |
|
my $mail_server_helo_domain = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_helo_domain}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:mail_server_address' => $mail_server_address, |
|
's2:mail_server_uuid' => $mail_server_uuid, |
|
's3:mail_server_port' => $mail_server_port, |
|
's4:mail_server_username' => $mail_server_username, |
|
's5:mail_server_password' => $anvil->Log->is_secure($mail_server_password), |
|
's6:mail_server_security' => $mail_server_security, |
|
's7:mail_server_authentication' => $mail_server_authentication, |
|
'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}) |
|
{ |
|
$anvil->data->{longest}{mail_server_address} = length($mail_server_address); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_address' => $anvil->data->{longest}{mail_server_address}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_port) > $anvil->data->{longest}{mail_server_port}) |
|
{ |
|
$anvil->data->{longest}{mail_server_port} = length($mail_server_port); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_port' => $anvil->data->{longest}{mail_server_port}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_username) > $anvil->data->{longest}{mail_server_username}) |
|
{ |
|
$anvil->data->{longest}{mail_server_username} = length($mail_server_username); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_username' => $anvil->data->{longest}{mail_server_username}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_password) > $anvil->data->{longest}{mail_server_password}) |
|
{ |
|
$anvil->data->{longest}{mail_server_password} = length($mail_server_password); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_password' => $anvil->data->{longest}{mail_server_password}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_security) > $anvil->data->{longest}{mail_server_security}) |
|
{ |
|
$anvil->data->{longest}{mail_server_security} = length($mail_server_security); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_security' => $anvil->data->{longest}{mail_server_security}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_authentication) > $anvil->data->{longest}{mail_server_authentication}) |
|
{ |
|
$anvil->data->{longest}{mail_server_authentication} = length($mail_server_authentication); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_authentication' => $anvil->data->{longest}{mail_server_authentication}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_helo_domain) > $anvil->data->{longest}{mail_server_helo_domain}) |
|
{ |
|
$anvil->data->{longest}{mail_server_helo_domain} = length($mail_server_helo_domain); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_helo_domain' => $anvil->data->{longest}{mail_server_helo_domain}, |
|
}}); |
|
} |
|
|
|
if (length($mail_server_uuid) > $anvil->data->{longest}{mail_server_uuid}) |
|
{ |
|
$anvil->data->{longest}{mail_server_uuid} = length($mail_server_uuid); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::mail_server_uuid' => $anvil->data->{longest}{mail_server_uuid}, |
|
}}); |
|
} |
|
} |
|
|
|
foreach my $alert_override_uuid (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{alert_override_uuid}}) |
|
{ |
|
my $alert_override_recipient_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid}; |
|
my $alert_override_recipient_name = $anvil->data->{recipients}{recipient_uuid}{$alert_override_recipient_uuid}{recipient_name}; |
|
my $alert_override_recipient_email = $anvil->data->{recipients}{recipient_uuid}{$alert_override_recipient_uuid}{recipient_email}; |
|
my $say_recipient = $alert_override_recipient_name." <".$alert_override_recipient_email.">"; |
|
my $alert_override_host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid}; |
|
my $alert_override_short_host_name = $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{short_host_name}; |
|
my $say_anvil_name = $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{anvil_name} : "--"; |
|
my $alert_override_alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:alert_override_uuid' => $alert_override_uuid, |
|
's2:alert_override_recipient_uuid' => $alert_override_recipient_uuid, |
|
's3:alert_override_recipient_name' => $alert_override_recipient_name, |
|
's4:alert_override_recipient_email' => $alert_override_recipient_email, |
|
's5:say_recipient' => $say_recipient, |
|
's6:alert_override_host_uuid' => $alert_override_host_uuid, |
|
's7:alert_override_short_host_name' => $alert_override_short_host_name, |
|
's8:say_anvil_name' => $say_anvil_name, |
|
's9:alert_override_alert_level' => $alert_override_alert_level, |
|
}}); |
|
|
|
if (length($say_recipient) > $anvil->data->{longest}{alert_override_recipient_name}) |
|
{ |
|
$anvil->data->{longest}{alert_override_recipient_name} = length($say_recipient); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::alert_override_recipient_name' => $anvil->data->{longest}{alert_override_recipient_name}, |
|
}}); |
|
} |
|
|
|
if (length($alert_override_short_host_name) > $anvil->data->{longest}{alert_override_host_name}) |
|
{ |
|
$anvil->data->{longest}{alert_override_host_name} = length($alert_override_short_host_name); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::alert_override_host_name' => $anvil->data->{longest}{alert_override_host_name}, |
|
}}); |
|
} |
|
|
|
if (length($say_anvil_name) > $anvil->data->{longest}{alert_override_anvil_name}) |
|
{ |
|
$anvil->data->{longest}{alert_override_anvil_name} = length($say_anvil_name); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::alert_override_anvil_name' => $anvil->data->{longest}{alert_override_anvil_name}, |
|
}}); |
|
} |
|
|
|
if (length($anvil->data->{say_alert}{$alert_override_alert_level}) > $anvil->data->{longest}{alert_override_alert_level}) |
|
{ |
|
$anvil->data->{longest}{alert_override_alert_level} = length($anvil->data->{say_alert}{$alert_override_alert_level}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::alert_override_alert_level' => $anvil->data->{longest}{alert_override_alert_level}, |
|
}}); |
|
} |
|
|
|
if (length($alert_override_uuid) > $anvil->data->{longest}{alert_override_uuid}) |
|
{ |
|
$anvil->data->{longest}{alert_override_uuid} = length($alert_override_uuid); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::alert_override_uuid' => $anvil->data->{longest}{alert_override_uuid}, |
|
}}); |
|
} |
|
|
|
# This will let us display over-rides by user in order. |
|
$anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name} = $alert_override_uuid; |
|
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name} = $say_recipient; |
|
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name} = $say_anvil_name; |
|
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{host_uuid} = $alert_override_host_uuid; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"s1:alert_overrides::name_to_uuid::${alert_override_recipient_name}" => $anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name}, |
|
"s2:alert_overrides::alert_override_uuid::${alert_override_uuid}::recipient_name" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name}, |
|
"s3:alert_overrides::alert_override_uuid::${alert_override_uuid}::anvil_name" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name}, |
|
"s4:alert_overrides::alert_override_uuid::${alert_override_uuid}::host_uuid" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{host_uuid}, |
|
}}); |
|
} |
|
|
|
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{recipients}{name_to_uuid}}) |
|
{ |
|
my $recipient_uuid = $anvil->data->{recipients}{name_to_uuid}{$recipient_name}; |
|
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 $say_language = $anvil->data->{sys}{languages}{$recipient_language}; |
|
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 => { |
|
"s1:recipient_name" => $recipient_name, |
|
"s2:recipient_uuid" => $recipient_uuid, |
|
"s3:recipient_email" => $recipient_email, |
|
"s4:recipient_language" => $recipient_language, |
|
"s5:say_language" => $say_language, |
|
"s6:recipient_level" => $recipient_level, |
|
}}); |
|
|
|
if (length($recipient_name) > $anvil->data->{longest}{recipient_name}) |
|
{ |
|
$anvil->data->{longest}{recipient_name} = length($recipient_name); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::recipient_name' => $anvil->data->{longest}{recipient_name}, |
|
}}); |
|
} |
|
|
|
if (length($recipient_email) > $anvil->data->{longest}{recipient_email}) |
|
{ |
|
$anvil->data->{longest}{recipient_email} = length($recipient_email); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::recipient_email' => $anvil->data->{longest}{recipient_email}, |
|
}}); |
|
} |
|
|
|
if (length($say_language) > $anvil->data->{longest}{recipient_language}) |
|
{ |
|
$anvil->data->{longest}{recipient_language} = length($say_language); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::recipient_language' => $anvil->data->{longest}{recipient_language}, |
|
}}); |
|
} |
|
|
|
if (length($recipient_level) > $anvil->data->{longest}{recipient_alert_level}) |
|
{ |
|
$anvil->data->{longest}{recipient_alert_level} = length($recipient_level); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::recipient_alert_level' => $anvil->data->{longest}{recipient_alert_level}, |
|
}}); |
|
} |
|
|
|
if (length($recipient_uuid) > $anvil->data->{longest}{recipient_uuid}) |
|
{ |
|
$anvil->data->{longest}{recipient_uuid} = length($recipient_uuid); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::recipient_uuid' => $anvil->data->{longest}{recipient_uuid}, |
|
}}); |
|
} |
|
} |
|
|
|
# Pull out the Strikers, node pair members and DR hosts. |
|
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}}) |
|
{ |
|
my $host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name}; |
|
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name}; |
|
my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type}; |
|
my $anvil_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} : "--"; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:host_name' => $host_name, |
|
's2:short_host_name' => $short_host_name, |
|
's3:host_type' => $host_type, |
|
's4:anvil_name' => $anvil_name, |
|
}}); |
|
|
|
if (length($short_host_name) > $anvil->data->{longest}{host_name}) |
|
{ |
|
$anvil->data->{longest}{host_name} = length($short_host_name); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::host_name' => $anvil->data->{longest}{host_name}, |
|
}}); |
|
} |
|
|
|
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = ""; |
|
if ($host_type eq "striker") |
|
{ |
|
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0003"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}, |
|
}}); |
|
} |
|
elsif ($host_type eq "node") |
|
{ |
|
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0007"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}, |
|
}}); |
|
} |
|
elsif ($host_type eq "dr") |
|
{ |
|
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0008"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}, |
|
}}); |
|
} |
|
if (length($anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}) > $anvil->data->{longest}{host_type}) |
|
{ |
|
$anvil->data->{longest}{host_type} = length($anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::host_type' => $anvil->data->{longest}{host_type}, |
|
}}); |
|
} |
|
|
|
if (length($anvil_name) > $anvil->data->{longest}{host_anvil_name}) |
|
{ |
|
$anvil->data->{longest}{host_anvil_name} = length($anvil_name); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::host_anvil_name' => $anvil->data->{longest}{host_anvil_name}, |
|
}}); |
|
} |
|
|
|
if (length($host_uuid) > $anvil->data->{longest}{host_uuid}) |
|
{ |
|
$anvil->data->{longest}{host_uuid} = length($host_uuid); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
'longest::host_uuid' => $anvil->data->{longest}{host_uuid}, |
|
}}); |
|
} |
|
} |
|
|
|
# Now show the data. |
|
if ($anvil->data->{sys}{show}{mail_servers}) |
|
{ |
|
my $longest_mail_server_address = $anvil->data->{longest}{mail_server_address}; |
|
my $longest_mail_server_port = $anvil->data->{longest}{mail_server_port}; |
|
my $longest_mail_server_username = $anvil->data->{longest}{mail_server_username}; |
|
my $longest_mail_server_password = $anvil->data->{longest}{mail_server_password}; |
|
my $longest_mail_server_security = $anvil->data->{longest}{mail_server_security}; |
|
my $longest_mail_server_authentication = $anvil->data->{longest}{mail_server_authentication}; |
|
my $longest_mail_server_helo_domain = $anvil->data->{longest}{mail_server_helo_domain}; |
|
my $longest_mail_server_uuid = $anvil->data->{longest}{mail_server_uuid}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:longest_mail_server_address' => $longest_mail_server_address, |
|
's2:longest_mail_server_port' => $longest_mail_server_port, |
|
's3:longest_mail_server_username' => $longest_mail_server_username, |
|
's4:longest_mail_server_password' => $longest_mail_server_password, |
|
's5:longest_mail_server_security' => $longest_mail_server_security, |
|
's6:longest_mail_server_authentication' => $longest_mail_server_authentication, |
|
's7:longest_mail_server_helo_domain' => $longest_mail_server_helo_domain, |
|
's8:longest_mail_server_uuid' => $longest_mail_server_uuid, |
|
}}); |
|
|
|
my $break_line = "+-".sprintf("%0${longest_mail_server_address}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_port}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_username}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_password}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_security}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_authentication}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_helo_domain}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_mail_server_uuid}d", 0)."-+"; |
|
$break_line =~ s/0/-/g; |
|
|
|
my $header_line = "| ".sprintf("%-${longest_mail_server_address}s", $anvil->Words->string({key => "header_0086"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_port}s", $anvil->Words->string({key => "header_0087"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_username}s", $anvil->Words->string({key => "header_0088"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_password}s", $anvil->Words->string({key => "header_0089"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_security}s", $anvil->Words->string({key => "header_0090"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", $anvil->Words->string({key => "header_0091"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", $anvil->Words->string({key => "header_0092"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", $anvil->Words->string({key => "header_0093"}))." |"; |
|
|
|
# Display |
|
print "-=] ".$anvil->Words->string({key => "striker_0187"})."\n"; |
|
print $break_line."\n"; |
|
print $header_line."\n"; |
|
print $break_line."\n"; |
|
my $mail_servers = 0; |
|
foreach my $mail_server_address (sort {$a cmp $b} keys %{$anvil->data->{mail_servers}{address_to_uuid}}) |
|
{ |
|
my $mail_server_uuid = $anvil->data->{mail_servers}{address_to_uuid}{$mail_server_address}; |
|
my $mail_server_port = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_port}; |
|
my $mail_server_username = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_username}; |
|
my $mail_server_password = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password}; |
|
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}; |
|
my $mail_server_helo_domain = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_helo_domain}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:mail_server_address' => $mail_server_address, |
|
's2:mail_server_uuid' => $mail_server_uuid, |
|
's3:mail_server_port' => $mail_server_port, |
|
's4:mail_server_username' => $mail_server_username, |
|
's5:mail_server_password' => $anvil->Log->is_secure($mail_server_password), |
|
's6:mail_server_security' => $mail_server_security, |
|
's7:mail_server_authentication' => $mail_server_authentication, |
|
's8:mail_server_helo_domain' => $mail_server_helo_domain, |
|
}}); |
|
next if $mail_server_helo_domain eq "DELETED"; |
|
|
|
my $entry_line = "| ".sprintf("%-${longest_mail_server_address}s", $mail_server_address)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_port}s", $mail_server_port)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_username}s", $mail_server_username)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_password}s", $mail_server_password)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_security}s", $mail_server_security)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", $mail_server_authentication)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", $mail_server_helo_domain)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", $mail_server_uuid)." |"; |
|
print $entry_line."\n"; |
|
|
|
$mail_servers++; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_servers => $mail_servers }}); |
|
} |
|
if (not $mail_servers) |
|
{ |
|
my $entry_line = "| ".sprintf("%-${longest_mail_server_address}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_port}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_username}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_password}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_security}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", '--')." |"; |
|
print $entry_line."\n"; |
|
} |
|
print $break_line."\n"; |
|
print "\n"; |
|
} |
|
|
|
if ($anvil->data->{sys}{show}{recipients}) |
|
{ |
|
my $longest_recipient_name = $anvil->data->{longest}{recipient_name}; |
|
my $longest_recipient_email = $anvil->data->{longest}{recipient_email}; |
|
my $longest_recipient_alert_level = $anvil->data->{longest}{recipient_alert_level}; |
|
my $longest_recipient_language = $anvil->data->{longest}{recipient_language}; |
|
my $longest_recipient_uuid = $anvil->data->{longest}{recipient_uuid}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:longest_recipient_name' => $longest_recipient_name, |
|
's2:longest_recipient_email' => $longest_recipient_email, |
|
's3:longest_recipient_alert_level' => $longest_recipient_alert_level, |
|
's4:longest_recipient_language' => $longest_recipient_language, |
|
's5:longest_recipient_uuid' => $longest_recipient_uuid, |
|
}}); |
|
|
|
my $break_line = "+-".sprintf("%0${longest_recipient_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_recipient_email}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_recipient_alert_level}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_recipient_language}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_recipient_uuid}d", 0)."-+"; |
|
$break_line =~ s/0/-/g; |
|
|
|
my $header_line = "| ".sprintf("%-${longest_recipient_name}s", $anvil->Words->string({key => "header_0003"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_recipient_email}s", $anvil->Words->string({key => "header_0095"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", $anvil->Words->string({key => "header_0096"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_recipient_language}s", $anvil->Words->string({key => "header_0097"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_recipient_uuid}s", $anvil->Words->string({key => "header_0098"}))." |"; |
|
|
|
# Display |
|
print "-=] ".$anvil->Words->string({key => "header_0094"})."\n"; |
|
print $break_line."\n"; |
|
print $header_line."\n"; |
|
print $break_line."\n"; |
|
my $recipients = 0; |
|
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{recipients}{name_to_uuid}}) |
|
{ |
|
my $recipient_uuid = $anvil->data->{recipients}{name_to_uuid}{$recipient_name}; |
|
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 $say_language = $anvil->data->{sys}{languages}{$recipient_language}; |
|
my $recipient_level = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_level}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"s1:recipient_name" => $recipient_name, |
|
"s2:recipient_uuid" => $recipient_uuid, |
|
"s3:recipient_email" => $recipient_email, |
|
"s4:recipient_language" => $recipient_language, |
|
"s5:say_language" => $say_language, |
|
"s6:recipient_level" => $recipient_level, |
|
}}); |
|
|
|
# Get the translated log level name. |
|
my $say_recipient_level = say_recipient_level($anvil, $recipient_level); |
|
|
|
my $entry_line = "| ".sprintf("%-${longest_recipient_name}s", $recipient_name)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_email}s", $recipient_email)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", $say_recipient_level)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_language}s", $say_language)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_uuid}s", $recipient_uuid)." |"; |
|
print $entry_line."\n"; |
|
|
|
$recipients++; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { recipients => $recipients }}); |
|
} |
|
if (not $recipients) |
|
{ |
|
my $entry_line = "| ".sprintf("%-${longest_recipient_name}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_email}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_language}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_recipient_uuid}s", '--')." |"; |
|
print $entry_line."\n"; |
|
} |
|
print $break_line."\n"; |
|
print "\n"; |
|
} |
|
|
|
if ($anvil->data->{sys}{show}{alert_overrides}) |
|
{ |
|
my $longest_alert_override_recipient_name = $anvil->data->{longest}{alert_override_recipient_name}; |
|
my $longest_alert_override_host_name = $anvil->data->{longest}{alert_override_host_name}; |
|
my $longest_alert_override_anvil_name = $anvil->data->{longest}{alert_override_anvil_name}; |
|
my $longest_alert_override_alert_level = $anvil->data->{longest}{alert_override_alert_level};; |
|
my $longest_alert_override_uuid = $anvil->data->{longest}{alert_override_uuid}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:longest_alert_override_recipient_name' => $longest_alert_override_recipient_name, |
|
's2:longest_alert_override_host_name' => $longest_alert_override_host_name, |
|
's3:longest_alert_override_anvil_name' => $longest_alert_override_anvil_name, |
|
's4:longest_alert_override_alert_level' => $longest_alert_override_alert_level, |
|
's5:longest_alert_override_uuid' => $longest_alert_override_uuid, |
|
}}); |
|
|
|
my $break_line = "+-".sprintf("%0${longest_alert_override_recipient_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_alert_override_host_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_alert_override_anvil_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_alert_override_alert_level}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_alert_override_uuid}d", 0)."-+"; |
|
$break_line =~ s/0/-/g; |
|
|
|
my $header_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", $anvil->Words->string({key => "header_0100"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", $anvil->Words->string({key => "header_0026"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", $anvil->Words->string({key => "header_0081"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", $anvil->Words->string({key => "header_0096"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", $anvil->Words->string({key => "header_0102"}))." |"; |
|
|
|
# Display |
|
print "-=] ".$anvil->Words->string({key => "header_0099"})."\n"; |
|
print $break_line."\n"; |
|
print $header_line."\n"; |
|
print $break_line."\n"; |
|
|
|
my $alert_overrides = 0; |
|
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{name_to_uuid}}) |
|
{ |
|
my $alert_override_uuid = $anvil->data->{alert_overrides}{name_to_uuid}{$recipient_name}; |
|
my $say_recipient = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name}; |
|
my $say_anvil_name = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name}; |
|
my $host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid}; |
|
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name}; |
|
my $alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level}; |
|
my $say_alert_level = $anvil->data->{say_alert}{$alert_level}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:alert_override_uuid' => $alert_override_uuid, |
|
's2:say_recipient' => $say_recipient, |
|
's3:say_anvil_name' => $say_anvil_name, |
|
's4:alert_level' => $alert_level, |
|
's5:say_alert_level' => $say_alert_level, |
|
}}); |
|
|
|
my $entry_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", $say_recipient)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", $short_host_name)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", $say_anvil_name)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", $say_alert_level)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", $alert_override_uuid)." |"; |
|
print $entry_line."\n"; |
|
|
|
$alert_overrides++; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { alert_overrides => $alert_overrides }}); |
|
} |
|
if (not $alert_overrides) |
|
{ |
|
my $entry_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", '--')." "; |
|
$entry_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", '--')." |"; |
|
print $entry_line."\n"; |
|
} |
|
print $break_line."\n"; |
|
print "\n"; |
|
} |
|
|
|
# Lastly, show machines. |
|
if ($anvil->data->{sys}{show}{systems}) |
|
{ |
|
my $longest_host_name = $anvil->data->{longest}{host_name}; |
|
my $longest_host_type = $anvil->data->{longest}{host_type}; |
|
my $longest_host_anvil_name = $anvil->data->{longest}{host_anvil_name}; |
|
my $longest_host_uuid = $anvil->data->{longest}{host_uuid}; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:longest_host_name' => $longest_host_name, |
|
's2:longest_host_type' => $longest_host_type, |
|
's3:longest_host_anvil_name' => $longest_host_anvil_name, |
|
's4:longest_host_uuid' => $longest_host_uuid, |
|
}}); |
|
|
|
my $break_line = "+-".sprintf("%0${longest_host_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_host_type}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_host_anvil_name}d", 0); |
|
$break_line .= "-+-".sprintf("%0${longest_host_uuid}d", 0)."-+"; |
|
$break_line =~ s/0/-/g; |
|
|
|
my $header_line = "| ".sprintf("%-${longest_host_name}s", $anvil->Words->string({key => "header_0026"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_host_type}s", $anvil->Words->string({key => "header_0103"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_host_anvil_name}s", $anvil->Words->string({key => "header_0081"}))." "; |
|
$header_line .= "| ".sprintf("%-${longest_host_uuid}s", $anvil->Words->string({key => "header_0104"}))." |"; |
|
|
|
# Display |
|
print "-=] ".$anvil->Words->string({key => "header_0105"})."\n"; |
|
print $break_line."\n"; |
|
print $header_line."\n"; |
|
print $break_line."\n"; |
|
foreach my $show_host_type ("striker", "node", "dr") |
|
{ |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { show_host_type => $show_host_type }}); |
|
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}}) |
|
{ |
|
my $host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name}; |
|
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name}; |
|
my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type}; |
|
my $say_host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}; |
|
my $anvil_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} : "--"; |
|
next if $host_type ne $show_host_type; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
's1:host_name' => $host_name, |
|
's2:host_uuid' => $host_uuid, |
|
's3:short_host_name' => $short_host_name, |
|
's4:host_type' => $host_type, |
|
's5:say_host_type' => $say_host_type, |
|
's6:anvil_name' => $anvil_name, |
|
}}); |
|
|
|
my $entry_line = "| ".sprintf("%-${longest_host_name}s", $short_host_name)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_host_type}s", $say_host_type)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_host_anvil_name}s", $anvil_name)." "; |
|
$entry_line .= "| ".sprintf("%-${longest_host_uuid}s", $host_uuid)." |"; |
|
print $entry_line."\n"; |
|
} |
|
} |
|
print $break_line."\n"; |
|
} |
|
|
|
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. |
|
sub check_switches |
|
{ |
|
my ($anvil) = @_; |
|
|
|
# Load data |
|
$anvil->Database->get_hosts(); |
|
$anvil->Database->get_anvils(); |
|
$anvil->Database->get_mail_servers(); |
|
$anvil->Database->get_recipients(); |
|
$anvil->Database->get_alert_overrides(); |
|
$anvil->Words->language_list(); |
|
|
|
### Now sanity check |
|
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}{alert_overrides} = 0; |
|
$anvil->data->{sys}{show}{systems} = 0; |
|
$anvil->data->{sys}{say_old_security} = ""; |
|
$anvil->data->{sys}{say_old_auth} = ""; |
|
|
|
# If we're given 'test', make sure the level is provides. |
|
if ($anvil->data->{switches}{test}) |
|
{ |
|
if (not $anvil->data->{switches}{level}) |
|
{ |
|
# Test requires a level |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0392"}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
|
|
# Is the level valid? |
|
# * 1 or "critical" |
|
# * 2 or "warning" |
|
# * 3 or "notice" |
|
# * 4 or "info" |
|
if (($anvil->data->{switches}{level} ne "critical") && |
|
($anvil->data->{switches}{level} ne "1") && |
|
($anvil->data->{switches}{level} ne "warning") && |
|
($anvil->data->{switches}{level} ne "2") && |
|
($anvil->data->{switches}{level} ne "notice") && |
|
($anvil->data->{switches}{level} ne "3") && |
|
($anvil->data->{switches}{level} ne "info") && |
|
($anvil->data->{switches}{level} ne "4")) |
|
{ |
|
# Invalid test alert level. |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0393", variables => { |
|
level => $anvil->data->{switches}{level}, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
|
|
# Validate UUIDs. |
|
foreach my $switch ("mail-server-uuid", "alert-override-uuid", "recipient-uuid", "alert-override-recipient-uuid", "alert-override-host-uuid") |
|
{ |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); |
|
if (($anvil->data->{switches}{$switch}) && (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{$switch}}))) |
|
{ |
|
# Invalid UUID. |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0380", variables => { |
|
uuid => $anvil->data->{switches}{$switch}, |
|
switch => $switch, |
|
}}); |
|
|
|
$problem = 1; |
|
$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. |
|
foreach my $switch ("mail-server-address", "mail-server-helo-domain") |
|
{ |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); |
|
if ($anvil->data->{switches}{$switch}) |
|
{ |
|
# 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}}))) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0381", variables => { |
|
name => $anvil->data->{switches}{$switch}, |
|
switch => $switch, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
} |
|
|
|
# Check log levels. |
|
foreach my $switch ("alert-override-alert-level", "recipient-level") |
|
{ |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); |
|
if ($anvil->data->{switches}{$switch} ne "") |
|
{ |
|
# If they used a level name, convert it to a number. |
|
# 0 = "ignore" |
|
# 1 = "critical" alerts only |
|
# 2 = "warning" and critical alerts |
|
# 3 = "notice", warning and critical 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") |
|
{ |
|
$anvil->data->{switches}{$switch} = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::".$switch => $anvil->data->{switches}{$switch} }}); |
|
} |
|
elsif ($anvil->data->{switches}{$switch} eq "warning") |
|
{ |
|
$anvil->data->{switches}{$switch} = 2; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::".$switch => $anvil->data->{switches}{$switch} }}); |
|
} |
|
elsif ($anvil->data->{switches}{$switch} eq "notice") |
|
{ |
|
$anvil->data->{switches}{$switch} = 3; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::".$switch => $anvil->data->{switches}{$switch} }}); |
|
} |
|
elsif ($anvil->data->{switches}{$switch} eq "info") |
|
{ |
|
$anvil->data->{switches}{$switch} = 4; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::".$switch => $anvil->data->{switches}{$switch} }}); |
|
} |
|
|
|
if (($anvil->data->{switches}{$switch} =~ /\D/) or |
|
($anvil->data->{switches}{$switch} < 0) or |
|
($anvil->data->{switches}{$switch} > 4)) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0382", variables => { |
|
level => $anvil->data->{switches}{$switch}, |
|
switch => $switch, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
} |
|
|
|
# Ports (there's only one) |
|
if ($anvil->data->{switches}{"mail-server-port"}) |
|
{ |
|
# Make sure it's a valid port. |
|
if (($anvil->data->{switches}{"mail-server-port"} =~ /\D/) or |
|
($anvil->data->{switches}{"mail-server-port"} < 1) or |
|
($anvil->data->{switches}{"mail-server-port"} > 65535)) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0383", variables => { |
|
port => $anvil->data->{switches}{"mail-server-port"}, |
|
switch => "--mail-server-port", |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
|
|
# Make sure mail server security is correct. |
|
$anvil->data->{sys}{say_new_security} = ""; |
|
if ($anvil->data->{switches}{"mail-server-security"}) |
|
{ |
|
$anvil->data->{switches}{"mail-server-security"} = lc($anvil->data->{switches}{"mail-server-security"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"switches::mail-server-security" => $anvil->data->{switches}{"mail-server-security"}, |
|
}}); |
|
if ($anvil->data->{switches}{"mail-server-security"} eq "none") |
|
{ |
|
$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"}, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
|
|
# If set, make sure the "alert-override-recipient-uuid" and "alert-override-host-uuid" are valid. |
|
if ($anvil->data->{switches}{"alert-override-recipient-uuid"}) |
|
{ |
|
my $recipient_uuid = $anvil->data->{switches}{"alert-override-recipient-uuid"}; |
|
if (not exists $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0390", variables => { |
|
uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"}, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
if ($anvil->data->{switches}{"alert-override-host-uuid"}) |
|
{ |
|
my $host_uuid = $anvil->data->{switches}{"alert-override-host-uuid"}; |
|
if (not exists $anvil->data->{hosts}{host_uuid}{$host_uuid}) |
|
{ |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0391", variables => { |
|
uuid => $anvil->data->{switches}{"alert-override-host-uuid"}, |
|
}}); |
|
|
|
$problem = 1; |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
|
} |
|
} |
|
|
|
$anvil->data->{sys}{say_new_auth} = ""; |
|
if ($anvil->data->{switches}{"mail-server-authentication"}) |
|
{ |
|
$anvil->data->{switches}{"mail-server-authentication"} = lc($anvil->data->{switches}{"mail-server-authentication"}); |
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
"switches::mail-server-authentication" => $anvil->data->{switches}{"mail-server-authentication"}, |
|
}}); |
|
if ($anvil->data->{switches}{"mail-server-authentication"} eq "none") |
|
{ |
|
# normal_password |
|
$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; |
|
$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 (not $anvil->Validate->email({email => $anvil->data->{switches}{"recipient-email"}})) |
|
{ |
|
$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 }}); |
|
} |
|
} |
|
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'. |
|
$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 ($problem) |
|
{ |
|
$anvil->nice_exit({exit_code => 1}); |
|
} |
|
|
|
return(0); |
|
}
|
|
|