* Improved infinite loop handling in Log->entry, but broke the Striker UI in the process. To be fixed next...

* Added a 'test' parameter to Log->entry, Storage->make_directory and Words->key to help debug in places that Log->x may not be usable.
* Converted many $anvil->Log->x calls to print if $test to help prevent recursive loops, but not all fixed yet.
* Added the new 'host_keys' database table to the schema for a possible new feature of removing passwords in favour if machines adding peers' public keys to their authorized_hosts file.
* Cleaned up the opening calls to $anvil->Tools->new() in most tools.
* Cleaned up some variables in tools/anvil-update-states after reading their values from files (clean trailing newlines).

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent d2c812ee03
commit 2c23c6beba
  1. 2
      Anvil/Tools.pm
  2. 92
      Anvil/Tools/Log.pm
  3. 11
      Anvil/Tools/Storage.pm
  4. 27
      Anvil/Tools/Words.pm
  5. 2
      cgi-bin/striker
  6. 59
      share/anvil.sql
  7. 9
      tools/anvil-change-password
  8. 4
      tools/anvil-daemon
  9. 3
      tools/anvil-jobs
  10. 5
      tools/anvil-maintenance-mode
  11. 4
      tools/anvil-manage-firewall
  12. 6
      tools/anvil-manage-power
  13. 6
      tools/anvil-manage-striker-peers
  14. 10
      tools/anvil-prep-database
  15. 3
      tools/anvil-scan-network
  16. 34
      tools/anvil-update-states
  17. 6
      tools/anvil-update-system
  18. 6
      tools/striker-manage-install-target

@ -167,8 +167,8 @@ sub new
$anvil->Validate->parent($anvil);
# Set some system paths and system default variables
$anvil->_set_paths();
$anvil->_set_defaults();
$anvil->_set_paths();
# Record the start time.
$anvil->data->{ENV_VALUES}{START_TIME} = Time::HiRes::time;

