fdm/deploy/check-access.py

23 lines
979 B
Python

import getpass
from pathlib import Path
import paramiko
client = paramiko.SSHClient()
client.load_host_keys(str(Path.home() / ".ssh" / "known_hosts"))
client.connect("47.108.78.12", username="root", password=getpass.getpass("SSH password: "), timeout=20)
try:
commands = [
"systemctl is-active fdm-studio; ss -ltnp '( sport = :9999 )'",
"grep -R -n -E 'listen|server_name' /etc/nginx/conf.d /etc/nginx/sites-enabled 2>/dev/null",
"curl -sS -I --resolve odacm.cn:443:127.0.0.1 https://odacm.cn; curl -sS -I http://odacm.cn",
"openssl x509 -in /etc/letsencrypt/live/odacm.cn/fullchain.pem -noout -issuer -subject -dates",
"tail -n 8 /var/log/nginx/fdm-access.log; tail -n 8 /var/log/nginx/fdm-error.log",
]
for command in commands:
print(command, flush=True)
_, out, err = client.exec_command(command, timeout=30)
print(out.read().decode() + err.read().decode(), flush=True)
finally:
client.close()