2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

FHEM/99_Utils.pm: add WriteFile (Forum #104804)

git-svn-id: https://svn.fhem.de/fhem/trunk@21112 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2020-02-04 10:02:12 +00:00
parent 3f3a9049e0
commit 549fbc2074

View File

@ -271,7 +271,7 @@ Svn_GetFile($$;$)
require HttpUtils;
return "Missing argument from or to" if(!$from || !$to);
return "Forbidden characters in from/to"
if($from =~ m/\.\./ || $to =~ m/\.\./);
if($from =~ m/\.\./ || $to =~ m/\.\./ || $to =~ m,^/,);
HttpUtils_NonblockingGet({
url=>"https://svn.fhem.de/trac/browser/trunk/fhem/$from?format=txt",
callback=>sub($$$){
@ -292,6 +292,20 @@ Svn_GetFile($$;$)
return "Download started, check the FHEM-log";
}
sub
WriteFile($$)
{
my ($filename, $data) = @_;
return "Forbidden characters in filename"
if($filename =~ m/\.\./ || $filename =~ m,^/,);
if(!open(FH,">$filename")) {
Log 1, "ERROR WriteFile $filename: $!";
return;
}
print FH $data;
close(FH);
}
1;
=pod
@ -396,6 +410,16 @@ Svn_GetFile($$;$)
</ul>
</li></br>
<li><b>WriteFile(file, content)</b><br>
Write a file in/below the curent directory.
Example:
<ul>
attr m2d readingList map:.* { WriteFile("www/images/map.png",$EVENT);; {map=>"images/map.png"} }
attr m2d devStateIcon { '<img src="fhem/images/map.png" style="max-width:256;;max-height:256;;">' }
</ul>
</li></br>
</ul>
</ul>
=end html