";
FW_pO "
";
@@ -1591,25 +1603,36 @@ FW_style($$)
} elsif($a[1] eq "save") {
my $fileName = $a[2];
+ my $cfgDB = defined($a[3]) ? $a[3] : "";
$fileName = $FW_webArgs{saveName}
if($FW_webArgs{saveAs} && $FW_webArgs{saveName});
$fileName =~ s,.*/,,g; # Little bit of security
my $filePath = FW_fileNameToPath($fileName);
- if(!open(FH, ">$filePath")) {
- FW_pO "
$filePath: $!
";
- return;
- }
- $FW_data =~ s/\r//g if($^O !~ m/Win/);
- binmode (FH);
- print FH $FW_data;
- close(FH);
+ if($cfgDB ne 'configDB') { # save file to filesystem
+ if(!open(FH, ">$filePath")) {
+ FW_pO "
$filePath: $!
";
+ return;
+ }
+ $FW_data =~ s/\r//g if($^O !~ m/Win/);
+ binmode (FH);
+ print FH $FW_data;
+ close(FH);
+ my $ret = FW_fC("rereadcfg") if($filePath eq $attr{global}{configfile});
+ $ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,);
+ $ret = ($ret ? "
ERROR:
$ret" : "Saved the file $fileName");
+ FW_style("style list", $ret);
+ $ret = "";
- my $ret = FW_fC("rereadcfg") if($filePath eq $attr{global}{configfile});
- $ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,);
- $ret = ($ret ? "
ERROR:
$ret" : "Saved the file $fileName");
- FW_style("style list", $ret);
- $ret = "";
+ } else { # save file to configDB
+ $FW_data =~ s/\r//g if($^O !~ m/Win/);
+ _cfgDB_Writefile($filePath, $FW_data);
+ my $ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,);
+ $ret = ($ret ? "
ERROR:
$ret" :
+ "Saved the file $fileName to configDB");
+ FW_style("style list", $ret);
+ $ret = "";
+ }
} elsif($a[1] eq "iconFor") {
FW_iconTable("iconFor", "icon", "style setIF $a[2] %s", undef);
diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm
index 3246501eb..b6feb4fd4 100755
--- a/fhem/FHEM/98_SVG.pm
+++ b/fhem/FHEM/98_SVG.pm
@@ -490,6 +490,9 @@ SVG_WriteGplot($)
print FH "plot ".join(",\\\n ", @plot)."\n";
close(FH);
+ # import the file into database and delete it.
+ _cfgDB_Fileimport($fName,1) if(configDBUsed());
+
return 0;
}
@@ -507,8 +510,19 @@ SVG_readgplotfile($$)
if($defs{$wl} && $defs{$wl}{LOGDEVICE} && $defs{$defs{$wl}{LOGDEVICE}});
$ldType = $wl if(!$ldType);
- open(FH, $gplot_pgm) || return (FW_fatal("$gplot_pgm: $!"), undef);
- while(my $l =
) {
+ my @svgplotfile;
+ if(configDBUsed()) {
+ my $hfile = _cfgDB_Readfile($gplot_pgm);
+ return (FW_fatal("$gplot_pgm: $!"), undef) unless defined $hfile;
+ @svgplotfile = split("\n", $hfile);
+ } else {
+ open(FH, $gplot_pgm) || return (FW_fatal("$gplot_pgm: $!"), undef);
+ @svgplotfile = ;
+ close(FH);
+ }
+
+ foreach my $l (@svgplotfile) {
+ $l = "$l\n" unless $l =~ m/\n$/;
$l =~ s/\r//g;
my $plotfn = undef;
if($l =~ m/^#$ldType (.*)$/) {
@@ -532,7 +546,6 @@ SVG_readgplotfile($$)
push(@filelog, $plotfn);
}
}
- close(FH);
return (undef, \@data, $plot, \@filelog);
}
@@ -767,7 +780,7 @@ SVG_showLog($)
my $gplot_pgm = "$FW_gplotdir/$type.gplot";
- if(!-r $gplot_pgm) {
+ if(!-r $gplot_pgm && !configDBUsed()) {
my $msg = "Cannot read $gplot_pgm";
Log3 $FW_wname, 1, $msg;
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index d4a046ad7..3a03cd2cd 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -1923,7 +1923,19 @@ CommandReload($$)
$param =~ s,/,,g;
$param =~ s,\.pm$,,g;
my $file = "$attr{global}{modpath}/FHEM/$param.pm";
- return "Can't read $file: $!" if(! -r "$file");
+ my $cfgDB = '-';
+
+ if( ! -r "$file" ) {
+ if(configDBUsed()) {
+ # try to find the file in configDB
+ my $r = _cfgDB_Fileexport($file); # create file temporarily
+ return "Can't read $file from configDB." if ($r =~ m/^0/);
+ $cfgDB = 'X';
+ } else {
+ # configDB not used and file not found: it's a real error!
+ return "Can't read $file: $!";
+ }
+ }
my $m = $param;
$m =~ s,^([0-9][0-9])_,,;
@@ -1933,6 +1945,7 @@ CommandReload($$)
no strict "refs";
my $ret = eval {
my $ret=do "$file";
+ unlink($file) if($cfgDB eq 'X'); # delete temp file
if(!$ret) {
Log 1, "reload: Error:Modul $param deactivated:\n $@";
return $@;
@@ -2096,6 +2109,14 @@ GlobalAttr($$$$)
$attr{global}{version} = $cvsid;
my $counter = 0;
+ if(configDBUsed()) {
+ my @dbList = split(/,/,cfgDB_Read99()); # retrieve filelist from configDB
+ foreach my $m (@dbList) {
+ CommandReload(undef, $m);
+ $counter++;
+ }
+ }
+
foreach my $m (sort readdir(DH)) {
next if($m !~ m/^([0-9][0-9])_(.*)\.pm$/);
$modules{$2}{ORDER} = $1;