mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
HTTP/SSL added
git-svn-id: https://svn.fhem.de/fhem/trunk@1648 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
322e4cad36
commit
6d321a6553
@ -41,7 +41,7 @@ FHEM2FHEM_Define($$)
|
|||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
if(@a < 4 || @a > 5 || !($a[3] =~ m/^(LOG|RAW):(.*)$/)) {
|
if(@a < 4 || @a > 5 || !($a[3] =~ m/^(LOG|RAW):(.*)$/)) {
|
||||||
my $msg = "wrong syntax: define <name> FHEM2FHEM host[:port] ".
|
my $msg = "wrong syntax: define <name> FHEM2FHEM host[:port][:SSL] ".
|
||||||
"[LOG:regexp|RAW:device] {portpasswort}";
|
"[LOG:regexp|RAW:device] {portpasswort}";
|
||||||
Log 2, $msg;
|
Log 2, $msg;
|
||||||
return $msg;
|
return $msg;
|
||||||
@ -63,6 +63,10 @@ FHEM2FHEM_Define($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $dev = $a[2];
|
my $dev = $a[2];
|
||||||
|
if($dev =~ m/^(.*):SSL$/) {
|
||||||
|
$dev = $1;
|
||||||
|
$hash->{SSL} = 1;
|
||||||
|
}
|
||||||
if($dev !~ m/^.+:[0-9]+$/) { # host:port
|
if($dev !~ m/^.+:[0-9]+$/) { # host:port
|
||||||
$dev = "$dev:7072";
|
$dev = "$dev:7072";
|
||||||
$hash->{Host} = $dev;
|
$hash->{Host} = $dev;
|
||||||
@ -90,7 +94,12 @@ FHEM2FHEM_Write($$)
|
|||||||
my $dev = $hash->{Host};
|
my $dev = $hash->{Host};
|
||||||
|
|
||||||
if(!$hash->{TCPDev2}) {
|
if(!$hash->{TCPDev2}) {
|
||||||
my $conn = IO::Socket::INET->new(PeerAddr => $dev);
|
my $conn;
|
||||||
|
if($hash->{SSL}) {
|
||||||
|
$conn = IO::Socket::SSL->new(PeerAddr => $dev);
|
||||||
|
} else {
|
||||||
|
$conn = IO::Socket::INET->new(PeerAddr => $dev);
|
||||||
|
}
|
||||||
return if(!$conn); # Hopefuly it is reported elsewhere
|
return if(!$conn); # Hopefuly it is reported elsewhere
|
||||||
$hash->{TCPDev2} = $conn;
|
$hash->{TCPDev2} = $conn;
|
||||||
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n")
|
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n")
|
||||||
@ -208,7 +217,15 @@ FHEM2FHEM_OpenDev($$)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conn = IO::Socket::INET->new(PeerAddr => $dev);
|
my $conn;
|
||||||
|
if($hash->{SSL}) {
|
||||||
|
eval "use IO::Socket::SSL";
|
||||||
|
Log 1, $@ if($@);
|
||||||
|
$conn = IO::Socket::SSL->new(PeerAddr => "$dev") if(!$@);
|
||||||
|
} else {
|
||||||
|
$conn = IO::Socket::INET->new(PeerAddr => $dev);
|
||||||
|
}
|
||||||
|
|
||||||
if($conn) {
|
if($conn) {
|
||||||
delete($hash->{NEXT_OPEN})
|
delete($hash->{NEXT_OPEN})
|
||||||
|
|
||||||
|
@ -16,39 +16,43 @@ urlEncode($) {
|
|||||||
|
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# if data (which is urlEncoded) is set, then a POST is performed, else a GET
|
# - if data (which is urlEncoded) is set, then a POST is performed, else a GET.
|
||||||
# noshutdown must be set for e.g the Fritz!Box
|
# - noshutdown must be set for e.g the Fritz!Box
|
||||||
sub
|
sub
|
||||||
GetFileFromURL($@)
|
GetFileFromURL($@)
|
||||||
{
|
{
|
||||||
my ($url, $timeout, $data, $noshutdown) = @_;
|
my ($url, $timeout, $data, $noshutdown) = @_;
|
||||||
$timeout = 4.0 if(!defined($timeout));
|
$timeout = 4.0 if(!defined($timeout));
|
||||||
|
|
||||||
if($url !~ /^(http):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
if($url !~ /^(http|https):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
||||||
Log 1, "GetFileFromURL $url: malformed URL";
|
Log 1, "GetFileFromURL $url: malformed or unsupported URL";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($protocol,$host,$port,$path)= ($1,$2,$3,$4);
|
my ($protocol,$host,$port,$path)= ($1,$2,$3,$4);
|
||||||
|
|
||||||
if(defined($port)) {
|
if(defined($port)) {
|
||||||
$port=~ s/^://;
|
$port =~ s/^://;
|
||||||
} else {
|
} else {
|
||||||
$port= 80;
|
$port = ($protocol eq "https" ? 443: 80);
|
||||||
}
|
}
|
||||||
$path= '/' unless defined($path);
|
$path= '/' unless defined($path);
|
||||||
|
|
||||||
if($protocol ne "http") {
|
|
||||||
Log 1, "GetFileFromURL $url: invalid protocol";
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $conn = IO::Socket::INET->new(PeerAddr => "$host:$port");
|
my $conn;
|
||||||
|
if($protocol eq "https") {
|
||||||
|
eval "use IO::Socket::SSL";
|
||||||
|
Log 1, $@ if($@);
|
||||||
|
$conn = IO::Socket::SSL->new(PeerAddr => "$host:$port") if(!$@);
|
||||||
|
} else {
|
||||||
|
$conn = IO::Socket::INET->new(PeerAddr => "$host:$port");
|
||||||
|
}
|
||||||
if(!$conn) {
|
if(!$conn) {
|
||||||
Log 1, "GetFileFromURL: Can't connect to $host:$port\n";
|
Log 1, "GetFileFromURL: Can't connect to $protocol://$host:$port\n";
|
||||||
undef $conn;
|
undef $conn;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host =~ s/:.*//;
|
$host =~ s/:.*//;
|
||||||
my $hdr = ($data ? "POST" : "GET")." $path HTTP/1.0\r\nHost: $host\r\n";
|
my $hdr = ($data ? "POST" : "GET")." $path HTTP/1.0\r\nHost: $host\r\n";
|
||||||
if(defined($data)) {
|
if(defined($data)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user