Files
gfil-blog/deploy_and_verify.py

120 lines
5.2 KiB
Python

import urllib.request, sys, io, paramiko, os, time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
JD_HOST = "111.228.37.165"
JD_USER = "root"
JD_PASS = "Liudecai110"
LAB_HOST = "216.144.233.14"
LAB_USER = "root"
LAB_PASS = "Kt9V72Tx2c48ChikKU"
# === Step 1: Connect and run the fix on server ===
print("=== STEP 1: Connect and modify ===")
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)
# Upload fix script
FIX_SCRIPT = r'''
import shutil
src = "/etc/nginx/sites-enabled/gfil"
bak = "/etc/nginx/sites-enabled/gfil.bak.before-robots"
shutil.copy2(src, bak)
with open(src, "r") as f:
content = f.read()
robots_block = " location = /robots.txt {\n alias /var/www/gfil-lab/robots.txt;\n default_type text/plain;\n }\n\n"
if "robots.txt" not in content:
content = content.replace(" location / {", robots_block + " location / {")
with open(src, "w") as f:
f.write(content)
print("INSERTED")
else:
print("ALREADY_EXISTS")
'''
script_path = r"C:\Users\thinkpad\AppData\Local\Temp\kilo\fix_nginx.py"
with open(script_path, "w") as f:
f.write(FIX_SCRIPT)
sftp = jd.open_sftp()
sftp.put(script_path, "/tmp/fix_nginx.py")
sftp.close()
# SCP to target
scp_cmd = "sshpass -p '" + LAB_PASS + "' scp -o StrictHostKeyChecking=no /tmp/fix_nginx.py " + LAB_USER + "@" + LAB_HOST + ":/tmp/fix_nginx.py"
stdin, stdout, stderr = jd.exec_command(scp_cmd, timeout=15)
stdout.channel.recv_exit_status()
# Run on target
run_cmd = "sshpass -p '" + LAB_PASS + "' ssh -o StrictHostKeyChecking=no " + LAB_USER + "@" + LAB_HOST + " 'python3 /tmp/fix_nginx.py && nginx -t 2>&1 && (systemctl reload nginx && echo NGINX_OK) || (cp /etc/nginx/sites-enabled/gfil.bak.before-robots /etc/nginx/sites-enabled/gfil && nginx -t 2>&1 && systemctl reload nginx && echo ROLLBACK_OK) && rm -f /tmp/fix_nginx.py'"
stdin, stdout, stderr = jd.exec_command(run_cmd, timeout=30)
print(stdout.read().decode())
jd.close()
time.sleep(2)
# === STEP 2: Code verification ===
print("\n=== STEP 2: Code verification (automated) ===")
# 2a. Verify Nginx config diff
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)
verify_cmd = "sshpass -p '" + LAB_PASS + "' ssh -o StrictHostKeyChecking=no " + LAB_USER + "@" + LAB_HOST + " 'echo DIFF: && diff /etc/nginx/sites-enabled/gfil /etc/nginx/sites-enabled/gfil.bak.before-robots && echo IDENTICAL || echo MODIFIED && echo CONFIG: && cat /etc/nginx/sites-enabled/gfil && echo NGINX_TEST: && nginx -t 2>&1'"
stdin, stdout, stderr = jd.exec_command(verify_cmd, timeout=30)
print(stdout.read().decode())
jd.close()
# 2b. External HTTP checks
print("=== External HTTP checks ===")
for domain in ["gfil-lab.com", "gfil-intel.xyz"]:
# Homepage
try:
req = urllib.request.Request("https://" + domain + "/", headers={"User-Agent": "Mozilla/5.0"})
r = urllib.request.urlopen(req, timeout=10)
print(f" {domain} homepage: {r.status} OK, size={len(r.read())} bytes")
except Exception as e:
print(f" {domain} homepage: ERROR {e}")
# robots.txt
try:
req = urllib.request.Request("https://" + domain + "/robots.txt", headers={"User-Agent": "Mozilla/5.0"})
r = urllib.request.urlopen(req, timeout=10)
content = r.read().decode()
has_gptbot = "GPTBot" in content
has_perplexity = "PerplexityBot" in content
has_sitemap = "Sitemap:" in content
print(f" {domain} robots.txt: {r.status} | GPTBot={has_gptbot} | PerplexityBot={has_perplexity} | Sitemap={has_sitemap} | {len(content)} chars")
except Exception as e:
print(f" {domain} robots.txt: ERROR {e}")
# 2c. Googlebot simulation
print("\n=== Googlebot simulation ===")
try:
req = urllib.request.Request("https://gfil-lab.com/robots.txt", headers={"User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"})
r = urllib.request.urlopen(req, timeout=10)
content = r.read().decode()
print(f" Googlebot -> gfil-lab.com/robots.txt: {r.status} OK, {len(content)} chars")
print(f" First 3 lines: {content[:150]}")
except Exception as e:
print(f" Googlebot check: ERROR {e}")
# === STEP 3: Human observation checklist ===
print("\n" + "=" * 60)
print("STEP 3: HUMAN OBSERVATION CHECKLIST")
print("=" * 60)
print("Please manually verify in your browser:")
print()
print("1. Open https://gfil-lab.com/ -> should load normally (EN homepage)")
print("2. Open https://gfil-lab.com/robots.txt -> should show full AI-crawler robots.txt")
print("3. Open https://gfil-intel.xyz/robots.txt -> should show robots.txt with Sitemap: https://gfil-intel.xyz/sitemap.xml")
print("4. Check login function works: https://gfil-lab.com/login")
print("5. Check WebSocket: terminal page should connect")
print()
print("If anything is broken, rollback command:")
print(" ssh root@216.144.233.14")
print(" cp /etc/nginx/sites-enabled/gfil.bak.before-robots /etc/nginx/sites-enabled/gfil")
print(" systemctl reload nginx")