mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_GoogleAuth.pm: rework code to use own package
git-svn-id: https://svn.fhem.de/fhem/trunk@23618 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
87cef8d564
commit
f9738d6bc4
@ -70,9 +70,14 @@
|
|||||||
# 2017-01-16 - added: attributes ga_showQR, ga_strictCheck
|
# 2017-01-16 - added: attributes ga_showQR, ga_strictCheck
|
||||||
# removed: FW_summaryFn (not really useful)
|
# removed: FW_summaryFn (not really useful)
|
||||||
#
|
#
|
||||||
|
# 2020-03-31 - changed: remove prototyping and undef results
|
||||||
|
#
|
||||||
|
# 2021-01-26 - changed: rework code to use own package
|
||||||
|
#
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
package main;
|
package FHEM::GoogleAuth; ## no critic
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
@ -81,15 +86,37 @@ use Authen::OATH;
|
|||||||
use URI::Escape;
|
use URI::Escape;
|
||||||
use Crypt::URandom qw( urandom );
|
use Crypt::URandom qw( urandom );
|
||||||
|
|
||||||
|
use GPUtils qw(GP_Import GP_Export);
|
||||||
|
|
||||||
sub GoogleAuth_Initialize {
|
## Import der FHEM Funktionen
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
# Import from main context
|
||||||
|
GP_Import(
|
||||||
|
qw( AttrVal
|
||||||
|
Debug
|
||||||
|
Log3
|
||||||
|
defs
|
||||||
|
readingFnAttributes
|
||||||
|
readingsSingleUpdate
|
||||||
|
setKeyValue
|
||||||
|
getKeyValue )
|
||||||
|
);
|
||||||
|
|
||||||
|
#-- Export to main context with different name
|
||||||
|
GP_Export(
|
||||||
|
qw( Initialize )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Initialize {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{DefFn} = "GoogleAuth_Define";
|
$hash->{DefFn} = \&Define;
|
||||||
$hash->{DeleteFn} = "GoogleAuth_Delete";
|
$hash->{DeleteFn} = \&Delete;
|
||||||
$hash->{SetFn} = "GoogleAuth_Set";
|
$hash->{SetFn} = \&Set;
|
||||||
$hash->{GetFn} = "GoogleAuth_Get";
|
$hash->{GetFn} = \&Get;
|
||||||
$hash->{FW_detailFn} = "GoogleAuth_Detail";
|
$hash->{FW_detailFn} = \&Detail;
|
||||||
|
|
||||||
$hash->{AttrList} = "ga_labelName ".
|
$hash->{AttrList} = "ga_labelName ".
|
||||||
"ga_qrSize:100x100,200x200,300x300,400x400 ".
|
"ga_qrSize:100x100,200x200,300x300,400x400 ".
|
||||||
@ -98,7 +125,7 @@ sub GoogleAuth_Initialize {
|
|||||||
"$readingFnAttributes";
|
"$readingFnAttributes";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Define {
|
sub 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);
|
||||||
@ -109,12 +136,12 @@ sub GoogleAuth_Define {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Delete {
|
sub Delete {
|
||||||
my ($hash,$name) = @_;
|
my ($hash,$name) = @_;
|
||||||
setKeyValue("googleAuth$name",undef);
|
setKeyValue("googleAuth$name",undef);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Set {
|
sub Set {
|
||||||
my ($hash, $name, $cmd, @args) = @_;
|
my ($hash, $name, $cmd, @args) = @_;
|
||||||
my $usage = "Unknown argument, choose one of new:noArg revoke:noArg";
|
my $usage = "Unknown argument, choose one of new:noArg revoke:noArg";
|
||||||
|
|
||||||
@ -136,7 +163,7 @@ sub GoogleAuth_Set {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Get {
|
sub Get {
|
||||||
my ($hash, $name, $cmd, $given_token) = @_;
|
my ($hash, $name, $cmd, $given_token) = @_;
|
||||||
my $usage = "Unknown argument, choose one of check";
|
my $usage = "Unknown argument, choose one of check";
|
||||||
|
|
||||||
@ -167,7 +194,7 @@ sub GoogleAuth_Get {
|
|||||||
return $usage;
|
return $usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GoogleAuth_Detail {
|
sub Detail {
|
||||||
my ($FW_wname, $name, $room, $pageHash) = @_;
|
my ($FW_wname, $name, $room, $pageHash) = @_;
|
||||||
my $qr_url = _ga_make_url($name);
|
my $qr_url = _ga_make_url($name);
|
||||||
my $secret_base32 = getKeyValue("googleAuth$name"); # read from fhem keystore
|
my $secret_base32 = getKeyValue("googleAuth$name"); # read from fhem keystore
|
||||||
@ -209,9 +236,12 @@ sub _ga_make_token_6 {
|
|||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package main;
|
||||||
|
|
||||||
sub gAuth {
|
sub gAuth {
|
||||||
my($name,$token) = @_;
|
my($name,$token) = @_;
|
||||||
return CommandGet(undef,"$name check $token");
|
my $myHash = $defs{$name};
|
||||||
|
return FHEM::GoogleAuth::Get($myHash,$name,'check',$token);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user