2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 04:36:36 +00:00

FB_checkPw with user

git-svn-id: https://svn.fhem.de/fhem/trunk@2691 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-02-11 20:30:13 +00:00
parent 672d1ba411
commit 69c4f826d0
4 changed files with 31 additions and 13 deletions

View File

@ -71,6 +71,7 @@
- feature: userReadings
- feature: average supports more than one value in combined readings (T:x H:y)
- feature: FHEMWEB serves arbitrary files from the www directory
- feature: FB_checkPw now works with a distinct fritzbox user
- 2012-10-28 (5.3)

View File

@ -2906,10 +2906,12 @@ FW_htmlEscape($)
Example:<br>
<code>
attr WEB basicAuth { "$user:$password" eq "admin:secret" }<br>
attr WEB basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$password") }
attr WEB basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$password") }<br>
</code>
or if you defined multiple users on the Fritzbox:<br>
<code>
attr WEB basicAuth {use FritzBoxUtils;;FB_checkPw("localhost","$user", "$password") }<br>
</code>
</li><br>
<a name="HTTPS"></a>

View File

@ -374,7 +374,11 @@ telnet_Undef($$)
Example:<br>
<code>
attr tPort password secret<br>
attr tPort password {use FritzBoxUtils;;FB_checkPw("localhost","$password") }
attr tPort password {use FritzBoxUtils;;FB_checkPw("localhost","$password") }<br>
</code>
or if you defined multiple users on the Fritzbox:<br>
<code>
attr tPort password {use FritzBoxUtils;;FB_checkPw("localhost","$user", "$password") }<br>
</code>
</li><br>

View File

@ -7,12 +7,14 @@ use warnings;
use Digest::MD5 "md5_hex";
use HttpUtils;
my ($lastOkPw, $lastOkHost, $lastOkTime) =("", "", 0);
my ($lastOkPw, $lastOkUser, $lastOkHost, $lastOkTime) =("", "", 0);
sub FB_checkPw(@);
sub
FB_doCheckPW($$)
FB_doCheckPW($$$)
{
my ($host, $pw) = @_;
my ($host, $user, $pw) = @_;
my $data = GetFileFromURL("http://$host/login_sid.lua", undef, undef, 1);
return undef if(!$data);
@ -33,7 +35,10 @@ FB_doCheckPW($$)
} else { # FritzOS >= 5.50
my @d = ( "response=$chlAnsw", "page=/login_sid.lua" );
$data = join("&", map {join("=", map {urlEncode($_)} split("=",$_,2))} @d);
$data = GetFileFromURL("http://$host/login_sid.lua", undef, $data, 1);
my $url = "http://$host/login_sid.lua";
$url .= "?username=$user" if($user);
$data = GetFileFromURL($url, undef, $data, 1);
my $sid = $1 if($data =~ /<SID>(\w+)<\/SID>/i);
$sid = undef if($sid =~ m/^0*$/);
return $sid;
@ -41,16 +46,22 @@ FB_doCheckPW($$)
}
sub
FB_checkPw($$)
FB_checkPw(@)
{
my ($host, $pw) = @_;
my ($host, $p1, $p2) = @_;
my $user = ($p2 ? $p1 : ""); # Compatibility mode: no user parameter
my $pw = ($p2 ? $p2 : $p1);
my $now = time();
return 1 if($lastOkPw eq $pw && $lastOkHost eq $host &&
return 1 if($lastOkPw eq $pw &&
$lastOkUser eq $user &&
$lastOkHost eq $host &&
($now - $lastOkTime) < 300); # 5min cache
if(FB_doCheckPW($host, $pw)) {
$lastOkPw = $pw;
if(FB_doCheckPW($host, $user, $pw)) {
$lastOkPw = $pw;
$lastOkUser = $user;
$lastOkTime = $now;
$lastOkHost = $host;
return 1;