@ -31,13 +31,13 @@ $( = $);
my $anvil = Anvil::Tools->new();
$anvil->Log->level({set => 2});
$anvil->Log->secure({set => 0 });
$anvil->Log->secure({set => 1 });
# Read switches
$anvil->Get->switches;
# Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{config}{'anvil.conf'}});
$anvil->Storage->read_config({file => $anvil->data->{path}{configs }{'anvil.conf'}});
# Make sure we're running as 'root'
# $< == real UID, $> == effective UID
@ -62,17 +62,20 @@ if (not $connections)
# 1. If we've been told of a password file, read it
# 2. If the user passed the password with --new-password <secret>, use that.
# 3. Ask the user for the new password.
if ($anvil->data->{switches}{password_file })
if ($anvil->data->{switches}{'password-file' })
{
# Read the password in from the file.
if (-e $anvil->data->{switches}{password_file})
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { "switches::password-file" => $anvil->data->{switches}{'password-file'} }});
if (-e $anvil->data->{switches}{'password-file'})
{
$anvil->data->{switches}{'new-password'} = $anvil->Storage->read_file({file => $anvil->data->{switches}{password_file}});
# Read it in and remove the new-line(s), if it(they) exist.
$anvil->data->{switches}{'new-password'} = $anvil->Storage->read_file({file => $anvil->data->{switches}{'password-file'}});
$anvil->data->{switches}{'new-password'} =~ s/\n//gs;
}
else
{
# The file doesn't exist.
print $anvil->Words->string({key => "error_0008", variables => { file => $anvil->data->{switches}{password_file } }});
print $anvil->Words->string({key => "error_0008", variables => { file => $anvil->data->{switches}{'password-file' } }});
$anvil->nice_exit({exit_code => 4});
}
}
@ -80,15 +83,13 @@ elsif (not $anvil->data->{switches}{'new-password'})
{
print $anvil->Words->string({key => "message_0018"})."\n";
# Turn off echo
my $old_stty = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." --save"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { old_stty => $old_stty }});
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." -echo"});
$anvil->System->stty_echo({set => "off"});
my $password1 = <STDIN>;
chomp($password1);
$password1 =~ s/^\s+//;
$password1 =~ s/\s+$//;
# Turn echo on
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." ".$old_stty });
$anvil->System->stty_echo({set => "on" });
if (not $password1)
{
@ -98,18 +99,18 @@ elsif (not $anvil->data->{switches}{'new-password'})
print $anvil->Words->string({key => "message_0019"})."\n";
# Turn off echo
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." -echo "});
$anvil->System->stty_echo({set => "off "});
my $password2 = <STDIN>;
chomp($password2);
$password2 =~ s/^\s+//;
$password2 =~ s/\s+$//;
# Turn echo on
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." ".$old_stty });
$anvil->System->stty_echo({set => "on" });
if ($password1 eq $password2)
{
$anvil->data->{switches}{'new-password'} = $password1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { "switches::new_ password" => $anvil->data->{switches}{'new-password'} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { "switches::new- password" => $anvil->data->{switches}{'new-password'} }});
}
else
{
@ -130,18 +131,27 @@ else
{
### TODO: Support '--peers' to also update the peer dashboards.
# Updating just ourself
print $anvil->Words->string({key => "message_0020"})."\n";
print $anvil->Words->string({key => "message_0021"})." ";
my $answer = <STDIN>;
chomp($answer);
if ($answer =~ /^y/)
$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";
update_local_passwords($anvil);
}
else
{
# Abort.
print $anvil->Words->string({key => "message_0022"})."\n";
print $anvil->Words->string({key => "message_0020"})."\n";
print $anvil->Words->string({key => "message_0021"})." ";
my $answer = <STDIN>;
chomp($answer);
if ($answer =~ /^y/)
{
update_local_passwords($anvil);
}
else
{
# Abort.
print $anvil->Words->string({key => "message_0022"})."\n";
}
}
}
@ -161,7 +171,7 @@ sub update_local_passwords
foreach my $user ("admin", "root")
{
print "Updating: [$user] with password: [".$anvil->data->{switches}{'new-password'}."]\n";
$anvil->System->change_shell_user_password({user => $user, new_password => $anvil->data->{switches}{'new-password'}});
$anvil->System->change_shell_user_password({debug => 2, user => $user, new_password => $anvil->data->{switches}{'new-password'}});
}
# Update the database password.