mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +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);
|
||||
|
||||
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 2, $msg;
|
||||
return $msg;
|
||||
@ -63,6 +63,10 @@ FHEM2FHEM_Define($$)
|
||||
}
|
||||
|
||||
my $dev = $a[2];
|
||||
if($dev =~ m/^(.*):SSL$/) {
|
||||
$dev = $1;
|
||||
$hash->{SSL} = 1;
|
||||
}
|
||||
if($dev !~ m/^.+:[0-9]+$/) { # host:port
|
||||
$dev = "$dev:7072";
|
||||
$hash->{Host} = $dev;
|
||||
@ -90,7 +94,12 @@ FHEM2FHEM_Write($$)
|
||||
my $dev = $hash->{Host};
|
||||
|
||||
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
|
||||
$hash->{TCPDev2} = $conn;
|
||||
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n")
|
||||
@ -208,7 +217,15 @@ FHEM2FHEM_OpenDev($$)
|
||||
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) {
|
||||
delete($hash->{NEXT_OPEN})
|
||||
|
||||
|
@ -16,39 +16,43 @@ urlEncode($) {
|
||||
|
||||
|
||||
##################
|
||||
# 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
|
||||
# - 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
|
||||
sub
|
||||
GetFileFromURL($@)
|
||||
{
|
||||
my ($url, $timeout, $data, $noshutdown) = @_;
|
||||
$timeout = 4.0 if(!defined($timeout));
|
||||
|
||||
if($url !~ /^(http):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
||||
Log 1, "GetFileFromURL $url: malformed URL";
|
||||
if($url !~ /^(http|https):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
||||
Log 1, "GetFileFromURL $url: malformed or unsupported URL";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my ($protocol,$host,$port,$path)= ($1,$2,$3,$4);
|
||||
|
||||
if(defined($port)) {
|
||||
$port=~ s/^://;
|
||||
$port =~ s/^://;
|
||||
} else {
|
||||
$port= 80;
|
||||
$port = ($protocol eq "https" ? 443: 80);
|
||||
}
|
||||
$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) {
|
||||
Log 1, "GetFileFromURL: Can't connect to $host:$port\n";
|
||||
Log 1, "GetFileFromURL: Can't connect to $protocol://$host:$port\n";
|
||||
undef $conn;
|
||||
return undef;
|
||||
}
|
||||
|
||||
$host =~ s/:.*//;
|
||||
my $hdr = ($data ? "POST" : "GET")." $path HTTP/1.0\r\nHost: $host\r\n";
|
||||
if(defined($data)) {
|
||||
|
Loading…
Reference in New Issue
Block a user