74 行
3.5 KiB
PHP
74 行
3.5 KiB
PHP
<?php
|
|
require __DIR__ . '/../includes/init.php';
|
|
requireStaff();
|
|
require '_common.php';
|
|
require __DIR__ . '/../includes/app_config.php';
|
|
if (!isAdminStaff()) {
|
|
adminHeader('系统更新', 'update');
|
|
echo '<p class="form-err"><i class="fas fa-lock"></i> 仅管理员可执行系统更新操作。</p>';
|
|
adminFooter();
|
|
exit;
|
|
}
|
|
function fetchUpdateInfo() {
|
|
$url = rtrim(UPDATE_API_URL, '/') . '?v=' . urlencode(MALL_VERSION);
|
|
$ctx = stream_context_create([
|
|
'http' => ['timeout' => 10, 'ignore_errors' => true, 'method' => 'GET',
|
|
'header' => "User-Agent: FNW-Mall-Updater\r\n"]
|
|
]);
|
|
$raw = false;
|
|
if (function_exists('curl_init')) {
|
|
$ch = curl_init($url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10,
|
|
CURLOPT_USERAGENT => 'FNW-Mall-Updater', CURLOPT_SSL_VERIFYPEER => false,
|
|
]);
|
|
$raw = curl_exec($ch);
|
|
curl_close($ch);
|
|
}
|
|
if ($raw === false && function_exists('file_get_contents')) {
|
|
$raw = @file_get_contents($url, false, $ctx);
|
|
}
|
|
if ($raw === false || $raw === null) return ['error' => '无法连接更新服务器,请检查 UPDATE_API_URL 或服务器网络。'];
|
|
$data = json_decode($raw, true);
|
|
if (!is_array($data)) return ['error' => '更新服务器返回数据格式异常。'];
|
|
return $data;
|
|
}
|
|
$info = fetchUpdateInfo();
|
|
$latest = $info['latest'] ?? null;
|
|
$updateAvailable = !empty($info['update_available']) && $latest;
|
|
$apiError = $info['error'] ?? null;
|
|
adminHeader('系统更新', 'update');
|
|
?>
|
|
<h1 class="page-title"><i class="fas fa-cloud-arrow-up"></i> 系统更新</h1>
|
|
<p class="muted">当前版本:<strong><?= h(MALL_VERSION) ?></strong></p>
|
|
<?php if ($apiError): ?>
|
|
<p class="form-err"><i class="fas fa-triangle-exclamation"></i> <?= h($apiError) ?></p>
|
|
<?php elseif (!$latest): ?>
|
|
<div class="panel"><p class="muted">更新服务器暂未发布任何版本。</p></div>
|
|
<?php elseif ($updateAvailable): ?>
|
|
<div class="panel" style="max-width:680px;border-color:
|
|
<div style="display:flex;align-items:center;gap:10px;margin-bottom:10px">
|
|
<span class="version-badge">v<?= h($latest['version']) ?></span>
|
|
<?php if (($latest['type'] ?? 'patch') === 'release'): ?>
|
|
<span class="badge badge-release">正式版</span>
|
|
<?php else: ?>
|
|
<span class="badge badge-patch">补丁</span>
|
|
<?php endif; ?>
|
|
<span class="muted">发布于 <?= h($latest['release_date'] ?? '—') ?></span>
|
|
</div>
|
|
<p style="white-space:pre-wrap;line-height:1.7"><?= h($latest['intro'] ?? '') ?></p>
|
|
<p class="muted" style="font-size:.85rem">下载地址:<code><?= h($latest['download_url'] ?? '') ?></code></p>
|
|
<div class="form-actions" style="margin-top:14px">
|
|
<a href="../update.php" class="btn btn-primary" onclick="return confirm('即将开始更新到 v<?= h($latest['version']) ?>,更新前请确保已备份数据。确定继续?');">
|
|
<i class="fas fa-rocket"></i> 立即更新到 v<?= h($latest['version']) ?>
|
|
</a>
|
|
</div>
|
|
<p class="muted" style="font-size:.8rem;margin-top:10px">更新过程需要输入 SITE_KEY 校验身份,并会自动备份被覆盖的文件到 storage/backups/。</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="panel" style="max-width:680px">
|
|
<p class="banner-ok"><i class="fas fa-check-circle"></i> 当前已是最新版本(v<?= h($latest['version']) ?>)。</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php adminFooter(); ?>
|