false, "message" => "CSRF token mismatch", "csrf" => csrf_token(), ]); exit; } $runnerDir = __DIR__ . "/../_runners/$id"; $srcDir = $runnerDir . "/src"; mkdir($srcDir, recursive: true); file_put_contents($srcDir . "/Program.java", $code); $isInDocker = getenv("IS_IN_DOCKER") === "1"; if ($isInDocker) file_put_contents("php://stderr", "[debug] In Docker\n"); chdir(__DIR__ . "/.."); $stderrFile = sys_get_temp_dir() . "/tmp{$id}.2"; exec( ($isInDocker ? "su-exec root " : "") . "./compile-and-run.sh '$id' Program 2>'$stderrFile'", $resultStr, $code); $resultStr = implode("\n", $resultStr); if (is_file($stderrFile)) { $stderrContents = file_get_contents($stderrFile); unlink($stderrFile); if (!empty($stderrContents)) { file_put_contents("php://stderr", "compile-and-run.sh failed: $stderrContents\n"); if ($code != 0) { echo json_encode([ "ok" => false, "message" => "Execution failed:\n$stderrContents", "csrf" => csrf_token(), ]); exit; } } } chdir(__DIR__); file_put_contents("php://stderr", "result: $result\n"); $csrf = csrf_token(); $result = [ "compile" => [ "status" => get($id, "c.s"), "stdout" => get($id, "c.0"), "stderr" => get($id, "c.1"), ], "run" => [ "status" => get($id, "r.s"), "stdout" => get($id, "r.0"), "stderr" => get($id, "r.1"), ], "runner" => $id, "ok" => true, "csrf" => $csrf, ]; delTree($runnerDir); echo json_encode($result); exit; } $csrf = csrf_token(); ?>
Powered by Eclipse Temurin