]> git.treefish.org Git - fex.git/blobdiff - lib/dop
Original release 20160328
[fex.git] / lib / dop
diff --git a/lib/dop b/lib/dop
index b41dbc1e074d9425e4936f1bf4ed1858eb1ea86c..dc92d7008fdd07f6a2fb43080ccb06f0a513689b 100755 (executable)
--- a/lib/dop
+++ b/lib/dop
@@ -223,15 +223,31 @@ sub http_output {
       }
       $dynamic = $htmldoc =~ s/$mark/$include/;
     }
-    # evaluate <<perl-code>>
-    while ($htmldoc =~ /<<(.+?)>>/s) {
-      local $pc = $1;
-      local $__ = '';
-      tie *STDOUT => "Buffer",\$__;
-      $__ .= eval $pc;
-      untie *STDOUT;
-      $dynamic = $htmldoc =~ s/<<(.+?)>>/$__/s;
-    };
+    # evaluate <<perl-code>> or <<<perl-code>>>
+    {
+      local $timeout = '';
+      local $SIG{ALRM} = sub { $timeout = '<h3>TIMEOUT!</h3>' };
+      alarm(10);
+      while ($htmldoc =~ /<<(.+?>?)>>/s) {
+        local $pc = $1;
+        if ($pc =~ s/^<(.+)>$/$1/) {
+          # eval code without output substitution
+          eval('package DOP;' . $pc);
+          last if $timeout;
+          $dynamic = $htmldoc =~ s/<<<(.+?)>>>//s;
+        } else {
+          # eval code with output substitution
+          local $__ = '';
+          tie *STDOUT => "Buffer",\$__;
+          $__ .= eval('package DOP;' . $pc);
+          untie *STDOUT;
+          last if $timeout;
+          $dynamic = $htmldoc =~ s/<<(.+?)>>/$__/s;
+        }
+      }
+      alarm(0);
+      $dynamic = $htmldoc =~ s/<<(.+?>?)>>/$timeout/sg if $timeout;
+    }
     # substitute $variable$ with value from environment (if present)
     while ($htmldoc =~ /\$([\w_]+)\$/g) {
       $var = $1;
@@ -269,7 +285,6 @@ sub http_output {
       "Content-Length: $size",
       "Content-Range: $range",
       "Content-Type: $type",
-      '',
     );
   } else {
     # streaming?
@@ -279,7 +294,6 @@ sub http_output {
         'Server: fexsrv',
         "Expires: 0",
         "Content-Type: $type",
-        '',
       );
     } else {
       # Java (clients) needs Last-Modified header!
@@ -298,10 +312,11 @@ sub http_output {
         "Content-Length: $size",
         "Content-Type: $type",
       );
-      nvt_print("Set-Cookie: locale=$locale") if $use_cookies and $locale;
-      nvt_print('');
+      # nvt_print("Set-Cookie: locale=$locale") if $use_cookies and $locale;
     }
   }
+  nvt_print($_) foreach(@extra_header);
+  nvt_print('');
 
   if ($ENV{REQUEST_METHOD} eq 'GET') {
     if ($type eq 'text/html') {