<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>系统提示</title>
		<style>
body {
	font-family: "Microsoft Yahei", sans-serif;
	text-align: center;
	padding-top: 80px;
	color: #333;
}
		.tip-forbidden {
			color: #dc3545;
			font-size: 22px;
			font-weight: bold;
		}
		.tip-notfound {
			color: #666;
			font-size: 22px;
			font-weight: bold;
		}
		.tip-servererr {
			color: #888;
			font-size: 22px;
			font-weight: bold;
		}
		.ip-box {
			font-size: 18px;
			margin-top: 20px;
		}
		.desc {
			color: #666;
			margin-top: 30px;
			font-size: 14px;
		}
		.hide {
			display: none;
		}
		</style>
	</head>
	<body>
		<!-- 403 禁止访问模块 -->
		<div id="block403" class="hide">
			<div class="tip-forbidden">403 Access Forbidden by SAU Data Service</div>
			<hr style="width:50%;margin:30px auto;">
			<div>服务器拒绝本次访问，请不要尝试非法扫描、越权访问、恶意渗透行为</div>
		</div>

		<!-- 404 不存在模块 -->
		<div id="block404" class="hide">
			<div class="tip-notfound">404 Not Found</div>
			<hr style="width:50%;margin:30px auto;">
			<div>您访问的页面地址不存在或已被删除</div>
		</div>

		<!-- 5xx 服务异常模块 -->
		<div id="block5xx" class="hide">
			<div class="tip-servererr">服务器内部错误</div>
			<hr style="width:50%;margin:30px auto;">
			<div>服务暂时无法访问，请稍后重试或联系管理员</div>
		</div>

		<div class="ip-box">
			访问源IP地址：<span id="clientIp"></span>
		</div>
		<div class="desc">
			沈阳航空航天大学数据业务服务部 | 访问行为已日志留存
		</div>

		<script>
			(async function(){
				try {
					const res = await fetch(window.location.href, {method: 'HEAD'});
					// 读取Nginx传递的真实错误码
					const errCode = res.headers.get('X-Error-Code');
					// 读取访客IP
					const ip = res.headers.get('X-Client-Real-IP');
					document.getElementById('clientIp').innerText = ip || '无法获取访问IP';

					// 根据状态码显示对应区块
					if (errCode === '403' || errCode === '401' || errCode === '402') {
						document.getElementById('block403').classList.remove('hide');
					} else if (errCode === '404') {
						document.getElementById('block404').classList.remove('hide');
					} else {
						document.getElementById('block5xx').classList.remove('hide');
					}
				} catch (e) {
					document.getElementById('block404').classList.remove('hide');
					document.getElementById('clientIp').innerText = '无法获取访问IP';
				}
			})();
		</script>
	</body>
</html>
