- 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
57 lines
2.1 KiB
PHP
57 lines
2.1 KiB
PHP
<?php
|
||
require_once('./include/db_info.inc.php');
|
||
require_once('./include/const.inc.php');
|
||
require_once('./include/memcache.php');
|
||
require_once('./include/setlang.php');
|
||
|
||
// 仅允许管理员访问
|
||
if (!isset($_SESSION[$OJ_NAME.'_'.'administrator'])) {
|
||
$view_errors = "Permission denied.";
|
||
require("template/".$OJ_TEMPLATE."/error.php");
|
||
exit(0);
|
||
}
|
||
|
||
// ====================================================
|
||
// 请在下方填写 sudo 用户名和密码
|
||
$SUDO_USER = 'jieer'; // 填写拥有 sudo 权限的用户名
|
||
$SUDO_PASSWORD = 'cmf[420;'; // 填写该用户的 sudo 密码
|
||
// ====================================================
|
||
|
||
$src_path = '/home/judge/src';
|
||
$output = [];
|
||
$return_code = -1;
|
||
|
||
// 打开页面或点击重试按钮时均执行更新
|
||
$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");
|
||
?>
|
||
|
||
<div class="ui segment" style="margin-top:20px;">
|
||
<h2 class="ui header">
|
||
<i class="cloud download icon"></i>
|
||
<div class="content">服务器更新 <small style="font-size:0.6em; color:#888;">(git pull <?php echo htmlspecialchars($src_path); ?>)</small></div>
|
||
</h2>
|
||
|
||
<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>
|
||
|
||
<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>
|
||
</div>
|
||
</div>
|
||
|
||
<?php require("template/".$OJ_TEMPLATE."/footer.php"); ?>
|