diff --git a/fhem/CHANGED b/fhem/CHANGED index bb4c92f0b..6a65d5643 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - changed: 76_SMAPortal: add check login Templates, multiple choice for attr + verbose5Data - bugfix: 76_SMAPortal: internal code changes, bug fixes show weather_icon - changed: 76_SMAPortal: internal code changes, minor bug fixes - bugfix: 70_BRAVIA: fix register procedure diff --git a/fhem/FHEM/76_SMAPortal.pm b/fhem/FHEM/76_SMAPortal.pm index 6f81a63a7..e1047cc6d 100644 --- a/fhem/FHEM/76_SMAPortal.pm +++ b/fhem/FHEM/76_SMAPortal.pm @@ -135,6 +135,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "2.10.5" => "12.06.2020 add check login by /Templates/, deeper/mulitple choice verbose5Data ", "2.10.4" => "11.06.2020 additional L1 Readings for Battery and more ", "2.10.3" => "11.06.2020 internal code changes, bug fixes show weather_icon ", "2.10.2" => "10.06.2020 bug fixes get/switch consumers ", @@ -248,7 +249,7 @@ sub Initialize { # "providerLevel:multiple-strict,".$v5d." ". "showPassInLog:1,0 ". "userAgent ". - "verbose5Data:none,loginData,".$v5d." ". + "verbose5Data:multiple-strict,none,loginData,".$v5d." ". $readingFnAttributes; eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; ## no critic 'eval' # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html) @@ -306,7 +307,7 @@ return; ############################################################### # SMAPortal Set ############################################################### -sub Set { ## no critic 'complexity' +sub Set { ## no critic 'complexity' my ($hash, @a) = @_; return "\"set X\" needs at least an argument" if ( @a < 2 ); my $name = $a[0]; @@ -772,6 +773,7 @@ sub GetSetData { ## no cri my $useragent = AttrVal($name, "userAgent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"); my $cookieLocation = AttrVal($name, "cookieLocation", "./log/".$name."_cookie.txt"); my $v5d = AttrVal($name, "verbose5Data", "none"); + my $verbose = AttrVal($name, "verbose", 3); my $dl = AttrVal($name, "detailLevel", 1); # selected Detail Level my $state = "ok"; my ($st,$lc) = ("",""); @@ -1098,16 +1100,22 @@ sub _checkLogin { my $hash = $defs{$name}; my $v5d = AttrVal($name, "verbose5Data", "none"); + my $verbose = AttrVal($name, "verbose", 3); my $loginp = $ua->post('https://www.sunnyportal.com/Templates/Start.aspx'); my $retcode = $loginp->code; my $location = $loginp->header('Location') // ""; + if($verbose == 5 && $v5d =~ /loginData/) { + $ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging + $ua->add_handler( response_done => sub { shift->dump; return } ); + } + if ($loginp->is_success) { - if($v5d eq "loginData") { + if($v5d =~ /loginData/) { Log3 ($name, 5, "$name - Status Login Page: ".$loginp->status_line); Log3 ($name, 5, "$name - Header Location: ".$location); - Log3 ($name, 5, "$name - Login Page content: ".encode("utf8", $loginp->decoded_content)); + # Log3 ($name, 5, "$name - Login Page content: ".encode("utf8", $loginp->decoded_content)); } $retcode = $loginp->code; @@ -1135,13 +1143,13 @@ sub _checkLogin { $retcode = $loginp->code; $location = $loginp->header('Location') // ""; - if($v5d eq "loginData") { + if($v5d =~ /loginData/) { Log3 ($name, 5, "$name - Status Redirect Page : ".$retcode); Log3 ($name, 5, "$name - Header Redirect Location: ".$location); - Log3 ($name, 5, "$name - Redirect Page content: ".encode("utf8", $loginp->decoded_content)); + # Log3 ($name, 5, "$name - Redirect Page content: ".encode("utf8", $loginp->decoded_content)); } - if($location =~ /\/FixedPages\//x && $retcode eq "302") { # Weiterleitung -> Login erfolgeich(Landing Pages können im Portal eingestellt werden!) + if($location =~ /\/FixedPages\/|\/Templates\//x && $retcode eq "302") { # Weiterleitung -> Login erfolgeich(Landing Pages können im Portal eingestellt werden!) Log3 ($name, 3, "$name - Login into SMA-Portal successfully done"); handleCounter ($name, "dailyIssueCookieCounter"); # Cookie Ausstellungszähler setzen @@ -1159,7 +1167,7 @@ sub _checkLogin { } elsif($loginp->is_redirect) { $retcode = $loginp->code; $location = $loginp->header('Location') // ""; - if($v5d eq "loginData") { + if($v5d =~ /loginData/) { Log3 ($name, 5, "$name - Redirect return code: ".$retcode); Log3 ($name, 5, "$name - Redirect Header Location: ".$location); } @@ -1171,6 +1179,9 @@ sub _checkLogin { Log3 ($name, 1, "$name - ERROR Login Page: ".$state); } + $ua->remove_handler('request_send'); + $ua->remove_handler('response_done'); + return ($state, $errstate); } @@ -1274,21 +1285,31 @@ sub _getData { my $call = $paref->{call}; my $tag = $paref->{tag}; + my $v5d = AttrVal($name, "verbose5Data", "none"); + my $verbose = AttrVal($name, "verbose", 3); + my $cont; - Log3 ($name, 4, "$name - Getting $tag"); + Log3 ($name, 4, "$name - Getting $tag"); + + if($verbose == 5 && $v5d =~ /$tag/) { + $ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging + $ua->add_handler( response_done => sub { shift->dump; return } ); + } - my $v5d = AttrVal($name, "verbose5Data", "none"); my $data = $ua->get( $call ); my $dcont = $data->content; $cont = eval{decode_json($dcont)} or do { $cont = $dcont }; - if($v5d eq $tag) { + if($v5d =~ /$tag/) { Log3 ($name, 5, "$name - Return Code: ".$data->code); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); } + $ua->remove_handler('request_send'); + $ua->remove_handler('response_done'); + return ($data,$dcont); } @@ -1303,11 +1324,18 @@ sub _postData { my $fields = $paref->{fields}; my $content = $paref->{content}; my $tag = $paref->{tag}; + my $v5d = AttrVal($name, "verbose5Data", "none"); + my $verbose = AttrVal($name, "verbose", 3); my $cont; Log3 ($name, 4, "$name - Getting $tag"); + + if($verbose == 5 && $v5d =~ /$tag/) { + $ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging + $ua->add_handler( response_done => sub { shift->dump; return } ); + } my $data = $ua->post( $call, %$fields, Content => $content ); @@ -1315,11 +1343,14 @@ sub _postData { $cont = eval{decode_json($dcont)} or do { $cont = $dcont }; - if($v5d eq $tag) { + if($v5d =~ /$tag/) { Log3 ($name, 5, "$name - Return Code: ".$data->code); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); } + $ua->remove_handler('request_send'); + $ua->remove_handler('response_done'); + return ($data,$dcont); } @@ -1390,7 +1421,7 @@ sub _analyzeData { ## n } } else { - my $njdat = $ad->as_string; + my $njdat = $ad->as_string; if($njdat =~ /401\s-\sUnauthorized/x) { Log3 ($name, 2, "$name - ERROR - User logged in but unauthorized"); @@ -1552,7 +1583,7 @@ return ($err); ################################################################ ## Auswertung Live Daten ################################################################ -sub extractLiveData { +sub extractLiveData { ## no critic 'complexity' my $hash = shift; my $daref = shift; my $live = shift; @@ -3300,8 +3331,9 @@ return;