2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

96_allowed/98_telnet.pm: fix disconnect after setting basicAuth attribute. (Forum #65298)

git-svn-id: https://svn.fhem.de/fhem/trunk@13169 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-01-21 13:28:14 +00:00
parent 38c38bbed9
commit f57185dd1c
2 changed files with 7 additions and 14 deletions

View File

@ -99,8 +99,8 @@ allowed_Authenticate($$$$)
# Check for Cookie in headers if no basicAuth header is set
my $authcookie;
if ( ( ! $secret ) && ( $FW_httpheader->{Cookie} ) ) {
if ( AttrVal($aName, "basicAuthExpiry", 0)) {
if (!$secret && $FW_httpheader->{Cookie}) {
if(AttrVal($aName, "basicAuthExpiry", 0)) {
my $cookie = "; ".$FW_httpheader->{Cookie}.";";
$authcookie = $1 if ( $cookie =~ /; AuthToken=([^;]+);/ );
$secret = $authcookie;
@ -120,18 +120,11 @@ allowed_Authenticate($$$$)
}
}
# Add Cookie header ONLY if
# authentication with basic auth was succesful
# (meaning if no or wrong authcookie set)
if ( ( $pwok ) &&
( ( ! defined($authcookie) ) || ( $secret ne $authcookie ) ) ) {
# no cookie set but authorization succesful
# check if cookie should be set --> Cookie Attribute != 0
my $time = int(AttrVal($aName, "basicAuthExpiry", 0));
# Add Cookie header ONLY if authentication with basicAuth was succesful
if($pwok && (!defined($authcookie) || $secret ne $authcookie)) {
my $time = AttrVal($aName, "basicAuthExpiry", 0);
if ( $time ) {
# time specified in days until next expiry (but timestamp is in seconds)
$time *= 86400;
$time += time();
$time = int($time*86400+time());
# generate timestamp according to RFC-1130 in Expires
my $expires = "Expires=".FmtDateTimeRFC1123($time);
# set header with expiry

View File

@ -247,7 +247,7 @@ telnet_Read($)
if(!defined($hash->{Authenticated})) {
syswrite($hash->{CD}, sprintf("%c%c%c\r\n", 255, 252, 1)); # WONT ECHO
if(Authenticate($hash, $cmd) == 1) {
if(Authenticate($hash, $cmd) != 2) {
$hash->{Authenticated} = 1;
next;
} else {