auto search for cURL binary
change code style geändert: lib/FHEM/backupToStorage.pm
This commit is contained in:
parent
71941e0398
commit
9c86f35abd
@ -1,2 +1,2 @@
|
|||||||
UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm
|
UPD 2020-06-18_11:26:15 3368 FHEM/98_backupToStorage.pm
|
||||||
UPD 2020-06-18_10:42:44 15143 lib/FHEM/backupToStorage.pm
|
UPD 2020-06-18_12:29:29 15616 lib/FHEM/backupToStorage.pm
|
||||||
|
@ -155,8 +155,9 @@ sub Define {
|
|||||||
if ( scalar( @{$aArg} ) != 2 );
|
if ( scalar( @{$aArg} ) != 2 );
|
||||||
|
|
||||||
my $name = shift @$aArg;
|
my $name = shift @$aArg;
|
||||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||||
$hash->{NOTIFYDEV} = 'global,' . $name;
|
$hash->{NOTIFYDEV} = 'global,' . $name;
|
||||||
|
$hash->{STORAGETYPE} = AttrVal( $name, 'bTSType', 'Nextcloud' );
|
||||||
|
|
||||||
Log3( $name, 3, "backupToStorage ($name) - defined" );
|
Log3( $name, 3, "backupToStorage ($name) - defined" );
|
||||||
|
|
||||||
@ -328,7 +329,9 @@ sub PushToStorage {
|
|||||||
my @fileNameAtStorage_array = split( '/', $backupFile );
|
my @fileNameAtStorage_array = split( '/', $backupFile );
|
||||||
my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array];
|
my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array];
|
||||||
|
|
||||||
$subprocess->{type} = AttrVal( $name, 'bTSType', 'Nextcloud' );
|
$subprocess->{curl} = qx(which curl);
|
||||||
|
chomp($subprocess->{curl});
|
||||||
|
$subprocess->{type} = $hash->{STORAGETYPE};
|
||||||
$subprocess->{host} = AttrVal( $name, 'bTS_Host', '' );
|
$subprocess->{host} = AttrVal( $name, 'bTS_Host', '' );
|
||||||
$subprocess->{user} = AttrVal( $name, 'bTS_User', '' );
|
$subprocess->{user} = AttrVal( $name, 'bTS_User', '' );
|
||||||
$subprocess->{pass} = ReadPassword( $hash, $name );
|
$subprocess->{pass} = ReadPassword( $hash, $name );
|
||||||
@ -404,7 +407,12 @@ sub FileUpload {
|
|||||||
my $response = {};
|
my $response = {};
|
||||||
|
|
||||||
if ( $subprocess->{type} eq 'Nextcloud' ) {
|
if ( $subprocess->{type} eq 'Nextcloud' ) {
|
||||||
$response->{ncUpload} = ExecuteNCupload($subprocess);
|
my ($returnString,$returnCode) = ExecuteNCupload($subprocess);
|
||||||
|
|
||||||
|
$response->{ncUpload} = ( $returnCode == 72057594037927935
|
||||||
|
&& $returnString eq ''
|
||||||
|
? 'upload successfully'
|
||||||
|
: $returnString );
|
||||||
}
|
}
|
||||||
|
|
||||||
my $json = eval { encode_json($response) };
|
my $json = eval { encode_json($response) };
|
||||||
@ -422,7 +430,8 @@ sub FileUpload {
|
|||||||
sub ExecuteNCupload {
|
sub ExecuteNCupload {
|
||||||
my $subprocess = shift;
|
my $subprocess = shift;
|
||||||
|
|
||||||
my $command = 'curl -u ';
|
my $command = $subprocess->{curl};
|
||||||
|
$command .= ' -s -u ';
|
||||||
$command .= $subprocess->{user} . ':' . $subprocess->{pass};
|
$command .= $subprocess->{user} . ':' . $subprocess->{pass};
|
||||||
$command .= ' -T ' . $subprocess->{backupfile};
|
$command .= ' -T ' . $subprocess->{backupfile};
|
||||||
$command .= ' "https://';
|
$command .= ' "https://';
|
||||||
@ -433,10 +442,13 @@ sub ExecuteNCupload {
|
|||||||
$command .= '/';
|
$command .= '/';
|
||||||
$command .= $subprocess->{fileNameAtStorage};
|
$command .= $subprocess->{fileNameAtStorage};
|
||||||
$command .= '"';
|
$command .= '"';
|
||||||
|
|
||||||
print 'DEBUG!!! - Command: ' . $command . "\n";
|
|
||||||
|
|
||||||
return qx{$command};
|
return ExecuteCommand($command);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub ExecuteCommand {
|
||||||
|
my $command = join q{ }, @_;
|
||||||
|
return ( $_ = qx{$command 2>&1}, $? >> 8 );
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
@ -546,15 +558,18 @@ sub CheckAttributsForCredentials {
|
|||||||
my $ncUser = AttrVal( $name, 'bTS_User', 'none' );
|
my $ncUser = AttrVal( $name, 'bTS_User', 'none' );
|
||||||
my $ncPass = ReadPassword( $hash, $name );
|
my $ncPass = ReadPassword( $hash, $name );
|
||||||
my $ncHost = AttrVal( $name, 'bTS_Host', 'none' );
|
my $ncHost = AttrVal( $name, 'bTS_Host', 'none' );
|
||||||
my $ncPath = AttrVal( $name, 'bTS_Path', 'none' );
|
|
||||||
my $status = 'ready';
|
my $status = 'ready';
|
||||||
|
|
||||||
$status = (
|
$status = ( $status eq 'ready'
|
||||||
$status eq 'ready' && $ncUser eq 'none' ? 'no user credential attribut'
|
&& $ncUser eq 'none'
|
||||||
: $status eq 'ready'
|
? 'no user credential attribut'
|
||||||
&& $ncHost eq 'none' ? 'no host credential attribut'
|
: $status eq 'ready'
|
||||||
: $status eq 'ready' && !defined($ncPass) ? 'no password set'
|
&& $ncHost eq 'none'
|
||||||
: $status
|
? 'no host credential attribut'
|
||||||
|
: $status eq 'ready'
|
||||||
|
&& !defined($ncPass)
|
||||||
|
? 'no password set'
|
||||||
|
: $status
|
||||||
);
|
);
|
||||||
|
|
||||||
return readingsSingleUpdate( $hash, 'state', $status, 1 );
|
return readingsSingleUpdate( $hash, 'state', $status, 1 );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user