Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
bdf9052535 | |||
6c715e9b5d | |||
48758f31ab | |||
631be8174f | |||
6d01e89d5b | |||
2692c1bceb | |||
a07173e5a9 | |||
08a76d09a8 | |||
da3582fb1e | |||
cbca8d4337 | |||
ec4e32d2fb | |||
f0da4a3e70 | |||
c897299103 | |||
4cd8b0ecea | |||
c28ae2e245 | |||
7ae03846bf | |||
1f3ab13b0c | |||
0e1468a032 | |||
37673b2da1 | |||
914c08850e | |||
c408ff36a2 | |||
b02ce13d59 | |||
674e9dce8f | |||
138ee2145f | |||
6dde3f7152 | |||
8460bc4a3e | |||
dc0c072ab5 | |||
16f8bdbce8 | |||
89b9d579c5 | |||
8f8e306e85 | |||
1a0553b92d | |||
d9bb3c4729 | |||
a5084429b0 | |||
18801f0a8f | |||
2aa7914642 | |||
57d95d6141 |
@ -34,6 +34,7 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
|
use FHEM::Meta;
|
||||||
|
|
||||||
use FHEM::backupToStorage;
|
use FHEM::backupToStorage;
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ sub backupToStorage_Initialize {
|
|||||||
$hash->{DefFn} = \&FHEM::backupToStorage::Define;
|
$hash->{DefFn} = \&FHEM::backupToStorage::Define;
|
||||||
$hash->{NotifyFn} = \&FHEM::backupToStorage::Notify;
|
$hash->{NotifyFn} = \&FHEM::backupToStorage::Notify;
|
||||||
$hash->{UndefFn} = \&FHEM::backupToStorage::Undef;
|
$hash->{UndefFn} = \&FHEM::backupToStorage::Undef;
|
||||||
|
$hash->{AttrFn} = \&FHEM::backupToStorage::Attr;
|
||||||
$hash->{RenameFn} = \&FHEM::backupToStorage::Rename;
|
$hash->{RenameFn} = \&FHEM::backupToStorage::Rename;
|
||||||
$hash->{DeleteFn} = \&FHEM::backupToStorage::Delete;
|
$hash->{DeleteFn} = \&FHEM::backupToStorage::Delete;
|
||||||
$hash->{ShutdownFn} = \&FHEM::backupToStorage::Shutdown;
|
$hash->{ShutdownFn} = \&FHEM::backupToStorage::Shutdown;
|
||||||
@ -54,7 +56,10 @@ sub backupToStorage_Initialize {
|
|||||||
'bTS_Host '
|
'bTS_Host '
|
||||||
. 'bTS_User '
|
. 'bTS_User '
|
||||||
. 'bTS_Path '
|
. 'bTS_Path '
|
||||||
. 'bTS_Type:Nextcloud';
|
. 'bTS_Proto:http '
|
||||||
|
. 'bTS_Type:Nextcloud,SynologyFileStation '
|
||||||
|
. 'disable:1 '
|
||||||
|
. 'disabledForIntervals';
|
||||||
$hash->{parseParams} = 1;
|
$hash->{parseParams} = 1;
|
||||||
|
|
||||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||||
@ -174,7 +179,7 @@ sub backupToStorage_Initialize {
|
|||||||
],
|
],
|
||||||
"release_status": "devepolment",
|
"release_status": "devepolment",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v1.0.0",
|
"version": "v1.2.3",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <fhemsupport@cooltux.net>"
|
"Marko Oldenburg <fhemsupport@cooltux.net>"
|
||||||
],
|
],
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
UPD 2020-06-19_08:28:14 6090 FHEM/98_backupToStorage.pm
|
UPD 2021-01-04_14:37:28 6262 FHEM/98_backupToStorage.pm
|
||||||
UPD 2020-06-19_07:55:06 15635 lib/FHEM/backupToStorage.pm
|
UPD 2021-01-04_14:53:20 19356 lib/FHEM/backupToStorage.pm
|
||||||
|
39
hooks/pre-commit
Executable file
39
hooks/pre-commit
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
use File::Basename;
|
||||||
|
use POSIX qw(strftime);
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
my @filenames = ( 'FHEM/98_backupToStorage.pm',
|
||||||
|
'lib/FHEM/backupToStorage.pm',
|
||||||
|
);
|
||||||
|
|
||||||
|
my $controlsfile = 'controls_backupToStorage.txt';
|
||||||
|
|
||||||
|
open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!");
|
||||||
|
|
||||||
|
for my $filename (@filenames) {
|
||||||
|
my @statOutput = stat($filename);
|
||||||
|
|
||||||
|
if (scalar @statOutput != 13) {
|
||||||
|
printf 'error: stat has unexpected return value for ' . $filename . "\n";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $mtime = $statOutput[9];
|
||||||
|
my $date = POSIX::strftime("%Y-%m-%d", localtime($mtime));
|
||||||
|
my $time = POSIX::strftime("%H:%M:%S", localtime($mtime));
|
||||||
|
my $filetime = $date."_".$time;
|
||||||
|
|
||||||
|
my $filesize = $statOutput[7];
|
||||||
|
|
||||||
|
printf FH 'UPD ' . $filetime . ' ' . $filesize . ' ' .$filename . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
close(FH);
|
||||||
|
|
||||||
|
system("git add $controlsfile");
|
||||||
|
|
||||||
|
print 'Create controls File succesfully' . "\n";
|
||||||
|
|
||||||
|
exit 0;
|
@ -122,10 +122,12 @@ BEGIN {
|
|||||||
readingsBeginUpdate
|
readingsBeginUpdate
|
||||||
readingsEndUpdate
|
readingsEndUpdate
|
||||||
ReadingsVal
|
ReadingsVal
|
||||||
|
ReadingsAge
|
||||||
gettimeofday
|
gettimeofday
|
||||||
InternalTimer
|
InternalTimer
|
||||||
defs
|
defs
|
||||||
modules
|
modules
|
||||||
|
IsDisabled
|
||||||
setKeyValue
|
setKeyValue
|
||||||
getKeyValue
|
getKeyValue
|
||||||
getUniqueId
|
getUniqueId
|
||||||
@ -148,10 +150,10 @@ sub Define {
|
|||||||
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
||||||
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
||||||
|
|
||||||
return 'only one backupToStorage instance allowed'
|
return qq{only one backupToStorage instance allowed}
|
||||||
if ( devspec2array('TYPE=backupToStorage') > 1 )
|
if ( devspec2array('TYPE=backupToStorage') > 1 )
|
||||||
; # es wird geprüft ob bereits eine Instanz unseres Modules existiert,wenn ja wird abgebrochen
|
; # es wird geprüft ob bereits eine Instanz unseres Modules existiert,wenn ja wird abgebrochen
|
||||||
return 'too few parameters: define <name> backupToStorage'
|
return qq{too few parameters: define <name> backupToStorage}
|
||||||
if ( scalar( @{$aArg} ) != 2 );
|
if ( scalar( @{$aArg} ) != 2 );
|
||||||
|
|
||||||
my $name = shift @$aArg;
|
my $name = shift @$aArg;
|
||||||
@ -159,7 +161,7 @@ sub Define {
|
|||||||
$hash->{NOTIFYDEV} = 'global,' . $name;
|
$hash->{NOTIFYDEV} = 'global,' . $name;
|
||||||
$hash->{STORAGETYPE} = AttrVal( $name, 'bTS_Type', 'Nextcloud' );
|
$hash->{STORAGETYPE} = AttrVal( $name, 'bTS_Type', 'Nextcloud' );
|
||||||
|
|
||||||
Log3( $name, 3, "backupToStorage ($name) - defined" );
|
Log3( $name, 3, qq{backupToStorage ($name) - defined} );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -168,7 +170,7 @@ sub Undef {
|
|||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
|
|
||||||
Log3( $name, 3, "backupToStorage ($name) - delete device $name" );
|
Log3( $name, 3, qq{backupToStorage ($name) - delete device $name} );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -201,15 +203,31 @@ sub Notify {
|
|||||||
my $devname = $dev->{NAME};
|
my $devname = $dev->{NAME};
|
||||||
my $devtype = $dev->{TYPE};
|
my $devtype = $dev->{TYPE};
|
||||||
my $events = deviceEvents( $dev, 1 );
|
my $events = deviceEvents( $dev, 1 );
|
||||||
return if ( !$events );
|
|
||||||
|
_CheckIsDisabledAfterSetAttr($hash)
|
||||||
|
if ( (
|
||||||
|
(
|
||||||
|
grep m{^DELETEATTR.$name.(disable|disabledForIntervals)$}xms,
|
||||||
|
@{$events}
|
||||||
|
or grep m{^ATTR.$name.(disable|disabledForIntervals).\S+$}xms,
|
||||||
|
@{$events}
|
||||||
|
)
|
||||||
|
&& $devname eq 'global'
|
||||||
|
&& $init_done
|
||||||
|
)
|
||||||
|
|| $devname eq $name
|
||||||
|
);
|
||||||
|
|
||||||
|
return if ( !$events
|
||||||
|
|| IsDisabled($name) );
|
||||||
|
|
||||||
|
|
||||||
Log3( $name, 4,
|
Log3( $name, 4,
|
||||||
"AutoShuttersControl ($name) - Devname: "
|
qq{backupToStorage ($name) -
|
||||||
. $devname
|
Devname: $devname
|
||||||
. " Name: "
|
Name: $name
|
||||||
. $name
|
Notify: } . Dumper $events
|
||||||
. " Notify: "
|
); # mit Dumper
|
||||||
. Dumper $events); # mit Dumper
|
|
||||||
|
|
||||||
PushToStorage($hash)
|
PushToStorage($hash)
|
||||||
if ( ( grep m{^backup.done(.+)?$}xms, @{$events} )
|
if ( ( grep m{^backup.done(.+)?$}xms, @{$events} )
|
||||||
@ -275,33 +293,93 @@ sub Set {
|
|||||||
|
|
||||||
my $name = shift @$aArg;
|
my $name = shift @$aArg;
|
||||||
my $cmd = shift @$aArg
|
my $cmd = shift @$aArg
|
||||||
// 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"
|
return qq{please set Attribut bTS_User first}
|
||||||
if ( AttrVal( $name, 'bTS_User', 'none' ) eq 'none' );
|
if ( AttrVal( $name, 'bTS_User', 'none' ) eq 'none' );
|
||||||
return "usage: $cmd <password>" if ( scalar( @{$aArg} ) != 1 );
|
return qq{usage: "$cmd" <password>} if ( scalar( @{$aArg} ) != 1 );
|
||||||
|
|
||||||
StorePassword( $hash, $name, $aArg->[0] );
|
StorePassword( $hash, $name, $aArg->[0] );
|
||||||
}
|
}
|
||||||
elsif ( lc $cmd eq 'deletepassword' ) {
|
elsif ( lc $cmd eq 'deletepassword' ) {
|
||||||
return "usage: $cmd" if ( scalar( @{$aArg} ) != 0 );
|
return qq{usage: $cmd} if ( scalar( @{$aArg} ) != 0 );
|
||||||
|
|
||||||
DeletePassword($hash);
|
DeletePassword($hash);
|
||||||
}
|
}
|
||||||
|
elsif ( lc $cmd eq 'active' ) {
|
||||||
|
return qq{usage: $cmd} if ( scalar( @{$aArg} ) != 0 );
|
||||||
|
|
||||||
|
readingsSingleUpdate( $hash, 'state', 'ready', 1 );
|
||||||
|
}
|
||||||
|
elsif ( lc $cmd eq 'inactive' ) {
|
||||||
|
return qq{usage: $cmd} if ( scalar( @{$aArg} ) != 0 );
|
||||||
|
|
||||||
|
readingsSingleUpdate( $hash, 'state', $cmd, 1 );
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
my $list = (
|
my $list = 'active:noArg inactive:noArg';
|
||||||
defined( ReadPassword( $hash, $name ) )
|
$list .= (
|
||||||
? 'deletepassword:noArg'
|
defined( ReadPassword( $hash, $name ) )
|
||||||
: 'addpassword'
|
? ' deletepassword:noArg'
|
||||||
);
|
: ' addpassword'
|
||||||
|
);
|
||||||
|
|
||||||
return 'Unknown argument ' . $cmd . ', choose one of ' . $list;
|
return qq{Unknown argument "$cmd", choose one of $list};
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub Attr {
|
||||||
|
my $cmd = shift;
|
||||||
|
my $name = shift;
|
||||||
|
|
||||||
|
my $hash = $defs{$name};
|
||||||
|
my $attrName = shift;
|
||||||
|
my $attrVal = shift;
|
||||||
|
|
||||||
|
|
||||||
|
if ( $attrName eq 'disable'
|
||||||
|
|| $attrName eq 'disabledForIntervals' ) {
|
||||||
|
|
||||||
|
if ( $cmd eq 'set' ) {
|
||||||
|
if ( $attrName eq 'disabledForIntervals' ) {
|
||||||
|
return
|
||||||
|
'check disabledForIntervals Syntax HH:MM-HH:MM or HH:MM-HH:MM HH:MM-HH:MM ...'
|
||||||
|
if ( $attrVal !~ /^((\d{2}:\d{2})-(\d{2}:\d{2})\s?)+$/ );
|
||||||
|
Log3( $name, 3, qq{backupToStorage ($name) - disabledForIntervals} );
|
||||||
|
}
|
||||||
|
elsif ( $attrName eq 'disable' ) {
|
||||||
|
Log3( $name, 3, qq{backupToStorage ($name) - disabled} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalTimer( gettimeofday() + 1,
|
||||||
|
'FHEM::backupToStorage::_CheckIsDisabledAfterSetAttr', $hash, 0 );
|
||||||
|
}
|
||||||
|
elsif ( $attrName eq 'bTS_Type' ) {
|
||||||
|
InternalTimer( gettimeofday() + 1,
|
||||||
|
sub { $hash->{STORAGETYPE} = AttrVal($name,'bTS_Type','Nextcloud'); }, $hash, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _CheckIsDisabledAfterSetAttr {
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $state = ( IsDisabled($name)
|
||||||
|
? 'inactive'
|
||||||
|
: 'ready' );
|
||||||
|
|
||||||
|
Log3( $name, 3, qq{backupToStorage ($name) - _CheckIsDisabledAfterSetAttr} );
|
||||||
|
|
||||||
|
readingsSingleUpdate($hash, 'state', $state, 1)
|
||||||
|
if ( ReadingsVal($name, 'state', 'ready' ) ne $state );
|
||||||
|
}
|
||||||
|
|
||||||
sub Rename {
|
sub Rename {
|
||||||
my $new = shift;
|
my $new = shift;
|
||||||
my $old = shift;
|
my $old = shift;
|
||||||
@ -319,50 +397,65 @@ sub PushToStorage {
|
|||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
Log3( $name, 4, "backupToStorage ($name) - push to storage function" );
|
Log3( $name, 4, qq{backupToStorage ($name) - push to storage function} );
|
||||||
|
|
||||||
|
return
|
||||||
|
if ( ReadingsAge($name,'fhemBackupFile',1) > 180 );
|
||||||
|
|
||||||
|
Log3( $name, 4, qq{backupToStorage ($name) - after readings age return} );
|
||||||
|
|
||||||
require "SubProcess.pm";
|
|
||||||
my $subprocess = SubProcess->new( { onRun => \&FileUpload } );
|
|
||||||
|
|
||||||
my $backupFile = ReadingsVal( $name, 'fhemBackupFile', 'none' );
|
if ( $hash->{STORAGETYPE} eq 'SynologyFileStation' ) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
require "SubProcess.pm";
|
||||||
|
my $subprocess = SubProcess->new( { onRun => \&FileUpload } );
|
||||||
|
|
||||||
my @fileNameAtStorage_array = split( '/', $backupFile );
|
my $backupFile = ReadingsVal( $name, 'fhemBackupFile', 'none' );
|
||||||
my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array];
|
|
||||||
|
|
||||||
$subprocess->{curl} = qx(which curl);
|
my @fileNameAtStorage_array = split( '/', $backupFile );
|
||||||
chomp($subprocess->{curl});
|
my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array];
|
||||||
$subprocess->{type} = $hash->{STORAGETYPE};
|
|
||||||
$subprocess->{host} = AttrVal( $name, 'bTS_Host', '' );
|
|
||||||
$subprocess->{user} = AttrVal( $name, 'bTS_User', '' );
|
|
||||||
$subprocess->{pass} = ReadPassword( $hash, $name );
|
|
||||||
$subprocess->{path} = AttrVal( $name, 'bTS_Path', '' );
|
|
||||||
$subprocess->{backupfile} = $backupFile;
|
|
||||||
$subprocess->{fileNameAtStorage} = $fileNameAtStorage;
|
|
||||||
|
|
||||||
my $pid = $subprocess->run();
|
$subprocess->{curl} = qx(which curl);
|
||||||
|
chomp($subprocess->{curl});
|
||||||
|
$subprocess->{type} = $hash->{STORAGETYPE};
|
||||||
|
$subprocess->{host} = AttrVal( $name, 'bTS_Host', '' );
|
||||||
|
$subprocess->{user} = AttrVal( $name, 'bTS_User', '' );
|
||||||
|
$subprocess->{pass} = ReadPassword( $hash, $name );
|
||||||
|
$subprocess->{path} = AttrVal( $name, 'bTS_Path', '' );
|
||||||
|
$subprocess->{backupfile} = $backupFile;
|
||||||
|
$subprocess->{fileNameAtStorage} = $fileNameAtStorage;
|
||||||
|
$subprocess->{proto} = AttrVal( $name, 'bTS_Proto', 'https' );
|
||||||
|
$subprocess->{loglevel} = AttrVal( $name, 'verbose', 3 );
|
||||||
|
|
||||||
readingsSingleUpdate( $hash, 'state', ' file upload in progress', 1 );
|
my $pid = $subprocess->run();
|
||||||
|
|
||||||
if ( !defined($pid) ) {
|
readingsSingleUpdate( $hash, 'state', ' file upload in progress', 1 );
|
||||||
Log3( $name, 1,
|
|
||||||
"backupToStorage ($name) - Cannot execute command asynchronously" );
|
|
||||||
|
|
||||||
CleanSubprocess($hash);
|
if ( !defined($pid) ) {
|
||||||
readingsSingleUpdate( $hash, 'state',
|
Log3( $name, 1,
|
||||||
'Cannot execute command asynchronously', 1 );
|
qq{backupToStorage ($name) - Cannot execute command asynchronously} );
|
||||||
return undef;
|
|
||||||
|
CleanSubprocess($hash);
|
||||||
|
readingsSingleUpdate( $hash, 'state',
|
||||||
|
'Cannot execute command asynchronously', 1 );
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log3( $name, 4,
|
||||||
|
qq{backupToStorage ($name) - execute command asynchronously (PID="$pid")}
|
||||||
|
);
|
||||||
|
|
||||||
|
$hash->{".fhem"}{subprocess} = $subprocess;
|
||||||
|
|
||||||
|
InternalTimer( gettimeofday() + 1,
|
||||||
|
"FHEM::backupToStorage::PollChild", $hash );
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3( $name, 4,
|
|
||||||
"backupToStorage ($name) - execute command asynchronously (PID=$pid)"
|
|
||||||
);
|
|
||||||
|
|
||||||
$hash->{".fhem"}{subprocess} = $subprocess;
|
|
||||||
|
|
||||||
InternalTimer( gettimeofday() + 1,
|
|
||||||
"FHEM::backupToStorage::PollChild", $hash );
|
|
||||||
Log3( $hash, 4,
|
Log3( $hash, 4,
|
||||||
"backupToStorage ($name) - control passed back to main loop." );
|
qq{backupToStorage ($name) - control passed back to main loop.} );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -378,20 +471,20 @@ sub PollChild {
|
|||||||
|
|
||||||
if ( !defined($json) ) {
|
if ( !defined($json) ) {
|
||||||
Log3( $name, 5,
|
Log3( $name, 5,
|
||||||
"backupToStorage ($name) - still waiting ("
|
qq{backupToStorage ($name) - still waiting ($subprocess->{lasterror}).}
|
||||||
. $subprocess->{lasterror}
|
);
|
||||||
. ")." );
|
|
||||||
InternalTimer( gettimeofday() + 1,
|
InternalTimer( gettimeofday() + 1,
|
||||||
"FHEM::backupToStorage::PollChild", $hash );
|
"FHEM::backupToStorage::PollChild", $hash );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3( $name, 4,
|
Log3( $name, 4,
|
||||||
"backupToStorage ($name) - got result from asynchronous parsing."
|
qq{backupToStorage ($name) - got result from asynchronous parsing: $json} );
|
||||||
);
|
|
||||||
$subprocess->wait();
|
$subprocess->wait();
|
||||||
Log3( $name, 4,
|
Log3( $name, 4,
|
||||||
"backupToStorage ($name) - asynchronous finished." );
|
qq{backupToStorage ($name) - asynchronous finished.} );
|
||||||
|
|
||||||
CleanSubprocess($hash);
|
CleanSubprocess($hash);
|
||||||
WriteReadings( $hash, $json );
|
WriteReadings( $hash, $json );
|
||||||
@ -408,17 +501,33 @@ sub FileUpload {
|
|||||||
|
|
||||||
if ( $subprocess->{type} eq 'Nextcloud' ) {
|
if ( $subprocess->{type} eq 'Nextcloud' ) {
|
||||||
my ($returnString,$returnCode) = ExecuteNCupload($subprocess);
|
my ($returnString,$returnCode) = ExecuteNCupload($subprocess);
|
||||||
|
|
||||||
$response->{ncUpload} = ( $returnCode == 72057594037927935
|
print 'backupToStorage File Upload - FileUpload Nextcloud, returnCode: '
|
||||||
&& $returnString eq ''
|
. $returnCode
|
||||||
? 'upload successfully'
|
. ' , returnString: '
|
||||||
: $returnString );
|
. $returnString . "\n"
|
||||||
|
if ( $subprocess->{loglevel} > 4 );
|
||||||
|
|
||||||
|
|
||||||
|
if ( $returnString =~ /100\s\s?[0-9].*\s100\s\s?[0-9].*/m
|
||||||
|
and $returnString =~ /\s\s<o:hint xmlns:o="o:">(.*)<\/o:hint>/m ) {
|
||||||
|
$response->{ncUpload} = $1;
|
||||||
|
}
|
||||||
|
elsif ( $returnString =~ /100\s\s?[0-9].*\s100\s\s?[0-9].*/m ) {
|
||||||
|
$response->{ncUpload} = 'upload successfully';
|
||||||
|
}
|
||||||
|
elsif ( $returnString =~ /(curl:\s.*)/ ){
|
||||||
|
$response->{ncUpload} = $1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$response->{ncUpload} = 'unknown error';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $json = eval { encode_json($response) };
|
my $json = eval { encode_json($response) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3( 'backupToStorage File Upload',
|
print 'backupToStorage File Upload backupToStorage - JSON error: $@'
|
||||||
1, "backupToStorage - JSON error: $@" );
|
. "\n";
|
||||||
$json = '{"jsonerror":"$@"}';
|
$json = '{"jsonerror":"$@"}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,10 +540,10 @@ sub ExecuteNCupload {
|
|||||||
my $subprocess = shift;
|
my $subprocess = shift;
|
||||||
|
|
||||||
my $command = $subprocess->{curl};
|
my $command = $subprocess->{curl};
|
||||||
$command .= ' -s -u ';
|
$command .= ' -k -u ';
|
||||||
$command .= $subprocess->{user} . ':' . $subprocess->{pass};
|
$command .= $subprocess->{user} . ':' . $subprocess->{pass};
|
||||||
$command .= ' -T ' . $subprocess->{backupfile};
|
$command .= ' -T ' . $subprocess->{backupfile};
|
||||||
$command .= ' "https://';
|
$command .= ' "' . $subprocess->{proto} . '://';
|
||||||
$command .= $subprocess->{host};
|
$command .= $subprocess->{host};
|
||||||
$command .= '/remote.php/dav/files/';
|
$command .= '/remote.php/dav/files/';
|
||||||
$command .= $subprocess->{user};
|
$command .= $subprocess->{user};
|
||||||
@ -461,7 +570,7 @@ sub CleanSubprocess {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
delete( $hash->{".fhem"}{subprocess} );
|
delete( $hash->{".fhem"}{subprocess} );
|
||||||
Log3( $name, 4, "backupToStorage ($name) - clean Subprocess" );
|
Log3( $name, 4, qq{backupToStorage ($name) - clean Subprocess} );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub StorePassword {
|
sub StorePassword {
|
||||||
@ -489,9 +598,9 @@ sub StorePassword {
|
|||||||
my $err = setKeyValue( $index, $enc_pwd );
|
my $err = setKeyValue( $index, $enc_pwd );
|
||||||
DoTrigger( $name, 'password add' );
|
DoTrigger( $name, 'password add' );
|
||||||
|
|
||||||
return "error while saving the password - $err" if ( defined($err) );
|
return qq{error while saving the password - $err} if ( defined($err) );
|
||||||
|
|
||||||
return "password successfully saved";
|
return qq{password successfully saved};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ReadPassword {
|
sub ReadPassword {
|
||||||
@ -502,14 +611,14 @@ sub ReadPassword {
|
|||||||
my $key = getUniqueId() . $index;
|
my $key = getUniqueId() . $index;
|
||||||
my ( $password, $err );
|
my ( $password, $err );
|
||||||
|
|
||||||
Log3( $name, 4, "backupToStorage ($name) - Read password from file" );
|
Log3( $name, 4, qq{backupToStorage ($name) - Read password from file} );
|
||||||
|
|
||||||
( $err, $password ) = getKeyValue($index);
|
( $err, $password ) = getKeyValue($index);
|
||||||
|
|
||||||
if ( defined($err) ) {
|
if ( defined($err) ) {
|
||||||
|
|
||||||
Log3( $name, 3,
|
Log3( $name, 3,
|
||||||
"backupToStorage ($name) - unable to read password from file: $err"
|
qq{backupToStorage ($name) - unable to read password from file: $err}
|
||||||
);
|
);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -532,7 +641,7 @@ sub ReadPassword {
|
|||||||
return $dec_pwd;
|
return $dec_pwd;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3( $name, 3, "backupToStorage ($name) - No password in file" );
|
Log3( $name, 3, qq{backupToStorage ($name) - No password in file} );
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,7 +692,7 @@ sub WriteReadings {
|
|||||||
|
|
||||||
my $decode_json = eval { decode_json($json) };
|
my $decode_json = eval { decode_json($json) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3( $name, 2, "backupToStorage ($name) - JSON error: $@" );
|
Log3( $name, 2, qq{backupToStorage ($name) - JSON error: $@} );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user