69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""RESTORE: Write correct Nginx config for gfil-lab.com"""
|
|
import paramiko
|
|
|
|
JD_HOST = "111.228.37.165"
|
|
JD_USER = "root"
|
|
JD_PASS = "Liudecai110"
|
|
|
|
LAB_HOST = "216.144.233.14"
|
|
LAB_USER = "root"
|
|
LAB_PASS = "Kt9V72Tx2c48ChikKU"
|
|
|
|
# This is the CORRECT config based on what we saw from the probe output
|
|
# (before our robots.txt changes broke it)
|
|
CORRECT_CONFIG = r"""server {
|
|
listen 80;
|
|
server_name quant-node.com gold-node.xyz gfil-intel.xyz quant-view.xyz;
|
|
|
|
location /static/ {
|
|
alias /GFIL/static/;
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://127.0.0.1:5000;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /socket.io/ {
|
|
proxy_pass http://127.0.0.1:5000/socket.io/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_buffering off;
|
|
proxy_read_timeout 86400s;
|
|
proxy_send_timeout 86400s;
|
|
}
|
|
}
|
|
"""
|
|
|
|
jd = paramiko.SSHClient()
|
|
jd.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
jd.connect(JD_HOST, port=22, username=JD_USER, password=JD_PASS,
|
|
timeout=20, banner_timeout=60, allow_agent=False, look_for_keys=False)
|
|
|
|
# First backup current broken config, then write the correct one
|
|
restore_cmd = f"""sshpass -p '{LAB_PASS}' ssh -o StrictHostKeyChecking=no {LAB_USER}@{LAB_HOST} '
|
|
# Backup broken config
|
|
cp /etc/nginx/sites-enabled/gfil /etc/nginx/sites-enabled/gfil.bak.broken
|
|
|
|
# Check if there is a gfil config in sites-available (original)
|
|
echo "=== sites-available ==="
|
|
ls -la /etc/nginx/sites-available/gfil* 2>/dev/null
|
|
|
|
# Check the default config too
|
|
echo "=== default config ==="
|
|
cat /etc/nginx/sites-enabled/default
|
|
'"""
|
|
stdin, stdout, stderr = jd.exec_command(restore_cmd, timeout=30)
|
|
print(stdout.read().decode())
|
|
|
|
jd.close()
|