diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm
index 51a51b07..b52f0e06 100644
--- a/Anvil/Tools/Database.pm
+++ b/Anvil/Tools/Database.pm
@@ -1669,7 +1669,7 @@ sub get_local_uuid
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
last;
}
- elsif ($anvil->Network->is_local($db_host))
+ elsif ($anvil->Network->is_local({host => $db_host}))
{
$local_uuid = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
diff --git a/share/words.xml b/share/words.xml
index 27794b2d..b6922dbe 100644
--- a/share/words.xml
+++ b/share/words.xml
@@ -776,7 +776,11 @@ Failed to promote the DRBD resource: [#!variable!resource!#] primary. Expected a
#!variable!section!#
====
- [ NOTE ] - We're about to do a ping scan of: [#!variable!range!#]. This could take a long time, please be patient!
+ [ 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.
+ Found the network device: [#!variable!mac!#] usingt the IP address: [#!variable!ip!#].
+ About to download: [#!variable!url!#] and save it to: [#!variable!file!#].
+ Ready to parse: [#!variable!file!#].
+ Parsed: [#!variable!records!#], adding/updating them to the database now.
Test
diff --git a/tools/anvil-daemon b/tools/anvil-daemon
index 1b6c1026..36541fbf 100755
--- a/tools/anvil-daemon
+++ b/tools/anvil-daemon
@@ -312,32 +312,32 @@ sub handle_periodic_tasks
});
$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.
-# ($job_uuid) = $anvil->Database->insert_or_update_jobs({
-# file => $THIS_FILE,
-# line => __LINE__,
-# job_command => $anvil->data->{path}{exe}{'striker-parse-oui'},
-# job_data => "",
-# job_name => "oui-data::refresh",
-# job_title => "job_0064",
-# job_description => "job_0065",
-# job_progress => 0,
-# });
-# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
-#
-# # Scan the networks
-# ($job_uuid) = $anvil->Database->insert_or_update_jobs({
-# file => $THIS_FILE,
-# line => __LINE__,
-# job_command => $anvil->data->{path}{exe}{'striker-scan-network'},
-# job_data => "",
-# job_name => "scan-network::refresh",
-# job_title => "job_0066",
-# job_description => "job_0067",
-# job_progress => 0,
-# });
-# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
+ # Update the OUI data.
+ ($job_uuid) = $anvil->Database->insert_or_update_jobs({
+ file => $THIS_FILE,
+ line => __LINE__,
+ job_command => $anvil->data->{path}{exe}{'striker-parse-oui'},
+ job_data => "",
+ job_name => "oui-data::refresh",
+ job_title => "job_0064",
+ job_description => "job_0065",
+ job_progress => 0,
+ });
+ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
+
+ # Scan the networks
+ ($job_uuid) = $anvil->Database->insert_or_update_jobs({
+ file => $THIS_FILE,
+ line => __LINE__,
+ job_command => $anvil->data->{path}{exe}{'striker-scan-network'},
+ job_data => "",
+ job_name => "scan-network::refresh",
+ job_title => "job_0066",
+ job_description => "job_0067",
+ job_progress => 0,
+ });
+ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
+ die;
}
# Update the next check time.
diff --git a/tools/striker-parse-oui b/tools/striker-parse-oui
index e1f31003..bd6f6814 100755
--- a/tools/striker-parse-oui
+++ b/tools/striker-parse-oui
@@ -25,6 +25,25 @@ $anvil->Log->level({set => 2});
$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->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";
$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 }});
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({
debug => 2,
url => $anvil->data->{path}{urls}{oui_file},
@@ -74,6 +98,7 @@ if ($download)
else
{
# 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 => {
url => $anvil->data->{path}{urls}{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))
{
- $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);
}
+# We're done
+print $anvil->Words->string({key => "message_0025"})."\n";
+update_progress($anvil, 100, "message_0025");
$anvil->nice_exit({exit_code => 0});
@@ -106,6 +125,25 @@ $anvil->nice_exit({exit_code => 0});
# 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.
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 }});
# 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 $vendor = "";
my $address = "";
- my $lines = 0;
my ($oui_body) = $anvil->Storage->read_file({
debug => 3,
file => $oui_file,
@@ -138,9 +177,8 @@ EOF
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_body => $oui_body }});
foreach my $line (split/\n/, $oui_body)
{
- $lines++;
$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"))
{
@@ -222,6 +260,10 @@ EOF
}
# 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}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
diff --git a/tools/striker-scan-network b/tools/striker-scan-network
index 7877e0fa..4ae9cd80 100755
--- a/tools/striker-scan-network
+++ b/tools/striker-scan-network
@@ -34,6 +34,15 @@ $anvil->Log->level({set => 2});
$anvil->Log->secure({set => 0});
$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->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
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?
-$anvil->data->{switches}{network} = "";
+$anvil->data->{switches}{network} = "";
+$anvil->data->{switches}{'job-uuid'} = "";
$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);
+# We're done
+print $anvil->Words->string({key => "message_0025"})."\n";
+update_progress($anvil, 100, "message_0025");
$anvil->nice_exit({exit_code => 0});
@@ -56,6 +77,26 @@ $anvil->nice_exit({exit_code => 0});
# 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.
sub scan
{
@@ -92,6 +133,7 @@ sub scan
if ((not $ip_valid) or (not $subnet_valid))
{
# 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->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 }});
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 => {
@@ -251,6 +295,13 @@ sub call_nmap
# Store
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({
debug => 3,
file => $THIS_FILE,
@@ -264,6 +315,8 @@ sub call_nmap
else
{
# 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 => {
ip => $this_ip,
mac => $this_mac,