mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
FRITZBOX: password read and store of fb_callmonitor implemented
git-svn-id: https://svn.fhem.de/fhem/trunk@7591 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d5732463ac
commit
ca5c4fe014
@ -253,12 +253,12 @@ sub FRITZBOX_Set($$@)
|
||||
|
||||
my $list = "alarm"
|
||||
. " call"
|
||||
. " createPwdFile"
|
||||
. " customerRingTone"
|
||||
. " dect:on,off"
|
||||
. " diversity"
|
||||
. " guestWlan:on,off"
|
||||
. " moh"
|
||||
. " password"
|
||||
. " ring"
|
||||
. " sendMail"
|
||||
. " startRadio"
|
||||
@ -302,18 +302,6 @@ sub FRITZBOX_Set($$@)
|
||||
# return FRITZBOX_ConvertRingTone $hash, @val;
|
||||
# }
|
||||
|
||||
} elsif ( lc $cmd eq 'createpwdfile') {
|
||||
if (int @val > 0)
|
||||
{
|
||||
my $pwdFile = AttrVal( $name, "pwdFile", "fb_pwd.txt");
|
||||
open( FILE, ">".$pwdFile)
|
||||
or return "Error when opening password file '$pwdFile': ".$!;
|
||||
print FILE join( " ", @val);
|
||||
close FILE
|
||||
or return "Error when closing password file '$pwdFile': ".$!;
|
||||
return "Created password file '$pwdFile'";
|
||||
}
|
||||
|
||||
} elsif ( lc $cmd eq 'customerringtone') {
|
||||
if (int @val > 0)
|
||||
{
|
||||
@ -368,6 +356,14 @@ sub FRITZBOX_Set($$@)
|
||||
return $resultStr;
|
||||
}
|
||||
}
|
||||
|
||||
# set password
|
||||
} elsif ( lc $cmd eq 'password') {
|
||||
if (int @val == 1)
|
||||
{
|
||||
return FRITZBOX_storePassword ( $hash, $val[0] );
|
||||
}
|
||||
|
||||
#set Ring
|
||||
} elsif ( lc $cmd eq 'ring') {
|
||||
if (int @val > 0)
|
||||
@ -440,8 +436,87 @@ sub FRITZBOX_Get($@)
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
} # end FRITZBOX_Get
|
||||
|
||||
# Starts the data capturing and sets the new readout timer
|
||||
|
||||
#####################################
|
||||
# checks and stores FritzBox password used for telnet connection
|
||||
sub FRITZBOX_storePassword($$)
|
||||
{
|
||||
my ($hash, $password) = @_;
|
||||
|
||||
my $index = $hash->{TYPE}."_".$hash->{NAME}."_passwd";
|
||||
my $key = getUniqueId().$index;
|
||||
|
||||
my $enc_pwd = "";
|
||||
|
||||
if(eval "use Digest::MD5;1")
|
||||
{
|
||||
$key = Digest::MD5::md5_hex(unpack "H*", $key);
|
||||
$key .= Digest::MD5::md5_hex($key);
|
||||
}
|
||||
|
||||
for my $char (split //, $password)
|
||||
{
|
||||
my $encode=chop($key);
|
||||
$enc_pwd.=sprintf("%.2x",ord($char)^ord($encode));
|
||||
$key=$encode.$key;
|
||||
}
|
||||
|
||||
my $err = setKeyValue($index, $enc_pwd);
|
||||
return "error while saving the password - $err" if(defined($err));
|
||||
|
||||
return "password successfully saved";
|
||||
} # end FRITZBOX_storePassword
|
||||
|
||||
|
||||
#####################################
|
||||
# reads the FritzBox password
|
||||
sub FRITZBOX_readPassword($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $index = $hash->{TYPE}."_".$hash->{NAME}."_passwd";
|
||||
my $key = getUniqueId().$index;
|
||||
|
||||
my ($password, $err);
|
||||
|
||||
FRITZBOX_Log $hash, 5, "Read FritzBox password from file";
|
||||
($err, $password) = getKeyValue($index);
|
||||
|
||||
if(defined($err))
|
||||
{
|
||||
FRITZBOX_Log $hash, 4, "unable to read FritzBox password from file: $err";
|
||||
return undef;
|
||||
}
|
||||
|
||||
if(defined($password))
|
||||
{
|
||||
if(eval "use Digest::MD5;1")
|
||||
{
|
||||
$key = Digest::MD5::md5_hex(unpack "H*", $key);
|
||||
$key .= Digest::MD5::md5_hex($key);
|
||||
}
|
||||
|
||||
my $dec_pwd = '';
|
||||
|
||||
for my $char (map { pack('C', hex($_)) } ($password =~ /(..)/g))
|
||||
{
|
||||
my $decode=chop($key);
|
||||
$dec_pwd.=chr(ord($char)^ord($decode));
|
||||
$key=$decode.$key;
|
||||
}
|
||||
|
||||
return $dec_pwd;
|
||||
}
|
||||
else
|
||||
{
|
||||
FRITZBOX_Log $hash, 4, "No password in file";
|
||||
return undef;
|
||||
}
|
||||
} # end FRITZBOX_readPassword
|
||||
|
||||
##########################################
|
||||
# Starts the data capturing and sets the new readout timer
|
||||
sub FRITZBOX_Readout_Start($)
|
||||
{
|
||||
my ($timerpara) = @_;
|
||||
@ -1909,21 +1984,24 @@ sub FRITZBOX_Open_Connection($)
|
||||
|
||||
my $host = AttrVal( $name, "fritzBoxIP", "fritz.box" );
|
||||
|
||||
my $pwdFile = AttrVal( $name, "pwdFile", "fb_pwd.txt");
|
||||
my $pwd;
|
||||
my $pwd = FRITZBOX_readPassword($hash);
|
||||
my $msg;
|
||||
my $before;
|
||||
my $match;
|
||||
|
||||
FRITZBOX_Log $hash, 5, "Open password file '$pwdFile' to extract password";
|
||||
if (open(IN, "<" . $pwdFile)) {
|
||||
$pwd = <IN>;
|
||||
close(IN);
|
||||
FRITZBOX_Log $hash, 5, "Close password file";
|
||||
} else {
|
||||
$msg = "Error: Cannot open password file '$pwdFile': $!";
|
||||
FRITZBOX_Log $hash, 2, $msg;
|
||||
return $msg;
|
||||
unless (defined $pwd)
|
||||
{
|
||||
my $pwdFile = AttrVal( $name, "pwdFile", "fb_pwd.txt");
|
||||
FRITZBOX_Log $hash, 5, "Open password file '$pwdFile' to extract password";
|
||||
if (open(IN, "<" . $pwdFile)) {
|
||||
$pwd = <IN>;
|
||||
close(IN);
|
||||
FRITZBOX_Log $hash, 5, "Close password file";
|
||||
} else {
|
||||
$msg = "Error: Cannot open password file '$pwdFile': $!";
|
||||
FRITZBOX_Log $hash, 2, $msg;
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
|
||||
my $user = AttrVal( $name, "telnetUser", "" );
|
||||
@ -2378,7 +2456,7 @@ sub FRITZBOX_fritztris($)
|
||||
signaling devices. MP3 files and Text2Speech can be played as ring tone or when calling phones.
|
||||
<a href="http://www.fhemwiki.de/wiki/FRITZBOX"><b>FHEM-Wiki-Link</b></a>
|
||||
<br/><br/>
|
||||
The modul switches in local mode if FHEM runs on a Fritz!Box (as root user!). Otherwise, it tries to open a telnet connection to "fritz.box", so telnet (#96*7*) has to be enabled on the Fritz!Box. For remote access the password must be stored in the file 'fb_pwd.txt' in the root directory of FHEM.
|
||||
The modul switches in local mode if FHEM runs on a Fritz!Box (as root user!). Otherwise, it tries to open a telnet connection to "fritz.box", so telnet (#96*7*) has to be enabled on the Fritz!Box. For remote access the password must once be set.
|
||||
<br/><br/>
|
||||
The commands are directly executed on the Fritz!Box shell. That means, no official API is used but mainly the internal interface program that links web interface and firmware kernel. An update of FritzOS might hence lead to modul errors if AVM changes the interface.
|
||||
<br>
|
||||
@ -2411,11 +2489,6 @@ sub FRITZBOX_fritztris($)
|
||||
Switches the alarm number (1, 2 or 3) on or off.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> createPwdFile <password></code>
|
||||
<br>
|
||||
Creates a file that contains the telnet password. The file name corresponds to the one used for remote telnet access.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> customerRingTone <internalNumber> <fullFilePath></code>
|
||||
<br>
|
||||
Uploads the file fullFilePath on the given handset. Only mp3 or G722 format is allowed.
|
||||
@ -2453,6 +2526,11 @@ sub FRITZBOX_fritztris($)
|
||||
<br>
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> password <password></code>
|
||||
<br>
|
||||
Stores the password for remote telnet access.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> ring <intNumbers> [duration [ringTone]] [show:Text] [say:Text | play:Link]</code>
|
||||
<br>
|
||||
Example:
|
||||
@ -2546,11 +2624,6 @@ sub FRITZBOX_fritztris($)
|
||||
IP address or URL of the Fritz!Box for remote telnet access. Default is "fritz.box".
|
||||
</li><br>
|
||||
|
||||
<li><code>pwdFile <fileName></code>
|
||||
<br>
|
||||
File that contains the password for telnet access. Default is 'fb_pwd.txt' in the root directory of FHEM.
|
||||
</li><br>
|
||||
|
||||
<li><code>telnetUser <user name></code>
|
||||
<br>
|
||||
User name that is used for telnet access. By default no user name is required to login.
|
||||
@ -2639,7 +2712,7 @@ sub FRITZBOX_fritztris($)
|
||||
Steuert gewisse Funktionen eines Fritz!Box Routers. Verbundene Fritz!Fon's (MT-F, MT-D, C3, C4) können als Signalgeräte genutzt werden. MP3-Dateien und Text (Text2Speech) können als Klingelton oder einem angerufenen Telefon abgespielt werden.
|
||||
<a href="http://www.fhemwiki.de/wiki/FRITZBOX"><b>FHEM-Wiki-Link</b></a>
|
||||
<br/><br/>
|
||||
Das Modul schaltet in den lokalen Modus, wenn FHEM auf einer Fritz!Box läuft (als root-Benutzer!). Ansonsten versucht es eine Telnet Verbindung zu "fritz.box" zu öffnen. D.h. Telnet (#96*7*) muss auf der Fritz!Box erlaubt sein. Für diesen Fernzugriff muss das Passwort in der Datei 'fb_pwd.txt' im Wurzelverzeichnis von FHEM gespeichert sein.
|
||||
Das Modul schaltet in den lokalen Modus, wenn FHEM auf einer Fritz!Box läuft (als root-Benutzer!). Ansonsten versucht es eine Telnet Verbindung zu "fritz.box" zu öffnen. D.h. Telnet (#96*7*) muss auf der Fritz!Box erlaubt sein. Für diesen Fernzugriff muss einmalig das Passwort gesetzt werden.
|
||||
<br/><br/>
|
||||
Die Steuerung erfolgt direkt über die Fritz!Box Shell. D.h. es wird keine offizielle API genutzt sondern vor allem die interne Schnittstelle der Box zwischen Webinterface und Firmware Kern. Eine Aktualisierung des FritzOS kann also zu Modul-Fehlern führen, wenn AVM diese Schnittstelle ändert.
|
||||
<br>
|
||||
@ -2672,11 +2745,6 @@ sub FRITZBOX_fritztris($)
|
||||
Schaltet den Weckruf Nummer 1, 2 oder 3 an oder aus.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> createPwdFile <password></code>
|
||||
<br>
|
||||
Erzeugt eine Datei welche das Telnet-Passwort enthält. Der Dateiname entspricht demjenigen, der für den Telnetzugriff genutzt wird.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> customerRingTone <internalNumber> <MP3DateiInklusivePfad></code>
|
||||
<br>
|
||||
Lädt die MP3-Datei als Klingelton auf das angegebene Telefon. Die Datei muss im Dateisystem der Fritzbox liegen.
|
||||
@ -2714,6 +2782,11 @@ sub FRITZBOX_fritztris($)
|
||||
<br>
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> password <Passwort></code>
|
||||
<br>
|
||||
Speichert das Passwort für den Fernzugriff über Telnet.
|
||||
</li><br>
|
||||
|
||||
<li><code>set <name> ring <intNummern> [Dauer [Klingelton]] [show:Text] [say:Text | play:Link]</code>
|
||||
Beispiel:
|
||||
<br>
|
||||
@ -2801,11 +2874,6 @@ sub FRITZBOX_fritztris($)
|
||||
<br>
|
||||
IP Adresse oder ULR der Fritz!Box für Fernzugriff per Telnet. Standard ist "fritz.box".
|
||||
</li><br>
|
||||
|
||||
<li><code>pwdFile <fileName></code>
|
||||
<br>
|
||||
Damit kann die Datei geündert werden, welche das Passwort für den Telnetzugang enthält. Der Standard ist 'fb_pwd.txt' im Wurzelverzeichnis von FHEM.
|
||||
</li><br>
|
||||
|
||||
<li><code>telnetUser <user name></code>
|
||||
<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user