41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
|
|
"""RESTORE: Copy clean config from sites-available/gfil"""
|
||
|
|
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"
|
||
|
|
|
||
|
|
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)
|
||
|
|
|
||
|
|
# Check sites-available/gfil content first, then copy it over
|
||
|
|
restore_cmd = f"""sshpass -p '{LAB_PASS}' ssh -o StrictHostKeyChecking=no {LAB_USER}@{LAB_HOST} '
|
||
|
|
# Show the clean original
|
||
|
|
echo "=== sites-available/gfil (original clean) ==="
|
||
|
|
cat /etc/nginx/sites-available/gfil
|
||
|
|
|
||
|
|
# Copy clean version over the broken one
|
||
|
|
cp /etc/nginx/sites-available/gfil /etc/nginx/sites-enabled/gfil
|
||
|
|
|
||
|
|
# Test
|
||
|
|
nginx -t 2>&1
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
systemctl reload nginx
|
||
|
|
echo "RESTORED: Nginx reloaded with clean config"
|
||
|
|
else
|
||
|
|
echo "STILL FAILING after restore"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Verify site is back
|
||
|
|
curl -s -o /dev/null -w "%{{http_code}}" http://localhost/ 2>/dev/null
|
||
|
|
'"""
|
||
|
|
stdin, stdout, stderr = jd.exec_command(restore_cmd, timeout=30)
|
||
|
|
print(stdout.read().decode())
|
||
|
|
jd.close()
|