2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

70_BOTVAC.pm: solved recursion while looking up hostname of server, hide readings: accessToken, secretKey

git-svn-id: https://svn.fhem.de/fhem/trunk@18621 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
vuffiraa 2019-02-17 17:09:37 +00:00
parent ce6d7998c8
commit 8d01497d2c
2 changed files with 46 additions and 33 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- bugfix: 70_BOTVAC: solved recursion while looking up hostname of server
- feature: limit reading/attr name length in featurelevel 6.0+ (Forum #97493) - feature: limit reading/attr name length in featurelevel 6.0+ (Forum #97493)
- feature: 49_SSCam: send recordings by telegram is integrated as well as - feature: 49_SSCam: send recordings by telegram is integrated as well as
sending snapshots sending snapshots

View File

@ -82,6 +82,7 @@ BEGIN {
readingsBulkUpdate readingsBulkUpdate
readingsBulkUpdateIfChanged readingsBulkUpdateIfChanged
readingsBeginUpdate readingsBeginUpdate
readingsDelete
readingsEndUpdate readingsEndUpdate
ReadingsNum ReadingsNum
ReadingsVal ReadingsVal
@ -189,6 +190,10 @@ sub GetStatus($;$) {
SendCommand($hash, "messages", "getRobotState", undef, @successor); SendCommand($hash, "messages", "getRobotState", undef, @successor);
} }
# cleanup
readingsDelete($hash, "accessToken");
readingsDelete($hash, "secretKey");
return; return;
} }
@ -628,14 +633,7 @@ sub SendCommand($$;$$@) {
Log3($name, 4, "BOTVAC $name: REQ $service/$cmd"); Log3($name, 4, "BOTVAC $name: REQ $service/$cmd");
} }
Log3($name, 4, "BOTVAC $name: REQ option $option") if (defined($option)); Log3($name, 4, "BOTVAC $name: REQ option $option") if (defined($option));
my $msg = "BOTVAC $name: REQ successors"; LogSuccessors($hash, @successor);
my @succ_item;
for (my $i = 0; $i < @successor; $i++) {
@succ_item = @{$successor[$i]};
$msg .= " $i: ";
$msg .= join(",", map { defined($_) ? $_ : '' } @succ_item);
}
Log3($name, 4, $msg);
$header = "Accept: application/vnd.neato.nucleo.v1"; $header = "Accept: application/vnd.neato.nucleo.v1";
$header .= "\r\nContent-Type: application/json"; $header .= "\r\nContent-Type: application/json";
@ -649,7 +647,7 @@ sub SendCommand($$;$$@) {
%sslArgs = ( SSL_verify_mode => 0 ); %sslArgs = ( SSL_verify_mode => 0 );
} elsif ($service eq "dashboard") { } elsif ($service eq "dashboard") {
$header .= "\r\nAuthorization: Token token=".ReadingsVal($name, "accessToken", ""); $header .= "\r\nAuthorization: Token token=".ReadingsVal($name, ".accessToken", "");
$URL .= GetBeehiveHost($hash->{VENDOR}); $URL .= GetBeehiveHost($hash->{VENDOR});
$URL .= "/dashboard"; $URL .= "/dashboard";
%sslArgs = ( SSL_verify_mode => 0 ); %sslArgs = ( SSL_verify_mode => 0 );
@ -658,7 +656,7 @@ sub SendCommand($$;$$@) {
my $serial = ReadingsVal($name, "serial", ""); my $serial = ReadingsVal($name, "serial", "");
return if ($serial eq ""); return if ($serial eq "");
$header .= "\r\nAuthorization: Token token=".ReadingsVal($name, "accessToken", ""); $header .= "\r\nAuthorization: Token token=".ReadingsVal($name, ".accessToken", "");
$URL .= GetBeehiveHost($hash->{VENDOR}); $URL .= GetBeehiveHost($hash->{VENDOR});
$URL .= "/users/me/robots/$serial/"; $URL .= "/users/me/robots/$serial/";
$URL .= (defined($cmd) ? $cmd : "maps"); $URL .= (defined($cmd) ? $cmd : "maps");
@ -757,7 +755,7 @@ sub SendCommand($$;$$@) {
my $now = time(); my $now = time();
my $date = FmtDateTimeRFC1123($now); my $date = FmtDateTimeRFC1123($now);
my $message = join("\n", (lc($serial), $date, $data)); my $message = join("\n", (lc($serial), $date, $data));
my $hmac = hmac_sha256_hex($message, ReadingsVal($name, "secretKey", "")); my $hmac = hmac_sha256_hex($message, ReadingsVal($name, ".secretKey", ""));
$header .= "\r\nDate: $date"; $header .= "\r\nDate: $date";
$header .= "\r\nAuthorization: NEATOAPP $hmac"; $header .= "\r\nAuthorization: NEATOAPP $hmac";
@ -819,13 +817,18 @@ sub ReceiveCommand($$$) {
if ($err) { if ($err) {
if ( !defined($cmd) || $cmd eq "" ) { if ( !defined($cmd) || $cmd eq "" ) {
Log3($name, 4, "BOTVAC $name:$service RCV $err"); Log3($name, 3, "BOTVAC $name:$service RCV $err");
} else { } else {
Log3($name, 4, "BOTVAC $name:$service/$cmd RCV $err"); Log3($name, 3, "BOTVAC $name:$service/$cmd RCV $err");
} }
# keep last state # keep last state
#readingsBulkUpdateIfChanged( $hash, "state", "Error" ); #readingsBulkUpdateIfChanged( $hash, "state", "Error" );
# stop pulling for current interval
Log3($name, 4, "BOTVAC $name: drop successors");
LogSuccessors($hash, @successor);
return;
} }
# data received # data received
@ -836,14 +839,7 @@ sub ReceiveCommand($$$) {
} else { } else {
Log3($name, 4, "BOTVAC $name: RCV $service/$cmd"); Log3($name, 4, "BOTVAC $name: RCV $service/$cmd");
} }
my $msg = "BOTVAC $name: RCV successors"; LogSuccessors($hash, @successor);
my @succ_item;
for (my $i = 0; $i < @successor; $i++) {
@succ_item = @{$successor[$i]};
$msg .= " $i: ";
$msg .= join(",", map { defined($_) ? $_ : '' } @succ_item);
}
Log3($name, 4, $msg);
if ( $data ne "" ) { if ( $data ne "" ) {
if ( $service eq "loadmap" ) { if ( $service eq "loadmap" ) {
@ -1098,7 +1094,7 @@ sub ReceiveCommand($$$) {
# Sessions # Sessions
elsif ( $service eq "sessions" ) { elsif ( $service eq "sessions" ) {
if ( ref($return) eq "HASH" and defined($return->{access_token})) { if ( ref($return) eq "HASH" and defined($return->{access_token})) {
readingsBulkUpdateIfChanged($hash, "accessToken", $return->{access_token}); readingsBulkUpdateIfChanged($hash, ".accessToken", $return->{access_token});
} }
} }
@ -1240,7 +1236,7 @@ sub SetRobot($$) {
readingsBulkUpdateIfChanged($hash, "model", $robots[$robot]->{model}); readingsBulkUpdateIfChanged($hash, "model", $robots[$robot]->{model});
readingsBulkUpdateIfChanged($hash, "firmwareLatest", $robots[$robot]->{recentFirmware}) readingsBulkUpdateIfChanged($hash, "firmwareLatest", $robots[$robot]->{recentFirmware})
if (defined($robots[$robot]->{recentFirmware})); if (defined($robots[$robot]->{recentFirmware}));
readingsBulkUpdateIfChanged($hash, "secretKey", $robots[$robot]->{secretKey}); readingsBulkUpdateIfChanged($hash, ".secretKey", $robots[$robot]->{secretKey});
readingsBulkUpdateIfChanged($hash, "macAddr", $robots[$robot]->{macAddr}); readingsBulkUpdateIfChanged($hash, "macAddr", $robots[$robot]->{macAddr});
readingsBulkUpdateIfChanged($hash, "nucleoUrl", $robots[$robot]->{nucleoUrl}); readingsBulkUpdateIfChanged($hash, "nucleoUrl", $robots[$robot]->{nucleoUrl});
readingsBulkUpdateIfChanged($hash, "robot", $robot); readingsBulkUpdateIfChanged($hash, "robot", $robot);
@ -1334,7 +1330,7 @@ sub CheckRegistration($$$$$) {
my ( $hash, $service, $cmd, $option, @successor ) = @_; my ( $hash, $service, $cmd, $option, @successor ) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if (ReadingsVal($name, "secretKey", "") eq "") { if (ReadingsVal($name, ".secretKey", "") eq "") {
my @nextCmd = ($service, $cmd, $option); my @nextCmd = ($service, $cmd, $option);
unshift(@successor, [$service, $cmd, $option]); unshift(@successor, [$service, $cmd, $option]);
@ -1347,8 +1343,8 @@ sub CheckRegistration($$$$$) {
} }
Log3($name, 4, "BOTVAC created".$msg); Log3($name, 4, "BOTVAC created".$msg);
SendCommand($hash, "sessions", undef, undef, @successor) if (ReadingsVal($name, "accessToken", "") eq ""); SendCommand($hash, "sessions", undef, undef, @successor) if (ReadingsVal($name, ".accessToken", "") eq "");
SendCommand($hash, "dashboard", undef, undef, @successor) if (ReadingsVal($name, "accessToken", "") ne ""); SendCommand($hash, "dashboard", undef, undef, @successor) if (ReadingsVal($name, ".accessToken", "") ne "");
return 1; return 1;
} }
@ -1557,6 +1553,21 @@ sub GetValidityEnd($) {
return ($validFor =~ /\d+/ ? FmtDateTime(time() + $validFor) : $validFor); return ($validFor =~ /\d+/ ? FmtDateTime(time() + $validFor) : $validFor);
} }
sub LogSuccessors($@) {
my ($hash,@successor) = @_;
my $name = $hash->{NAME};
my $msg = "BOTVAC $name: RCV successors";
my @succ_item;
for (my $i = 0; $i < @successor; $i++) {
@succ_item = @{$successor[$i]};
$msg .= " $i: ";
$msg .= join(",", map { defined($_) ? $_ : '' } @succ_item);
}
Log3($name, 4, $msg);
}
sub ShowMap($;$$) { sub ShowMap($;$$) {
my ($name,$width,$height) = @_; my ($name,$width,$height) = @_;
@ -1628,7 +1639,7 @@ sub wsHandshake($) {
my $now = time(); my $now = time();
my $date = FmtDateTimeRFC1123($now); my $date = FmtDateTimeRFC1123($now);
my $message = lc($serial) . "\n" . $date . "\n"; my $message = lc($serial) . "\n" . $date . "\n";
my $hmac = hmac_sha256_hex($message, ReadingsVal($name, "secretKey", "")); my $hmac = hmac_sha256_hex($message, ReadingsVal($name, ".secretKey", ""));
my $wsHandshakeCmd = "GET $path HTTP/1.1\r\n"; my $wsHandshakeCmd = "GET $path HTTP/1.1\r\n";
$wsHandshakeCmd .= "Host: $host:$port\r\n"; $wsHandshakeCmd .= "Host: $host:$port\r\n";
@ -2098,6 +2109,7 @@ sub wsMasking($$) {
<ul> <ul>
<br> <br>
<li> <li>
<a name="actionInterval"></a>
<code>actionInterval</code> <code>actionInterval</code>
<br> <br>
time in seconds between status requests while Device is working time in seconds between status requests while Device is working