2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

01_FHEMWEB.pm: websocket bugfix: do not crash if Digest::SHA is not installed

git-svn-id: https://svn.fhem.de/fhem/trunk@12960 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-01-04 22:10:55 +00:00
parent 54a23d0a2f
commit f112d1eb1c

View File

@ -328,7 +328,6 @@ FW_Read($$)
} }
} }
if(!$reread) { if(!$reread) {
# Data from HTTP Client # Data from HTTP Client
my $buf; my $buf;
@ -423,14 +422,24 @@ FW_Read($$)
$hash->{LASTACCESS} = $now; $hash->{LASTACCESS} = $now;
if($method eq 'GET' && $FW_httpheader{Connection} =~ /Upgrade/i ) { if($method eq 'GET' && $FW_httpheader{Connection} =~ /Upgrade/i ) {
use Digest::SHA1 qw(sha1_base64);
my $shastr = eval {
require Digest::SHA1;
Digest::SHA1::sha1_base64($FW_httpheader{'Sec-WebSocket-Key'}.
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
};
if($@) {
Log3 $FW_wname, 1, $@;
Log3 $FW_wname, 1, "$FW_wname: Can't load Digest::SHA, no websocket";
$attr{$FW_wname}{longpoll} = 1;
return -1;
}
TcpServer_WriteBlocking($FW_chash, TcpServer_WriteBlocking($FW_chash,
"HTTP/1.1 101 Switching Protocols\r\n" . "HTTP/1.1 101 Switching Protocols\r\n" .
"Upgrade: websocket\r\n" . "Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" . "Connection: Upgrade\r\n" .
"Sec-WebSocket-Accept:". "Sec-WebSocket-Accept:$shastr=\r\n".
sha1_base64($FW_httpheader{'Sec-WebSocket-Key'}.
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")."=\r\n" .
"\r\n" ); "\r\n" );
$FW_chash->{websocket} = 1; $FW_chash->{websocket} = 1;