From 007d50cccde07083e465c270ade944638970b56e Mon Sep 17 00:00:00 2001 From: giteaadmin Date: Fri, 24 Apr 2026 12:33:12 +0000 Subject: [PATCH] Admin: justice-git page + API for Gitea push --- www/html/Admin/api/justice-push.php | 40 ++++++++++ www/html/Admin/justice-git.html | 111 ++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 www/html/Admin/api/justice-push.php create mode 100644 www/html/Admin/justice-git.html diff --git a/www/html/Admin/api/justice-push.php b/www/html/Admin/api/justice-push.php new file mode 100644 index 0000000..149cc6e --- /dev/null +++ b/www/html/Admin/api/justice-push.php @@ -0,0 +1,40 @@ + false, 'error' => 'ใช้ POST เท่านั้น'], 405); +} + +$body = require_json_body(); +$raw = isset($body['message']) ? trim((string) $body['message']) : ''; +if (strlen($raw) > 180) { + json_response(['ok' => false, 'error' => 'ข้อความ commit ยาวเกิน 180 ตัวอักษร'], 400); +} +// กันทำลาย shell / git -m +$safe = str_replace(["\n", "\r", "\0", '"', "'", '`', '$', '\\'], '', $raw); +$msg = $safe !== '' ? $safe : ('Admin: Gitea justice ' . gmdate('Y-m-d H:i:s') . ' UTC'); + +$cmd = 'sudo /usr/local/sbin/justice-gitea-sync.sh ' . escapeshellarg($msg) . ' 2>&1'; +$output = []; +$code = 0; +exec($cmd, $output, $code); +$log = implode("\n", $output); + +if ($code !== 0) { + json_response([ + 'ok' => false, + 'error' => 'ซิงค์หรือ push ไม่สำเร็จ', + 'exitCode' => $code, + 'log' => $log, + ], 500); +} + +json_response([ + 'ok' => true, + 'message' => $msg, + 'log' => $log, +]); diff --git a/www/html/Admin/justice-git.html b/www/html/Admin/justice-git.html new file mode 100644 index 0000000..29e3eff --- /dev/null +++ b/www/html/Admin/justice-git.html @@ -0,0 +1,111 @@ + + + + + + + + อัปขึ้น Gitea — Project justice + + + + + + +
+

อัปขึ้น Gitea — Project justice

+

ซิงค์ /var/www/html/ + ไฟล์ Nginx หลัก เข้า repo แล้ว git push (ต้องล็อกอิน Admin ก่อน)

+ + + + +
+ + +