로그인 상태 유지와 다마고치 수정 화면 정리
Paramix Studio / build (push) Canceled after 0s
Paramix Studio / pages (push) Canceled after 0s

This commit is contained in:
syskiller committed 2026-11-16 19:08:53 +09:00
1 parent 80d332a79c
commit 40615838ac
33 files changed
+248 -73

No files matched your search

+15 -27
View File
@@ -149,11 +149,15 @@ class Handler(BaseHTTPRequestHandler):
self.send_header('X-Content-Type-Options', 'nosniff')
self.send_header('X-Robots-Tag', 'noindex')
for key, val in (headers or {}).items():
self.send_header(key, val)
for value in val if isinstance(val, list) else [val]:
self.send_header(key, value)
self.end_headers()
self.wfile.write(body)
def authorized(self):
user = members().user(self)
if user and user['username'] == config()['username'].lower():
return True
cookie = self.headers.get('Cookie', '')
match = re.search(r'(?:^|;\s*)tama_admin=([a-f0-9]{64})(?:;|$)', cookie)
token = match.group(1) if match else None
@@ -163,6 +167,12 @@ class Handler(BaseHTTPRequestHandler):
del SESSIONS[key]
return bool(token and token in SESSIONS)
def clear_admin_session(self):
match = re.search(r'(?:^|;\s*)tama_admin=([a-f0-9]{64})(?:;|$)', self.headers.get('Cookie', ''))
with LOCK:
if match:
SESSIONS.pop(match[1], None)
def body(self, limit):
if self.headers.get('Transfer-Encoding'):
raise ValueError('지원하지 않는 전송 방식입니다.')
@@ -236,6 +246,10 @@ class Handler(BaseHTTPRequestHandler):
def post(self):
path = self.path
if path == '/api/login':
return members().post(self, '/api/member/login', admin_only=True)
if path == '/api/admin/logout':
return members().post(self, '/api/member/logout')
if path.startswith('/api/member/') or path == '/api/admin/members':
return members().post(self, path)
if path == '/api/device-backups':
@@ -257,32 +271,6 @@ class Handler(BaseHTTPRequestHandler):
self.close_connection = True
return self.reply(401, {'error': '관리자 로그인이 필요합니다.'})
body = json.loads(self.body(4096))
if path == '/api/login':
ip = self.headers.get('X-Real-IP', self.client_address[0])
with LOCK:
# Bound the table as well as the number of guesses per client.
for key in list(ATTEMPTS):
ATTEMPTS[key] = [t for t in ATTEMPTS[key] if t > time.time() - 900]
if not ATTEMPTS[key]:
del ATTEMPTS[key]
tries = ATTEMPTS.setdefault(ip, [])
if len(tries) >= 8 or len(ATTEMPTS) > 10000:
return self.reply(429, {'error': '로그인 시도가 많습니다. 15분 뒤 다시 시도하세요.'})
cfg = config()
if body.get('username') != cfg['username'] or not password_ok(str(body.get('password', '')), cfg['passwordHash']):
tries.append(time.time())
return self.reply(401, {'error': '아이디 또는 비밀번호가 다릅니다.'})
ATTEMPTS.pop(ip, None)
token = secrets.token_hex(32)
SESSIONS[token] = time.time() + 28800
return self.reply(200, {'ok': True}, headers={'Set-Cookie': 'tama_admin=' + token + '; Path=/api; HttpOnly; Secure; SameSite=Strict; Max-Age=28800'})
if path == '/api/admin/logout':
cookie = self.headers.get('Cookie', '')
match = re.search(r'tama_admin=([a-f0-9]{64})', cookie)
with LOCK:
if match:
SESSIONS.pop(match.group(1), None)
return self.reply(200, {'ok': True}, headers={'Set-Cookie': 'tama_admin=; Path=/api; HttpOnly; Secure; SameSite=Strict; Max-Age=0'})
if path == '/api/admin/settings':
with LOCK:
cfg = config()