mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-29 23:47:10 +00:00
98_GoogleAuth.pm: under development
- FW_detailFn added - code cleanup git-svn-id: https://svn.fhem.de/fhem/trunk@13075 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9d0ae31080
commit
a595ae8720
@ -16,43 +16,26 @@ sub GoogleAuth_Initialize($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{DefFn} = "GoogleAuth_Define";
|
$hash->{DefFn} = "GoogleAuth_Define";
|
||||||
$hash->{UndefFn} = "GoogleAuth_Undefine";
|
|
||||||
$hash->{DeleteFn} = "GoogleAuth_Delete";
|
$hash->{DeleteFn} = "GoogleAuth_Delete";
|
||||||
$hash->{SetFn} = "GoogleAuth_Set";
|
$hash->{SetFn} = "GoogleAuth_Set";
|
||||||
$hash->{GetFn} = "GoogleAuth_Get";
|
$hash->{GetFn} = "GoogleAuth_Get";
|
||||||
$hash->{detailFn} = "GoogleAuth_Detail";
|
$hash->{FW_detailFn} = "GoogleAuth_Detail";
|
||||||
# $hash->{AttrFn} = "GoogleAuth_Attr";
|
# $hash->{AttrFn} = "GoogleAuth_Attr";
|
||||||
$hash->{AttrList} = "ga_qrsize ".
|
$hash->{AttrList} = "ga_qrsize ".
|
||||||
"$readingFnAttributes";
|
"$readingFnAttributes";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Detail {
|
|
||||||
#Debug "detailFn called";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub GoogleAuth_Define($$) {
|
sub GoogleAuth_Define($$) {
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
return "Usage: Use Google Authenticator" if(@a != 2);
|
return "Usage: Use Google Authenticator" if(@a != 2);
|
||||||
|
|
||||||
## ich würde keine Prüfung auf bereits vorhandene GA machen,
|
|
||||||
## es kann durchaus Fälle geben, in denen man mehr als 1 Schlüssel definieren möchte
|
|
||||||
|
|
||||||
# my $d = $modules{$hash->{TYPE}}{defptr};
|
|
||||||
# return "$hash->{TYPE} device already defined as $d->{NAME}." if( defined($d) );
|
|
||||||
Log3($hash,4,"googleAuth $name: defined");
|
Log3($hash,4,"googleAuth $name: defined");
|
||||||
readingsSingleUpdate($hash,'state','defined',1);
|
readingsSingleUpdate($hash,'state','defined',1);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Undefine($$) {
|
|
||||||
my ($hash, $arg) = @_;
|
|
||||||
delete $modules{$hash->{TYPE}}{defptr};
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub GoogleAuth_Delete() {
|
sub GoogleAuth_Delete() {
|
||||||
my ($hash, $arg) = @_;
|
my ($hash, $arg) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -73,15 +56,13 @@ sub GoogleAuth_Set($$@) {
|
|||||||
setKeyValue("googleAuth$name",$secret_base32); # write to fhem keystore
|
setKeyValue("googleAuth$name",$secret_base32); # write to fhem keystore
|
||||||
|
|
||||||
my $label = "FHEM%20Authentication%20$name";
|
my $label = "FHEM%20Authentication%20$name";
|
||||||
my $qrsize = AttrVal("$name",'ga_qrsize','200x200');
|
my $qrsize = AttrVal($name,'ga_qrsize','200x200');
|
||||||
my $url = "otpauth://totp/$label?secret=$secret_base32";
|
my $url = "otpauth://totp/$label?secret=$secret_base32";
|
||||||
my $qr_url = "https://chart.googleapis.com/chart?cht=qr&chs=$qrsize"."&chl=".uri_escape($url);
|
my $qr_url = "https://chart.googleapis.com/chart?cht=qr&chs=$qrsize"."&chl=".uri_escape($url);
|
||||||
|
|
||||||
readingsSingleUpdate($hash,'qr_url',$qr_url,1);
|
readingsSingleUpdate($hash,'qr_url',$qr_url,0);
|
||||||
my $ret = "<html><a href=\"$qr_url\"><img src=\"$qr_url\" ><\/a></html>";
|
readingsSingleUpdate($hash,'state','active',1);
|
||||||
return $ret;
|
return undef;
|
||||||
;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $usage;
|
return $usage;
|
||||||
}
|
}
|
||||||
@ -113,6 +94,18 @@ sub GoogleAuth_Get($$@) {
|
|||||||
return $usage;
|
return $usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub GoogleAuth_Detail($@) {
|
||||||
|
my ($FW_wname, $d, $room, $pageHash) = @_;
|
||||||
|
my $qr_url = ReadingsVal($d,'qr_url',undef);
|
||||||
|
return unless defined($qr_url);
|
||||||
|
my $ret = "<a href=\"$qr_url\"><img src=\"$qr_url\"><\/a><br>";
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# helper functions
|
||||||
|
|
||||||
sub _ga_make_token_6($) {
|
sub _ga_make_token_6($) {
|
||||||
my $token = shift;
|
my $token = shift;
|
||||||
while (length $token < 6) {
|
while (length $token < 6) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user