mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-26 10:34:52 +00:00
HttpUtils.pm: proxy global attribute (Forum #60471)
git-svn-id: https://svn.fhem.de/fhem/trunk@15017 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b2259b20de
commit
04834553af
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# 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
|
- bugfix: 93_DbLog: V2.22.5, several fixes Forum:#75894
|
||||||
- feature: 74_GardenaSmartDevice: check character for create devicenames
|
- feature: 74_GardenaSmartDevice: check character for create devicenames
|
||||||
- bugfix: FHEM2FHEM: addStateEvent attribute (Forum #76229)
|
- bugfix: FHEM2FHEM: addStateEvent attribute (Forum #76229)
|
||||||
|
@ -78,6 +78,8 @@ HttpUtils_Close($)
|
|||||||
delete($hash->{hu_filecount});
|
delete($hash->{hu_filecount});
|
||||||
delete($hash->{hu_blocking});
|
delete($hash->{hu_blocking});
|
||||||
delete($hash->{hu_portSfx});
|
delete($hash->{hu_portSfx});
|
||||||
|
delete($hash->{hu_proxy});
|
||||||
|
delete($hash->{hu_port});
|
||||||
delete($hash->{directReadFn});
|
delete($hash->{directReadFn});
|
||||||
delete($hash->{directWriteFn});
|
delete($hash->{directWriteFn});
|
||||||
}
|
}
|
||||||
@ -291,10 +293,22 @@ HttpUtils_Connect($)
|
|||||||
$port = ($hash->{protocol} eq "https" ? 443: 80);
|
$port = ($hash->{protocol} eq "https" ? 443: 80);
|
||||||
}
|
}
|
||||||
$hash->{hu_portSfx} = ($port =~ m/^(80|443)$/ ? "" : ":$port");
|
$hash->{hu_portSfx} = ($port =~ m/^(80|443)$/ ? "" : ":$port");
|
||||||
|
$hash->{hu_port} = $port;
|
||||||
$hash->{path} = '/' unless defined($hash->{path});
|
$hash->{path} = '/' unless defined($hash->{path});
|
||||||
$hash->{addr} = "$hash->{protocol}://$host:$port";
|
$hash->{addr} = "$hash->{protocol}://$host:$port";
|
||||||
$hash->{auth} = urlDecode("$user:$pwd") if($authstring);
|
$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});
|
return HttpUtils_Connect2($hash) if($hash->{conn} && $hash->{keepalive});
|
||||||
|
|
||||||
if($hash->{callback}) { # Nonblocking staff
|
if($hash->{callback}) { # Nonblocking staff
|
||||||
@ -389,6 +403,20 @@ HttpUtils_Connect2($)
|
|||||||
return $errstr;
|
return $errstr;
|
||||||
} else {
|
} else {
|
||||||
$hash->{conn}->blocking(1);
|
$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");
|
my $sslVersion = AttrVal("global", "sslVersion", "SSLv23:!SSLv3:!SSLv2");
|
||||||
$sslVersion = AttrVal($hash->{NAME}, "sslVersion", $sslVersion)
|
$sslVersion = AttrVal($hash->{NAME}, "sslVersion", $sslVersion)
|
||||||
if($hash->{NAME});
|
if($hash->{NAME});
|
||||||
@ -453,7 +481,11 @@ HttpUtils_Connect2($)
|
|||||||
$method = ($data ? "POST" : "GET") if( !$method );
|
$method = ($data ? "POST" : "GET") if( !$method );
|
||||||
|
|
||||||
my $httpVersion = $hash->{httpversion} ? $hash->{httpversion} : "1.0";
|
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 .= "Host: $hash->{host}$hash->{hu_portSfx}\r\n";
|
||||||
$hdr .= "User-Agent: fhem\r\n"
|
$hdr .= "User-Agent: fhem\r\n"
|
||||||
if(!$hash->{header} || $hash->{header} !~ "User-Agent:");
|
if(!$hash->{header} || $hash->{header} !~ "User-Agent:");
|
||||||
|
@ -1507,7 +1507,7 @@ The following local attributes are used by a wider range of devices:
|
|||||||
Windows.
|
Windows.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
<a name="pidfilename="></a>
|
<a name="pidfilename"></a>
|
||||||
<li>pidfilename<br>
|
<li>pidfilename<br>
|
||||||
Write the process id of the perl process to the specified file. The
|
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
|
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.
|
shutdown.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
|
<a name="proxy"></a>
|
||||||
|
<li>proxy<br>
|
||||||
|
IP:PORT of the proxy server to be used by HttpUtils.
|
||||||
|
</li><br>
|
||||||
|
<a name="proxyExclude"></a>
|
||||||
|
<li>proxyExclude<br>
|
||||||
|
regexp for hosts to exclude when using a proxy
|
||||||
|
</li><br>
|
||||||
|
|
||||||
<li><a href="#fheminfo">sendStatistics</a><br>
|
<li><a href="#fheminfo">sendStatistics</a><br>
|
||||||
|
|
||||||
<a name="statefile"></a>
|
<a name="statefile"></a>
|
||||||
|
@ -1612,12 +1612,22 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
|
|
||||||
<a name="pidfilename="></a>
|
<a name="pidfilename="></a>
|
||||||
<li>pidfilename<br>
|
<li>pidfilename<br>
|
||||||
Schreibt die PERL Prozess-ID in die angegebene Datei. Der Server läuft
|
Schreibt die PERL Prozess-ID in die angegebene Datei. Der Server
|
||||||
als Daemon und einige Distributionen wollen anhand der PID testen, ob der
|
läuft als Daemon und einige Distributionen wollen anhand der PID
|
||||||
FHEM Prozess läuft. Die Datei wird bei Ausführung des "shutdown"-Kommandos
|
testen, ob der FHEM Prozess läuft. Die Datei wird bei
|
||||||
gelöscht.
|
Ausführung des "shutdown"-Kommandos gelöscht.
|
||||||
</li><br>
|
</li><br>
|
||||||
|
|
||||||
|
<a name="proxy"></a>
|
||||||
|
<li>proxy<br>
|
||||||
|
IP:PORT des proxy Servers, wird von HttpUtils benutzt.
|
||||||
|
</li><br>
|
||||||
|
<a name="proxyExclude"></a>
|
||||||
|
<li>proxyExclude<br>
|
||||||
|
Regexp, um bestimmte Hosts nicht via proxy zu kontaktieren.
|
||||||
|
</li><br>
|
||||||
|
|
||||||
|
|
||||||
<li><a href="#fheminfo">sendStatistics</a><br>
|
<li><a href="#fheminfo">sendStatistics</a><br>
|
||||||
|
|
||||||
<a name="statefile"></a>
|
<a name="statefile"></a>
|
||||||
|
11
fhem/fhem.pl
11
fhem/fhem.pl
@ -308,7 +308,8 @@ my @globalAttrList = qw(
|
|||||||
nrarchive
|
nrarchive
|
||||||
perlSyntaxCheck:0,1
|
perlSyntaxCheck:0,1
|
||||||
pidfilename
|
pidfilename
|
||||||
port
|
proxy
|
||||||
|
proxyExclude
|
||||||
restartDelay
|
restartDelay
|
||||||
restoreDirs
|
restoreDirs
|
||||||
sendStatistics:onUpdate,manually,never
|
sendStatistics:onUpdate,manually,never
|
||||||
@ -561,14 +562,6 @@ if($pfn) {
|
|||||||
close(PID);
|
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:";
|
my $sc_text = "SecurityCheck:";
|
||||||
$attr{global}{motd} = "$sc_text\n\n"
|
$attr{global}{motd} = "$sc_text\n\n"
|
||||||
if(!$attr{global}{motd} || $attr{global}{motd} =~ m/^$sc_text/);
|
if(!$attr{global}{motd} || $attr{global}{motd} =~ m/^$sc_text/);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user