change code style
add new functions to handling password and password container add rename function
This commit is contained in:
parent
f0de2c5605
commit
5b3ee18585
@ -6,7 +6,7 @@
|
|||||||
# All rights reserved
|
# All rights reserved
|
||||||
#
|
#
|
||||||
# Special thanks goes to:
|
# Special thanks goes to:
|
||||||
# -
|
# -
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# This script is free software; you can redistribute it and/or modify
|
# This script is free software; you can redistribute it and/or modify
|
||||||
@ -53,6 +53,9 @@ BEGIN {
|
|||||||
readingsEndUpdate
|
readingsEndUpdate
|
||||||
defs
|
defs
|
||||||
modules
|
modules
|
||||||
|
setKeyValue
|
||||||
|
getKeyValue
|
||||||
|
getUniqueId
|
||||||
Log3
|
Log3
|
||||||
CommandAttr
|
CommandAttr
|
||||||
attr
|
attr
|
||||||
@ -80,6 +83,12 @@ sub Define {
|
|||||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||||
$hash->{NOTIFYDEV} = 'global';
|
$hash->{NOTIFYDEV} = 'global';
|
||||||
|
|
||||||
|
readingsSingleUpdate( $hash, 'state',
|
||||||
|
'please set storage account credentials first', 1 )
|
||||||
|
if ( AttrVal( $name, 'bTS_Host', 'none' ) eq 'none'
|
||||||
|
|| AttrVal( $name, 'bTS_User', 'none' ) eq 'none'
|
||||||
|
|| !defined( ReadPassword( $hash, $name ) ) );
|
||||||
|
|
||||||
Log3( $name, 3, "backupToStorage ($name) - defined" );
|
Log3( $name, 3, "backupToStorage ($name) - defined" );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -113,22 +122,12 @@ sub Notify {
|
|||||||
. Dumper $events); # mit Dumper
|
. Dumper $events); # mit Dumper
|
||||||
|
|
||||||
PushToStorage($hash)
|
PushToStorage($hash)
|
||||||
if (
|
if ( grep /^backup.done/,
|
||||||
(
|
@{$events} && $devname eq 'global' && $init_done );
|
||||||
grep /^backup.done/,
|
|
||||||
@{$events}
|
|
||||||
and $devname eq 'global'
|
|
||||||
&& $init_done)
|
|
||||||
)
|
|
||||||
and defined( $hash->{UID} )
|
|
||||||
);
|
|
||||||
|
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub Set {
|
sub Set {
|
||||||
my $hash = shift // return;
|
my $hash = shift // return;
|
||||||
my $aArg = shift // return;
|
my $aArg = shift // return;
|
||||||
@ -138,6 +137,8 @@ sub Set {
|
|||||||
// return qq{"set $name" needs at least one argument};
|
// return qq{"set $name" needs at least one argument};
|
||||||
|
|
||||||
if ( lc $cmd eq 'addpassword' ) {
|
if ( lc $cmd eq 'addpassword' ) {
|
||||||
|
return "please set Attribut bTS_User first"
|
||||||
|
if ( AttrVal( $name, 'bTS_User', 'none' ) eq 'none' );
|
||||||
return "usage: $cmd <password>" if ( scalar( @{$aArg} ) != 1 );
|
return "usage: $cmd <password>" if ( scalar( @{$aArg} ) != 1 );
|
||||||
|
|
||||||
StorePassword( $hash, $name, $aArg->[0] );
|
StorePassword( $hash, $name, $aArg->[0] );
|
||||||
@ -148,22 +149,18 @@ sub Set {
|
|||||||
DeletePassword($hash);
|
DeletePassword($hash);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 'Unknown argument '
|
return 'Unknown argument ' . $cmd
|
||||||
. $cmd
|
. ', choose one of addpassword,deletepassword';
|
||||||
. ', choose one of addpassword,deletepassword';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub PushToStorage {
|
sub PushToStorage {
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,14 +207,12 @@ sub ReadPassword {
|
|||||||
if ( defined($err) ) {
|
if ( defined($err) ) {
|
||||||
|
|
||||||
Log3 $name, 3,
|
Log3 $name, 3,
|
||||||
"backupToStorage ($name) - unable to read password from file: $err";
|
"backupToStorage ($name) - unable to read password from file: $err";
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined($password) ) {
|
if ( defined($password) ) {
|
||||||
if ( eval "use Digest::MD5;1" ) {
|
if ( eval "use Digest::MD5;1" ) {
|
||||||
|
|
||||||
$key = Digest::MD5::md5_hex( unpack "H*", $key );
|
$key = Digest::MD5::md5_hex( unpack "H*", $key );
|
||||||
$key .= Digest::MD5::md5_hex($key);
|
$key .= Digest::MD5::md5_hex($key);
|
||||||
}
|
}
|
||||||
@ -232,10 +227,8 @@ sub ReadPassword {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $dec_pwd;
|
return $dec_pwd;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Log3 $name, 3, "backupToStorage ($name) - No password in file";
|
Log3 $name, 3, "backupToStorage ($name) - No password in file";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user