2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 16:46:35 +00:00

fhem.pl: perlSyntaxCheck added

git-svn-id: https://svn.fhem.de/fhem/trunk@11178 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-04-03 14:20:32 +00:00
parent ea85a68358
commit eaf756f238
5 changed files with 77 additions and 10 deletions

View File

@ -2409,13 +2409,12 @@ FW_makeEdit($$$)
my ($name, $n, $val) = @_;
# Toggle Edit-Window visibility script.
my $pgm = "Javascript:" .
"s=document.getElementById('edit').style;".
"s.display = s.display=='none' ? 'block' : 'none';".
"s=document.getElementById('disp').style;".
"s.display = s.display=='none' ? 'block' : 'none';";
my $psc = AttrVal("global", "perlSyntaxCheck", ($featurelevel>5.7) ? 1 : 0);
my $pgm = "var old = \$('#edit').css('display');".
"\$('#edit').css('display', old=='none' ? 'block' : 'none');".
"\$('#disp').css('display', old=='none' ? 'none' : 'block');";
FW_pO "<td>";
FW_pO "<a onClick=\"$pgm\">$n</a>";
FW_pO "<a onClick=\"$pgm\" style=\"cursor:pointer\">$n</a>";
FW_pO "</td>";
$val =~ s,\\\n,\n,g;
@ -2435,7 +2434,7 @@ FW_makeEdit($$$)
my $ncols = $FW_ss ? 30 : 60;
FW_pO "<textarea name=\"val.${cmd}$name\" ".
"cols=\"$ncols\" rows=\"10\">$val</textarea>";
FW_pO "<br>" . FW_submit("cmd.${cmd}$name", "$cmd $name");
FW_pO "<br>" . FW_submit("cmd.${cmd}$name", "$cmd $name",($psc?"psc":""));
FW_pO "</form></div>";
FW_pO "</td>";
}
@ -2791,7 +2790,7 @@ FW_Set($@)
if($a[1] eq "clearSvgCache") {
my $cDir = "$FW_dir/SVGcache";
if(opendir(DH, $cDir)) {
map { my $n="$cDir/$_"; unlink($n) if(-f $n); } readdir(DH);;
map { my $n="$cDir/$_"; unlink($n) if(-f $n); } readdir(DH);
closedir(DH);
} else {
return "Can't open $cDir: $!";

View File

@ -79,6 +79,9 @@ at_Define($$)
}
return "datespec is not allowed with + or *" if($abstime && ($rel || $rep));
my $err = perlSyntaxCheck($command, ());
return $err if($err);
$rel = "" if(!defined($rel));
$rep = "" if(!defined($rep));
$cnt = "" if(!defined($cnt));
@ -88,6 +91,7 @@ at_Define($$)
$hash->{TIMESPEC} = $tspec;
$hash->{COMMAND} = $command;
my $ot = $data{AT_TRIGGERTIME} ? $data{AT_TRIGGERTIME} : gettimeofday();
$ot = int($ot) if(!$rel); # No way to specify subseconds
my $nt = $ot;
@ -530,6 +534,8 @@ EOF
</ul>
</li><br>
<li><a href="#perlSyntaxCheck">perlSyntaxCheck</a></li>
</ul>
<br>
</ul>
@ -701,6 +707,8 @@ EOF
</ul>
</li><br>
<li><a href="#perlSyntaxCheck">perlSyntaxCheck</a></li>
</ul>
<br>

View File

@ -44,6 +44,14 @@ notify_Define($$)
eval { "Hallo" =~ m/^$re$/ };
return "Bad regexp: $@" if($@);
$hash->{REGEXP} = $re;
my %specials= (
"%NAME" => $name,
"%TYPE" => $name,
"%EVENT" => "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0",
"%SELF" => $name,
);
my $err = perlSyntaxCheck($command, %specials);
return $err if($err);
$hash->{".COMMAND"} = $command;
my $doTrigger = ($name !~ m/^$re$/); # Forum #34516
@ -435,6 +443,13 @@ notify_fhemwebFn($$$$)
</code></ul>
</li>
<a name="perlSyntaxCheck"></a>
<li>perlSyntaxCheck<br>
by setting the <b>global</b> attribute perlSyntaxCheck, a syntax check
will be executed upon definition or modification, if the command is
perl and FHEM is already started.
</li>
</ul>
<br>
@ -645,6 +660,14 @@ notify_fhemwebFn($$$$)
attr n readLog
</code></ul>
</li>
<a name="perlSyntaxCheck"></a>
<li>perlSyntaxCheck<br>
nach setzen des <b>global</b> Attributes perlSyntaxCheck wird eine
Syntax-Pr&uuml;fung der Anweisung durchgef&uuml;hrt bei jeder
&Auml;nderung (define oder modify), falls die Anweisung Perl ist, und
FHEM bereits gestartet ist. </li>
</ul>
<br>

View File

@ -117,6 +117,7 @@ sub getUniqueId();
sub latin1ToUtf8($);
sub myrename($$$);
sub notifyRegexpChanged($$);
sub perlSyntaxCheck($%);
sub readingsBeginUpdate($);
sub readingsBulkUpdate($$$@);
sub readingsEndUpdate($$);
@ -284,6 +285,7 @@ my @globalAttrList = qw(
mseclog:1,0
nofork:1,0
nrarchive
perlSyntaxCheck
pidfilename
port
restartDelay
@ -4562,4 +4564,18 @@ RefreshAuthList()
$auth_refresh = 0;
}
sub
perlSyntaxCheck($%)
{
my ($exec, %specials)= @_;
my $psc = AttrVal("global", "perlSyntaxCheck", ($featurelevel>5.7) ? 1 : 0);
return undef if(!$psc || !$init_done);
return undef if($exec !~ m/^{.*}$/s);
$exec = EvalSpecials("{return undef; $exec}", %specials);
my $r = AnalyzePerlCommand(undef, $exec);
return $r;
}
1;

View File

@ -198,6 +198,7 @@ FW_jqueryReadyFn()
FW_smallScreenCommands();
FW_inlineModify();
}
// Show the webCmd list in a dialog if: smallScreen & hiddenroom=detail & room
@ -287,10 +288,10 @@ FW_cmd(arg, callback)
req.open("POST", arg, true);
req.send(null);
req.onreadystatechange = function(){
if(req.readyState == 4 && req.responseText) {
if(req.readyState == 4) {
if(callback)
callback(req.responseText);
else
else if(req.responseText)
FW_errmsg(req.responseText, 5000);
}
}
@ -456,6 +457,26 @@ FW_replaceLink(el)
$(el).css("cursor", "pointer");
}
function
FW_inlineModify() // Do not generate a new HTML page upon pressing modify
{
$("div#edit input.psc[type=submit]").click(function(e){
e.preventDefault();
var newDef = $(this).closest("form").find("textarea").val();
var cmd = $(this).attr("name")+"="+$(this).attr("value")+" "+newDef;
FW_cmd(FW_root+"?"+encodeURIComponent(cmd)+"&XHR=1", function(resp){
if(resp)
return FW_okDialog(resp);
newDef = newDef.replace(/&/g, '&amp;') // Same as in 01_FHEMWEB
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
if(newDef.indexOf("\n") >= 0)
newDef = '<pre>'+newDef+'</pre>';
$("div#disp").html(newDef).css("display", "");
$("div#edit").css("display", "none");
});
});
}
/*************** LONGPOLL START **************/
var FW_pollConn;