nomadro/apps/ebook/dymini/deploy/setup_ssl.py
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -05:00

82 lines
2.2 KiB
Python

import paramiko
from pathlib import Path
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("82.157.112.245", username="ubuntu", password="Xiao4669805", timeout=20)
cmd = """
if [ ! -d /etc/letsencrypt/live/admin.nomadro.cn ]; then
sudo certbot certonly --webroot -w /www/wwwroot/admin.nomadro.cn -d admin.nomadro.cn --non-interactive --agree-tos -m admin@nomadro.cn
fi
"""
_, o, e = c.exec_command(cmd)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
Path("deploy/certbot.txt").write_text(out + "\n" + err, encoding="utf-8")
# write ssl nginx if cert exists
cmd2 = """
if [ -d /etc/letsencrypt/live/admin.nomadro.cn ]; then
sudo tee /www/server/panel/vhost/nginx/admin.nomadro.cn.conf >/dev/null <<'EOF'
server
{
listen 80;
server_name admin.nomadro.cn;
root /www/wwwroot/admin.nomadro.cn;
location ~ ^/\\.well-known/ {
allow all;
}
location / {
return 301 https://$host$request_uri;
}
access_log /www/wwwlogs/admin.nomadro.cn.log;
error_log /www/wwwlogs/admin.nomadro.cn.error.log;
}
server
{
listen 443 ssl http2;
server_name admin.nomadro.cn;
root /www/wwwroot/admin.nomadro.cn;
index index.html;
client_max_body_size 20m;
ssl_certificate /etc/letsencrypt/live/admin.nomadro.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/admin.nomadro.cn/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ~ ^/\\.well-known/ {
allow all;
}
location /assets/ {
try_files $uri =404;
expires 30d;
add_header Cache-Control "public, immutable";
}
location / {
try_files $uri $uri/ /index.html;
}
access_log /www/wwwlogs/admin.nomadro.cn.log;
error_log /www/wwwlogs/admin.nomadro.cn.error.log;
}
EOF
sudo nginx -t && sudo /etc/init.d/nginx reload
fi
curl -s https://admin.nomadro.cn/ | head -c 120
echo
curl -s https://api.nomadro.cn/health
echo
"""
_, o2, _ = c.exec_command(cmd2)
Path("deploy/certbot2.txt").write_text(o.read().decode("utf-8","replace") + o2.read().decode("utf-8","replace"), encoding="utf-8")
c.close()
print("ok")