@ -36,7 +36,7 @@ my $anvil = Anvil::Tools->new();
if (($< != 0) && ($> != 0))
{
# Not root
print $anvil->Words->string({key => "error_0005"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0005"}) ;
$anvil->nice_exit({exit_code => 1});
}
@ -50,7 +50,7 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure =
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
print $anvil->Words->string({key => "error_0003"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0003"}) ;
$anvil->nice_exit({exit_code => 2});
}
@ -71,7 +71,7 @@ if ($anvil->data->{switches}{'password-file'})
else
{
# The file doesn't exist.
print $anvil->Words->string({ key => "error_0008", variables => { file => $anvil->data->{switches}{'password-file'} }})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0008", variables => { file => $anvil->data->{switches}{'password-file'} }});
$anvil->nice_exit({exit_code => 4});
}
}
@ -110,7 +110,7 @@ elsif (not $anvil->data->{switches}{'new-password'})
}
else
{
print $anvil->Words->string({key => "error_0007"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0007"}) ;
$anvil->nice_exit({exit_code => 3});
}
}
@ -130,7 +130,7 @@ else
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { "switches::new-password" => $anvil->data->{switches}{'new-password'} }});
if (($anvil->data->{switches}{y}) or ($anvil->data->{switches}{yes}))
{
print $anvil->Words->string({key => "message_0023"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "message_0023"}) ;
update_local_passwords($anvil);
}
else
@ -151,9 +151,10 @@ else
}
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0750"});
$anvil->nice_exit({exit_code => 0});
#############################################################################################################
# Functions #
#############################################################################################################
@ -165,7 +166,7 @@ sub update_local_passwords
# Update the 'admin' user password in the database.
my $user = "admin";
print $anvil->Words->string({ key => "message_0024", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0024", variables => { user => $user }});
my $user_uuid = $anvil->Database->insert_or_update_users({
debug => 2,
@ -177,7 +178,7 @@ sub update_local_passwords
});
# Log out any Striker sessions.
$anvil->Account->logout({host_uuid => "all"});
print $anvil->Words->string({key => "message_0025"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"}) ;
# Validate
my $valid = $anvil->Account->validate_password({
@ -215,25 +216,25 @@ sub update_local_passwords
my $owner_name = $results->[0]->[1];
foreach my $user ("postgres", $owner_name)
{
print $anvil->Words->string({ key => "message_0026", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0026", variables => { user => $user }});
my $query = "ALTER ROLE ".$user." WITH PASSWORD ".$dbh->quote($anvil->data->{switches}{'new-password'});
$dbh->do($query) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0090", variables => {
query => $anvil->Log->is_secure($query),
server => "localhost",
db_error => $DBI::errstr,
}});
print $anvil->Words->string({key => "message_0025"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"}) ;
}
# Update our database password in anvil.conf
print $anvil->Words->string({ key => "message_0027", variables => { file => $anvil->data->{switches}{'new-password'} }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0027", variables => { file => $anvil->data->{switches}{'new-password'} }});
$anvil->Storage->update_config({
debug => 2,
secure => 1,
variable => "database::${host_uuid}::password",
value => $anvil->data->{switches}{'new-password'},
});
print $anvil->Words->string({key => "message_0025"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"}) ;
### TODO: Loop through any other dashboards and nodes we know about and call the above with 'target'
### (and password, port and remote_user) set.
@ -241,13 +242,13 @@ sub update_local_passwords
# Update the local users.
foreach my $user ("admin", "root")
{
print $anvil->Words->string({ key => "message_0028", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0028", variables => { user => $user }});
$anvil->System->change_shell_user_password({debug => 2, user => $user, new_password => $anvil->data->{switches}{'new-password'}});
print $anvil->Words->string({key => "message_0025"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"}) ;
}
# All done!
print $anvil->Words->string({key => "message_0029"})."\n" ;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0029"}) ;
return(0);
}