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.
91 lines
2.5 KiB
91 lines
2.5 KiB
#!/usr/bin/perl |
|
# |
|
# This program sets/changes passwords on the Anvil! platform (nodes and dashboards). |
|
# |
|
# Exit codes; |
|
# 0 = Normal exit. |
|
# 1 = The program is not running as root. |
|
# 2 = Failed to connect to database(s). |
|
# |
|
|
|
use strict; |
|
use warnings; |
|
use Data::Dumper; |
|
use Anvil::Tools; |
|
|
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
|
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
|
{ |
|
$running_directory =~ s/^\./$ENV{PWD}/; |
|
} |
|
|
|
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. |
|
$| = 1; |
|
|
|
# Prevent a discrepency between UID/GID and EUID/EGID from throwing an error. |
|
$< = $>; |
|
$( = $); |
|
|
|
my $anvil = Anvil::Tools->new(); |
|
$anvil->Log->level({set => 2}); |
|
$anvil->Log->secure({set => 0}); |
|
|
|
# Read switches |
|
$anvil->Get->switches; |
|
|
|
# Paths |
|
$anvil->Storage->read_config({file => $anvil->data->{path}{config}{'anvil.conf'}}); |
|
|
|
# Make sure we're running as 'root' |
|
# $< == real UID, $> == effective UID |
|
if (($< != 0) && ($> != 0)) |
|
{ |
|
# Not root |
|
print $anvil->Words->string({key => "error_0005"})."\n"; |
|
$anvil->nice_exit({code => 1}); |
|
} |
|
|
|
# Connect |
|
my $connections = $anvil->Database->connect(); |
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132", variables => { connections => $connections }}); |
|
if (not $connections) |
|
{ |
|
# No databases, exit. |
|
print $anvil->Words->string({key => "error_0003"}); |
|
$anvil->nice_exit({exit_code => 2}); |
|
} |
|
|
|
### TODO: Check for access to all known Anvil! nodes and warn the user that they will have to manually update |
|
### the password for us on any node we can't access |
|
### NOTE: 'anvil' can be a name or UUID |
|
# If we're called without an '--anvil' switch, then change the local password only. |
|
if ($anvil->data->{switches}{anvil}) |
|
{ |
|
# Find the Anvil! and verify access to both nodes. If neither are accessible, abort. |
|
} |
|
else |
|
{ |
|
### TODO: Support '--peers' to also update the peer dashboards. |
|
# Updating just ourself |
|
update_local_passwords($anvil); |
|
} |
|
|
|
|
|
$anvil->nice_exit({code => 0}); |
|
|
|
############################################################################################################# |
|
# Functions # |
|
############################################################################################################# |
|
|
|
# This updates the local passwords. |
|
sub update_local_passwords |
|
{ |
|
my ($anvil) = @_; |
|
|
|
# Update the local users. |
|
|
|
# Update the database password. |
|
|
|
return(0); |
|
}
|
|
|