From f88f3012c8689b6da08b2cf0b418247f85228ad9 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Tue, 22 Apr 2014 19:11:59 +0000 Subject: [PATCH] fhem.pl/SVG/FHEMWEB: configDB changes by betateilchen git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@5602 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 77 ++++++++++++++++++++++++++--------------- fhem/FHEM/98_SVG.pm | 21 ++++++++--- fhem/fhem.pl | 23 +++++++++++- 3 files changed, 89 insertions(+), 32 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index a8583f55a..8e94a1cc5 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -1327,6 +1327,7 @@ FW_fileList($) push(@ret, $f); } closedir(DH); + @ret = cfgDB_FW_fileList($dir,$re,@ret) if (configDBUsed()); return sort @ret; } @@ -1478,16 +1479,19 @@ FW_displayFileList($@) $hid =~ s/[^A-Za-z]/_/g; FW_pO "
$heading
"; FW_pO ""; + my $cfgDB = ""; my $row = 0; foreach my $f (@files) { + $cfgDB = ($f =~ s,\.configDB$,,); + $cfgDB = ($cfgDB) ? "configDB" : ""; FW_pO ""; - FW_pH "cmd=style edit $f", $f, 1; + FW_pH "cmd=style edit $f $cfgDB", $f, 1; FW_pO ""; $row = ($row+1)%2; } FW_pO "
"; FW_pO "
"; -} +} ################## sub @@ -1533,14 +1537,15 @@ FW_style($$) FW_displayFileList("Own modules and helper files", FW_fileList("$MW_dir/^(.*sh|[0-9][0-9].*Util.*pm|.*cfg|.*holiday". "|.*layout)\$")); - FW_displayFileList("styles", - FW_fileList("$FW_cssdir/^.*(css|svg)\$")); FW_displayFileList("gplot files", FW_fileList("$FW_gplotdir/^.*gplot\$")); + FW_displayFileList("styles", + FW_fileList("$FW_cssdir/^.*(css|svg)\$")); FW_pO $end; } elsif($a[1] eq "select") { - my @fl = grep { $_ !~ m/(floorplan|dashboard)/ } FW_fileList("$FW_cssdir/.*style.css"); + my @fl = grep { $_ !~ m/(floorplan|dashboard)/ } + FW_fileList("$FW_cssdir/.*style.css"); FW_pO "$start"; my $row = 0; foreach my $file (@fl) { @@ -1564,17 +1569,24 @@ FW_style($$) } elsif($a[1] eq "edit") { my $fileName = $a[2]; - $fileName =~ s,.*/,,g; # Little bit of security - my $filePath = FW_fileNameToPath($fileName); - if(!open(FH, $filePath)) { - FW_pO "
$filePath: $!
"; - return; + my $data = ""; + my $cfgDB = defined($a[3]) ? $a[3] : ""; + if ($cfgDB eq 'configDB') { + my $filePath = FW_fileNameToPath($fileName); + $data = _cfgDB_Readfile($filePath); + } else { + $fileName =~ s,.*/,,g; # Little bit of security + my $filePath = FW_fileNameToPath($fileName); + if(!open(FH, $filePath)) { + FW_pO "
$filePath: $!
"; + return; + } + $data = join("", ); + close(FH); } - my $data = join("", ); - close(FH); $data =~ s/&/&/g; - + my $ncols = $FW_ss ? 40 : 80; FW_pO "
"; FW_pO "
"; @@ -1583,7 +1595,7 @@ FW_style($$) FW_pO FW_submit("saveAs", "Save as"); FW_pO FW_textfieldv("saveName", 30, "saveName", $fileName); FW_pO "

"; - FW_pO FW_hidden("cmd", "style save $fileName"); + FW_pO FW_hidden("cmd", "style save $fileName $cfgDB"); FW_pO ""; 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;