@ -230,6 +230,10 @@ sub entry
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $test = defined $parameter->{test} ? $parameter->{test} : 0;
# If we're called before $anvil->_set_defaults, this will be undefined.
$anvil->data->{defaults}{'log'}{level} = 1 if not defined $anvil->data->{defaults}{'log'}{level};
my $key = defined $parameter->{key} ? $parameter->{key} : "";
my $language = defined $parameter->{language} ? $parameter->{language} : $anvil->Log->language;
@ -244,7 +248,45 @@ sub entry
my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $tag = defined $parameter->{tag} ? $parameter->{tag} : $anvil->data->{defaults}{'log'}{tag};
my $variables = defined $parameter->{variables} ? $parameter->{variables} : "";
#print $THIS_FILE." ".__LINE__."; [ Debug ] - level: [$level], defaults::log::level: [".$anvil->Log->{defaults}{'log'}{level}."], logging secure? [".$anvil->Log->secure."]\n";
$anvil->data->{loop}{count} = 0 if not defined $anvil->data->{loop}{count};
$anvil->data->{loop}{count}++;
print $THIS_FILE." ".__LINE__."; [ Debug ] - level: [".$level."], defaults::log::level: [".$anvil->data->{defaults}{'log'}{level}."], logging secure? [".$anvil->Log->secure."], loop::count: [".$anvil->data->{loop}{count}."]\n" if $test;
if ($anvil->data->{loop}{count} > 1000)
{
if ($anvil->environment eq "html")
{
### NOTE: Don't use the template, it could be part of the infinite loop problem.
print "Content-type: text/html; charset=utf-8\n\n";
print "<pre>\n";
}
print $THIS_FILE." ".__LINE__."; Infinite loop detected trying to log:\n";
print $THIS_FILE." ".__LINE__."; - key: ..... [".$key."]:\n";
print $THIS_FILE." ".__LINE__."; - language: [".$language."]:\n";
print $THIS_FILE." ".__LINE__."; - level: ... [".$level."]:\n";
print $THIS_FILE." ".__LINE__."; - line: .... [".$line."]:\n";
print $THIS_FILE." ".__LINE__."; - print: ... [".$print."]:\n";
print $THIS_FILE." ".__LINE__."; - priority: [".$priority."]:\n";
print $THIS_FILE." ".__LINE__."; - raw: ..... [".$raw."]:\n";
print $THIS_FILE." ".__LINE__."; - secure: .. [".$secure."]:\n";
print $THIS_FILE." ".__LINE__."; - server: .. [".$server."]:\n";
print $THIS_FILE." ".__LINE__."; - source: .. [".$source."]:\n";
print $THIS_FILE." ".__LINE__."; - tag: ..... [".$tag."]:\n";
print $THIS_FILE." ".__LINE__."; - variables: [".$variables."]:\n";
if (ref($variables) eq "HASH")
{
print $THIS_FILE." ".__LINE__."; - variable hash dump:\n";
print $THIS_FILE." ".__LINE__."; =====================\n";
use Data::Dumper;
print Dumper $variables;
print $THIS_FILE." ".__LINE__."; =====================\n";
}
# Don't use nice_exit, it might be part of the problem.
if ($anvil->environment eq "html")
{
print "</pre>\n";
}
exit (1);
}
# Exit immediately if this isn't going to be logged
if ($level > $anvil->Log->level)
@ -274,6 +316,7 @@ sub entry
{
$priority_string .= ".debug";
}
print $THIS_FILE." ".__LINE__."; priority string: [".$priority_string."]\n" if $test;
# Log the file and line, if passed.
my $string = "";
@ -282,70 +325,88 @@ sub entry
{
# Keep the debug level super high to avoid Get->date_and_time() going into an infinite loop.
$string .= $anvil->Get->date_and_time({debug => 99}).":";
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
}
if (($source) && ($line))
{
$string .= "$source:$line; ";
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
}
elsif ($source)
{
$string .= "$source; ";
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
}
elsif ($line)
{
$string .= "$line; ";
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
}
# If I have a raw string, do no more processing.
print $THIS_FILE." ".__LINE__."; raw: [".$raw."], key: [".$key."]\n" if $test;
if ($raw)
{
$string .= $raw;
$print_string .= $raw;
print $THIS_FILE." ".__LINE__."; string: ..... [".$string."]\n" if $test;
print $THIS_FILE." ".__LINE__."; print_string: [".$print_string."]\n" if $test;
}
elsif ($key)
{
# Build the string from the key/variables.
print $THIS_FILE." ".__LINE__."; debug: [".$debug."], language: [".$language."], key: [".$key."], variables: [".$variables."]\n" if $test;
my $message .= $anvil->Words->string({
test => $test,
debug => $debug,
language => $language,
key => $key,
variables => $variables,
});
#print $THIS_FILE." ".__LINE__."; [ Debug ] - message: [$message]\n";
print $THIS_FILE." ".__LINE__."; [ Debug ] - message: [$message]\n" if $test;
$string .= $message;
$print_string .= $message;
print $THIS_FILE." ".__LINE__."; string: ..... [".$string."]\n" if $test;
print $THIS_FILE." ".__LINE__."; print_string: [".$print_string."]\n" if $test;
}
# If the user set a log file, log to that. Otherwise, log via Log::Journald.
print $THIS_FILE." ".__LINE__."; path::log::main: [".$anvil->data->{path}{'log'}{main}."]\n" if $test;
if ($anvil->data->{path}{'log'}{main})
{
# TODO: Switch back to journald later, using a file for testing for now
if ($string !~ /\n$/)
{
$string .= "\n";
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
}
# Open the file?
print $THIS_FILE." ".__LINE__."; HANDLE::log::main: [".$anvil->data->{HANDLE}{'log'}{main}."]\n" if $test;
if (not $anvil->data->{HANDLE}{'log'}{main})
{
# If the file doesn't start with a '/', we'll put it under /var/log.
my $log_file = $anvil->data->{path}{'log'}{main} =~ /^\// ? $anvil->data->{path}{'log'}{main} : "/var/log/".$anvil->data->{path}{'log'}{main};
my ($directory, $file) = ($log_file =~ /^(\/.*)\/(.*)$/);
print $THIS_FILE." ".__LINE__."; log_file: [".$log_file."]. directory: [".$directory."], file: [".$file."]\n" if $test;
### WARNING: We MUST set the debug level really high, or else we'll go into a deep
### recursion!
# Make sure the log directory exists.
$anvil->Storage->make_directory({debug => 99, directory => $directory, mode => 755});
$anvil->Storage->make_directory({test => $test, debug => 99, directory => $directory, mode => 755});
# Now open the log
my $shell_call = $log_file;
print $THIS_FILE." ".__LINE__."; shell_call: [".$shell_call."]\n" if $test;
# NOTE: Don't call '$anvil->Log->entry()' here, it will cause a loop!
open (my $file_handle, ">>", $shell_call) or die "Failed to open: [$shell_call] for writing. The error was: $!\n";
$file_handle->autoflush(1);
$anvil->data->{HANDLE}{'log'}{main} = $file_handle;
print $THIS_FILE." ".__LINE__."; HANDLE::log::main: [".$anvil->data->{HANDLE}{'log'}{main}."]\n" if $test;
# Make sure it can be written to by apache.
$anvil->Storage->change_mode({debug => $debug, target => $log_file, mode => "0666"});
$anvil->Storage->change_mode({test => $test, debug => $debug, target => $log_file, mode => "0666"});
}
if (not $anvil->data->{HANDLE}{'log'}{main})
@ -356,6 +417,7 @@ sub entry
# The handle has to be wrapped in a block to make 'print' happy as it doesn't like non-scalars for file handles
print { $anvil->data->{HANDLE}{'log'}{main} } $string;
$anvil->data->{loop}{count} = 0;
}
else
{
@ -572,6 +634,7 @@ sub variables
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $test = defined $parameter->{test} ? $parameter->{test} : 0;
my $language = defined $parameter->{language} ? $parameter->{language} : $anvil->data->{defaults}{'log'}{language};
my $level = defined $parameter->{level} ? $parameter->{level} : 2;
@ -585,6 +648,8 @@ sub variables
my $tag = defined $parameter->{tag} ? $parameter->{tag} : $anvil->data->{defaults}{'log'}{tag};
# Exit immediately if this isn't going to be logged
print $THIS_FILE." ".__LINE__."; debug: [".$debug."], level: [".$level."], Log->level: [".$anvil->Log->level."]\n" if $test;
die if $test;
if (not defined $level)
{
die $THIS_FILE." ".__LINE__."; Log->variables() called without 'level': [".$level."] defined from: [$source : $line]\n";
@ -598,6 +663,7 @@ sub variables
{
return(1);
}
print $THIS_FILE." ".__LINE__."; secure: [".$secure."], Log->secure: [".$anvil->Log->secure."]\n" if $test;
if (($secure) && (not $anvil->Log->secure))
{
return(2);
@ -606,15 +672,18 @@ sub variables
# If I don't have a list, or the list is empty, return.
my $entry = 1;
my $entries = keys %{$list};
print $THIS_FILE." ".__LINE__."; entries: [".$entries."]\n" if $test;
if ($entries)
{
# If the key points to an undefined value, convert it to '!!undef!!' so that we don't scare
# the user with 'undefined variable' warnings.
foreach my $key (sort {$a cmp $b} keys %{$list})
{
print $THIS_FILE." ".__LINE__."; key: [".$key."]\n" if $test;
if (not defined $list->{$key})
{
$list->{$key} = "!!undef!!";
print $THIS_FILE." ".__LINE__."; list->{$key}: [".$list->{$key}."]\n" if $test;
}
}
my $raw = "";
@ -624,12 +693,15 @@ sub variables
# Put all the entries on one line.
foreach my $key (sort {$a cmp $b} keys %{$list})
{
print $THIS_FILE." ".__LINE__."; key: [".$key."]\n" if $test;
# Strip a leading 'sX:' in case the user is sorting the output.
my $say_key = $key;
$say_key =~ s/^s(\d+)://;
$raw .= "$say_key: [".$list->{$key}."], ";
print $THIS_FILE." ".__LINE__."; raw: [".$raw."]\n" if $test;
}
$raw =~ s/, $//;
print $THIS_FILE." ".__LINE__."; raw: [".$raw."]\n" if $test;
}
else
{
@ -639,22 +711,28 @@ sub variables
my $length = 0;
foreach my $key (sort {$a cmp $b} keys %{$list})
{
print $THIS_FILE." ".__LINE__."; key: [".$key."]\n" if $test;
if (length($key) > $length)
{
$length = length($key);
print $THIS_FILE." ".__LINE__."; length: [".$length."]\n" if $test;
}
}
# We add '1' to account for the colon we append.
$length++;
print $THIS_FILE." ".__LINE__."; length: [".$length."]\n" if $test;
$raw .= $anvil->Words->string({key => "log_0019"})."\n";
print $THIS_FILE." ".__LINE__."; raw: [".$raw."]\n" if $test;
foreach my $key (sort {$a cmp $b} keys %{$list})
{
print $THIS_FILE." ".__LINE__."; key: [".$key."]\n" if $test;
# Strip a leading 'sX:' in case the user is sorting the output.
my $say_key = $key;
$say_key =~ s/^s(\d+)://;
$say_key .= ":";
my $difference = $length - length($say_key);
print $THIS_FILE." ".__LINE__."; say_key: [".$say_key."], difference: [".$difference."]\n" if $test;
if ($difference)
{
$say_key .= " ";
@ -663,20 +741,26 @@ sub variables
$say_key .= ".";
}
}
print $THIS_FILE." ".__LINE__."; entry: [".$entry."], entries: [".$entries."]\n" if $test;
if ($entry ne $entries)
{
$raw .= "|- $say_key [".$list->{$key}."]\n";
print $THIS_FILE." ".__LINE__."; raw: [".$raw."]\n" if $test;
}
else
{
$raw .= "\\- $say_key [".$list->{$key}."]\n";
print $THIS_FILE." ".__LINE__."; raw: [".$raw."]\n" if $test;
}
$entry++;
print $THIS_FILE." ".__LINE__."; entry: [".$entry."]\n" if $test;
}
}
# Do the raw log entry.
$anvil->Log->entry({
test => $test,
language => $language,
level => $level,
line => $line,

@ -915,6 +915,7 @@ sub make_directory
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $test = defined $parameter->{test} ? $parameter->{test} : 0;
my $directory = defined $parameter->{directory} ? $parameter->{directory} : "";
my $group = defined $parameter->{group} ? $parameter->{group} : getgrgid($();
@ -925,7 +926,9 @@ sub make_directory
my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $user = defined $parameter->{user} ? $parameter->{user} : getpwuid($<);
my $failed = 0;
print $THIS_FILE." ".__LINE__."; debug: [".$debug."], directory: [".$directory."], target: [".$target."]\n" if $test;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
test => $test,
directory => $directory,
group => $group,
mode => $mode,
@ -939,6 +942,7 @@ sub make_directory
# Make sure the user and group and just one digit or word.
$user =~ s/^(\S+)\s.*$/$1/;
$group =~ s/^(\S+)\s.*$/$1/;
print $THIS_FILE." ".__LINE__."; user: [".$user."], group: [".$group."]\n" if $test;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
group => $group,
user => $user,
@ -951,6 +955,7 @@ sub make_directory
next if not $this_directory;
$working_directory .= "/$this_directory";
$working_directory =~ s/\/\//\//g;
print $THIS_FILE." ".__LINE__."; working_directory: [".$working_directory."]\n" if $test;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { working_directory => $working_directory }});
# Are we working locally or remotely?
@ -1021,6 +1026,7 @@ fi;";
# Directory doesn't exist, so create it.
my $error = "";
my $shell_call = $anvil->data->{path}{exe}{'mkdir'}." ".$working_directory;
print $THIS_FILE." ".__LINE__."; shell_call: [".$shell_call."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
@ -1032,10 +1038,12 @@ fi;";
}
close $file_handle;
print $THIS_FILE." ".__LINE__."; mode: [".$mode."]\n" if $test;
if ($mode)
{
$anvil->Storage->change_mode({debug => $debug, target => $working_directory, mode => $mode});
}
print $THIS_FILE." ".__LINE__."; user: [".$user."], group: [".$group."]\n" if $test;
if (($user) or ($group))
{
$anvil->Storage->change_owner({debug => $debug, target => $working_directory, user => $user, group => $group});
@ -1044,6 +1052,7 @@ fi;";
if (not -e $working_directory)
{
$failed = 1;
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0168", variables => {
directory => $working_directory,
error => $error,
@ -1051,9 +1060,11 @@ fi;";
}
}
}
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
last if $failed;
}
print $THIS_FILE." ".__LINE__."; failed: [".$failed."]\n" if $test;
return($failed);
}

