Files
gfil-blog/deploy_robots.py

104 lines
4.1 KiB
Python
Raw Permalink Normal View History

"""Deploy robots.txt to gfil-lab.com (216.144.233.14) and gfil-intel.xyz (107.174.186.162) via JD Cloud"""
import paramiko
import os
import time
JD_HOST = "111.228.37.165"
JD_USER = "root"
JD_PASS = "Liudecai110"
# gfil-lab.com server
LAB_HOST = "216.144.233.14"
LAB_USER = "root"
LAB_PASS = "Kt9V72Tx2c48ChikKU" # from .env GFIL_SSH_PASSWORD
# gfil-intel.xyz server (same as blog)
RN_HOST = "107.174.186.162"
RN_USER = "root"
RN_PASS = "liudapao2026"
TEMP_DIR = r"C:\Users\thinkpad\AppData\Local\Temp\kilo"
def deploy():
# Step 1: Connect to JD Cloud
print("[1/4] Connecting to JD Cloud...")
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)
sftp = jd.open_sftp()
print(" Connected")
# Step 2: Upload robots.txt files to JD Cloud
print("\n[2/4] Uploading robots.txt files to JD Cloud...")
sftp.put(os.path.join(TEMP_DIR, "robots_gfil_lab.txt"), "/tmp/robots_gfil_lab.txt")
sftp.put(os.path.join(TEMP_DIR, "robots_gfil_intel.txt"), "/tmp/robots_gfil_intel.txt")
print(" Uploaded")
# Step 3: Deploy to gfil-lab.com (216.144.233.14)
print("\n[3/4] Deploying to gfil-lab.com (216.144.233.14)...")
# Find the web root - could be /GFIL/static/ or Nginx serves from elsewhere
# The Flask app serves static from /GFIL/static/, but robots.txt needs to be at web root
# Nginx config shows: location /static/ { alias /GFIL/static/; }
# For robots.txt at root, we need to place it where Nginx can serve it
# Best approach: add to Nginx config or put in a root directory
deploy_cmd = f"""sshpass -p '{LAB_PASS}' ssh -o StrictHostKeyChecking=no {LAB_USER}@{LAB_HOST} '
# Find Nginx config and web root
echo "=== Finding web root ==="
grep -r "root " /etc/nginx/sites-enabled/ 2>/dev/null | head -5
grep -r "root " /etc/nginx/conf.d/ 2>/dev/null | head -5
ls -la /var/www/ 2>/dev/null
ls -la /GFIL/static/ 2>/dev/null | head -5
# Deploy robots.txt - try multiple locations
cp /tmp/robots_gfil_lab.txt /GFIL/robots.txt 2>/dev/null
cp /tmp/robots_gfil_lab.txt /GFIL/static/robots.txt 2>/dev/null
cp /tmp/robots_gfil_lab.txt /var/www/html/robots.txt 2>/dev/null
mkdir -p /var/www/gfil-lab.com 2>/dev/null
cp /tmp/robots_gfil_lab.txt /var/www/gfil-lab.com/robots.txt 2>/dev/null
# Check if Nginx has a root directive we can use
cat /etc/nginx/sites-enabled/gfil-lab.com 2>/dev/null || cat /etc/nginx/conf.d/gfil-lab.com.conf 2>/dev/null || echo "No gfil-lab nginx config found"
echo "=== Verifying ==="
find / -name "robots.txt" -maxdepth 4 2>/dev/null | head -5
'"""
stdin, stdout, stderr = jd.exec_command(deploy_cmd, timeout=30)
output = stdout.read().decode()
print(output[:2000])
# Step 4: Deploy to gfil-intel.xyz (107.174.186.162 - RackNerd)
print("\n[4/4] Deploying to gfil-intel.xyz (RackNerd 107.174.186.162)...")
deploy_cmd2 = f"""sshpass -p '{RN_PASS}' ssh -o StrictHostKeyChecking=no {RN_USER}@{RN_HOST} '
# Find where gfil-intel.xyz is served from
echo "=== Finding gfil-intel.xyz web root ==="
grep -r "gfil-intel" /etc/nginx/ 2>/dev/null | head -10
ls -la /var/www/ 2>/dev/null | head -10
find /var/www -name "index.html" -maxdepth 3 2>/dev/null | head -5
# Deploy robots.txt to likely locations
cp /tmp/robots_gfil_intel.txt /var/www/gfil-intel.xyz/robots.txt 2>/dev/null
cp /tmp/robots_gfil_intel.txt /var/www/html/robots.txt 2>/dev/null
cp /tmp/robots_gfil_intel.txt /var/www/blog/robots.txt 2>/dev/null
echo "=== Nginx config ==="
grep -l "gfil-intel" /etc/nginx/sites-enabled/ 2>/dev/null
cat /etc/nginx/sites-enabled/gfil-intel* 2>/dev/null | head -30
echo "=== Verifying ==="
find /var/www -name "robots.txt" -maxdepth 3 2>/dev/null
'"""
stdin, stdout, stderr = jd.exec_command(deploy_cmd2, timeout=30)
output = stdout.read().decode()
print(output[:2000])
# Cleanup
jd.exec_command("rm -f /tmp/robots_gfil_lab.txt /tmp/robots_gfil_intel.txt", timeout=5)
sftp.close()
jd.close()
print("\nDone!")
if __name__ == "__main__":
deploy()