feat(gitpull): execute git pull on page load and add retry button

- Changed git pull execution from POST-only to always run on page load
- Replaced sudo with su for better user switching in command execution
- Removed form submission in favor of direct execution with retry button
- Simplified UI by always showing result message and conditionally showing retry button
This commit is contained in:
2026-03-13 15:36:13 +08:00
parent 73049b71b6
commit 66bf57911b

View File

@@ -21,13 +21,12 @@ $src_path = '/home/judge/src';
$output = [];
$return_code = -1;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cmd = "echo " . escapeshellarg($SUDO_PASSWORD)
. " | sudo -S -u " . escapeshellarg($SUDO_USER)
. " git -C " . escapeshellarg($src_path)
. " pull 2>&1";
exec($cmd, $output, $return_code);
}
// 打开页面或点击重试按钮时均执行更新
$cmd = "echo " . escapeshellarg($SUDO_PASSWORD)
. " | su -c " . escapeshellarg("git -C " . $src_path . " pull")
. " " . escapeshellarg($SUDO_USER)
. " 2>&1";
exec($cmd, $output, $return_code);
$show_title = "Git Pull - " . $OJ_NAME;
require("template/".$OJ_TEMPLATE."/header.php");
@@ -39,19 +38,19 @@ require("template/".$OJ_TEMPLATE."/header.php");
<div class="content">服务器更新 <small style="font-size:0.6em; color:#888;">(git pull <?php echo htmlspecialchars($src_path); ?>)</small></div>
</h2>
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST'): ?>
<div class="ui <?php echo $return_code === 0 ? 'success' : 'error'; ?> message">
<div class="header"><?php echo $return_code === 0 ? '更新成功' : '更新失败(返回码:' . $return_code . ''; ?></div>
<pre style="margin-top:8px; white-space:pre-wrap; word-break:break-all;"><?php echo htmlspecialchars(implode("\n", $output)); ?></pre>
</div>
<?php endif; ?>
<div class="ui <?php echo $return_code === 0 ? 'success' : 'error'; ?> message">
<div class="header"><?php echo $return_code === 0 ? '更新成功' : '更新失败(返回码:' . $return_code . ''; ?></div>
<pre style="margin-top:8px; white-space:pre-wrap; word-break:break-all;"><?php echo htmlspecialchars(implode("\n", $output)); ?></pre>
</div>
<form method="post" action="gitpull.php" style="margin-top:16px;">
<button type="submit" class="ui primary button">
<i class="refresh icon"></i> 立即执行 git pull
</button>
<div style="margin-top:16px;">
<?php if ($return_code !== 0): ?>
<a class="ui primary button" href="gitpull.php">
<i class="refresh icon"></i> 重试 git pull
</a>
<?php endif; ?>
<a class="ui button" href="javascript:history.back()">返回</a>
</form>
</div>
</div>
<?php require("template/".$OJ_TEMPLATE."/footer.php"); ?>