@ -171,6 +171,7 @@ sub key
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $test = defined $parameter->{test} ? $parameter->{test} : 0;
# Setup default values
my $key = defined $parameter->{key} ? $parameter->{key} : "";
@ -178,16 +179,17 @@ sub key
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $string = "#!not_found!#";
my $error = 0;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - key: [$key], language: [$language], file: [$file]"});
### NOTE: Don't call Log->entry or Log->variable in here, it'll cause a recursive loop! Use 'test' when needed
print $THIS_FILE." ".__LINE__."; [ Debug ] - key: [$key], language: [$language], file: [$file]\n" if $test;
if (not $key)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => "[ Error ] - Anvil::Tools::Words->key()' called without a key name to read."});
print $THIS_FILE." ".__LINE__."; [ Error ] - Anvil::Tools::Words->key()' called without a key name to read.\n" if $test;
$error = 1;
}
if (not $language)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => "[ Error ] - Anvil::Tools::Words->key()' called without a language, and 'defaults::languages::output' is not set."});
print $THIS_FILE." ".__LINE__."; [ Error ] - Anvil::Tools::Words->key()' called without a language, and 'defaults::languages::output' is not set.\n" if $test;
$error = 2;
}
@ -195,13 +197,13 @@ sub key
{
foreach my $this_file (sort {$a cmp $b} keys %{$anvil->data->{words}})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - this_file: [$this_file], file: [$file]"});
print $THIS_FILE." ".__LINE__."; [ Debug ] - this_file: [$this_file], file: [$file]\n" if $test;
# If they've specified a file and this doesn't match, skip it.
next if (($file) && ($this_file !~ /$file$/));
if (exists $anvil->data->{words}{$this_file}{language}{$language}{key}{$key}{content})
{
$string = $anvil->data->{words}{$this_file}{language}{$language}{key}{$key}{content};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - string: [$string]"});
print $THIS_FILE." ".__LINE__."; [ Debug ] - string: [$string]\n" if $test;
last;
}
}
@ -209,10 +211,10 @@ sub key
if ($string eq "#!not_found!")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => "[ Error ] - Failed to find the string key: [".$key."]!!"});
print $THIS_FILE." ".__LINE__."; [ Error ] - Failed to find the string key: [".$key."]!!\n" if $test;
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - string: [$string]"});
print $THIS_FILE." ".__LINE__."; [ Debug ] - string: [$string]\n" if $test;
return($string);
}
@ -515,6 +517,7 @@ sub string
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $test = defined $parameter->{test} ? $parameter->{test} : 0;
# Setup default values
my $key = defined $parameter->{key} ? $parameter->{key} : "";
@ -522,7 +525,8 @@ sub string
my $file = defined $parameter->{file} ? $parameter->{file} : $anvil->data->{path}{words}{'words.xml'};
my $string = defined $parameter->{string} ? $parameter->{string} : "";
my $variables = defined $parameter->{variables} ? $parameter->{variables} : "";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - key: [$key], language: [$language], file: [$file], string: [$string], variables: [$variables]"});
### NOTE: Don't call Log->entry here, or we'll get a recursive loop! Use 'test' to debug.
print $THIS_FILE." ".__LINE__."; key: [".$key."], language: [$language], file: [$file], string: [$string], variables: [$variables]\n" if $test;
# If we weren't passed a raw string, we'll get the string from our ->key() method, then inject any
# variables, if needed. This also handles the initial sanity checks. If we get back '#!not_found!#',
@ -530,13 +534,16 @@ sub string
if (not $string)
{
$string = $anvil->Words->key({
test => $test,
debug => $debug,
key => $key,
language => $language,
file => $file,
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, raw => "[ Debug ] - string: [$string]"});
print $THIS_FILE." ".__LINE__."; [ Debug ] - string: [$string]\n" if $test;
}
print $THIS_FILE." ".__LINE__."; string: [".$string."]\n" if $test;
if (($string ne "#!not_found!#") && ($string =~ /#!([^\s]+?)!#/))
{
# We've got a string and variables from the caller, so inject them as needed.
@ -555,7 +562,7 @@ sub string
$loops++;
die "$THIS_FILE ".__LINE__."; Infinite loop detected while processing the string: [".$string."] from the key: [$key] in language: [$language], exiting.\n" if $loops > $limit;
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0042", variables => { string => $string }});
print $THIS_FILE." ".__LINE__."; [ Error ] - The method Words->string() was asked to process the string: [".$string."] which has insertion variables, but nothing was passed to the 'variables' parameter.\n" if $test;
return("#!error!#");
}

@ -26,7 +26,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
### NOTE: We'll print the headers only when we need to. If we print them hear, it will block cookies being set.
### NOTE: We'll print the headers only when we need to. If we print them here, it will block cookies being set.
# Set the log level to 2. Setting 3 slows he program down a LOT.

@ -44,16 +44,16 @@ $$;
CREATE TABLE hosts (
host_uuid uuid not null primary key, -- This is the single most important record in Anvil!. Everything links back to here.
host_name text not null,
host_type text not null, -- Either 'node' or 'dashboard'.
host_type text, -- Either 'node' or 'dashboard' or 'dr_host'. It is left empty until the host is configured.
modified_date timestamp with time zone not null
);
ALTER TABLE hosts OWNER TO admin;
CREATE TABLE history.hosts (
history_id bigserial,
host_uuid uuid not null,
host_name text not null,
host_type text not null,
host_uuid uuid,
host_name text,
host_type text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.hosts OWNER TO admin;
@ -85,6 +85,57 @@ CREATE TRIGGER trigger_hosts
FOR EACH ROW EXECUTE PROCEDURE history_hosts();
-- This stores the SSH _public_ keys for a given user on a host.
CREATE TABLE host_keys (
host_key_uuid uuid not null primary key, -- This is the single most important record in Anvil!. Everything links back to here.
host_key_host_uuid uuid not null,
host_key_user_name text not null, -- This is the user name on the system, not a web interface user.
host_key_public_key text not null, -- Either 'node' or 'dashboard'.
modified_date timestamp with time zone not null,
FOREIGN KEY(host_key_host_uuid) REFERENCES hosts(host_uuid),
);
ALTER TABLE host_keys OWNER TO admin;
CREATE TABLE history.host_keys (
history_id bigserial,
host_key_uuid uuid,
host_key_host_uuid uuid,
host_key_user_name text,
host_key_public_key text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.host_keys OWNER TO admin;
CREATE FUNCTION history_host_keys() RETURNS trigger
AS $$
DECLARE
history_host_keys RECORD;
BEGIN
SELECT INTO history_host_keys * FROM host_keys WHERE host_key_uuid = new.host_key_uuid;
INSERT INTO history.host_keys
(host_key_uuid,
host_key_host_uuid,
host_key_user_name,
host_key_public_key,
modified_date)
VALUES
(history_host_keys.host_key_uuid,
history_host_keys.host_key_host_uuid,
history_host_keys.host_key_user_name,
history_host_keys.host_key_public_key,
history_host_keys.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_host_keys() OWNER TO admin;
CREATE TRIGGER trigger_host_keys
AFTER INSERT OR UPDATE ON host_keys
FOR EACH ROW EXECUTE PROCEDURE history_host_keys();
-- This stores information about users.
-- Note that is all permissions are left false, the user can still interact with the Anvil! doing safe things, like changing optical media, perform migrations, start servers (but not stop them), etc.
CREATE TABLE users (

@ -29,13 +29,8 @@ $| = 1;
$< = $>;
$( = $);
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1});
# Read switches
$anvil->Get->switches;
# Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Make sure we're running as 'root'
# $< == real UID, $> == effective UID

@ -61,8 +61,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server.

@ -23,7 +23,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# I should have been passed a 'job_uuid'. Read in the details.

@ -25,9 +25,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{set} = "";

@ -39,9 +39,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1});
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
my $anvil = Anvil::Tools->new();
# If the user has disabled auto-management of the firewall, exit.
if (not $anvil->data->{sys}{manage}{firewall})

@ -32,10 +32,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{'poweroff'} = "";

@ -38,7 +38,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{list} = "";
@ -61,9 +62,6 @@ if (($< != 0) && ($> != 0))
$anvil->nice_exit({code => 1});
}
# Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
# We'll try to connect in case we're adding additional peers.
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});

