43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
|
|
"""REVERT: Remove broken robots.txt block from gfil-lab.com Nginx config"""
|
||
|
|
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)
|
||
|
|
|
||
|
|
# Remove ALL robots.txt related lines from the Nginx config
|
||
|
|
revert_cmd = """sshpass -p 'Kt9V72Tx2c48ChikKU' ssh -o StrictHostKeyChecking=no root@216.144.233.14 '
|
||
|
|
# Remove the broken "n" line
|
||
|
|
sed -i "/^n location/d" /etc/nginx/sites-enabled/gfil
|
||
|
|
# Remove the robots.txt location block (3 lines: open, alias, close)
|
||
|
|
sed -i "/location = \/robots\.txt/,/}/d" /etc/nginx/sites-enabled/gfil
|
||
|
|
# Remove any leftover empty lines
|
||
|
|
sed -i "/^$/N;/^\\n$/d" /etc/nginx/sites-enabled/gfil
|
||
|
|
|
||
|
|
# Verify config is clean
|
||
|
|
echo "=== Cleaned config ==="
|
||
|
|
cat /etc/nginx/sites-enabled/gfil
|
||
|
|
|
||
|
|
# Test
|
||
|
|
nginx -t 2>&1
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
systemctl reload nginx
|
||
|
|
echo "Nginx reloaded OK - config reverted"
|
||
|
|
else
|
||
|
|
echo "STILL FAILING - showing full config"
|
||
|
|
cat -n /etc/nginx/sites-enabled/gfil
|
||
|
|
fi
|
||
|
|
'"""
|
||
|
|
stdin, stdout, stderr = jd.exec_command(revert_cmd, timeout=30)
|
||
|
|
print(stdout.read().decode())
|
||
|
|
jd.close()
|