from pathlib import Path
src = Path('/etc/caddy/Caddyfile')
out = Path('/tmp/Caddyfile.bankort')
text = src.read_text()
if 'bankort.tap365.org' in text:
    raise SystemExit('bankort.tap365.org already exists in Caddyfile')
block = r'''

# bankort.tap365.org -> 银行执行材料 OCR 处理台 static prototype
bankort.tap365.org {
    root * /srv/bankort.tap365.org
    encode zstd gzip

    basic_auth {
        admin $2a$14$yZk9wnXSf8E3cK5mkbBFMuFAs5ZsRFvW0PGZM/1fX3c3heatdTAi2
    }

    @html path / /index.html
    header @html Cache-Control "no-cache, no-store, must-revalidate"

    handle / {
        rewrite * /index.html
        file_server
    }

    handle {
        try_files {path} /index.html
        file_server
    }

    log {
        output file /var/log/caddy/bankort.tap365.org.log {
            roll_size 50mb
            roll_keep 5
        }
        format json
    }
}
'''
out.write_text(text.rstrip() + block + '\n')
print(out)
