From 42c0ae378d898038abcb0b8839aa1e33c3982c81 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 28 Dec 2023 14:21:04 +0800 Subject: [PATCH] update --- .gitignore | 3 ++- conv.php | 2 ++ web/public/convert.php | 14 ++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 85e7c1df..5ba56c97 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/.idea/ +/.idea +/logs diff --git a/conv.php b/conv.php index 3df89e4f..113c78be 100644 --- a/conv.php +++ b/conv.php @@ -235,6 +235,8 @@ class Translator return $this->parseCall($value); case 'Constant': return $this->parseConstant($value); + case 'Attribute': + return $this->parseAttribute($value); case 'Name': return $this->parseName($value); case 'List': diff --git a/web/public/convert.php b/web/public/convert.php index 3fa3f383..44dbbdd0 100644 --- a/web/public/convert.php +++ b/web/public/convert.php @@ -3,15 +3,21 @@ if (empty($_POST['code'])) { die('require code'); } -$file = tempnam('/tmp', 'py2php'); +define('ROOT_PATH', dirname(__DIR__, 2)); + +$id = date('Ymd_H_') . uniqid(); + +$file = ROOT_PATH . '/logs/' . $id . '.py'; +$out_file = ROOT_PATH . '/logs/' . $id . '.php'; + file_put_contents($file, $_POST['code']); -$conv = dirname(__DIR__, 2) . '/conv.php'; +$conv = ROOT_PATH . '/conv.php'; $cmd = 'php ' . $conv . ' ' . $file; $out = shell_exec($cmd); echo json_encode([ - 'data' => ['code' => $out, 'cmd' => $cmd] + 'data' => ['code' => $out,] ]); -unlink($file); +file_put_contents($out_file, $out);