Dns validation for https #49
Binary file not shown.
@@ -89,32 +89,60 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
def _open_tty():
|
||||||
|
# Certbot may capture stdout/stderr of hooks; /dev/tty forces user-visible IO
|
||||||
|
# when an interactive terminal exists.
|
||||||
|
try:
|
||||||
|
return open("/dev/tty", "r+", encoding="utf-8", buffering=1)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
domain = os.environ.get("CERTBOT_DOMAIN", "").strip()
|
domain = os.environ.get("CERTBOT_DOMAIN", "").strip()
|
||||||
validation = os.environ.get("CERTBOT_VALIDATION", "").strip()
|
validation = os.environ.get("CERTBOT_VALIDATION", "").strip()
|
||||||
if not domain or not validation:
|
if not domain or not validation:
|
||||||
print("Missing CERTBOT_DOMAIN/CERTBOT_VALIDATION in environment.", file=sys.stderr)
|
print("Missing CERTBOT_DOMAIN/CERTBOT_VALIDATION in environment.", file=sys.stderr, flush=True)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
record_name = f"_acme-challenge.{domain}"
|
record_name = f"_acme-challenge.{domain}"
|
||||||
print("\\n=== DNS-01 challenge required ===")
|
msg = (
|
||||||
print(f"Create/Update this TXT record:")
|
"\\n=== DNS-01 challenge required ===\\n"
|
||||||
print(f" Name: {record_name}")
|
"Create/Update this TXT record:\\n"
|
||||||
print(f" Type: TXT")
|
f" Name: {record_name}\\n"
|
||||||
print(f" Value: {validation}")
|
" Type: TXT\\n"
|
||||||
print("\\nAfter the record is published and has propagated, press Enter to continue.")
|
f" Value: {validation}\\n"
|
||||||
|
"\\nAfter the record is published and has propagated, press Enter to continue.\\n"
|
||||||
|
"> "
|
||||||
|
)
|
||||||
|
|
||||||
# If we're in a non-interactive environment, wait a bit and then continue.
|
tty = _open_tty()
|
||||||
if not sys.stdin.isatty():
|
if tty is not None:
|
||||||
wait_s = int(os.environ.get("LE_DNS_WAIT_SECONDS", "60"))
|
tty.write(msg)
|
||||||
print(f"(non-interactive stdin detected; waiting {wait_s}s then continuing...)")
|
tty.flush()
|
||||||
time.sleep(max(0, wait_s))
|
try:
|
||||||
|
tty.readline()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
tty.write("\\nAborted.\\n")
|
||||||
|
tty.flush()
|
||||||
|
return 130
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
tty.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# Fallback: best-effort stdout + either wait or read stdin if interactive.
|
||||||
|
print(msg, end="", flush=True)
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
wait_s = int(os.environ.get("LE_DNS_WAIT_SECONDS", "300"))
|
||||||
|
print(f"\\n(non-interactive stdin detected; waiting {wait_s}s then continuing...)", flush=True)
|
||||||
|
time.sleep(max(0, wait_s))
|
||||||
|
return 0
|
||||||
try:
|
try:
|
||||||
input("> ")
|
input("")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\\nAborted.", file=sys.stderr)
|
print("\\nAborted.", file=sys.stderr, flush=True)
|
||||||
return 130
|
return 130
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -125,11 +153,27 @@ if __name__ == "__main__":
|
|||||||
cleanup_contents = """#!/usr/bin/env python3
|
cleanup_contents = """#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
def _open_tty():
|
||||||
|
try:
|
||||||
|
return open("/dev/tty", "w", encoding="utf-8", buffering=1)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
domain = os.environ.get("CERTBOT_DOMAIN", "").strip()
|
domain = os.environ.get("CERTBOT_DOMAIN", "").strip()
|
||||||
if domain:
|
if not domain:
|
||||||
print("\\nDNS-01 cleanup:")
|
return 0
|
||||||
print(f"You may now remove the TXT record: _acme-challenge.{domain}")
|
msg = "\\nDNS-01 cleanup:\\nYou may now remove the TXT record: _acme-challenge.%s\\n" % domain
|
||||||
|
tty = _open_tty()
|
||||||
|
if tty is not None:
|
||||||
|
tty.write(msg)
|
||||||
|
tty.flush()
|
||||||
|
try:
|
||||||
|
tty.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return 0
|
||||||
|
print(msg, end="", flush=True)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user