53 lines
2.4 KiB
Python
53 lines
2.4 KiB
Python
"""Phase 1: IMAP/SMTP/포트 사전 검증"""
|
|
import paramiko, sys, json, socket, ssl, imaplib, smtplib, base64
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
|
|
G = base64.b64encode(b'zio:Zio@Admin2026!').decode()
|
|
|
|
def run(cmd, timeout=10):
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
return o.read().decode('utf-8','replace').strip()
|
|
|
|
result = {}
|
|
|
|
# 1. 포트 가용성
|
|
result['port_8025'] = 'free' if '8025' not in run('ss -tlnp') else 'in_use'
|
|
result['port_8026'] = 'free' if '8026' not in run('ss -tlnp') else 'in_use'
|
|
|
|
# 2. IMAP 테스트
|
|
imap_test = run('python3 -c "'
|
|
'import imaplib, ssl; ctx=ssl.create_default_context(); '
|
|
'ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE; '
|
|
'M=imaplib.IMAP4_SSL(\'localhost\', 993, ssl_context=ctx); '
|
|
'print(M.login(\'ythong\', \'1q2w3e!Q\')); M.logout()"')
|
|
result['imap_login'] = 'ok' if 'OK' in imap_test else f'fail:{imap_test[:80]}'
|
|
|
|
# 3. SMTP 테스트
|
|
smtp_test = run('python3 -c "'
|
|
'import smtplib; s=smtplib.SMTP(\'localhost\', 587); '
|
|
's.ehlo(); s.starttls(); s.login(\'ythong\', \'1q2w3e!Q\'); '
|
|
'print(\'ok\'); s.quit()"')
|
|
result['smtp_login'] = 'ok' if 'ok' in smtp_test else f'fail:{smtp_test[:80]}'
|
|
|
|
# 4. Gitea repo 확인
|
|
gitea = run(f'curl -sf "http://127.0.0.1:9003/api/v1/repos/zio/zioinfo-mail" '
|
|
f'-H "Authorization: Basic {G}" 2>/dev/null | '
|
|
'python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get(\'full_name\',\'?\'))" 2>/dev/null || echo "not_found"')
|
|
result['gitea_repo'] = gitea
|
|
|
|
# 5. SSL cert
|
|
cert = run('ls /etc/ssl/guardia/server.crt 2>/dev/null && echo exists || echo missing')
|
|
result['ssl_cert'] = cert
|
|
result['lets_encrypt'] = run('ls /etc/letsencrypt/live/zioinfo.co.kr/fullchain.pem 2>/dev/null && echo exists || echo missing')
|
|
|
|
# 6. Python 패키지 확인
|
|
result['aioimaplib'] = run('pip3 show aioimaplib 2>/dev/null | head -1 || echo missing')
|
|
result['aiosmtplib'] = run('pip3 show aiosmtplib 2>/dev/null | head -1 || echo missing')
|
|
|
|
c.close()
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
import os; os.makedirs('C:/GUARDiA/.claude/agents/_workspace', exist_ok=True)
|
|
with open('C:/GUARDiA/.claude/agents/_workspace/infra-check.json','w') as f:
|
|
json.dump(result, f, ensure_ascii=False, indent=2)
|