From 55fbbb08fb6530dc0d0931e61250bb96ebb96694 Mon Sep 17 00:00:00 2001 From: FredericoFalcao Date: Sat, 7 Jun 2025 14:08:39 +0300 Subject: [PATCH] Add python trigger generation and sandbox execution --- plt/generatePythonTriggerCode.inc.php | 51 +++++++++++++++++++++++++++ plt/runSandboxedPython.inc.php | 49 +++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 plt/generatePythonTriggerCode.inc.php create mode 100644 plt/runSandboxedPython.inc.php diff --git a/plt/generatePythonTriggerCode.inc.php b/plt/generatePythonTriggerCode.inc.php new file mode 100644 index 0000000..f185cde --- /dev/null +++ b/plt/generatePythonTriggerCode.inc.php @@ -0,0 +1,51 @@ + ' ' . $line, explode("\n", $pyCode))); + + // Assemble complete Python script + $pythonCode = << ['pipe', 'w'], // stdout + 2 => ['pipe', 'w'], // stderr + ]; + + // Execute the Python code using proc_open + $process = proc_open($command, $descriptorspec, $pipes); + + if (!is_resource($process)) { + unlink($tempFile); + throw new Exception('Failed to execute sandboxed Python code.'); + } + + // Capture stdout and stderr + $stdout = stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $stderr = stream_get_contents($pipes[2]); + fclose($pipes[2]); + + // Get the exit code + $exitCode = proc_close($process); + + // Cleanup temporary file + unlink($tempFile); + + return $exitCode; +}