fhem.pl/SVG/FHEMWEB: configDB changes by betateilchen

git-svn-id: https://svn.fhem.de/fhem/trunk@5602 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2014-04-22 19:11:59 +00:00
parent 0189eb9137
commit 3f103552bf
3 changed files with 89 additions and 32 deletions

View File

@@ -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 "<div class=\"fileList $hid\">$heading</div>";
FW_pO "<table class=\"block fileList\">";
my $cfgDB = "";
my $row = 0;
foreach my $f (@files) {
$cfgDB = ($f =~ s,\.configDB$,,);
$cfgDB = ($cfgDB) ? "configDB" : "";
FW_pO "<tr class=\"" . ($row?"odd":"even") . "\">";
FW_pH "cmd=style edit $f", $f, 1;
FW_pH "cmd=style edit $f $cfgDB", $f, 1;
FW_pO "</tr>";
$row = ($row+1)%2;
}
FW_pO "</table>";
FW_pO "<br>";
}
}
##################
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<table class=\"block fileList\">";
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 "<div id=\"content\">$filePath: $!</div>";
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 "<div id=\"content\">$filePath: $!</div>";
return;
}
$data = join("", <FH>);
close(FH);
}
my $data = join("", <FH>);
close(FH);
$data =~ s/&/&amp;/g;
my $ncols = $FW_ss ? 40 : 80;
FW_pO "<div id=\"content\">";
FW_pO "<form method=\"$FW_formmethod\">";
@@ -1583,7 +1595,7 @@ FW_style($$)
FW_pO FW_submit("saveAs", "Save as");
FW_pO FW_textfieldv("saveName", 30, "saveName", $fileName);
FW_pO "<br><br>";
FW_pO FW_hidden("cmd", "style save $fileName");
FW_pO FW_hidden("cmd", "style save $fileName $cfgDB");
FW_pO "<textarea name=\"data\" cols=\"$ncols\" rows=\"30\">" .
"$data</textarea>";
FW_pO "</form>";
@@ -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 "<div id=\"content\">$filePath: $!</div>";
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 "<div id=\"content\">$filePath: $!</div>";
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 ? "<h3>ERROR:</h3><b>$ret</b>" : "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 ? "<h3>ERROR:</h3><b>$ret</b>" : "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 ? "<h3>ERROR:</h3><b>$ret</b>" :
"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);

View File

@@ -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 = <FH>) {
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 = <FH>;
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;

View File

@@ -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;