Files
hustoj/web/gitpull.php
klarkxy 73049b71b6 feat: add admin-only git pull interface and remove auto-pull
- Add new `gitpull.php` page for manual git pull execution by administrators
- Remove automatic git pull on homepage visit to prevent unintended updates
- Include git pull link in admin navigation menu for easy access
- Secure interface with admin-only access and sudo credentials configuration
2026-03-13 15:32:53 +08:00

58 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
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);
}
$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>
<?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; ?>
<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>
<a class="ui button" href="javascript:history.back()">返回</a>
</form>
</div>
<?php require("template/".$OJ_TEMPLATE."/footer.php"); ?>