diff --git a/fhem/CHANGED b/fhem/CHANGED index cbd413f14..826c6a3c0 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: proxy global attribute for HttpUtils (Forum #60471) - bugfix: 93_DbLog: V2.22.5, several fixes Forum:#75894 - feature: 74_GardenaSmartDevice: check character for create devicenames - bugfix: FHEM2FHEM: addStateEvent attribute (Forum #76229) diff --git a/fhem/FHEM/HttpUtils.pm b/fhem/FHEM/HttpUtils.pm index 7790238a8..e92a6cb63 100644 --- a/fhem/FHEM/HttpUtils.pm +++ b/fhem/FHEM/HttpUtils.pm @@ -78,6 +78,8 @@ HttpUtils_Close($) delete($hash->{hu_filecount}); delete($hash->{hu_blocking}); delete($hash->{hu_portSfx}); + delete($hash->{hu_proxy}); + delete($hash->{hu_port}); delete($hash->{directReadFn}); delete($hash->{directWriteFn}); } @@ -291,10 +293,22 @@ HttpUtils_Connect($) $port = ($hash->{protocol} eq "https" ? 443: 80); } $hash->{hu_portSfx} = ($port =~ m/^(80|443)$/ ? "" : ":$port"); + $hash->{hu_port} = $port; $hash->{path} = '/' unless defined($hash->{path}); $hash->{addr} = "$hash->{protocol}://$host:$port"; $hash->{auth} = urlDecode("$user:$pwd") if($authstring); + my $proxy = AttrVal("global", "proxy", undef); + if($proxy) { + my $pe = AttrVal("global", "proxyExclude", undef); + if(!$pe || $host !~ m/$pe/) { + my @hp = split(":", $proxy); + $host = $hp[0]; + $port = $hp[1] if($hp[1]); + $hash->{hu_proxy} = 1; + } + } + return HttpUtils_Connect2($hash) if($hash->{conn} && $hash->{keepalive}); if($hash->{callback}) { # Nonblocking staff @@ -389,6 +403,20 @@ HttpUtils_Connect2($) return $errstr; } else { $hash->{conn}->blocking(1); + + if($hash->{hu_proxy}) { # can block! + my $hdr = "CONNECT $hash->{host}:$hash->{hu_port} HTTP/1.0\r\n". + "User-Agent: fhem\r\n". + "\r\n"; + syswrite $hash->{conn}, $hdr; + my $buf; + my $len = sysread($hash->{conn},$buf,65536); + if(!defined($len) || $len <= 0 || $buf !~ m/HTTP.*200/) { + HttpUtils_Close($hash); + return "Proxy denied CONNECT"; + } + } + my $sslVersion = AttrVal("global", "sslVersion", "SSLv23:!SSLv3:!SSLv2"); $sslVersion = AttrVal($hash->{NAME}, "sslVersion", $sslVersion) if($hash->{NAME}); @@ -453,7 +481,11 @@ HttpUtils_Connect2($) $method = ($data ? "POST" : "GET") if( !$method ); my $httpVersion = $hash->{httpversion} ? $hash->{httpversion} : "1.0"; - my $hdr = "$method $hash->{path} HTTP/$httpVersion\r\n"; + + my $path = $hash->{path}; + $path = "$hash->{protocol}://$hash->{host}$hash->{hu_portSfx}$path" + if($hash->{hu_proxy}); + my $hdr = "$method $path HTTP/$httpVersion\r\n"; $hdr .= "Host: $hash->{host}$hash->{hu_portSfx}\r\n"; $hdr .= "User-Agent: fhem\r\n" if(!$hash->{header} || $hash->{header} !~ "User-Agent:"); diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index 27cd1afa4..6888a79f8 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -1507,7 +1507,7 @@ The following local attributes are used by a wider range of devices: Windows.
- +
  • pidfilename
    Write the process id of the perl process to the specified file. The server runs as a daemon, and some distributions would like to check by @@ -1515,6 +1515,15 @@ The following local attributes are used by a wider range of devices: shutdown.

  • + +
  • proxy
    + IP:PORT of the proxy server to be used by HttpUtils. +

  • + +
  • proxyExclude
    + regexp for hosts to exclude when using a proxy +

  • +
  • sendStatistics
    diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 6b125e434..3a61c6c2b 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -1612,12 +1612,22 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
  • pidfilename
    - Schreibt die PERL Prozess-ID in die angegebene Datei. Der Server läuft - als Daemon und einige Distributionen wollen anhand der PID testen, ob der - FHEM Prozess läuft. Die Datei wird bei Ausführung des "shutdown"-Kommandos - gelöscht. + Schreibt die PERL Prozess-ID in die angegebene Datei. Der Server + läuft als Daemon und einige Distributionen wollen anhand der PID + testen, ob der FHEM Prozess läuft. Die Datei wird bei + Ausführung des "shutdown"-Kommandos gelöscht.

  • + +
  • proxy
    + IP:PORT des proxy Servers, wird von HttpUtils benutzt. +

  • + +
  • proxyExclude
    + Regexp, um bestimmte Hosts nicht via proxy zu kontaktieren. +

  • + +
  • sendStatistics
    diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 4dced4987..3e04068f5 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -308,7 +308,8 @@ my @globalAttrList = qw( nrarchive perlSyntaxCheck:0,1 pidfilename - port + proxy + proxyExclude restartDelay restoreDirs sendStatistics:onUpdate,manually,never @@ -561,14 +562,6 @@ if($pfn) { close(PID); } -my $gp = $attr{global}{port}; -if($gp) { - Log 3, "Converting 'attr global port $gp' to 'define telnetPort telnet $gp'"; - my $ret = CommandDefine(undef, "telnetPort telnet $gp"); - Log 1, "$ret" if($ret); - delete($attr{global}{port}); -} - my $sc_text = "SecurityCheck:"; $attr{global}{motd} = "$sc_text\n\n" if(!$attr{global}{motd} || $attr{global}{motd} =~ m/^$sc_text/);