74_Nmap: check if Nmap is located at given path
git-svn-id: https://svn.fhem.de/fhem/trunk@13809 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -29,14 +29,16 @@ package main;
|
|||||||
|
|
||||||
use Blocking;
|
use Blocking;
|
||||||
|
|
||||||
my $rc = eval{
|
use Nmap::Parser;
|
||||||
require Nmap::Parser;
|
|
||||||
Nmap::Parser->import();
|
|
||||||
1;
|
|
||||||
};
|
|
||||||
|
|
||||||
return("Error loading Nmap::Parser. Maybe this module is not installed?")
|
# my $rc = eval{
|
||||||
unless($rc);
|
# require Nmap::Parser;
|
||||||
|
# Nmap::Parser->import();
|
||||||
|
# 1;
|
||||||
|
# };
|
||||||
|
#
|
||||||
|
# return("Error loading Nmap::Parser. Maybe this module is not installed?")
|
||||||
|
# unless($rc);
|
||||||
|
|
||||||
# forward declarations ########################################################
|
# forward declarations ########################################################
|
||||||
sub Nmap_Initialize($);
|
sub Nmap_Initialize($);
|
||||||
@@ -153,6 +155,9 @@ sub Nmap_Set($@) {
|
|||||||
if($argument eq "interrupt"){
|
if($argument eq "interrupt"){
|
||||||
BlockingKill($hash->{helper}{RUNNING_PID})
|
BlockingKill($hash->{helper}{RUNNING_PID})
|
||||||
if(defined($hash->{helper}{RUNNING_PID}));
|
if(defined($hash->{helper}{RUNNING_PID}));
|
||||||
|
|
||||||
|
Nmap_aborted($hash);
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(
|
InternalTimer(
|
||||||
gettimeofday() + $hash->{INTERVAL}, "Nmap_statusRequest", $hash
|
gettimeofday() + $hash->{INTERVAL}, "Nmap_statusRequest", $hash
|
||||||
@@ -247,6 +252,9 @@ sub Nmap_statusRequest($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $SELF = $hash->{NAME};
|
my $SELF = $hash->{NAME};
|
||||||
my $TYPE = $hash->{TYPE};
|
my $TYPE = $hash->{TYPE};
|
||||||
|
my $interval = $hash->{INTERVAL};
|
||||||
|
my $timeout = $interval - 1;
|
||||||
|
my $path = $hash->{PATH};
|
||||||
|
|
||||||
BlockingKill($hash->{helper}{RUNNING_PID})
|
BlockingKill($hash->{helper}{RUNNING_PID})
|
||||||
if(defined($hash->{helper}{RUNNING_PID}));
|
if(defined($hash->{helper}{RUNNING_PID}));
|
||||||
@@ -255,12 +263,22 @@ sub Nmap_statusRequest($) {
|
|||||||
return if(IsDisabled($SELF));
|
return if(IsDisabled($SELF));
|
||||||
|
|
||||||
InternalTimer(
|
InternalTimer(
|
||||||
gettimeofday() + $hash->{INTERVAL}, "Nmap_statusRequest", $hash
|
gettimeofday() + $interval, "Nmap_statusRequest", $hash
|
||||||
);
|
);
|
||||||
|
|
||||||
|
unless(-X $path){
|
||||||
|
readingsSingleUpdate($hash, "state", "aborted", 1);
|
||||||
|
Log3(
|
||||||
|
$SELF, 1, "$TYPE ($SELF) - "
|
||||||
|
. "please check if Nmap ist installed and available at path $path"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
AttrVal($SELF, "sudo", 0) == 1
|
AttrVal($SELF, "sudo", 0) == 1
|
||||||
&& qx(sudo -n $hash->{PATH} -V 2>&1 > /dev/null)
|
&& qx(sudo -n $path -V 2>&1 > /dev/null)
|
||||||
){
|
){
|
||||||
readingsSingleUpdate($hash, "state", "aborted", 1);
|
readingsSingleUpdate($hash, "state", "aborted", 1);
|
||||||
Log3($SELF, 1, "$TYPE ($SELF) - sudo password required");
|
Log3($SELF, 1, "$TYPE ($SELF) - sudo password required");
|
||||||
@@ -272,9 +290,8 @@ sub Nmap_statusRequest($) {
|
|||||||
Log3($SELF, 3, "$TYPE ($SELF) - starting network scan");
|
Log3($SELF, 3, "$TYPE ($SELF) - starting network scan");
|
||||||
|
|
||||||
$hash->{helper}{RUNNING_PID} = BlockingCall(
|
$hash->{helper}{RUNNING_PID} = BlockingCall(
|
||||||
"Nmap_blocking_statusRequest", $SELF
|
"Nmap_blocking_statusRequest", $SELF, "Nmap_done"
|
||||||
, "Nmap_done", $hash->{INTERVAL}-1
|
, $timeout, "Nmap_aborted", $hash
|
||||||
, "Nmap_aborted", $hash
|
|
||||||
) unless(exists($hash->{helper}{RUNNING_PID}));
|
) unless(exists($hash->{helper}{RUNNING_PID}));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -462,7 +479,8 @@ sub Nmap_done($) {
|
|||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
|
|
||||||
my $deleteOldReadings = AttrVal($SELF, "deleteOldReadings", 0);
|
my $deleteOldReadings = AttrVal($SELF, "deleteOldReadings", 0);
|
||||||
Nmap_deleteOldReadings($hash, $deleteOldReadings) if($deleteOldReadings != 0);
|
Nmap_deleteOldReadings($hash, $deleteOldReadings)
|
||||||
|
if($deleteOldReadings ne "0");
|
||||||
|
|
||||||
Log3($SELF, 3, "$TYPE ($SELF) - network scan done");
|
Log3($SELF, 3, "$TYPE ($SELF) - network scan done");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user