SaveAs, bugfixes

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1152 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2011-12-30 09:08:36 +00:00
parent 21fdfffbd4
commit 4ddb26ea30
4 changed files with 29 additions and 17 deletions

View File

@ -29,6 +29,7 @@
- change: HTTPS certs directory moved from cwd into modpath - change: HTTPS certs directory moved from cwd into modpath
- feature: shutdown parameter restart added - feature: shutdown parameter restart added
- feature: usb scan/create command added (part of autocreate). - feature: usb scan/create command added (part of autocreate).
- feature: SaveAs added to FHEMWEB Edit-Files
- 2011-07-08 (5.1) - 2011-07-08 (5.1)

View File

@ -173,6 +173,7 @@ structure_Attr($@)
{ {
my ($type, @list) = @_; my ($type, @list) = @_;
return undef if($list[1] eq "alias");
my $hash = $defs{$list[0]}; my $hash = $defs{$list[0]};
$hash->{INATTR} = 1; $hash->{INATTR} = 1;
my $ret = ""; my $ret = "";

View File

@ -30,7 +30,9 @@ XmlEscape($)
$a =~ s/"/"/g; $a =~ s/"/"/g;
$a =~ s/</&lt;/g; $a =~ s/</&lt;/g;
$a =~ s/>/&gt;/g; $a =~ s/>/&gt;/g;
$a =~ s/([^ -~])/sprintf("&#%02x;", ord($1))/ge; # Not needed since we've gone UTF-8
# $a =~ s/([^ -~])/sprintf("&#%02x;", ord($1))/ge;
return $a; return $a;
} }

View File

