From 593a78a13677621a43e226fa271b81b9470e33c7 Mon Sep 17 00:00:00 2001 From: mike3436 Date: Thu, 23 Mar 2017 18:57:34 +0000 Subject: [PATCH] 26_tahoma.pm:V0213 username and password stored encrypted git-svn-id: https://svn.fhem.de/fhem/trunk@13783 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/26_KM273.pm | 14 ++++++++++-- fhem/FHEM/26_tahoma.pm | 48 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/26_KM273.pm b/fhem/FHEM/26_KM273.pm index bb05a94e0..b49325376 100755 --- a/fhem/FHEM/26_KM273.pm +++ b/fhem/FHEM/26_KM273.pm @@ -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($)
  • DoNotPoll 0|1
    When you set DoNotPoll to "1", the module is only listening to the telegrams on CAN bus. Default is "0".
  • +
  • HeatCircuit2Active 0|1
    + When you set HeatCircuit2Active to "1", the module read and set also the values for the second heating circuit E12. Default is "0". +
  • diff --git a/fhem/FHEM/26_tahoma.pm b/fhem/FHEM/26_tahoma.pm index f4ac5cc34..303b0d076 100644 --- a/fhem/FHEM/26_tahoma.pm +++ b/fhem/FHEM/26_tahoma.pm @@ -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;