* Fixed a bug in Database->get_local_uuid() where ->is_local() was being called incorrectly.
* Added job parsing to tools/striker-parse-oui and tools/striker-scan-network, and enabled them in anvil-daemon. Signed-off-by: Digimer <digimer@alteeve.ca>
This commit is contained in:
parent
1d13e669a7
commit
4d0a02ce74
@ -1669,7 +1669,7 @@ sub get_local_uuid
|
|||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
elsif ($anvil->Network->is_local($db_host))
|
elsif ($anvil->Network->is_local({host => $db_host}))
|
||||||
{
|
{
|
||||||
$local_uuid = $uuid;
|
$local_uuid = $uuid;
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
|
||||||
|
@ -776,7 +776,11 @@ Failed to promote the DRBD resource: [#!variable!resource!#] primary. Expected a
|
|||||||
#!variable!section!#
|
#!variable!section!#
|
||||||
====
|
====
|
||||||
</key>
|
</key>
|
||||||
<key name="log_0445">[ NOTE ] - We're about to do a ping scan of: [#!variable!range!#]. This could take a long time, please be patient!</key>
|
<key name="log_0445">[ Note ] - We're about to do a ping scan of: [#!variable!range!#]. This could take a long time, please be patient! If you think this process is hung, please run 'pgrep nmap' on the host. If a process is returned, this is still running. We go slow to avoid upsetting network security devices or admin.</key>
|
||||||
|
<key name="log_0446">Found the network device: [#!variable!mac!#] usingt the IP address: [#!variable!ip!#].</key>
|
||||||
|
<key name="log_0447">About to download: [#!variable!url!#] and save it to: [#!variable!file!#].</key>
|
||||||
|
<key name="log_0448">Ready to parse: [#!variable!file!#].</key>
|
||||||
|
<key name="log_0449">Parsed: [#!variable!records!#], adding/updating them to the database now.</key>
|
||||||
|
|
||||||
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
|
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
|
||||||
<key name="t_0000">Test</key>
|
<key name="t_0000">Test</key>
|
||||||
|
@ -312,32 +312,32 @@ sub handle_periodic_tasks
|
|||||||
});
|
});
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
||||||
|
|
||||||
### TODO: Restore this when these tools hand jobs properly
|
# Update the OUI data.
|
||||||
# # Update the OUI data.
|
($job_uuid) = $anvil->Database->insert_or_update_jobs({
|
||||||
# ($job_uuid) = $anvil->Database->insert_or_update_jobs({
|
file => $THIS_FILE,
|
||||||
# file => $THIS_FILE,
|
line => __LINE__,
|
||||||
# line => __LINE__,
|
job_command => $anvil->data->{path}{exe}{'striker-parse-oui'},
|
||||||
# job_command => $anvil->data->{path}{exe}{'striker-parse-oui'},
|
job_data => "",
|
||||||
# job_data => "",
|
job_name => "oui-data::refresh",
|
||||||
# job_name => "oui-data::refresh",
|
job_title => "job_0064",
|
||||||
# job_title => "job_0064",
|
job_description => "job_0065",
|
||||||
# job_description => "job_0065",
|
job_progress => 0,
|
||||||
# job_progress => 0,
|
});
|
||||||
# });
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
||||||
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
|
||||||
#
|
# Scan the networks
|
||||||
# # Scan the networks
|
($job_uuid) = $anvil->Database->insert_or_update_jobs({
|
||||||
# ($job_uuid) = $anvil->Database->insert_or_update_jobs({
|
file => $THIS_FILE,
|
||||||
# file => $THIS_FILE,
|
line => __LINE__,
|
||||||
# line => __LINE__,
|
job_command => $anvil->data->{path}{exe}{'striker-scan-network'},
|
||||||
# job_command => $anvil->data->{path}{exe}{'striker-scan-network'},
|
job_data => "",
|
||||||
# job_data => "",
|
job_name => "scan-network::refresh",
|
||||||
# job_name => "scan-network::refresh",
|
job_title => "job_0066",
|
||||||
# job_title => "job_0066",
|
job_description => "job_0067",
|
||||||
# job_description => "job_0067",
|
job_progress => 0,
|
||||||
# job_progress => 0,
|
});
|
||||||
# });
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
||||||
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update the next check time.
|
# Update the next check time.
|
||||||
|
@ -25,6 +25,25 @@ $anvil->Log->level({set => 2});
|
|||||||
$anvil->Log->secure({set => 0});
|
$anvil->Log->secure({set => 0});
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
|
$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})
|
||||||
|
{
|
||||||
|
# No databases, exit.
|
||||||
|
print $anvil->Words->string({key => "error_0003"})."\n";
|
||||||
|
$anvil->nice_exit({exit_code => 2});
|
||||||
|
}
|
||||||
|
|
||||||
|
$anvil->data->{switches}{'job-uuid'} = "";
|
||||||
|
$anvil->Get->switches;
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||||||
|
"switches::job-uuid" => $anvil->data->{switches}{'job-uuid'},
|
||||||
|
}});
|
||||||
|
|
||||||
|
update_progress($anvil, 0, "clear");
|
||||||
|
update_progress($anvil, 1, "log_0239,!!job-uuid!".$anvil->data->{switches}{'job-uuid'}."!!");
|
||||||
|
$anvil->data->{progress} = 1;
|
||||||
|
|
||||||
my $oui_file = $anvil->Get->users_home({debug => 3})."/oui.txt";
|
my $oui_file = $anvil->Get->users_home({debug => 3})."/oui.txt";
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_file => $oui_file }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_file => $oui_file }});
|
||||||
|
|
||||||
@ -58,6 +77,11 @@ if (-e $oui_file)
|
|||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { download => $download }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { download => $download }});
|
||||||
if ($download)
|
if ($download)
|
||||||
{
|
{
|
||||||
|
update_progress($anvil, 10, "log_0447,!!url!".$anvil->data->{path}{urls}{oui_file}."!!,!!file!".$oui_file."!!");
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "error_0095", variables => {
|
||||||
|
url => $anvil->data->{path}{urls}{oui_file},
|
||||||
|
file => $oui_file,
|
||||||
|
}});
|
||||||
my $download_file = $anvil->Network->download({
|
my $download_file = $anvil->Network->download({
|
||||||
debug => 2,
|
debug => 2,
|
||||||
url => $anvil->data->{path}{urls}{oui_file},
|
url => $anvil->data->{path}{urls}{oui_file},
|
||||||
@ -74,6 +98,7 @@ if ($download)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
# Something went wrong. Even if the file exists, there's no sense processing it.
|
# Something went wrong. Even if the file exists, there's no sense processing it.
|
||||||
|
update_progress($anvil, 50, "error_0095,!!url!".$anvil->data->{path}{urls}{oui_file}."!!,!!file!".$oui_file."!!");
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "error_0095", variables => {
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "error_0095", variables => {
|
||||||
url => $anvil->data->{path}{urls}{oui_file},
|
url => $anvil->data->{path}{urls}{oui_file},
|
||||||
file => $oui_file,
|
file => $oui_file,
|
||||||
@ -87,18 +112,12 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list
|
|||||||
}});
|
}});
|
||||||
if ((-e $oui_file) && ($process))
|
if ((-e $oui_file) && ($process))
|
||||||
{
|
{
|
||||||
$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})
|
|
||||||
{
|
|
||||||
# No databases, exit.
|
|
||||||
print $anvil->Words->string({key => "error_0003"})."\n";
|
|
||||||
$anvil->nice_exit({exit_code => 2});
|
|
||||||
}
|
|
||||||
|
|
||||||
process_oui($anvil, $oui_file);
|
process_oui($anvil, $oui_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# We're done
|
||||||
|
print $anvil->Words->string({key => "message_0025"})."\n";
|
||||||
|
update_progress($anvil, 100, "message_0025");
|
||||||
$anvil->nice_exit({exit_code => 0});
|
$anvil->nice_exit({exit_code => 0});
|
||||||
|
|
||||||
|
|
||||||
@ -106,6 +125,25 @@ $anvil->nice_exit({exit_code => 0});
|
|||||||
# Functions #
|
# Functions #
|
||||||
#############################################################################################################
|
#############################################################################################################
|
||||||
|
|
||||||
|
# If this is being called as a job, this will allow the progress to be updated.
|
||||||
|
sub update_progress
|
||||||
|
{
|
||||||
|
my ($anvil, $progress, $message) = @_;
|
||||||
|
|
||||||
|
if (not $anvil->data->{switches}{'job-uuid'})
|
||||||
|
{
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$anvil->Job->update_progress({
|
||||||
|
progress => $progress,
|
||||||
|
message => $message,
|
||||||
|
job_uuid => $anvil->data->{switches}{'job-uuid'},
|
||||||
|
});
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
# This actually processes the OUI file.
|
# This actually processes the OUI file.
|
||||||
sub process_oui
|
sub process_oui
|
||||||
{
|
{
|
||||||
@ -113,10 +151,11 @@ sub process_oui
|
|||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_file => $oui_file }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_file => $oui_file }});
|
||||||
|
|
||||||
# Read in the file.
|
# Read in the file.
|
||||||
|
update_progress($anvil, 25, "log_0448,!!file!".$oui_file."!!");
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0448", variables => { file => $oui_file }});
|
||||||
my $oui = "";
|
my $oui = "";
|
||||||
my $vendor = "";
|
my $vendor = "";
|
||||||
my $address = "";
|
my $address = "";
|
||||||
my $lines = 0;
|
|
||||||
my ($oui_body) = $anvil->Storage->read_file({
|
my ($oui_body) = $anvil->Storage->read_file({
|
||||||
debug => 3,
|
debug => 3,
|
||||||
file => $oui_file,
|
file => $oui_file,
|
||||||
@ -138,9 +177,8 @@ EOF
|
|||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_body => $oui_body }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_body => $oui_body }});
|
||||||
foreach my $line (split/\n/, $oui_body)
|
foreach my $line (split/\n/, $oui_body)
|
||||||
{
|
{
|
||||||
$lines++;
|
|
||||||
$line = $anvil->Words->clean_spaces({'string' => $line});
|
$line = $anvil->Words->clean_spaces({'string' => $line});
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 's1:lines' => $lines, 's2:line' => $line }});
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
|
||||||
|
|
||||||
if ((not $line) or ($line eq "EOF"))
|
if ((not $line) or ($line eq "EOF"))
|
||||||
{
|
{
|
||||||
@ -222,6 +260,10 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Record the details.
|
# Record the details.
|
||||||
|
my $records = keys %{$anvil->data->{oui}};
|
||||||
|
$records = $anvil->Convert->add_commas({number => $records });
|
||||||
|
update_progress($anvil, 50, "log_0449,!!records!".$records."!!");
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0449", variables => { records => $records }});
|
||||||
foreach my $oui (sort {$a cmp $b} keys %{$anvil->data->{oui}})
|
foreach my $oui (sort {$a cmp $b} keys %{$anvil->data->{oui}})
|
||||||
{
|
{
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||||||
|
@ -34,6 +34,15 @@ $anvil->Log->level({set => 2});
|
|||||||
$anvil->Log->secure({set => 0});
|
$anvil->Log->secure({set => 0});
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
|
$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
|
||||||
|
if (($< != 0) && ($> != 0))
|
||||||
|
{
|
||||||
|
# Not root
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0005"});
|
||||||
|
$anvil->nice_exit({code => 5});
|
||||||
|
}
|
||||||
|
|
||||||
$anvil->Database->connect;
|
$anvil->Database->connect;
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
|
||||||
if (not $anvil->data->{sys}{database}{connections})
|
if (not $anvil->data->{sys}{database}{connections})
|
||||||
@ -44,11 +53,23 @@ if (not $anvil->data->{sys}{database}{connections})
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Do we have a specified network to scan?
|
# Do we have a specified network to scan?
|
||||||
$anvil->data->{switches}{network} = "";
|
$anvil->data->{switches}{network} = "";
|
||||||
|
$anvil->data->{switches}{'job-uuid'} = "";
|
||||||
$anvil->Get->switches;
|
$anvil->Get->switches;
|
||||||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||||||
|
"switches::network" => $anvil->data->{switches}{network},
|
||||||
|
"switches::job-uuid" => $anvil->data->{switches}{'job-uuid'},
|
||||||
|
}});
|
||||||
|
|
||||||
|
update_progress($anvil, 0, "clear");
|
||||||
|
update_progress($anvil, 1, "log_0239,!!job-uuid!".$anvil->data->{switches}{'job-uuid'}."!!");
|
||||||
|
$anvil->data->{progress} = 1;
|
||||||
|
|
||||||
scan($anvil);
|
scan($anvil);
|
||||||
|
|
||||||
|
# We're done
|
||||||
|
print $anvil->Words->string({key => "message_0025"})."\n";
|
||||||
|
update_progress($anvil, 100, "message_0025");
|
||||||
$anvil->nice_exit({exit_code => 0});
|
$anvil->nice_exit({exit_code => 0});
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +77,26 @@ $anvil->nice_exit({exit_code => 0});
|
|||||||
# Functions #
|
# Functions #
|
||||||
#############################################################################################################
|
#############################################################################################################
|
||||||
|
|
||||||
|
# If this is being called as a job, this will allow the progress to be updated.
|
||||||
|
sub update_progress
|
||||||
|
{
|
||||||
|
my ($anvil, $progress, $message) = @_;
|
||||||
|
$progress = 95 if $progress > 100;
|
||||||
|
|
||||||
|
if (not $anvil->data->{switches}{'job-uuid'})
|
||||||
|
{
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$anvil->Job->update_progress({
|
||||||
|
progress => $progress,
|
||||||
|
message => $message,
|
||||||
|
job_uuid => $anvil->data->{switches}{'job-uuid'},
|
||||||
|
});
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
# This scans any networks passed in.
|
# This scans any networks passed in.
|
||||||
sub scan
|
sub scan
|
||||||
{
|
{
|
||||||
@ -92,6 +133,7 @@ sub scan
|
|||||||
if ((not $ip_valid) or (not $subnet_valid))
|
if ((not $ip_valid) or (not $subnet_valid))
|
||||||
{
|
{
|
||||||
# Bail out.
|
# Bail out.
|
||||||
|
update_progress($anvil, 100, "error_0097,!!range!".$anvil->data->{switches}{network}."!!");
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0097", variables => { range => $anvil->data->{switches}{network} }});
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0097", variables => { range => $anvil->data->{switches}{network} }});
|
||||||
$anvil->nice_exit({exit_code => 2});
|
$anvil->nice_exit({exit_code => 2});
|
||||||
}
|
}
|
||||||
@ -206,6 +248,8 @@ sub call_nmap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$anvil->data->{progress} += 10;
|
||||||
|
update_progress($anvil, $anvil->data->{progress}, "log_0445,!!range!".$address."!!");
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "log_0445", variables => { range => $address }});
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "log_0445", variables => { range => $address }});
|
||||||
my ($nmap_data, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{nmap}." -sn -n ".$address });
|
my ($nmap_data, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{nmap}." -sn -n ".$address });
|
||||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||||||
@ -251,6 +295,13 @@ sub call_nmap
|
|||||||
# Store
|
# Store
|
||||||
if (($mac_valid) && ($ip_valid))
|
if (($mac_valid) && ($ip_valid))
|
||||||
{
|
{
|
||||||
|
$anvil->data->{progress} += 1;
|
||||||
|
$anvil->data->{progress} = 95 if $anvil->data->{progress} > 95;
|
||||||
|
update_progress($anvil, $anvil->data->{progress}, "log_0446,!!ip!".$this_ip."!!,!!mac!".$this_mac."!!,!!section!".$section."!!");
|
||||||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "log_0446", variables => {
|
||||||
|
ip => $this_ip,
|
||||||
|
mac => $this_mac,
|
||||||
|
}});
|
||||||
my ($mac_to_ip_uuid) = $anvil->Database->insert_or_update_mac_to_ip({
|
my ($mac_to_ip_uuid) = $anvil->Database->insert_or_update_mac_to_ip({
|
||||||
debug => 3,
|
debug => 3,
|
||||||
file => $THIS_FILE,
|
file => $THIS_FILE,
|
||||||
@ -264,6 +315,8 @@ sub call_nmap
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
# Parse error
|
# Parse error
|
||||||
|
$anvil->data->{progress} += 2;
|
||||||
|
update_progress($anvil, $anvil->data->{progress}, "log_0444,!!ip!".$this_ip."!!,!!mac!".$this_mac."!!,!!section!".$section."!!");
|
||||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0444", variables => {
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0444", variables => {
|
||||||
ip => $this_ip,
|
ip => $this_ip,
|
||||||
mac => $this_mac,
|
mac => $this_mac,
|
||||||
|
Loading…
Reference in New Issue
Block a user