diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm index 7dfd7f69e..4cbb9d717 100644 --- a/fhem/FHEM/72_FRITZBOX.pm +++ b/fhem/FHEM/72_FRITZBOX.pm @@ -41,7 +41,7 @@ use warnings; use Blocking; use HttpUtils; -my $ModulVersion = "07.50.10a"; +my $ModulVersion = "07.50.12"; my $missingModul = ""; my $missingModulWeb = ""; my $missingModulTR064 = ""; @@ -51,6 +51,8 @@ my $FRITZBOX_TR064user; eval "use URI::Escape;1" or $missingModul .= "URI::Escape "; eval "use MIME::Base64;1" or $missingModul .= "MIME::Base64 "; eval "use IO::Socket;1" or $missingModul .= "IO::Socket "; +eval "use Net::Ping;1" or $missingModul .= "Net::Ping "; + use FritzBoxUtils; ## only for web access login @@ -210,12 +212,14 @@ sub FRITZBOX_Initialize($) # ."ringWithIntern:0,1,2 " # ."useGuiHack:0,1 " ."userTickets " + ."enableKidProfiles:0,1 " ."enablePassivLanDevices:0,1 " ."enableVPNShares:0,1 " ."enableUserInfo:0,1 " ."enableAlarmInfo:0,1 " ."enableWLANneighbors:0,1 " ."wlanNeighborsPrefix " + ."disableHostIPv4check:0,1 " ."disableDectInfo:0,1 " ."disableFonInfo:0,1 " ."enableSIP:0,1 " @@ -256,12 +260,20 @@ sub FRITZBOX_Define($$) if (defined $args[2] && $args[2] !~ m=$URL_MATCH=i) { my $phost = inet_aton($args[2]); - FRITZBOX_Log $hash, 2, "DEBUG: phost -> $phost"; - return "FRITZBOX-define: DNS name $args[2] could not be resolved" if (! defined($phost)); + if (! defined($phost)) { + FRITZBOX_Log $hash, 2, "INFO: phost -> not defined"; + return "FRITZBOX-define: DNS name $args[2] could not be resolved"; + } my $host = inet_ntoa($phost); - FRITZBOX_Log $hash, 2, "DEBUG: host -> $host"; - return "FRITZBOX-define: DNS name could not be resolved" if (! defined($host)); + + if (! defined($host)) { + FRITZBOX_Log $hash, 2, "INFO: host -> $host"; + return "FRITZBOX-define: DNS name could not be resolved"; + } + $hash->{HOST} = $host; + } else { + $hash->{HOST} = $args[2]; } my $name = $args[0]; @@ -269,7 +281,7 @@ sub FRITZBOX_Define($$) $hash->{NAME} = $name; $hash->{VERSION} = $ModulVersion; - $hash->{HOST} = $args[2]; +# $hash->{HOST} = $args[2]; $hash->{fhem}{definedHost} = $hash->{HOST}; # to cope with old attribute definitions @@ -498,6 +510,14 @@ sub FRITZBOX_Attr($@) } } + if ($aName eq "enableKidProfiles") { + if ($cmd eq "del" || $aVal == 0) { + foreach (keys %{ $hash->{READINGS} }) { + readingsDelete($hash, $_) if $_ =~ /^kidprofile(\d+)/ && defined $hash->{READINGS}{$_}{VAL}; + } + } + } + if ($aName eq "enableVPNShares") { if ($cmd eq "del" || $aVal == 0) { foreach (keys %{ $hash->{READINGS} }) { @@ -590,6 +610,11 @@ sub FRITZBOX_Set($$@) my $resultStr = ""; my $mesh = ReadingsVal($name, "box_meshRole", "master"); + my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); + + my $FW1 = substr($fwV[1],0,2); + my $FW2 = substr($fwV[2],0,2); + my $list = " checkAPIs:noArg" . " password" . " update:noArg"; @@ -612,18 +637,24 @@ sub FRITZBOX_Set($$@) # set abhängig von TR064 und data.lua $list .= " macFilter:on,off" - . " enableVPNshare" if ($hash->{LUADATA} == 1) && defined ($hash->{MODEL}) && ($hash->{MODEL} =~ "Box") && $hash->{TR064} == 1 && $hash->{SECPORT} && $mesh eq "master"; + $list .= " enableVPNshare" + if ($hash->{LUADATA} == 1) && defined ($hash->{MODEL}) && ($hash->{MODEL} =~ "Box") && $hash->{TR064} == 1 && $hash->{SECPORT} && $mesh eq "master" && $FW1 == 7 && $FW2 >= 21; + + # set abhängig von data.lua $list .= " switchIPv4DNS:provider,other" . " dect:on,off" - . " dectRingblock" . " lockLandevice" . " macFilter:on,off" . " chgProfile" if ($hash->{LUADATA} == 1) && defined ($hash->{MODEL}) && ($hash->{MODEL} =~ "Box") && $mesh eq "master"; + $list .= " wakeUpCall" + . " dectRingblock" + if ($hash->{LUADATA} == 1) && defined ($hash->{MODEL}) && ($hash->{MODEL} =~ "Box" && $FW1 == 7 && $FW2 >= 21); + # $list .= " alarm" # . " startRadio"; @@ -750,11 +781,7 @@ sub FRITZBOX_Set($$@) return undef; } } - elsif ( lc $cmd eq 'dectringblock' && $mesh eq "master") { - my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); - - my $FW1 = substr($fwV[1],0,2); - my $FW2 = substr($fwV[2],0,2); + elsif ( lc $cmd eq 'dectringblock' && $mesh eq "master" && $FW1 == 7 && $FW2 >= 21) { FRITZBOX_Log $hash, 5, "DEBUG: set $name $cmd für Version: $FW1.$FW2 "; @@ -882,11 +909,6 @@ sub FRITZBOX_Set($$@) elsif ( lc $cmd eq 'switchipv4dns' && $mesh eq "master") { if (int @val == 1 && $val[0] =~ /^(provider|other)$/) { - my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); - - my $FW1 = substr($fwV[1],0,2); - my $FW2 = substr($fwV[2],0,2); - FRITZBOX_Log $hash, 4, "INFO: set $name $cmd für Version: $FW1.$FW2 "; if ($FW1 <= 7 && $FW2 < 21) { @@ -978,13 +1000,9 @@ sub FRITZBOX_Set($$@) } } - elsif ( lc $cmd eq 'enablevpnshare' && $mesh eq "master") { + elsif ( lc $cmd eq 'enablevpnshare' && $mesh eq "master" && $FW1 == 7 && $FW2 >= 21) { if ( int @val == 2 && $val[1] =~ /^(on|off)$/ ) { - my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); - - my $FW1 = substr($fwV[1],0,2); - my $FW2 = substr($fwV[2],0,2); FRITZBOX_Log $hash, 4, "INFO: set $name $cmd für Version: $FW1.$FW2 "; @@ -1069,6 +1087,69 @@ sub FRITZBOX_Set($$@) return "ERROR: for chgprofile arguments"; } } + elsif ( (lc $cmd eq 'wakeupcall') && ($hash->{LUADATA} == 1) && defined ($hash->{MODEL}) && ($hash->{MODEL} =~ "Box") && $FW1 == 7 && $FW2 >= 21 ) { + # xhr 1 lang de page alarm xhrId all / get Info + + # xhr: 1 + # active: 1 | 0 + # hour: 07 + # minutes: 00 + # device: 70 + # name: Wecker 1 + # optionRepeat: daily | only_once | per_day { mon: 1 tue: 0 wed: 1 thu: 0 fri: 1 sat: 0 sun: 0 } + # apply: true + # lang: de + # page: alarm | alarm1 | alarm2 + + # alarm1 62 per_day 10:00 mon:1 tue:0 wed:1 thu:0 fri:1 sat:0 sun:0 + + # set wakeUpCall + + return "wakeUpCall: to few parameters" if int @val < 2; + + # return "Amount off parameter:" . int @val; + + if (int @val == 2) { + return "wakeUpCall: 1st Parameter must be one of the alarm pages: alarm1,alarm2 or alarm3" if $val[0] !~ /^(alarm1|alarm2|alarm3)$/; + return "wakeUpCall: 2nd Parameter must be 'off'" if $val[1] !~ /^(off)$/; + } elsif (int @val > 2) { + return "wakeUpCall: 2nd Parameter must be one of the alarm pages: alarm1,alarm2 or alarm3" if $val[0] !~ /^(alarm1|alarm2|alarm3)$/; + my $device = "fd_" . $val[1]; + my $devname = "fdn_" . $val[1]; + unless ($hash->{fhem}->{$device} || $hash->{fhem}->{$devname}) { + return "wakeUpCall: dect or fon Device name/number $val[1] not defined"; # unless $hash->{fhem}->{$device}; + } elsif ($hash->{fhem}->{$devname}) { + $val[1] = $hash->{fhem}->{$devname}; + } + } + + if ( int @val >= 3 && $val[2] !~ /^(daily|only_once|per_day)$/) { + return "wakeUpCall: 3rd Parameter must be daily, only_once or per_day"; + } elsif ( int @val >= 3 && $val[3] !~ /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$/) { + return "wakeUpCall: 4th Parameter must be a valid time"; + } elsif ( int @val == 11 && $val[2] ne "per_day") { + return "wakeUpCall: 3rd Parameter must be per_day"; + } elsif ( int @val == 11 && $val[2] eq "per_day") { + + my $fError = 0; + for(my $i = 4; $i <= 10; $i++) { + if ($val[$i] !~ /^(mon|tue|wed|thu|fri|sat|sun):(0|1)$/) { + $fError = $i; + last; + } + } + + return "wakeUpCall: wrong argument for per_day: $val[$fError]" if $fError; + + } elsif (int(@val) != 4 && int(@val) != 11 && $val[1] !~ /^(off)$/) { + return "wakeUpCall: wrong number of arguments per_day."; + } + + FRITZBOX_Log $hash, 4, "INFO: set $name $cmd ".join(" ", @val); + push @cmdBuffer, "wakeupcall " . join(" ", @val); + return FRITZBOX_Set_Cmd_Start $hash->{helper}{TimerCmd}; + + } elsif ( lc $cmd eq 'guestwlan') { if (int @val == 1 && $val[0] =~ /^(on|off)$/) { FRITZBOX_Log $hash, 4, "INFO: set $name $cmd ".join(" ", @val); @@ -1076,12 +1157,6 @@ sub FRITZBOX_Set($$@) return FRITZBOX_Set_Cmd_Start $hash->{helper}{TimerCmd}; } } -# elsif ( lc $cmd eq 'moh' && $mesh eq "master") { -# if (int @val > 0) -# { -# FRITZBOX_Log $hash, 4, "INFO: set $name $cmd ".join(" ", @val); -# } -# } # set password elsif ( lc $cmd eq 'password') { if (int @val == 1) @@ -1173,6 +1248,11 @@ sub FRITZBOX_Get($@) my ($hash, $name, $cmd, @val) = @_; my $returnStr; + my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); + + my $FW1 = substr($fwV[1],0,2); + my $FW2 = substr($fwV[2],0,2); + if( lc $cmd eq "luaquery" && $hash->{LUAQUERY}) { # get Fritzbox luaQuery inetstat:status/Today/BytesReceivedLow # get Fritzbox luaQuery telcfg:settings/AlarmClock/list(Name,Active,Time,Number,Weekdays) @@ -1199,7 +1279,6 @@ sub FRITZBOX_Get($@) $returnStr .= "----------------------------------------------------------------------\n"; my $result = FRITZBOX_Web_Query( $hash, $val[0], "", "luaCall") ; - #my $result = FRITZBOX_Lua_Call( $hash, $val[0], $val[1]) ; my $tmp = FRITZBOX_ERR_Result($hash, $result); @@ -1245,6 +1324,11 @@ sub FRITZBOX_Get($@) } elsif( lc $cmd eq "fritzlog" && $hash->{LUADATA}) { + if (($FW1 <= 7 && $FW2 < 21) || ($FW1 <= 6)) { + FRITZBOX_Log $hash, 2, "ERROR: FritzOS version must be greater than 7.20"; + return "FritzOS version must be greater than 7.20."; + } + return "Wrong number of arguments, usage: get $name argName1 argValue1" if int @val != 2; return "Wrong 1st parmeter, usage hash or table for first parameter" if $val[0] !~ /hash|table/; return "Wrong 2nd parmeter, usage all, sys, wlan, usb, net, fon" if $val[1] !~ /all|sys|wlan|usb|net|fon/; @@ -1258,14 +1342,10 @@ sub FRITZBOX_Get($@) } } elsif( lc $cmd eq "luainfo") { - my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); - - my $FW1 = substr($fwV[1],0,2); - my $FW2 = substr($fwV[2],0,2); FRITZBOX_Log $hash, 4, "INFO: set $name $cmd für Version: $FW1.$FW2 "; - if ($FW1 <= 7 && $FW2 < 21) { + if (($FW1 <= 7 && $FW2 < 21) || ($FW1 <= 6)) { FRITZBOX_Log $hash, 2, "ERROR: FritzOS version must be greater than 7.20"; return "FritzOS version must be greater than 7.20."; } @@ -1351,12 +1431,14 @@ sub FRITZBOX_Get($@) $list .= " luaFunction" if $hash->{LUAQUERY}; # luaData - $list .= " luaInfo:" if $hash->{LUADATA} || $hash->{LUAQUERY}; - $list .= "lanDevices,vpnShares,wlanNeighborhood" if $hash->{LUADATA}; - $list .= ",kidProfiles,userInfos" if $hash->{LUAQUERY}; - $list .= ",docsisInformation" if $hash->{LUADATA} && ($avmModel =~ "Box") && (lc($avmModel) =~ "6[4,5,6][3,6,9][0,1]"); + if (($hash->{LUADATA} || $hash->{LUAQUERY}) && ($FW1 >= 7) ){ + $list .= " luaInfo:"; + $list .= "lanDevices,vpnShares,wlanNeighborhood" if $hash->{LUADATA}; + $list .= ",kidProfiles,userInfos" if $hash->{LUAQUERY}; + $list .= ",docsisInformation" if $hash->{LUADATA} && ($avmModel =~ "Box") && (lc($avmModel) =~ "6[4,5,6][3,6,9][0,1]"); + } - $list .= " fritzLog" if $hash->{LUADATA}; + $list .= " fritzLog" if $hash->{LUADATA} && (($FW1 >= 6 && $FW2 >= 80) || ($FW1 >= 7)); $list .= " lanDeviceInfo" if $hash->{LUADATA}; @@ -1780,6 +1862,8 @@ sub FRITZBOX_Readout_Run_Web($) my $rName; my @roReadings; my %dectFonID; + my %fonFonID; + my %devID; my %resultHash; my $startTime = time(); my $runNo; @@ -1804,7 +1888,7 @@ sub FRITZBOX_Readout_Run_Web($) my $queryStr = "&radio=configd:settings/WEBRADIO/list(Name)"; # Webradio $queryStr .= "&box_dect=dect:settings/enabled"; # DECT Sender $queryStr .= "&handsetCount=dect:settings/Handset/count"; # Anzahl Handsets - $queryStr .= "&handset=dect:settings/Handset/list(User,Manufacturer,Model,FWVersion)"; # DECT Handsets + $queryStr .= "&handset=dect:settings/Handset/list(User,Manufacturer,Model,FWVersion,Productname)"; # DECT Handsets $queryStr .= "&wlanList=wlan:settings/wlanlist/list(mac,speed,speed_rx,rssi,is_guest)"; # WLAN devices $queryStr .= "&wlanListNew=wlan:settings/wlanlist/list(mac,speed,rssi)"; # WLAN devices fw>=6.69 #wlan:settings/wlanlist/list(hostname,mac,UID,state,rssi,quality,is_turbo,cipher,wmm_active,powersave,is_ap,ap_state,is_repeater,flags,flags_set,mode,is_guest,speed,speed_rx,channel_width,streams) #wlan:settings/wlanlist/list(hostname,mac,UID,state,rssi,quality,is_turbo,wmm_active,cipher,powersave,is_repeater,flags,flags_set,mode,is_guest,speed,speed_rx,speed_rx_max,speed_tx_max,channel_width,streams,mu_mimo_group,is_fail_client) @@ -1896,7 +1980,7 @@ sub FRITZBOX_Readout_Run_Web($) # Abbruch wenn Fehler beim Lesen der Fritzbox-Antwort if ( defined $result->{Error} ) { - FRITZBOX_Log $hash, 2, "ERROR: ".$result->{Error}; + FRITZBOX_Log $hash, 4, "INFO: ".$result->{Error}; my $returnStr = "Error|" . $result->{Error}; $returnStr .= "|fhem->sidTime|0" if defined $result->{ResetSID}; $returnStr .= "|" . join('|', @roReadings ) if int @roReadings; @@ -1904,7 +1988,7 @@ sub FRITZBOX_Readout_Run_Web($) } if ( defined $result->{AuthorizationRequired} ) { - FRITZBOX_Log $hash, 2, "ERROR: AuthorizationRequired=".$result->{AuthorizationRequired}; + FRITZBOX_Log $hash, 4, "INFO: AuthorizationRequired=".$result->{AuthorizationRequired}; my $returnStr = "Error|Authorization required"; $returnStr .= "|fhem->sidTime|0" if defined $result->{ResetSID}; $returnStr .= "|" . join('|', @roReadings ) if int @roReadings; @@ -1987,11 +2071,12 @@ sub FRITZBOX_Readout_Run_Web($) FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); -# Dect-Geräteliste erstellen +# Dect-Geräteliste erstellen if ( $result->{handsetCount} =~ /[1-9]/ ) { $runNo = 0; foreach ( @{ $result->{dectUser} } ) { my $intern = $_->{Intern}; + my $name = $_->{Name}; my $id = $_->{Id}; if ($intern) { @@ -2009,6 +2094,9 @@ sub FRITZBOX_Readout_Run_Web($) $dectFonID{$id}{Intern} = $intern; $dectFonID{$id}{User} = $runNo; + $dectFonID{$name} = $runNo; + FRITZBOX_Log $hash, 5, "INFO: dect: $name, $runNo"; + } $runNo++; } @@ -2022,7 +2110,8 @@ sub FRITZBOX_Readout_Run_Web($) if ($dectUser) { FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectUser."_manufacturer", $_->{Manufacturer}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectUser."_model", $_->{Model}, "model"; +# FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectUser."_model", $_->{Model}, "model"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectUser."_model", $_->{Productname}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectUser."_fwVersion", $_->{FWVersion}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->$intern->brand", $_->{Manufacturer}; @@ -2035,9 +2124,11 @@ sub FRITZBOX_Readout_Run_Web($) foreach ( @{ $result->{fonPort} } ) { if ( $_->{Name} ) { + my $name = $_->{Name}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$runNo, $_->{Name}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$runNo."_out", $_->{MSN}; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$runNo."_intern", $runNo; + $fonFonID{$name} = $runNo; } $runNo++; } @@ -2547,13 +2638,83 @@ sub FRITZBOX_Readout_Run_Web($) my $resultData; my $tmpData; - if ( $FW1 >= 7 && $FW2 >= 21 && $hash->{LUADATA}) { + if ( (($FW1 ==6 && $FW2 >= 80) || ($FW1 >= 7 && $FW2) >= 21) && $hash->{LUADATA}) { + + # xhr 1 lang de page alarm xhrId all + @webCmdArray = (); + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "alarm"; + push @webCmdArray, "xhrId" => "all"; + + $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + + if(defined $resultData->{Error}) { + $tmpData = FRITZBOX_ERR_Result($hash, $resultData); + FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; + } else { + + FRITZBOX_Log $hash, 5, "DEBUG: \n" . Dumper ($resultData->{data}); + + $nbViews = 0; + if (defined $resultData->{data}->{phonoptions}) { + $views = $resultData->{data}->{phonoptions}; + $nbViews = scalar @$views; + } + + my $devname; + my $device; + + if ($nbViews > 0) { + + # proof on redundant phone names + eval { + for(my $i = 0; $i <= $nbViews - 1; $i++) { + $devname = $resultData->{data}->{phonoptions}->[$i]->{text}; + $device = $resultData->{data}->{phonoptions}->[$i]->{value}; + + FRITZBOX_Log $hash, 5, "DEBUG: fd-Dev-Org: $devname $device"; + + if ($devID{$devname}) { + my $defNewName = $devname . "[" . $devID{$devname} ."] redundant name in FB:" . $devname; + $devID{$defNewName} = $devID{$devname}; + $devID{$devname} = ""; + $defNewName = $devname . "[" . $device ."] redundant name in FB:" . $devname; + $devID{$defNewName} = $device; + } else { + $devID{$devname} = $device; + } + } + }; + + for(keys %devID) { + + next if $devID{$_} eq ""; + $devname = $_; + $device = $devID{$_}; + + FRITZBOX_Log $hash, 5, "DEBUG: fd-Dev: $devname $device"; + + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "dect".$dectFonID{$devname}."_device", $device if $dectFonID{$devname}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$fonFonID{$devname}."_device", $device if $fonFonID{$devname}; + if (!$fonFonID{$devname} && !$dectFonID{$devname}) { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$device, $devname ; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fon".$device."_device", $device ; + } + my $fd_devname = "fdn_" . $devname; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->$fd_devname", $device; + my $fd_device = "fd_" . $device; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->$fd_device", $devname; + } + } + } my %oldMeshDevice; #$oldMeshDevice{box_meshRole} = $hash->{READINGS}{box_meshRole}{VAL} if defined $hash->{READINGS}{box_meshRole}{VAL}; # xhr 1 lang de page wlanmesh xhrId all + @webCmdArray = (); push @webCmdArray, "xhr" => "1"; push @webCmdArray, "lang" => "de"; push @webCmdArray, "page" => "wlanmesh"; @@ -2621,9 +2782,12 @@ sub FRITZBOX_Readout_Run_Web($) for(my $i = 0; $i <= $nbViews - 1; $i++) { my $dName = $resultData->{data}->{scanlist}->[$i]->{ssid}; $dName .= " (Kanal: " . $resultData->{data}->{scanlist}->[$i]->{channel}; - $dName .= ", Band: " . $resultData->{data}->{scanlist}->[$i]->{bandId} . ")"; - $dName =~ s/24ghz/2.4 GHz/; - $dName =~ s/5ghz/5 GHz/; + if (($FW1 == 7 && $FW2 < 50)) { + $dName .= ", Band: " . $resultData->{data}->{scanlist}->[$i]->{bandId}; + $dName =~ s/24ghz/2.4 GHz/; + $dName =~ s/5ghz/5 GHz/; + } + $dName .= ")"; $rName = $resultData->{data}->{scanlist}->[$i]->{mac}; $rName =~ s/:/_/g; @@ -2653,84 +2817,177 @@ sub FRITZBOX_Readout_Run_Web($) FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_lastScanTime", ""; } - # WLAN log expanded status + if (AttrVal( $name, "enableKidProfiles", "0") && $hash->{LUADATA} && (($FW1 == 6 && $FW2 >= 80) || ($FW1 >= 7))) { - # xhr 1 lang de page log xhrId log filter wlan + # kid profiles - @webCmdArray = (); - push @webCmdArray, "xhr" => "1"; - push @webCmdArray, "lang" => "de"; - push @webCmdArray, "page" => "log"; - push @webCmdArray, "xhrId" => "log"; - push @webCmdArray, "filter" => "wlan"; + # xhr 1 lang de page kidPro - $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + my @webCmdArray; + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "kidPro"; - if(defined $resultData->{Error}) { - $tmpData = FRITZBOX_ERR_Result($hash, $resultData); - FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; - } else { - $tmpData = $resultData->{data}->{wlan} ? "on" : "off"; - FRITZBOX_Log $hash, 5, "DEBUG: wlanLogExtended -> " . $tmpData; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogExtended", $tmpData; - } - if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "wlan" && defined $resultData->{data}->{log}) { - $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; - FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", $tmpData; - } else { - FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", "none"; + my $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + + if(defined $resultData->{Error}) { + $tmpData = FRITZBOX_ERR_Result($hash, $resultData); + FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; + } else { + + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "kidprofile2", "unbegrenzt [filtprof3]"; + + my $views = $resultData->{data}->{kidProfiles}; + + eval { + foreach my $key (keys %$views) { + FRITZBOX_Log $hash, 5, "DEBUG: Kid Profiles: ".$key; + + my $kProfile = $resultData->{data}->{kidProfiles}->{$key}{Name} . " [" . $resultData->{data}->{kidProfiles}->{$key}{Id} ."]"; + + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "kid" . $key, $kProfile; + + } + }; + } } - # SYS log error while login (505) + if ( (($FW1 == 6 && $FW2 >= 80) || ($FW1 >= 7)) && $hash->{LUADATA} ) { + # WLAN log expanded status - # xhr 1 lang de page log xhrId log filter sys + # xhr 1 lang de page log xhrId log filter wlan - @webCmdArray = (); - push @webCmdArray, "xhr" => "1"; - push @webCmdArray, "lang" => "de"; - push @webCmdArray, "page" => "log"; - push @webCmdArray, "xhrId" => "log"; - push @webCmdArray, "filter" => "sys"; + @webCmdArray = (); + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "log"; + push @webCmdArray, "xhrId" => "log"; - $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + push @webCmdArray, "filter" => "4"; + } elsif ($FW1 >= 7 && $FW2 >= 50) { + push @webCmdArray, "filter" => "wlan"; + } - if(defined $resultData->{Error}) { - $tmpData = FRITZBOX_ERR_Result($hash, $resultData); - FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; - } elsif ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "sys" && defined $resultData->{data}->{log}) { - $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; - FRITZBOX_Log $hash, 5, "DEBUG: sysLogLast -> " . $tmpData; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", $tmpData; - } else { - FRITZBOX_Log $hash, 5, "DEBUG: sysLogLast -> none"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", "none"; - } + $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; - # FON log error while login (505) + if(defined $resultData->{Error}) { + $tmpData = FRITZBOX_ERR_Result($hash, $resultData); + FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; + } else { + $tmpData = $resultData->{data}->{wlan} ? "on" : "off"; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogExtended -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogExtended", $tmpData; + } - # xhr 1 lang de page log xhrId log filter fon + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "4" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0][3] . " " . $resultData->{data}->{log}->[0][0] . " " . $resultData->{data}->{log}->[0][1] ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", "none"; + } + } elsif ($FW1 >= 7 && $FW2 >= 50) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "wlan" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_LogNewest", "none"; + } + } - @webCmdArray = (); - push @webCmdArray, "xhr" => "1"; - push @webCmdArray, "lang" => "de"; - push @webCmdArray, "page" => "log"; - push @webCmdArray, "xhrId" => "log"; - push @webCmdArray, "filter" => "fon"; + # SYS log error while login (505) - $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + # xhr 1 lang de page log xhrId log filter sys + + @webCmdArray = (); + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "log"; + push @webCmdArray, "xhrId" => "log"; + + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + push @webCmdArray, "filter" => "1"; + } elsif ($FW1 >= 7 && $FW2 >= 50) { + push @webCmdArray, "filter" => "sys"; + } + + $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + + if(defined $resultData->{Error}) { + $tmpData = FRITZBOX_ERR_Result($hash, $resultData); + FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; + } else { + + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "1" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0][3] . " " . $resultData->{data}->{log}->[0][0] . " " . $resultData->{data}->{log}->[0][1] ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", "none"; + } + } elsif ($FW1 >= 7 && $FW2 >= 50) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "sys" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_sys_LogNewest", "none"; + } + } + } + + # FON log error while login (505) + + # xhr 1 lang de page log xhrId log filter fon + + @webCmdArray = (); + push @webCmdArray, "xhr" => "1"; + push @webCmdArray, "lang" => "de"; + push @webCmdArray, "page" => "log"; + push @webCmdArray, "xhrId" => "log"; + + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + push @webCmdArray, "filter" => "3"; + } elsif ($FW1 >= 7 && $FW2 >= 50) { + push @webCmdArray, "filter" => "fon"; + } + + $resultData = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + + if(defined $resultData->{Error}) { + $tmpData = FRITZBOX_ERR_Result($hash, $resultData); + FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; + } else { + + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "3" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0][3] . " " . $resultData->{data}->{log}->[0][0] . " " . $resultData->{data}->{log}->[0][1] ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", "none"; + } + } elsif ($FW1 >= 7 && $FW2 >= 50) { + if ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "fon" && defined $resultData->{data}->{log}->[0]) { + $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> " . $tmpData; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", $tmpData; + } else { + FRITZBOX_Log $hash, 5, "DEBUG: wlanLogLast -> none"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", "none"; + } + } + } - if(defined $resultData->{Error}) { - $tmpData = FRITZBOX_ERR_Result($hash, $resultData); - FRITZBOX_Log $hash, 3, "ERROR: " . $tmpData; - } elsif ( defined $resultData->{data}->{filter} && $resultData->{data}->{filter} eq "sys" && defined $resultData->{data}->{log}) { - $tmpData = $resultData->{data}->{log}->[0]->{id} . " " . $resultData->{data}->{log}->[0]->{date} . " " . $resultData->{data}->{log}->[0]->{time} ; - FRITZBOX_Log $hash, 5, "DEBUG: sysLogLast -> " . $tmpData; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", $tmpData; - } else { - FRITZBOX_Log $hash, 5, "DEBUG: sysLogLast -> none"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_fon_LogNewest", "none"; } # DOCSIS Informationen FB Cable @@ -3120,11 +3377,13 @@ sub FRITZBOX_Readout_Process($$) # ."useGuiHack:0,1 " ."userTickets " ."enablePassivLanDevices:0,1 " + ."enableKidProfiles:0,1 " ."enableVPNShares:0,1 " ."enableUserInfo:0,1 " ."enableAlarmInfo:0,1 " ."enableWLANneighbors:0,1 " ."wlanNeighborsPrefix " + ."disableHostIPv4check:0,1 " ."disableDectInfo:0,1 " ."disableFonInfo:0,1 " ."enableSIP:0,1 " @@ -3470,6 +3729,13 @@ sub FRITZBOX_Set_Cmd_Start($) $handover = $name . "|" . join( "|", @val ); $cmdFunction = "FRITZBOX_Run_enableVPNshare"; } +# Preparing SET wakeUpCall + elsif ($val[0] eq "wakeupcall") { + $timeout = 10; + $cmdBufferTimeout = time() + $timeout; + $handover = $name . "|" . join( "|", @val ); + $cmdFunction = "FRITZBOX_Run_wakeUpCall"; + } # Preparing GET fritzlog information elsif ($val[0] eq "fritzloginfo") { $timeout = 20; @@ -3538,6 +3804,98 @@ sub FRITZBOX_Set_Cmd_Aborted($) } # end FRITZBOX_Set_Cmd_Aborted +sub FRITZBOX_Run_wakeUpCall($) +####################################################################### +{ + my ($string) = @_; + my ($name, $cmd, @val) = split "\\|", $string; + my $hash = $defs{$name}; + my $result; + my @webCmdArray; + my @roReadings; + my $startTime = time(); + + my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); + + my $FW1 = substr($fwV[1],0,2); + my $FW2 = substr($fwV[2],0,2); + + + # xhr 1 lang de page alarm xhrId all + + # xhr: 1 + # active: 1 | 0 + # hour: 07 + # minutes: 00 + # device: 70 + # name: Wecker 1 + # optionRepeat: daily | only_once | per_day { mon: 1 tue: 0 wed: 1 thu: 0 fri: 1 sat: 0 sun: 0 } + # apply: true + # lang: de + # page: alarm | alarm1 | alarm2 + + my $wecker = "Fhem Device $name Wecker "; + $wecker .= substr($val[0],-1); + + my $page; + $page = "alarm" if $val[0] =~ /alarm1/; + $page = "alarm1" if $val[0] =~ /alarm2/; + $page = "alarm2" if $val[0] =~ /alarm3/; + + push @webCmdArray, "xhr" => "1"; + + if ($FW1 == 7 && $FW2 < 50) { + push @webCmdArray, "apply" => ""; + } else { + push @webCmdArray, "apply" => "true"; + } + push @webCmdArray, "lang" => "de"; + + # alarm1 62 per_day 10:00 mon:1 tue:0 wed:1 thu:0 fri:1 sat:0 sun:0 + # alarm1 62 only_once 08:03 + + # set wakeUpCall + if (int @val == 2) { # turn wakeUpCall off + push @webCmdArray, "page" => $page; + push @webCmdArray, "active" => "0"; + } elsif (int @val > 2) { + push @webCmdArray, "active" => "1"; + push @webCmdArray, "page" => $page; + push @webCmdArray, "device" => $val[1]; + push @webCmdArray, "hour" => substr($val[3],0,2); + push @webCmdArray, "minutes" => substr($val[3],3,2); + push @webCmdArray, "name" => $wecker; + + if ( $val[2] =~ /^(daily|only_once)$/) { + push @webCmdArray, "optionRepeat" => $val[2]; + } elsif ( $val[2] eq "per_day" ) { + push @webCmdArray, "optionRepeat" => $val[2]; + + for(my $i = 4; $i <= 10; $i++) { + push @webCmdArray, substr($val[$i],0,3) => substr($val[$i],4,1); + } + } + } + + FRITZBOX_Log $hash, 5, "DEBUG: data.lua: \n" . join(" ", @webCmdArray); + + $result = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; + + if(defined $result->{Error}) { + FRITZBOX_Log $hash, 2, "ERROR: setting wakeUpCall: " . $result->{Error}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "retStat_wakeUpCall", "->ERROR: " . $result->{Error}; + } else { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "retStat_wakeUpCall", "done"; + } + + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); + + my $returnStr = join('|', @roReadings ); + FRITZBOX_Log $hash, 5, "DEBUG: Handover to main process: " . $returnStr; + return $name . "|2|" . encode_base64($returnStr,""); + +} # end FRITZBOX_Run_wakeUpCall + ####################################################################### sub FRITZBOX_Run_fritzloginfo($) { @@ -3549,7 +3907,8 @@ sub FRITZBOX_Run_fritzloginfo($) my @roReadings; my $startTime = time(); - # xhr 1 lang de page log apply nop filter wlan wlan off -> off oder on erweitertes WLAN-Logging + # Frizt!OS >= 7.50 + # xhr 1 lang de page log apply nop filter wlan wlan on | off -> on oder off erweitertes WLAN-Logging # xhr 1 lang de page log xhrId log filter all useajax 1 no_sidrenew nop -> Log-Einträge Alle # xhr 1 lang de page log xhrId log filter sys useajax 1 no_sidrenew nop -> Log-Einträge System @@ -3558,14 +3917,36 @@ sub FRITZBOX_Run_fritzloginfo($) # xhr 1 lang de page log xhrId log filter net useajax 1 no_sidrenew nop -> Log-Einträge Internetverbindung # xhr 1 lang de page log xhrId log filter fon useajax 1 no_sidrenew nop -> Log-Einträge Fon + # Frizt!OS < 7.50 + # xhr 1 lang de page log xhrId all wlan 7 (on) | 6 (off) -> on oder off erweitertes WLAN-Logging + + # xhr 1 lang de page log xhrId log filter 0 useajax 1 no_sidrenew nop -> Log-Einträge Alle + # xhr 1 lang de page log xhrId log filter 1 useajax 1 no_sidrenew nop -> Log-Einträge System + # xhr 1 lang de page log xhrId log filter 4 useajax 1 no_sidrenew nop -> Log-Einträge WLAN + # xhr 1 lang de page log xhrId log filter 5 useajax 1 no_sidrenew nop -> Log-Einträge USB + # xhr 1 lang de page log xhrId log filter 2 useajax 1 no_sidrenew nop -> Log-Einträge Internetverbindung + # xhr 1 lang de page log xhrId log filter 3 useajax 1 no_sidrenew nop -> Log-Einträge Fon + + my @fwV = split(/\./, ReadingsVal($name, "box_fwVersion", "0.0.0.error")); + + my $FW1 = substr($fwV[1],0,2); + my $FW2 = substr($fwV[2],0,2); + if ($cmd eq "wlanlogextended") { FRITZBOX_Log $hash, 4, "DEBUG: fritzlog -> $cmd, $val[0]"; push @webCmdArray, "xhr" => "1"; push @webCmdArray, "lang" => "de"; push @webCmdArray, "page" => "log"; - push @webCmdArray, "filter" => "wlan"; - push @webCmdArray, "wlan" => $val[0]; - push @webCmdArray, "apply" => ""; + + if (($FW1 == 6 && $FW2 >= 80) || ($FW1 == 7 && $FW2 < 50)) { + push @webCmdArray, "wlan" => $val[0] eq "on" ? "7" : "6"; + } elsif ($FW1 >= 7 && $FW2 >= 50) { + push @webCmdArray, "filter" => "wlan"; + push @webCmdArray, "apply" => ""; + push @webCmdArray, "wlan" => $val[0]; + } else { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "retStat_wlanLogExtended", "Nicht unterstütze Fritz!OS Version $FW1.$FW2"; + } FRITZBOX_Log $hash, 5, "DEBUG: data.lua: \n" . join(" ", @webCmdArray); @@ -3581,16 +3962,27 @@ sub FRITZBOX_Run_fritzloginfo($) } } else { + FRITZBOX_Log $hash, 4, "DEBUG: fritzlog -> $cmd, $val[0], $val[1]"; push @webCmdArray, "xhr" => "1"; push @webCmdArray, "lang" => "de"; push @webCmdArray, "page" => "log"; push @webCmdArray, "xhrId" => "log"; - push @webCmdArray, "filter" => $val[1]; push @webCmdArray, "useajax" => "1"; push @webCmdArray, "no_sidrenew" => ""; + if (($FW1 == 6 && $FW2 >= 83) || ($FW1 == 7 && $FW2 < 50)) { + push @webCmdArray, "filter" => "0" if $val[1] =~ /all/; + push @webCmdArray, "filter" => "1" if $val[1] =~ /sys/; + push @webCmdArray, "filter" => "2" if $val[1] =~ /net/; + push @webCmdArray, "filter" => "3" if $val[1] =~ /fon/; + push @webCmdArray, "filter" => "4" if $val[1] =~ /wlan/; + push @webCmdArray, "filter" => "5" if $val[1] =~ /usb/; + } elsif ($FW1 >= 7 && $FW2 >= 50) { + push @webCmdArray, "filter" => $val[1]; + } + FRITZBOX_Log $hash, 5, "DEBUG: data.lua: \n" . join(" ", @webCmdArray); my $result = FRITZBOX_Lua_Data( $hash, \@webCmdArray) ; @@ -4279,20 +4671,23 @@ sub FRITZBOX_Run_GuestWlan_Web($) $result = FRITZBOX_Web_Query( $hash, $queryStr) ; - my @reading_list = split(/\,/, AttrVal($name, "disableBoxReadings", "none")); + if ( defined $result->{Error} ) { + FRITZBOX_Log $hash, 2, "ERROR: ".$result->{Error}; + } else { - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_2.4GHz", $result->{box_wlan_24GHz}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_5GHz", $result->{box_wlan_5GHz}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlan", $result->{box_guestWlan}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlanRemain", $result->{box_guestWlanRemain}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_macFilter_active", $result->{box_macFilter_active}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_2.4GHz", $result->{box_wlan_24GHz}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_5GHz", $result->{box_wlan_5GHz}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlan", $result->{box_guestWlan}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlanRemain", $result->{box_guestWlanRemain}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_macFilter_active", $result->{box_macFilter_active}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); + } my $returnStr = join('|', @roReadings ); - FRITZBOX_Log $hash, 5, "DEBUG: Handover to main process: ".$returnStr; + FRITZBOX_Log $hash, 5, "DEBUG: Handover to main process: " . $returnStr; return $name."|2|".encode_base64($returnStr,""); } # end FRITZBOX_Run_GuestWlan_Shell @@ -4335,17 +4730,19 @@ sub FRITZBOX_Wlan_Run_Web($) $result = FRITZBOX_Web_Query( $hash, $queryStr) ; - my @reading_list = split(/\,/, AttrVal($name, "disableBoxReadings", "none")); + if ( defined $result->{Error} ) { + FRITZBOX_Log $hash, 2, "ERROR: ".$result->{Error}; + } else { + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_2.4GHz", $result->{box_wlan_24GHz}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_5GHz", $result->{box_wlan_5GHz}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlan", $result->{box_guestWlan}, "onoff"; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlanRemain", $result->{box_guestWlanRemain}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_macFilter_active", $result->{box_macFilter_active}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_2.4GHz", $result->{box_wlan_24GHz}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_wlan_5GHz", $result->{box_wlan_5GHz}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlan", $result->{box_guestWlan}, "onoff"; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_guestWlanRemain", $result->{box_guestWlanRemain}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "box_macFilter_active", $result->{box_macFilter_active}, "onoff"; - - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid}; - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid}; + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); + FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); + } my $returnStr = join('|', @roReadings ); FRITZBOX_Log $hash, 5, "DEBUG: Handover to main process: ".$returnStr; @@ -4415,7 +4812,7 @@ sub FRITZBOX_Ring_Run_Web($) if ($portName) { push @tr064CmdArray, ["X_VoIP:1", "x_voip", "X_AVM-DE_DialSetConfig", "NewX_AVM-DE_PhoneName", $portName]; @tr064Result = FRITZBOX_TR064_Cmd( $hash, 0, \@tr064CmdArray ); - FRITZBOX_Log $hash, 3, "INFO: Switch ClickToDial on, set dial port '$portName'"; + FRITZBOX_Log $hash, 4, "INFO: Switch ClickToDial on, set dial port '$portName'"; } } else { #oder Pech gehabt @@ -4451,8 +4848,9 @@ sub FRITZBOX_Ring_Run_Web($) $result = FRITZBOX_TR064_Cmd( $hash, 0, \@tr064CmdArray ) if $hash->{SECPORT}; } - if ( $result->[0] == 1 ) { - FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->[1]; +# if ( $result->[0] == 1 ) { + if ( $result == "1" ) { +# FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->[1]; FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time(); } FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime); @@ -4464,57 +4862,6 @@ sub FRITZBOX_Ring_Run_Web($) # return $name."|1|Ringing done"; } # end FRITZBOX_Ring_Run_Web -####################################################################### -sub FRITZBOX_Set_Alarm_Web($@) -{ - my ($hash, @val) = @_; - my $name = $hash->{NAME}; - my @webCmdArray; - - my $alarm = $val[0]; - shift @val; - - my $para = " ".join(" ", @val); - - my $state = 1; - my $stateTxt = "on"; - if ($para =~ /off/i) - { - $state = 0; - $stateTxt = "off"; - } - - my $time; - my $timeTxt; - if ($para =~ /([0-2]?\d):([0-5]\d)/ ) - { - if ($1<10) - { - $time = 0; - $timeTxt = "0"; - } - $time .= $1.$2; - $timeTxt .= $1.":".$2; - $time = undef if $time > 2359; - } - - my $day; my $dayTxt; - my %alDayValues = %alarmDays; - $alDayValues{0} = "once"; - $alDayValues{127} = "daily"; - while (my ($key, $value) = each(%alDayValues) ) - { - if ($para =~ /$value/i) - { - $day += $key ; - $dayTxt .= $value." "; - } - } - - - return undef; -} # end FRITZBOX_Set_Alarm_Web - ####################################################################### sub FRITZBOX_SetMOH($@) { @@ -4722,12 +5069,16 @@ sub FRITZBOX_StartRadio_Web($@) my $startValue = FRITZBOX_Web_Query( $hash, $queryStr ); # Set ring tone Internet Radio + if ( defined $startValue->{Error} ) { + FRITZBOX_Log $hash, 2, "ERROR: ".$startValue->{Error}; + } else { - FRITZBOX_Log $hash, 5, "DEBUG: Call $intNo"; + FRITZBOX_Log $hash, 5, "DEBUG: Call $intNo"; - if ($hash->{SECPORT}) { #ring with TR-064 - push @tr064CmdArray, ["X_VoIP:1", "x_voip", "X_AVM-DE_DialNumber", "NewX_AVM-DE_PhoneNumber", "**".$intNo."#"]; - FRITZBOX_TR064_Cmd( $hash, 0, \@tr064CmdArray ); + if ($hash->{SECPORT}) { #ring with TR-064 + push @tr064CmdArray, ["X_VoIP:1", "x_voip", "X_AVM-DE_DialNumber", "NewX_AVM-DE_PhoneNumber", "**".$intNo."#"]; + FRITZBOX_TR064_Cmd( $hash, 0, \@tr064CmdArray ); + } } return undef; @@ -4993,6 +5344,40 @@ sub FRITZBOX_Web_OpenCon ($) return undef; } + FRITZBOX_Log $hash, 5, "DEBUG: checking HOST -> " . $hash->{DEF}; + + # my $hash = $defs{$name}; + my $host = $hash->{HOST}; + + my $URL_MATCH = FRITZBOX_Url_Regex(); + + if (defined $hash->{DEF} && $hash->{DEF} !~ m=$URL_MATCH=i) { + + my $phost = inet_aton($hash->{DEF}); + if (! defined($phost)) { + FRITZBOX_Log $hash, 2, "INFO: phost -> not defined"; + return "offline" if !AttrVal($name, "disableHostIPv4check", 0); + } + + my $host = inet_ntoa($phost); + + if (! defined($host)) { + FRITZBOX_Log $hash, 2, "INFO: host -> $host"; + return "offline" if !AttrVal($name, "disableHostIPv4check", 0); + } + $hash->{HOST} = $host; + + } + + my $p = Net::Ping->new; + my $isAlive = $p->ping($host); + $p->close; + + unless ($isAlive) { + FRITZBOX_Log $hash, 4, "INFO: Host $host not available"; + return "offline" if !AttrVal($name, "disableHostIPv4check", 0); + } + # Use old sid if last access later than 9.5 minutes my $sid = $hash->{fhem}{sid}; @@ -5001,8 +5386,6 @@ sub FRITZBOX_Web_OpenCon ($) return $sid } - my $host = $hash->{HOST}; - my $pwd = FRITZBOX_readPassword($hash); unless (defined $pwd) { @@ -5021,6 +5404,7 @@ sub FRITZBOX_Web_OpenCon ($) } FRITZBOX_Log $hash, 2, "ERROR: Web connection could not be established. Please check your credentials (password, user)."; + return undef; } # end FRITZBOX_Web_OpenCon @@ -5038,9 +5422,11 @@ sub FRITZBOX_Web_Query($$@) my $sid = FRITZBOX_Web_OpenCon( $hash ); unless ($sid) { - FRITZBOX_Log $hash, 2, "INFO: Didn't get a session ID. ResetSID"; my %retHash = ( "Error" => "Didn't get a session ID", "ResetSID" => "1" ) ; return \%retHash; + } elsif ($sid eq "offline") { + my %retHash = ( "Error" => "Device is offline", "ResetSID" => "1" ) ; + return \%retHash; } FRITZBOX_Log $hash, 5, "DEBUG: Request data via API " . $f_lua; @@ -5112,7 +5498,9 @@ sub FRITZBOX_Lua_Data($$@) my $sid = FRITZBOX_Web_OpenCon( $hash ); unless ($sid) { my %retHash = ( "Error" => "Didn't get a session ID", "ResetSID" => "1" ) ; - FRITZBOX_Log $hash, 2, "INFO: Didn't get a session ID"; + return \%retHash; + } elsif ($sid eq "offline") { + my %retHash = ( "Error" => "Device is offline", "ResetSID" => "1" ) ; return \%retHash; } @@ -5125,17 +5513,52 @@ sub FRITZBOX_Lua_Data($$@) my $agent = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 180); my $response = $agent->post ( $url, $queryStr ); - FRITZBOX_Log $hash, $LogInfo, "INFO: Response: " . $response->status_line . "\n" . $response->content; + FRITZBOX_Log $hash, 5, "DEBUG: Response: " . $response->status_line . "\n" . $response->content; unless ($response->is_success) { my %retHash = ("Error" => $response->status_line, "ResetSID" => "1"); - FRITZBOX_Log $hash, 2, "ERROR: ".$response->status_line; + FRITZBOX_Log $hash, $LogInfo, "INFO: \n".$response->status_line; return \%retHash; } my $data = $response->content; + # handling for getting wakeUpCall Informations + ########### HTML ################################# + + if ( $data =~ m/\