From eaf756f238afcede371b27c3f87447c4ff97cb10 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 3 Apr 2016 14:20:32 +0000 Subject: [PATCH] fhem.pl: perlSyntaxCheck added git-svn-id: https://svn.fhem.de/fhem/trunk@11178 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 15 +++++++-------- fhem/FHEM/90_at.pm | 8 ++++++++ fhem/FHEM/91_notify.pm | 23 +++++++++++++++++++++++ fhem/fhem.pl | 16 ++++++++++++++++ fhem/www/pgm2/fhemweb.js | 25 +++++++++++++++++++++++-- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 80f0d95fb..c605ec68d 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -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 ""; - FW_pO "$n"; + FW_pO "$n"; FW_pO ""; $val =~ s,\\\n,\n,g; @@ -2435,7 +2434,7 @@ FW_makeEdit($$$) my $ncols = $FW_ss ? 30 : 60; FW_pO ""; - FW_pO "
" . FW_submit("cmd.${cmd}$name", "$cmd $name"); + FW_pO "
" . FW_submit("cmd.${cmd}$name", "$cmd $name",($psc?"psc":"")); FW_pO ""; FW_pO ""; } @@ -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: $!"; diff --git a/fhem/FHEM/90_at.pm b/fhem/FHEM/90_at.pm index 9b1f11dc2..43182b153 100755 --- a/fhem/FHEM/90_at.pm +++ b/fhem/FHEM/90_at.pm @@ -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
+
  • perlSyntaxCheck
  • +
    @@ -701,6 +707,8 @@ EOF
    +
  • perlSyntaxCheck
  • +
    diff --git a/fhem/FHEM/91_notify.pm b/fhem/FHEM/91_notify.pm index 9aec16277..165b98493 100755 --- a/fhem/FHEM/91_notify.pm +++ b/fhem/FHEM/91_notify.pm @@ -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($$$$) + +
  • perlSyntaxCheck
    + by setting the global attribute perlSyntaxCheck, a syntax check + will be executed upon definition or modification, if the command is + perl and FHEM is already started. +
  • +
    @@ -645,6 +660,14 @@ notify_fhemwebFn($$$$) attr n readLog + + +
  • perlSyntaxCheck
    + nach setzen des global Attributes perlSyntaxCheck wird eine + Syntax-Prüfung der Anweisung durchgeführt bei jeder + Änderung (define oder modify), falls die Anweisung Perl ist, und + FHEM bereits gestartet ist.
  • +
    diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 140518698..f2496126e 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -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; diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index e681f54b3..4a103abae 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -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, '&') // Same as in 01_FHEMWEB + .replace(//g, '>'); + if(newDef.indexOf("\n") >= 0) + newDef = '
    '+newDef+'
    '; + $("div#disp").html(newDef).css("display", ""); + $("div#edit").css("display", "none"); + }); + }); +} /*************** LONGPOLL START **************/ var FW_pollConn;