@ -48,6 +48,7 @@ my $try_zlib = 1;
######################### #########################
# As we are _not_ multithreaded, it is safe to use global variables. # As we are _not_ multithreaded, it is safe to use global variables.
# Note: for delivering SVG plots we fork # Note: for delivering SVG plots we fork
my %FW_webArgs; # all arguments specifie in the GET
my $FW_cmdret; # Returned data by the fhem call my $FW_cmdret; # Returned data by the fhem call
my $FW_data; # Filecontent from browser when editing a file my $FW_data; # Filecontent from browser when editing a file
my $FW_detail; # currently selected device for detail view my $FW_detail; # currently selected device for detail view
@ -519,6 +520,7 @@ FW_digestCgi($)
$FW_XHR = undef; $FW_XHR = undef;
$FW_inform = undef; $FW_inform = undef;
%FW_webArgs = ();
$arg =~ s,^[?/],,; $arg =~ s,^[?/],,;
foreach my $pv (split("&", $arg)) { foreach my $pv (split("&", $arg)) {
$pv =~ s/\+/ /g; $pv =~ s/\+/ /g;
@ -527,6 +529,7 @@ FW_digestCgi($)
# Multiline: escape the NL for fhem # Multiline: escape the NL for fhem
$v =~ s/[\r]\n/\\\n/g if($v && $p && $p ne "data"); $v =~ s/[\r]\n/\\\n/g if($v && $p && $p ne "data");
$FW_webArgs{$p} = $v;
if($p eq "detail") { $FW_detail = $v; } if($p eq "detail") { $FW_detail = $v; }
if($p eq "room") { $FW_room = $v; } if($p eq "room") { $FW_room = $v; }
@ -544,7 +547,7 @@ FW_digestCgi($)
$cmd.=" $dev{$c}" if(defined($dev{$c})); $cmd.=" $dev{$c}" if(defined($dev{$c}));
$cmd.=" $arg{$c}" if(defined($arg{$c})); $cmd.=" $arg{$c}" if(defined($arg{$c}));
$cmd.=" $val{$c}" if(defined($val{$c})); $cmd.=" $val{$c}" if(defined($val{$c}));
Log 1, "CMD: $cmd";
return $cmd; return $cmd;
} }
@ -759,9 +762,9 @@ FW_roomOverview($)
"", "", "", "",
"Howto", "$FW_ME/HOWTO.html", "Howto", "$FW_ME/HOWTO.html",
"Wiki", "http://fhemwiki.de", "Wiki", "http://fhemwiki.de",
"FAQ", "$FW_ME/faq.html", # "FAQ", "$FW_ME/faq.html",
"Details", "$FW_ME/commandref.html", "Details", "$FW_ME/commandref.html",
"Examples", "$FW_ME/cmd=style%20examples", # "Examples", "$FW_ME/cmd=style%20examples",
"Edit files", "$FW_ME/cmd=style%20list", "Edit files", "$FW_ME/cmd=style%20list",
"Select style","$FW_ME/cmd=style%20select", "Select style","$FW_ME/cmd=style%20select",
"", ""); "", "");
@ -1410,11 +1413,11 @@ FW_style($$)
push(@fl, ""); push(@fl, "");
push(@fl, FW_fileList("$FW_dir/(.*.sh|.*Util.*)")); push(@fl, FW_fileList("$FW_dir/(.*.sh|.*Util.*)"));
push(@fl, ""); push(@fl, "");
push(@fl, FW_fileList("$FW_dir/.*.(css|svg|js)")); push(@fl, FW_fileList("$FW_dir/.*.(css|svg)"));
push(@fl, ""); push(@fl, "");
push(@fl, FW_fileList("$FW_dir/.*.gplot")); push(@fl, FW_fileList("$FW_dir/.*.gplot"));
push(@fl, ""); # push(@fl, "");
push(@fl, FW_fileList("$FW_dir/.*html")); # push(@fl, FW_fileList("$FW_dir/.*html"));
pO $start; pO $start;
pO "$msg<br><br>" if($msg); pO "$msg<br><br>" if($msg);
@ -1486,7 +1489,11 @@ FW_style($$)
pO "<div id=\"content\">"; pO "<div id=\"content\">";
pO "<form>"; pO "<form>";
$f =~ s,^.*/,,; $f =~ s,^.*/,,;
pO FW_submit("save", "Save $f") . "<br><br>"; pO FW_submit("save", "Save $f");
pO "&nbsp;&nbsp;";
pO FW_submit("saveAs", "Save as");
pO FW_textfield("saveName", 30);
pO "<br><br>";
pO FW_hidden("cmd", "style save $a[2]"); pO FW_hidden("cmd", "style save $a[2]");
pO "<textarea name=\"data\" cols=\"$ncols\" rows=\"30\">" . pO "<textarea name=\"data\" cols=\"$ncols\" rows=\"30\">" .
"$data</textarea>"; "$data</textarea>";
@ -1494,21 +1501,22 @@ FW_style($$)
pO "</div>"; pO "</div>";
} elsif($a[1] eq "save") { } elsif($a[1] eq "save") {
my $fName = $a[2];
$a[2] =~ s,/,,g; # little bit of security $fName = $FW_webArgs{saveName}
my $f = ($a[2] eq "fhem.cfg" ? $attr{global}{configfile} : if($FW_webArgs{saveAs} && $FW_webArgs{saveName});
"$FW_dir/$a[2]"); $fName =~ s,/,,g; # little bit of security
if(!open(FH, ">$f")) { $fName = ($fName eq "fhem.cfg" ? $attr{global}{configfile} :
pO "$f: $!"; "$FW_dir/$fName");
if(!open(FH, ">$fName")) {
pO "$fName: $!";
return; return;
} }
$FW_data =~ s/\r//g if($^O !~ m/Win/); $FW_data =~ s/\r//g if($^O !~ m/Win/);
binmode (FH); binmode (FH);
print FH $FW_data; print FH $FW_data;
close(FH); close(FH);
$f =~ s,^.*/,,; FW_style("style list", "Saved the file $fName");
FW_style("style list", "Saved the file $f"); fC("rereadcfg") if($fName eq $attr{global}{configfile});
fC("rereadcfg") if($a[2] eq "fhem.cfg");
} }
} }