Files
TK-FB-Project/web-ui/pages/common/12.html

497 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rate Limit 관리</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
display: flex;
align-items: center;
justify-content: space-between;
}
.header h1 {
font-size: 24px;
display: flex;
align-items: center;
gap: 10px;
}
.shield-icon {
width: 24px;
height: 24px;
fill: white;
}
.user-level {
background: rgba(255, 255, 255, 0.2);
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
}
.content {
padding: 30px;
}
.status-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.status-card {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 20px;
text-align: center;
}
.status-card .label {
font-size: 14px;
color: #6c757d;
margin-bottom: 8px;
}
.status-card .value {
font-size: 18px;
font-weight: bold;
font-family: 'Courier New', monospace;
color: #495057;
}
.buttons-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 30px;
}
.btn {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 12px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
text-decoration: none;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-blue {
background: #007bff;
color: white;
}
.btn-blue:hover:not(:disabled) {
background: #0056b3;
}
.btn-green {
background: #28a745;
color: white;
}
.btn-green:hover:not(:disabled) {
background: #1e7e34;
}
.btn-orange {
background: #fd7e14;
color: white;
}
.btn-orange:hover:not(:disabled) {
background: #e55a00;
}
.btn-gray {
background: #6c757d;
color: white;
}
.btn-gray:hover:not(:disabled) {
background: #545b62;
}
.message {
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
font-weight: 500;
}
.message.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.message.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.message.warning {
background: #fff3cd;
color: #856404;
border: 1px solid #ffeaa7;
}
.help-section {
background: #e3f2fd;
border: 1px solid #bbdefb;
border-radius: 8px;
padding: 20px;
margin-top: 20px;
}
.help-section h3 {
color: #1565c0;
margin-bottom: 10px;
}
.help-section ul {
color: #1976d2;
line-height: 1.6;
}
.help-section li {
margin-bottom: 5px;
}
.loading {
opacity: 0.7;
pointer-events: none;
}
.no-permission {
background: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
text-align: center;
}
.icon {
width: 16px;
height: 16px;
fill: currentColor;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>
<svg class="shield-icon" viewBox="0 0 24 24">
<path d="M12,1L3,5V11C3,16.55 6.84,21.74 12,23C17.16,21.74 21,16.55 21,11V5L12,1M12,7C13.4,7 14.8,8.6 14.8,10V11H16V21H8V11H9.2V10C9.2,8.6 10.6,7 12,7M12,8.2C11.2,8.2 10.4,8.7 10.4,10V11H13.6V10C13.6,8.7 12.8,8.2 12,8.2Z"/>
</svg>
Rate Limit 관리
</h1>
<div class="user-level" id="userLevel">권한 레벨: -</div>
</div>
<div class="content">
<!-- 권한 없음 메시지 -->
<div class="no-permission" id="noPermission" style="display: none;">
<svg class="icon" viewBox="0 0 24 24" style="width: 24px; height: 24px; margin-bottom: 10px;">
<path d="M12,2C13.1,2 14,2.9 14,4C14,5.1 13.1,6 12,6C10.9,6 10,5.1 10,4C10,2.9 10.9,2 12,2M21,9V7L15,1H5C3.89,1 3,1.89 3,3V21A2,2 0 0,0 5,23H19A2,2 0 0,0 21,21V9M19,9H14V4H5V21H19V9Z"/>
</svg>
<h3>접근 권한 부족</h3>
<p>Rate Limit 관리 기능은 권한 레벨 4 이상의 사용자만 사용할 수 있습니다.</p>
</div>
<!-- 현재 상태 -->
<div id="statusSection">
<h2 style="margin-bottom: 20px; display: flex; align-items: center; gap: 8px;">
<svg class="icon" viewBox="0 0 24 24">
<path d="M12,2C13.1,2 14,2.9 14,4C14,5.1 13.1,6 12,6C10.9,6 10,5.1 10,4C10,2.9 10.9,2 12,2M21,9V7L15,1H5C3.89,1 3,1.89 3,3V21A2,2 0 0,0 5,23H19A2,2 0 0,0 21,21V9M19,9H14V4H5V21H19V9Z"/>
</svg>
현재 상태
</h2>
<div class="status-grid">
<div class="status-card">
<div class="label">클라이언트 IP</div>
<div class="value" id="clientIP">로딩 중...</div>
</div>
<div class="status-card">
<div class="label">API 제한</div>
<div class="value" id="apiLimit">로딩 중...</div>
</div>
<div class="status-card">
<div class="label">로그인 제한</div>
<div class="value" id="loginLimit">로딩 중...</div>
</div>
<div class="status-card">
<div class="label">시간 윈도우</div>
<div class="value">15분</div>
</div>
</div>
</div>
<!-- 컨트롤 버튼들 -->
<div id="controlSection">
<div class="buttons-grid">
<button class="btn btn-blue" onclick="resetRateLimit()">
<svg class="icon" viewBox="0 0 24 24">
<path d="M12,2C13.1,2 14,2.9 14,4C14,5.1 13.1,6 12,6C10.9,6 10,5.1 10,4C10,2.9 10.9,2 12,2M21,9V7L15,1H5C3.89,1 3,1.89 3,3V21A2,2 0 0,0 5,23H19A2,2 0 0,0 21,21V9M19,9H14V4H5V21H19V9Z"/>
</svg>
내 IP 제한 초기화
</button>
<button class="btn btn-green" onclick="bypassRateLimit(3600000)">
<svg class="icon" viewBox="0 0 24 24">
<path d="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2Z"/>
</svg>
1시간 제한 해제
</button>
<button class="btn btn-orange" onclick="bypassRateLimit(86400000)">
<svg class="icon" viewBox="0 0 24 24">
<path d="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2Z"/>
</svg>
24시간 제한 해제
</button>
<button class="btn btn-gray" onclick="checkStatus()">
<svg class="icon" viewBox="0 0 24 24">
<path d="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z"/>
</svg>
상태 새로고침
</button>
</div>
</div>
<!-- 메시지 표시 영역 -->
<div id="messageArea"></div>
<!-- 도움말 -->
<div class="help-section">
<h3>💡 사용 가이드</h3>
<ul>
<li><strong>초기화</strong>: 현재 IP의 요청 카운터를 0으로 리셋</li>
<li><strong>제한 해제</strong>: 지정된 시간 동안 Rate Limit 완전 비활성화</li>
<li><strong>권한 요구사항</strong>: 레벨 4-5 사용자만 접근 가능</li>
<li><strong>자동 해제</strong>: 임시 해제는 설정된 시간 후 자동으로 복구됨</li>
</ul>
</div>
</div>
</div>
<script>
let userLevel = 0;
let loading = false;
// 토큰 가져오기
function getToken() {
return localStorage.getItem('token') || sessionStorage.getItem('token');
}
// 로딩 상태 설정
function setLoading(isLoading) {
loading = isLoading;
const container = document.querySelector('.container');
if (isLoading) {
container.classList.add('loading');
} else {
container.classList.remove('loading');
}
}
// 메시지 표시
function showMessage(message, type = 'info') {
const messageArea = document.getElementById('messageArea');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type}`;
messageDiv.textContent = message;
messageArea.innerHTML = '';
messageArea.appendChild(messageDiv);
// 5초 후 자동 제거
setTimeout(() => {
if (messageDiv.parentNode) {
messageDiv.parentNode.removeChild(messageDiv);
}
}, 5000);
}
// 사용자 권한 확인
async function checkUserPermission() {
try {
const token = getToken();
if (!token) {
showMessage('로그인이 필요합니다.', 'error');
return false;
}
const response = await fetch('/api/auth/me', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const userData = await response.json();
userLevel = userData.access_level || 0;
document.getElementById('userLevel').textContent = `권한 레벨: ${userLevel}`;
if (userLevel < 4) {
document.getElementById('noPermission').style.display = 'block';
document.getElementById('statusSection').style.display = 'none';
document.getElementById('controlSection').style.display = 'none';
return false;
}
return true;
} else {
showMessage('사용자 정보 확인 실패', 'error');
return false;
}
} catch (error) {
showMessage('네트워크 오류: ' + error.message, 'error');
return false;
}
}
// 현재 상태 조회
async function checkStatus() {
if (loading || userLevel < 4) return;
setLoading(true);
try {
const token = getToken();
const response = await fetch('/api/admin/rate-limit/status', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
document.getElementById('clientIP').textContent = data.clientIP;
document.getElementById('apiLimit').textContent = `${data.rateLimitInfo.apiLimit}회/15분`;
document.getElementById('loginLimit').textContent = `${data.rateLimitInfo.loginLimit}회/15분`;
} else {
const errorData = await response.json();
showMessage('상태 조회 실패: ' + (errorData.error || response.statusText), 'error');
}
} catch (error) {
showMessage('네트워크 오류: ' + error.message, 'error');
}
setLoading(false);
}
// Rate Limit 초기화
async function resetRateLimit(targetIP = null) {
if (loading || userLevel < 4) return;
setLoading(true);
try {
const token = getToken();
const response = await fetch('/api/admin/rate-limit/reset', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ targetIP })
});
const data = await response.json();
if (response.ok) {
showMessage('✅ ' + data.message, 'success');
checkStatus(); // 상태 새로고침
} else {
showMessage('❌ ' + data.error, 'error');
}
} catch (error) {
showMessage('❌ 초기화 실패: ' + error.message, 'error');
}
setLoading(false);
}
// Rate Limit 임시 비활성화
async function bypassRateLimit(duration = 3600000) {
if (loading || userLevel < 4) return;
setLoading(true);
try {
const token = getToken();
const response = await fetch('/api/admin/rate-limit/bypass', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ duration })
});
const data = await response.json();
if (response.ok) {
const hours = duration / 3600000;
showMessage(`🔓 ${hours}시간 동안 Rate Limit가 해제되었습니다.`, 'success');
checkStatus();
} else {
showMessage('❌ ' + data.error, 'error');
}
} catch (error) {
showMessage('❌ Bypass 설정 실패: ' + error.message, 'error');
}
setLoading(false);
}
// 페이지 로드 시 초기화
async function init() {
const hasPermission = await checkUserPermission();
if (hasPermission) {
await checkStatus();
}
}
// 페이지 로드 시 실행
document.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>