@ -26,14 +26,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 0});
# Read switches
$anvil->Get->switches;
# Read in our config.
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $local_uuid = $anvil->Database->get_local_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { local_uuid => $local_uuid }});

@ -29,7 +29,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
scan($anvil);

@ -18,13 +18,10 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
@ -84,10 +81,23 @@ sub update_network
my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0;
my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half?
my $operational = -e $full_path."/operstate" ? $anvil->Storage->read_file({file => $full_path."/operstate"}) : "unknown"; # up or down
my $speed = $link_state ? $anvil->Storage->read_file({debug => 3, file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
my $media = "unknown";
my $type = "interface";
# Clean up some newlines.
$mac_address =~ s/\n$//;
$link_state =~ s/\n$//;
$mtu =~ s/\n$//;
$duplex =~ s/\n$//;
$operational =~ s/\n$//;
$speed =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface,
speed => $speed,
mac_address => $mac_address,
}});
# These are variables that will be needed if this is a bond interface.
my $ip_address = "";
my $subnet_mask = "";
@ -104,7 +114,7 @@ sub update_network
{
$ip_address = $anvil->data->{sys}{network}{interface}{$interface}{ip} ? $anvil->data->{sys}{network}{interface}{$interface}{ip} : "";
$subnet_mask = $anvil->data->{sys}{network}{interface}{$interface}{subnet} ? $anvil->data->{sys}{network}{interface}{$interface}{subnet} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_address => $ip_address,
subnet_mask => $subnet_mask,
}});
@ -117,7 +127,7 @@ sub update_network
{
# It's a slave.
$mac_address = $anvil->Storage->read_file({file => $mac_bond_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac_address => $mac_address }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }});
}
# If this is a virtual interface, set some fake values that don't actually exist on
@ -128,7 +138,7 @@ sub update_network
# Speed is "as fast as possible", so we'll record 100 Gbps, but that is really kind of arbitrary.
$speed = 100000 if ((not $speed) or ($speed eq "-1"));
$duplex = "full" if not $duplex;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
speed => $speed,
duplex => $duplex,
}});
@ -137,7 +147,7 @@ sub update_network
if (not $link_state)
{
$speed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { speed => $speed }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { speed => $speed }});
}
# Is this a bond interface?
@ -157,7 +167,7 @@ sub update_network
$mii_polling_interval = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/miimon"});
$up_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/updelay"});
$down_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/downdelay"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
active_slave => $active_slave,
bond_mode => $bond_mode,
mii_polling_interval => $mii_polling_interval,
@ -171,13 +181,13 @@ sub update_network
# No, but it's slaved to one.
my $target = readlink($full_path."/master");
$bond_master = ($target =~ /^.*\/(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target,
bond_master => $bond_master,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
active_slave => $active_slave,
bond_master => $bond_master,
bond_mode => $bond_mode,

@ -34,10 +34,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{'job-uuid'} = "";

@ -46,10 +46,8 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 0});
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{check} = 0;

Loading…
Cancel
Save