# -*- coding: utf-8 -*-
r"""B109: đọc mật khẩu app (file cấu hình) + mục 'mật khẩu' trong HDSD để biết pass nào cho cổng nào."""
import os, re

APP = {
    'HLQT': r'C:\Claw 2\Nghien cuu\Du-an-A-Quy-trinh-son\HLQT-app',
    'CALIB': r'C:\Claw 2\Nghien cuu\Du-an-B-He-mau-Stain-Glaze\calib-app',
    'Agent-Lab': r'C:\Claw 2\Nghien cuu\Agent-Lab',
    'Tra cuu CSDL': r'C:\c\deepseek-harness\claw2-db',
}
for ten, d in APP.items():
    print('=' * 90)
    print('APP:', ten, '->', d)
    if not os.path.isdir(d):
        print('   (không có thư mục)'); continue
    for f in sorted(os.listdir(d)):
        if re.search(r'(mat_khau|pass|bi_mat|bi.?mat)', f, re.I) and f.endswith('.txt'):
            try:
                v = open(os.path.join(d, f), encoding='utf-8').read().strip()
            except Exception as e:
                v = 'LỖI %s' % e
            print('   %-18s = %s' % (f, v))
    for hd in ('HDSD_HLQT.md', 'HDSD_CALIB.md', 'HDSD_AGENT_LAB.md'):
        p = os.path.join(d, hd)
        if os.path.exists(p):
            s = open(p, encoding='utf-8', errors='replace').read()
            for m in re.finditer(r'[^\n]*(mật khẩu|password|pass)[^\n]*', s, re.I):
                print('   [HDSD] %s' % m.group(0).strip()[:160])
