mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
72_FRITZBOX.pm: Version 07.57.12a
git-svn-id: https://svn.fhem.de/fhem/trunk@28575 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5fbcf3b647
commit
e39e430640
@ -45,7 +45,7 @@ use warnings;
|
||||
use Blocking;
|
||||
use HttpUtils;
|
||||
|
||||
my $ModulVersion = "07.57.12";
|
||||
my $ModulVersion = "07.57.12a";
|
||||
my $missingModul = "";
|
||||
my $FRITZBOX_TR064pwd;
|
||||
my $FRITZBOX_TR064user;
|
||||
@ -92,7 +92,6 @@ sub FRITZBOX_Readout_SetGet_Aborted($);
|
||||
|
||||
# Sub, die einen Set Befehl nonBlocking umsetzen
|
||||
sub FRITZBOX_Set_check_APIs($);
|
||||
sub FRITZBOX_Set_check_m3u($$);
|
||||
sub FRITZBOX_Set_block_Incoming_Phone_Call($);
|
||||
sub FRITZBOX_Set_GuestWlan_OnOff($);
|
||||
sub FRITZBOX_Set_call_Phone($);
|
||||
@ -275,11 +274,8 @@ while (my ($key, $value) = each %ringTone) {
|
||||
}
|
||||
|
||||
my %alarmDays = qw{1 Mo 2 Tu 4 We 8 Th 16 Fr 32 Sa 64 Su};
|
||||
|
||||
my %userType = qw{1 IP 2 PC-User 3 Default 4 Guest};
|
||||
|
||||
my %mohtype = (0=>"default", 1=>"sound", 2=>"customer", "err"=>"" );
|
||||
|
||||
my %landevice = ();
|
||||
|
||||
my %LOG_Text = (
|
||||
@ -295,14 +291,6 @@ my %LOG_Text = (
|
||||
my @cmdBuffer=();
|
||||
my $cmdBufferTimeout=0;
|
||||
|
||||
my $ttsCmdTemplate = 'wget -U Mozilla -O "[ZIEL]" "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&prev=input&tl=[SPRACHE]&q=[TEXT]"';
|
||||
my $ttsLinkTemplate = 'http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&prev=input&tl=[SPRACHE]&q=[TEXT]';
|
||||
# VoiceRSS: http://www.voicerss.org/api/documentation.aspx
|
||||
|
||||
my $mohUpload = '/var/tmp/fhem_moh_upload';
|
||||
my $mohOld = '/var/tmp/fhem_fx_moh_old';
|
||||
my $mohNew = '/var/tmp/fhem_fx_moh_new';
|
||||
|
||||
#######################################################################
|
||||
sub FRITZBOX_Log($$$)
|
||||
{
|
||||
@ -349,11 +337,9 @@ sub FRITZBOX_DebugLog($$$$;$) {
|
||||
$loglevel .= ":" if ($loglevel);
|
||||
$loglevel ||= "";
|
||||
|
||||
my $dirdef = AttrVal('global', 'logdir', $attr{global}{modpath}.'/log/');
|
||||
|
||||
my ($seconds, $microseconds) = gettimeofday();
|
||||
my @t = localtime($seconds);
|
||||
my $nfile = $dirdef . ResolveDateWildcards($filename, @t);
|
||||
my $nfile = ResolveDateWildcards("%L/" . $filename, @t);
|
||||
|
||||
unless ($timestamp) {
|
||||
|
||||
@ -401,7 +387,7 @@ sub FRITZBOX_dbgLogInit($@) {
|
||||
|
||||
return if $aVal && $aVal == -1;
|
||||
|
||||
my $dirdef = AttrVal('global', 'logdir', $attr{global}{modpath}.'/log/');
|
||||
my $dirdef = Logdir() . "/";
|
||||
my $dbgLogFile = $dirdef . $hash->{helper}{debugLog} . '-%Y-%m.dlog';
|
||||
|
||||
if ($cmd eq "set" ) {
|
||||
@ -628,7 +614,6 @@ sub FRITZBOX_Define($$)
|
||||
$hash->{TIMEOUT} = 55;
|
||||
$hash->{SID_RENEW_ERR_CNT} = 0;
|
||||
$hash->{SID_RENEW_CNT} = 0;
|
||||
$hash->{_BETA} = 0;
|
||||
|
||||
$hash->{fhem}{LOCAL} = 0;
|
||||
$hash->{fhem}{is_double_wlan} = -1;
|
||||
@ -638,19 +623,19 @@ sub FRITZBOX_Define($$)
|
||||
$hash->{helper}{FhemLog3Std} = AttrVal($name, "FhemLog3Std", 0);
|
||||
$hash->{helper}{timerInActive} = 0;
|
||||
|
||||
# my $tr064Port = FRITZBOX_init_TR064 ($hash);
|
||||
# $hash->{SECPORT} = $tr064Port if $tr064Port;
|
||||
$hash->{fhem}{sidTime} = 0;
|
||||
$hash->{fhem}{sidErrCount} = 0;
|
||||
$hash->{fhem}{sidNewCount} = 0;
|
||||
|
||||
# Check APIs after fhem.cfg is processed
|
||||
$hash->{APICHECKED} = 0;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
$hash->{LUAQUERY} = -1;
|
||||
$hash->{LUADATA} = -1;
|
||||
$hash->{TR064} = -1;
|
||||
$hash->{UPNP} = -1;
|
||||
|
||||
|
||||
FRITZBOX_Log $hash, 4, "start of Device readout parameters";
|
||||
RemoveInternalTimer($hash->{helper}{TimerReadout});
|
||||
InternalTimer(gettimeofday() + 1 , "FRITZBOX_Readout_Start", $hash->{helper}{TimerReadout}, 0);
|
||||
@ -996,6 +981,7 @@ sub FRITZBOX_Attr($@)
|
||||
if ( ($aName =~ /m3uFileLocal|m3uFileURL|m3uFileActive/ && $hash->{APICHECKED} == 1) || $aName =~ /disable|INTERVAL|nonblockingTimeOut/ ) {
|
||||
FRITZBOX_Log $hash, 4, "Attr $cmd $aName -> Neustart internal Timer";
|
||||
$hash->{APICHECKED} = 0;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
RemoveInternalTimer($hash->{helper}{TimerReadout});
|
||||
InternalTimer(gettimeofday()+1, "FRITZBOX_Readout_Start", $hash->{helper}{TimerReadout}, 1);
|
||||
# FRITZBOX_Readout_Start($hash->{helper}{TimerReadout});
|
||||
@ -1021,6 +1007,8 @@ sub FRITZBOX_Set($$@)
|
||||
. " update:noArg"
|
||||
. " inActive:on,off";
|
||||
|
||||
# available, if passwor is set correctly
|
||||
if ($hash->{WEBCONNECT}) {
|
||||
# set abhängig von TR064
|
||||
$list .= " reboot"
|
||||
if $hash->{TR064} == 1 && $hash->{SECPORT};
|
||||
@ -1074,6 +1062,7 @@ sub FRITZBOX_Set($$@)
|
||||
$list .= " rescanWLANneighbors:noArg"
|
||||
. " wlanLogExtended:on,off"
|
||||
if ($hash->{LUADATA} == 1);
|
||||
}
|
||||
|
||||
if ( lc $cmd eq 'smarthome') {
|
||||
|
||||
@ -1204,6 +1193,7 @@ sub FRITZBOX_Set($$@)
|
||||
$hash->{helper}{timerInActive} = 0;
|
||||
FRITZBOX_Log $hash, 4, "set $name $cmd -> Neustart internal Timer";
|
||||
$hash->{APICHECKED} = 0;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
RemoveInternalTimer($hash->{helper}{TimerReadout});
|
||||
InternalTimer(gettimeofday()+1, "FRITZBOX_Readout_Start", $hash->{helper}{TimerReadout}, 1);
|
||||
}
|
||||
@ -1269,6 +1259,7 @@ sub FRITZBOX_Set($$@)
|
||||
elsif ( lc $cmd eq 'checkapis') {
|
||||
FRITZBOX_Log $hash, 3, "set $name $cmd " . join(" ", @val);
|
||||
$hash->{APICHECKED} = 0;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
$hash->{APICHECK_RET_CODES} = "-";
|
||||
$hash->{fhem}{sidTime} = 0;
|
||||
$hash->{fhem}{sidErrCount} = 0;
|
||||
@ -1875,7 +1866,27 @@ sub FRITZBOX_Set($$@)
|
||||
elsif ( lc $cmd eq 'password') {
|
||||
if (int @val == 1)
|
||||
{
|
||||
return FRITZBOX_Helper_store_Password ( $hash, $val[0] );
|
||||
my $msg = FRITZBOX_Helper_store_Password ( $hash, $val[0] );
|
||||
return $msg if $msg =~ /error/;
|
||||
|
||||
my $result = FRITZBOX_open_Web_Connection( $hash );
|
||||
|
||||
if (defined $result->{Error}) {
|
||||
$hash->{fhem}{sidErrCount} += 1;
|
||||
$hash->{fhem}{sidTime} = 0;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
} else {
|
||||
$hash->{fhem}{sid} = $result->{sid};
|
||||
$hash->{fhem}{sidNewCount} = defined $result->{sidNew} ? $result->{sidNew} : 0;
|
||||
$hash->{fhem}{sidTime} = time();
|
||||
$hash->{fhem}{sidErrCount} = 0;
|
||||
$hash->{WEBCONNECT} = 1;
|
||||
}
|
||||
|
||||
$hash->{fhem}{LOCAL} = 1;
|
||||
FRITZBOX_Readout_Start($hash->{helper}{TimerReadout});
|
||||
$hash->{fhem}{LOCAL} = 0;
|
||||
return $msg
|
||||
}
|
||||
} # end password
|
||||
|
||||
@ -2261,9 +2272,9 @@ sub FRITZBOX_Set($$@)
|
||||
|
||||
elsif ( lc $cmd eq 'update' ) {
|
||||
FRITZBOX_Log $hash, 3, "set $name $cmd " . join(" ", @val);
|
||||
$hash->{fhem}{LOCAL}=1;
|
||||
$hash->{fhem}{LOCAL} = 1;
|
||||
FRITZBOX_Readout_Start($hash->{helper}{TimerReadout});
|
||||
$hash->{fhem}{LOCAL}=0;
|
||||
$hash->{fhem}{LOCAL} = 0;
|
||||
return undef;
|
||||
} # end update
|
||||
|
||||
@ -2671,6 +2682,10 @@ sub FRITZBOX_Get($@)
|
||||
}
|
||||
|
||||
my $list;
|
||||
|
||||
# available, if passwor is set correctly
|
||||
if ($hash->{WEBCONNECT}) {
|
||||
|
||||
$list .= "luaQuery" if $hash->{LUAQUERY} == 1;
|
||||
$list .= " luaData" if $hash->{LUADATA} == 1;
|
||||
$list .= " luaDectRingTone" if $hash->{LUADATA};
|
||||
@ -2692,6 +2707,7 @@ sub FRITZBOX_Get($@)
|
||||
$list .= " tr064Command" if defined $hash->{SECPORT};
|
||||
$list .= " tr064ServiceList:noArg" if defined $hash->{SECPORT};
|
||||
# $list .= " soapCommand" if defined $hash->{SECPORT};
|
||||
}
|
||||
|
||||
return "Unknown argument $cmd, choose one of $list" if defined $list;
|
||||
|
||||
@ -5053,7 +5069,8 @@ sub FRITZBOX_Readout_Run_Web($)
|
||||
FRITZBOX_Log $hash, 4, "TR064: $hash->{TR064} or secure Port:" . ($hash->{SECPORT} ? $hash->{SECPORT} : "none") . " not available or wrong Fritz!OS: $FW1.$FW2.";
|
||||
}
|
||||
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS", "");
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS_BOXUSER", "");
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS_PASSWORD", "");
|
||||
|
||||
# Ende und Rückkehr zum Hauptprozess
|
||||
|
||||
@ -5063,6 +5080,7 @@ sub FRITZBOX_Readout_Run_Web($)
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time();
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidErrCount", 0;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidNewCount", $sidNew;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->WEBCONNECT", 1;
|
||||
|
||||
push @roReadings, "readoutTime", sprintf( "%.2f", time()-$startTime);
|
||||
my $returnStr = join('|', @roReadings );
|
||||
@ -5085,6 +5103,8 @@ sub FRITZBOX_Readout_Response($$$@)
|
||||
push @{$roReadings}, "fhem->sid", $result->{sid} if $result->{sid};
|
||||
push @{$roReadings}, "fhem->sidTime", time();
|
||||
push @{$roReadings}, "fhem->sidErrCount", 0;
|
||||
push @{$roReadings}, "->WEBCONNECT", 1;
|
||||
|
||||
if (defined $sidNew) {
|
||||
push @{$roReadings}, "fhem->sidNewCount", $sidNew;
|
||||
} elsif (defined $result->{sidNew}) {
|
||||
@ -5096,6 +5116,7 @@ sub FRITZBOX_Readout_Response($$$@)
|
||||
|
||||
elsif ( defined $result->{Error} ) {
|
||||
# Abbruch wenn Fehler beim Lesen der Fritzbox-Antwort
|
||||
push @{$roReadings}, "->WEBCONNECT", 0;
|
||||
FRITZBOX_Log $hash, 2, "" . $result->{Error};
|
||||
$returnStr = "Error|" . $result->{Error};
|
||||
$returnStr .= "|";
|
||||
@ -5111,16 +5132,18 @@ sub FRITZBOX_Readout_Response($$$@)
|
||||
|
||||
else {
|
||||
FRITZBOX_Log $hash, 4, "undefined situation\n"; # . Dumper $result;
|
||||
|
||||
push @{$roReadings}, "->WEBCONNECT", 0;
|
||||
$returnStr = "Error|undefined situation";
|
||||
$returnStr .= "|";
|
||||
}
|
||||
|
||||
if (defined $result->{ResetSID}) {
|
||||
if ($result->{ResetSID}) {
|
||||
my $sidCnt = $hash->{fhem}{sidErrCount} + 1;
|
||||
$returnStr .= "fhem->sidTime|0" . "|fhem->sidErrCount|$sidCnt";
|
||||
$returnStr .= "|";
|
||||
}
|
||||
}
|
||||
|
||||
$returnStr .= join('|', @{$roReadings} ) if int @{$roReadings};
|
||||
|
||||
@ -5192,23 +5215,24 @@ sub FRITZBOX_Readout_Process($$)
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
if ( defined $values{Error} ) {
|
||||
readingsBulkUpdate( $hash, "retStat_lastReadout", $values{Error} );
|
||||
readingsBulkUpdate( $hash, "retStat_lastReadoutError", $values{Error} );
|
||||
readingsBulkUpdate( $hash, "state", $values{Error} );
|
||||
if (defined $values{"fhem->sidTime"}) {
|
||||
$hash->{fhem}{sidTime} = $values{"fhem->sidTime"};
|
||||
FRITZBOX_Log $hash, 4, "Reset SID";
|
||||
}
|
||||
if (defined $values{"fhem->sidErrCount"}) {
|
||||
$hash->{fhem}{sidErrCount} = $values{"fhem->sidErrCount"};
|
||||
}
|
||||
if (defined $values{"->APICHECKED"}) {
|
||||
$hash->{APICHECKED} = $values{"->APICHECKED"};
|
||||
}
|
||||
if (defined $values{"->APICHECK_RET_CODES"}) {
|
||||
$hash->{APICHECK_RET_CODES} = $values{"->APICHECK_RET_CODES"};
|
||||
}
|
||||
|
||||
} else {
|
||||
# if (defined $values{"fhem->sidTime"}) {
|
||||
# $hash->{fhem}{sidTime} = $values{"fhem->sidTime"};
|
||||
# FRITZBOX_Log $hash, 4, "Reset SID";
|
||||
# }
|
||||
# if (defined $values{"fhem->sidErrCount"}) {
|
||||
# $hash->{fhem}{sidErrCount} = $values{"fhem->sidErrCount"};
|
||||
# }
|
||||
# if (defined $values{"->APICHECKED"}) {
|
||||
# $hash->{APICHECKED} = $values{"->APICHECKED"};
|
||||
# }
|
||||
# if (defined $values{"->APICHECK_RET_CODES"}) {
|
||||
# $hash->{APICHECK_RET_CODES} = $values{"->APICHECK_RET_CODES"};
|
||||
# }
|
||||
#
|
||||
# } else {
|
||||
# Statistics
|
||||
if ($mesh ne "slave") {
|
||||
if ( defined $values{".box_TodayBytesReceivedLow"} && defined $hash->{READINGS}{".box_TodayBytesReceivedLow"}) {
|
||||
@ -5270,7 +5294,8 @@ sub FRITZBOX_Readout_Process($$)
|
||||
else {
|
||||
$hash->{$rName1}{$rName2} = $rValue;
|
||||
}
|
||||
delete ($hash->{HINWEIS}) if $rName2 eq "HINWEIS" && $rValue eq "";
|
||||
delete ($hash->{HINWEIS_BOXUSER}) if $rName2 eq "HINWEIS_BOXUSER" && $rValue eq "";
|
||||
delete ($hash->{HINWEIS_PASSWORD}) if $rName2 eq "HINWEIS_PASSWORD" && $rValue eq "";
|
||||
}
|
||||
elsif ($rName eq "-<fhem") {
|
||||
FRITZBOX_Log $hash, 5, "calling fhem() with: " . $rValue;
|
||||
@ -5279,6 +5304,10 @@ sub FRITZBOX_Readout_Process($$)
|
||||
elsif ($rName eq "box_fwVersion" && defined $values{box_fwUpdate}) {
|
||||
$rValue .= " (old)" if $values{box_fwUpdate} eq "1";
|
||||
}
|
||||
elsif ( $rName eq "Error" ) {
|
||||
readingsBulkUpdate( $hash, "retStat_lastReadoutError", $rValue );
|
||||
readingsBulkUpdate( $hash, "state", $rValue );
|
||||
}
|
||||
elsif ($rName eq "box_model") {
|
||||
$hash->{MODEL} = $rValue;
|
||||
if (($rValue =~ "Box") && (lc($rValue) =~ "6[4,5,6][3,6,9][0,1]") ) {
|
||||
@ -5336,7 +5365,7 @@ sub FRITZBOX_Readout_Process($$)
|
||||
}
|
||||
|
||||
# writing all other readings
|
||||
if ($rName !~ /-<|->|box_fwUpdate|box_oem|readoutTime/) {
|
||||
if ($rName !~ /-<|->|box_fwUpdate|box_oem|readoutTime|Error/) {
|
||||
my $rFilter = $rName;
|
||||
$rFilter =~ s/[1-9]//g;
|
||||
if ($rValue ne "" && $rName !~ /$reading_list/) {
|
||||
@ -5401,7 +5430,7 @@ sub FRITZBOX_Readout_Process($$)
|
||||
my $msg = keys( %values ) . " values captured in " . $values{readoutTime} . " s";
|
||||
readingsBulkUpdate( $hash, "retStat_lastReadout", $msg );
|
||||
FRITZBOX_Log $hash, 5, "BulkUpdate lastReadout: " . $msg;
|
||||
}
|
||||
# }
|
||||
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
@ -5809,7 +5838,7 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
my $fwVersion = "0.0.0.error";
|
||||
my $startTime = time();
|
||||
my $apiError = "";
|
||||
my $tr064 = 0;
|
||||
my $crdOK = 0;
|
||||
my @roReadings;
|
||||
my $response;
|
||||
|
||||
@ -5824,9 +5853,19 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
$tmp .= " boxUser (bei Repeatern nicht unbedingt notwendig)" if $boxUser eq "";
|
||||
$tmp .= " nicht definiert. Bitte auch das Passwort mit <set $name password> setzen.";
|
||||
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS", $tmp);
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS_BOXUSER", $tmp);
|
||||
|
||||
FRITZBOX_Log $hash, 3, "" . $tmp;
|
||||
} else {
|
||||
FRITZBOX_Readout_Add_Reading ($hash, \@roReadings, "->HINWEIS_BOXUSER", "");
|
||||
}
|
||||
|
||||
unless (FRITZBOX_Helper_read_Password($hash)) {
|
||||
FRITZBOX_Log $hash, 2, "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->HINWEIS_PASSWORD", "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
} else {
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->HINWEIS_PASSWORD", "";
|
||||
$crdOK = 1;
|
||||
}
|
||||
|
||||
# change host name if necessary
|
||||
@ -5892,13 +5931,13 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
if ($response->is_success) { #determine TR064-Port
|
||||
$content = $response->content;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->TR064", 1;
|
||||
$tr064 = 1;
|
||||
FRITZBOX_Log $hash, 5-$myVerbose, "API TR-064 found.";
|
||||
|
||||
#Determine TR064-Port
|
||||
my $tr064Port = FRITZBOX_init_TR064 ( $hash, $host );
|
||||
if ($tr064Port) {
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->SECPORT", $tr064Port;
|
||||
$hash->{SECPORT} = $tr064Port;
|
||||
FRITZBOX_Log $hash, 5-$myVerbose, "TR-064-SecurePort is $tr064Port.";
|
||||
}
|
||||
else {
|
||||
@ -5927,12 +5966,14 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
|
||||
}
|
||||
|
||||
if ( $fwVersion =~ /error/ && $response->code != 500) {
|
||||
my $boxCRD = FRITZBOX_Helper_read_Password($hash);
|
||||
|
||||
if ( $fwVersion =~ /error/ && $response->code != 500 && $crdOK) {
|
||||
# Ansonsten ermitteln Box Model, FritzOS Version, OEM aus jason_boxinfo
|
||||
FRITZBOX_Log $hash, 5, "Read 'jason_boxinfo' from " . $host;
|
||||
|
||||
$FRITZBOX_TR064pwd = FRITZBOX_Helper_read_Password($hash);
|
||||
|
||||
if ($FRITZBOX_TR064pwd) {
|
||||
|
||||
$agent = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 10);
|
||||
my $url = "http://" . $host . "/jason_boxinfo.xml";
|
||||
$response = $agent->get( $url );
|
||||
@ -5943,7 +5984,7 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
|
||||
my $agentPW = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 10);
|
||||
my $req = HTTP::Request->new( GET => "http://" . $host . "/jason_boxinfo.xml");
|
||||
$req->authorization_basic( "$boxUser", "$boxCRD" );
|
||||
$req->authorization_basic( "$boxUser", "$FRITZBOX_TR064pwd" );
|
||||
$response = $agentPW->request( $req );
|
||||
}
|
||||
|
||||
@ -5976,7 +6017,7 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
|
||||
my $agentPW = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 10);
|
||||
my $req = HTTP::Request->new( GET => "http://" . $host . "/cgi-bin/system_status");
|
||||
$req->authorization_basic( "$boxUser", "$boxCRD" );
|
||||
$req->authorization_basic( "$boxUser", "$FRITZBOX_TR064pwd" );
|
||||
$response = $agentPW->request( $req );
|
||||
}
|
||||
|
||||
@ -6014,9 +6055,12 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
FRITZBOX_Log $hash, 4-$myVerbose, "" . $response->status_line;
|
||||
}
|
||||
}
|
||||
$boxCRD = undef;
|
||||
$FRITZBOX_TR064pwd = undef;
|
||||
} else {
|
||||
FRITZBOX_Log $hash, 2, "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->HINWEIS_PASSWORD", "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($apiError =~ /500/) {
|
||||
@ -6027,30 +6071,27 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->APICHECKED", 1;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->APICHECK_RET_CODES", "Ok";
|
||||
|
||||
# initialize first SID
|
||||
my $sidNew = 0;
|
||||
my $resetSID = 1;
|
||||
|
||||
# initialize first SID if password available
|
||||
if ( $crdOK ) {
|
||||
my $result = FRITZBOX_open_Web_Connection( $hash );
|
||||
|
||||
if (defined $result->{Error}) {
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "Error", $result->{Error};
|
||||
} else {
|
||||
$resetSID = 0;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->WEBCONNECT", 0;
|
||||
my $sidCnt = $hash->{fhem}{sidErrCount} + 1;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", 0;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidErrCount", $sidCnt;
|
||||
|
||||
$sidNew = $result->{sidNew} if defined $result->{sidNew};
|
||||
} else {
|
||||
my $sidNew = defined $result->{sidNew} ? $result->{sidNew} : 0;
|
||||
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sid", $result->{sid};
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidNewCount", $sidNew;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", time();
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidErrCount", 0;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->WEBCONNECT", 1;
|
||||
}
|
||||
|
||||
if ($resetSID) {
|
||||
FRITZBOX_Log $hash, 3, "SID Response -> " . $resetSID;
|
||||
my $sidCnt = $hash->{fhem}{sidErrCount} + 1;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidTime", 0;
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->sidErrCount", $sidCnt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6066,84 +6107,6 @@ sub FRITZBOX_Set_check_APIs($)
|
||||
|
||||
} #end FRITZBOX_Set_check_APIs
|
||||
|
||||
# Starts the data capturing via query.lua and sets the new timer
|
||||
#######################################################################
|
||||
sub FRITZBOX_Set_check_m3u($$)
|
||||
{
|
||||
my ($hash, $host) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my @roReadings;
|
||||
my $response;
|
||||
|
||||
|
||||
# Check if m3u can be created and the URL tested
|
||||
if ( AttrVal( $name, "m3uFileActive", 0) ) {
|
||||
my $globalModPath = AttrVal( "global", "modpath", "." );
|
||||
my $m3uFileLocal = AttrVal( $name, "m3uFileLocal", $globalModPath."/www/images/" . $name . ".m3u" );
|
||||
|
||||
if (open my $fh, '>', $m3uFileLocal) {
|
||||
my $ttsText = uri_escape("Lirumlarumlöffelstielwerdasnichtkannderkannnichtviel");
|
||||
my $ttsLink = $ttsLinkTemplate;
|
||||
$ttsLink =~ s/\[TEXT\]/$ttsText/;
|
||||
$ttsLink =~ s/\[SPRACHE\]/fr/;
|
||||
print $fh $ttsLink;
|
||||
close $fh;
|
||||
FRITZBOX_Log $hash, 3, "Created m3u file '$m3uFileLocal'.";
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->M3U_LOCAL", $m3uFileLocal;
|
||||
|
||||
# Get the m3u-URL
|
||||
my $m3uFileURL = AttrVal( $name, "m3uFileURL", "unknown" );
|
||||
|
||||
# if no URL and no local file defined, then try to build the correct URL
|
||||
if ( $m3uFileURL eq "unknown" && AttrVal( $name, "m3uFileLocal", "" ) eq "" ) {
|
||||
|
||||
# Getting IP of FHEM host
|
||||
FRITZBOX_Log $hash, 5, "Try to get my IP address.";
|
||||
my $socket = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => 'http(80)' );
|
||||
my $ip;
|
||||
$ip = $socket->sockhost if $socket; #A side-effect of making a socket connection is that our IP address is available from the 'sockhost' method
|
||||
FRITZBOX_Log $hash, 3, "Could not determine my ip address" unless $ip;
|
||||
|
||||
# Get a web port
|
||||
my $port;
|
||||
FRITZBOX_Log $hash, 5, "Try to get a FHEMWEB port.";
|
||||
|
||||
foreach( keys %defs ) {
|
||||
if ( $defs{$_}->{TYPE} eq "FHEMWEB" && !defined $defs{$_}->{TEMPORARY} && defined $defs{$_}->{PORT} ) {
|
||||
$port = $defs{$_}->{PORT};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
FRITZBOX_Log $hash, 3, "Could not find a FHEMWEB device." unless $port;
|
||||
if (defined $ip && defined $port) {
|
||||
$m3uFileURL = "http://$ip:$port/fhem/www/images/$name.m3u";
|
||||
}
|
||||
}
|
||||
|
||||
# Check if m3u can be accessed
|
||||
unless ( $m3uFileURL eq "unknown" ) {
|
||||
FRITZBOX_Log $hash, 5, "Try to get '$m3uFileURL'";
|
||||
my $agent = LWP::UserAgent->new( env_proxy => 1, keep_alive => 1, protocols_allowed => ['http'], timeout => 10);
|
||||
$response = $agent->get( $m3uFileURL );
|
||||
if ($response->is_error) {
|
||||
FRITZBOX_Log $hash, 3, "Failed to get '$m3uFileURL': ".$response->status_line;
|
||||
$m3uFileURL = "unknown" ;
|
||||
}
|
||||
}
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->M3U_URL", $m3uFileURL;
|
||||
}
|
||||
else {
|
||||
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->M3U_LOCAL", "undefined";
|
||||
FRITZBOX_Log $hash, 2, "Cannot create save file '$m3uFileLocal' because $!\n";
|
||||
}
|
||||
}
|
||||
|
||||
return join('|', @roReadings );
|
||||
|
||||
} #end FRITZBOX_Set_check_m3u
|
||||
|
||||
#######################################################################
|
||||
sub FRITZBOX_Set_block_Incoming_Phone_Call($)
|
||||
{
|
||||
@ -9027,7 +8990,6 @@ sub FRITZBOX_Get_Lua_Kids($$@)
|
||||
return \%retHash;
|
||||
}
|
||||
|
||||
|
||||
#################
|
||||
#FRITZBOX_Log $hash, 3, "Response: ".$response->content;
|
||||
#################
|
||||
@ -9044,14 +9006,14 @@ sub FRITZBOX_Get_Lua_Kids($$@)
|
||||
else {
|
||||
$jsonResult = JSON->new->latin1->decode( $jsonText );
|
||||
}
|
||||
#Not a HASH reference at ./FHEM/72_FRITZBOX.pm line 4662.
|
||||
# 2018.03.19 18:43:28 3: FRITZBOX: get Fritzbox luaQuery settings/sip
|
||||
|
||||
if ( ref ($jsonResult) ne "HASH" ) {
|
||||
chop $jsonText;
|
||||
FRITZBOX_Log $hash, 5, "no json string returned (" . $jsonText . ")";
|
||||
my %retHash = ("Error" => "no json string returned (" . $jsonText . ")", "ResetSID" => "1");
|
||||
return \%retHash;
|
||||
}
|
||||
|
||||
$jsonResult->{sid} = $result->{sid};
|
||||
$jsonResult->{sidNew} = $sidNew;
|
||||
$jsonResult->{Error} = $jsonResult->{error} if defined $jsonResult->{error};
|
||||
@ -9501,13 +9463,6 @@ sub FRITZBOX_open_Web_Connection ($)
|
||||
FRITZBOX_Log $hash, 4, "renewing SID while: " . $msg;
|
||||
}
|
||||
|
||||
my $pwd = FRITZBOX_Helper_read_Password($hash);
|
||||
unless (defined $pwd) {
|
||||
FRITZBOX_Log $hash, 2, "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
%retHash = ( "Error" => "No password set", "ResetSID" => "1" ) ;
|
||||
return \%retHash;
|
||||
}
|
||||
|
||||
my $avmModel = InternalVal($name, "MODEL", $hash->{boxModel});
|
||||
my $user = AttrVal( $name, "boxUser", "" );
|
||||
|
||||
@ -9518,8 +9473,17 @@ sub FRITZBOX_open_Web_Connection ($)
|
||||
}
|
||||
|
||||
FRITZBOX_Log $hash, 4, "Open Web connection to $host:" . $user ne "" ? $user : "user not defined";
|
||||
$FRITZBOX_TR064pwd = FRITZBOX_Helper_read_Password($hash);
|
||||
unless (defined $FRITZBOX_TR064pwd) {
|
||||
FRITZBOX_Log $hash, 2, "No password set. Please define it (once) with 'set $name password YourPassword'";
|
||||
%retHash = ( "Error" => "No password set", "ResetSID" => "1" ) ;
|
||||
return \%retHash;
|
||||
}
|
||||
|
||||
FRITZBOX_Log $hash, 4, "getting new SID";
|
||||
$sid = (FB_doCheckPW($host, $user, $pwd));
|
||||
$sid = (FB_doCheckPW($host, $user, $FRITZBOX_TR064pwd));
|
||||
|
||||
$FRITZBOX_TR064pwd = undef;
|
||||
|
||||
if ($sid) {
|
||||
FRITZBOX_Log $hash, 4, "Web session opened with sid $sid";
|
||||
@ -9906,8 +9870,13 @@ sub FRITZBOX_Helper_analyse_Lua_Result($$;@)
|
||||
my $tmp;
|
||||
|
||||
if (defined $result->{ResetSID}) {
|
||||
if ($result->{ResetSID}) {
|
||||
$hash->{fhem}{sidErrCount} += 1;
|
||||
$hash->{SID_RENEW_ERR_CNT} += 1;
|
||||
$hash->{WEBCONNECT} = 0;
|
||||
} else {
|
||||
$hash->{WEBCONNECT} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $result->{Error} ) {
|
||||
@ -9921,6 +9890,7 @@ sub FRITZBOX_Helper_analyse_Lua_Result($$;@)
|
||||
$hash->{fhem}{sid} = $result->{sid};
|
||||
$hash->{fhem}{sidTime} = time();
|
||||
$hash->{fhem}{sidErrCount} = 0;
|
||||
$hash->{WEBCONNECT} = 1;
|
||||
$hash->{SID_RENEW_ERR_CNT} = 0;
|
||||
|
||||
if (defined $result->{sidNew} && $result->{sidNew}) {
|
||||
|
Loading…
Reference in New Issue
Block a user