26_tahoma.pm:V0213 username and password stored encrypted

git-svn-id: https://svn.fhem.de/fhem/trunk@13783 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mike3436
2017-03-23 18:57:34 +00:00
parent fc9ea94618
commit 593a78a136
2 changed files with 54 additions and 8 deletions

View File

@@ -73,6 +73,7 @@
# 0011 01.06.2016 mike3436 KM273_ReadElementList negative min values corrected: value interpretation has to be as signed int64, XDHW_TIME+XDHW_STOP_TEMP added to KM273_gets
# 0012 02.06.2016 mike3436 KM273_ReadElementList byte nibbles in extid turned
# 0013 07.01.2017 mike3436 KM273_gets HOLIDAY params added for get/set, cyclic read for some alarms and requests activated in KM273_elements_default
# 0014 22.03.2017 mike3436 KM273_getsAdd add variables for 2nd heating circuit if Attribut HeatCircit2Active is set to 1
package main;
use strict;
@@ -2171,6 +2172,7 @@ sub KM273_UpdateElements($)
{
my ($hash) = @_;
my $name = $hash->{NAME} . ": KM273_UpdateElements";
my $name1 = $hash->{NAME};
Log 3, "$name";
foreach my $element (keys %KM273_elements_default)
@@ -2178,7 +2180,7 @@ sub KM273_UpdateElements($)
my $text = $KM273_elements_default{$element}{text};
my $read = $KM273_elements_default{$element}{read};
my $elem1 = $KM273_ReadElementListElements{$text};
if ((!defined $elem1) && ($read != 0))
if ((!defined $elem1) && (($read == 1) || (($read == 2) && defined($attr{$name1}{HeatCircuit2Active}) && ($attr{$name1}{HeatCircuit2Active} == 1))))
{
my @days = ("1MON","2TUE","3WED","4THU","5FRI","6SAT","7SUN");
foreach my $day (@days)
@@ -2214,12 +2216,14 @@ sub KM273_CreatePollingList($)
{
my ($hash) = @_;
my $name = $hash->{NAME} . ": KM273_CreatePollingList";
my $name1 = $hash->{NAME};
Log 3, "$name";
@KM273_readingsRTR = ();
foreach my $element (keys %KM273_elements)
{
push @KM273_readingsRTR, $KM273_elements{$element}{rtr} if $KM273_elements{$element}{read} == 1;
push @KM273_readingsRTR, $KM273_elements{$element}{rtr} if ($KM273_elements{$element}{read} == 2) && defined($attr{$name1}{HeatCircuit2Active}) && ($attr{$name1}{HeatCircuit2Active} == 1);
}
foreach my $val (@KM273_readingsRTR)
{
@@ -2264,6 +2268,7 @@ sub KM273_Initialize($)
"ConsoleMessage " .
"DoNotPoll " .
"ReadBackDelay " .
"HeatCircuit2Active " .
$readingFnAttributes;
}
@@ -2273,7 +2278,7 @@ sub KM273_Define($$)
my $name = $hash->{NAME} . ": KM273_Define";
Log 5, "$name";
$hash->{VERSION} = "0013";
$hash->{VERSION} = "0014";
my @param = split('[ \t]+', $def);
@@ -2321,6 +2326,7 @@ sub KM273_Get($@)
my $opt = shift @param;
if(!defined($KM273_gets{$opt})) {
my @cList = keys %KM273_gets;
push @cList, keys %KM273_getsAdd if defined($attr{$name}{HeatCircuit2Active}) && ($attr{$name}{HeatCircuit2Active} == 1);
return "Unknown argument $opt, choose one of " . join(" ", @cList);
}
@@ -2352,6 +2358,7 @@ sub KM273_Set($@)
if(!defined($KM273_gets{$opt}) && !defined($KM273_writingsTXD{$opt})) {
my @cList = keys %KM273_gets;
push @cList, keys %KM273_getsAdd if defined($attr{$name}{HeatCircuit2Active}) && ($attr{$name}{HeatCircuit2Active} == 1);
return "Unknown argument $opt, choose one of " . join(" ", @cList);
}
@@ -2840,6 +2847,9 @@ sub CAN_DoInit($)
<li><i>DoNotPoll</i> 0|1<br>
When you set DoNotPoll to "1", the module is only listening to the telegrams on CAN bus. Default is "0".
</li>
<li><i>HeatCircuit2Active</i> 0|1<br>
When you set HeatCircuit2Active to "1", the module read and set also the values for the second heating circuit E12. Default is "0".
</li>
</ul>
</ul>
</ul>

View File

@@ -42,6 +42,7 @@
# 2017-01-24 V 0212 start scene with launchActionGroup so cancel is working on scenes now
# 2017-01-24 V 0212 Attribut interval used to disable or enable refreshAllstates
# 2017-01-24 V 0212 Setup changes recognized for reading places
# 2017-03-23 V 0213 username and password stored encrypted
package main;
@@ -94,7 +95,7 @@ sub tahoma_Define($$)
my @a = split("[ \t][ \t]*", $def);
my $ModuleVersion = "0212";
my $ModuleVersion = "0213";
my $subtype;
my $name = $a[0];
@@ -149,13 +150,15 @@ sub tahoma_Define($$)
} elsif( $a[2] eq "ACCOUNT" && @a == 5 ) {
$subtype = "ACCOUNT";
my $username = $a[@a-2];
my $password = $a[@a-1];
my $username = tahoma_encrypt($a[@a-2]);
my $password = tahoma_encrypt($a[@a-1]);
$hash->{Clients} = ":tahoma:";
$hash->{username} = $username;
$hash->{password} = $password;
$hash->{DEF} = "$subtype $username $password";
$hash->{helper}{username} = $username;
$hash->{helper}{password} = $password;
$hash->{BLOCKING} = 0;
$hash->{INTERVAL} = 0;
$hash->{VERSION} = $ModuleVersion;
@@ -229,7 +232,7 @@ sub tahoma_login($)
noshutdown => 1,
hash => $hash,
page => 'login',
data => {'userId' => $hash->{username} , 'userPassword' => $hash->{password}},
data => {'userId' => tahoma_decrypt($hash->{helper}{username}) , 'userPassword' => tahoma_decrypt($hash->{helper}{password})},
callback => \&tahoma_dispatch,
nonblocking => 1,
});
@@ -1428,6 +1431,39 @@ sub tahoma_GetCookies($$)
}
sub tahoma_encrypt($)
{
my ($decoded) = @_;
my $key = getUniqueId();
my $encoded;
return $decoded if( $decoded =~ /^crypt:(.*)/ );
for my $char (split //, $decoded) {
my $encode = chop($key);
$encoded .= sprintf("%.2x",ord($char)^ord($encode));
$key = $encode.$key;
}
return 'crypt:'. $encoded;
}
sub tahoma_decrypt($)
{
my ($encoded) = @_;
my $key = getUniqueId();
my $decoded;
$encoded = $1 if( $encoded =~ /^crypt:(.*)/ );
for my $char (map { pack('C', hex($_)) } ($encoded =~ /(..)/g)) {
my $decode = chop($key);
$decoded .= chr(ord($char)^ord($decode));
$key = $decode.$key;
}
return $decoded;
}
1;