From 682baf5753ff1af71b9dfe3f9e12a108f1819e8a Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 9 Sep 2017 10:20:16 +0000 Subject: [PATCH] HttpUtils: add proxyAuth (Forum #60471) git-svn-id: https://svn.fhem.de/fhem/trunk@15033 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/HttpUtils.pm | 11 +++++++++-- fhem/docs/commandref_frame.html | 4 ++++ fhem/docs/commandref_frame_DE.html | 4 ++++ fhem/fhem.pl | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fhem/FHEM/HttpUtils.pm b/fhem/FHEM/HttpUtils.pm index e92a6cb63..8744fd51f 100644 --- a/fhem/FHEM/HttpUtils.pm +++ b/fhem/FHEM/HttpUtils.pm @@ -392,6 +392,7 @@ sub HttpUtils_Connect2($) { my ($hash) = @_; + my $usingSSL; $hash->{host} =~ s/:.*//; if($hash->{protocol} eq "https" && $hash->{conn} && !$hash->{hu_sslAdded}) { @@ -403,11 +404,13 @@ HttpUtils_Connect2($) return $errstr; } else { $hash->{conn}->blocking(1); + $usingSSL = 1; if($hash->{hu_proxy}) { # can block! + my $pw = AttrVal("global", "proxyAuth", ""); + $pw = "Proxy-Authorization: Basic $pw\r\n" if($pw); my $hdr = "CONNECT $hash->{host}:$hash->{hu_port} HTTP/1.0\r\n". - "User-Agent: fhem\r\n". - "\r\n"; + "User-Agent: fhem\r\n$pw\r\n"; syswrite $hash->{conn}, $hdr; my $buf; my $len = sysread($hash->{conn},$buf,65536); @@ -504,6 +507,10 @@ HttpUtils_Connect2($) $hdr .= "Content-Type: application/x-www-form-urlencoded\r\n" if ($hdr !~ "Content-Type:"); } + if(!$usingSSL) { + my $pw = AttrVal("global", "proxyAuth", ""); + $hdr .= "Proxy-Authorization: Basic $pw\r\n" if($pw); + } Log3 $hash, $hash->{loglevel}+1, "HttpUtils request header:\n$hdr"; $hdr .= "\r\n"; diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index 6888a79f8..228f338da 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -1519,6 +1519,10 @@ The following local attributes are used by a wider range of devices:
  • proxy
    IP:PORT of the proxy server to be used by HttpUtils.

  • + +
  • proxyAuth
    + Base64 encoded username:password +

  • proxyExclude
    regexp for hosts to exclude when using a proxy diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 3a61c6c2b..0ae5c5209 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -1622,6 +1622,10 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
  • proxy
    IP:PORT des proxy Servers, wird von HttpUtils benutzt.

  • + +
  • proxyAuth
    + Base64 kodiertes Benutzername:Passwort +

  • proxyExclude
    Regexp, um bestimmte Hosts nicht via proxy zu kontaktieren. diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 3e04068f5..b22fb2bcd 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -309,6 +309,7 @@ my @globalAttrList = qw( perlSyntaxCheck:0,1 pidfilename proxy + proxyAuth proxyExclude restartDelay restoreDirs