import paramiko
import os

HOST = "135.125.102.180"
USER = "ubuntu"
PASS = "BotPascal2026!"
REMOTE_BASE = "/var/www/html/repondeur_mail_grok"

def main():
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username=USER, password=PASS)
        
        sftp = ssh.open_sftp()
        
        local_path = os.path.join(os.getcwd(), "public/index.php")
        remote_path = f"{REMOTE_BASE}/public/index.php"
        tmp_remote = f"/tmp/index_site_{os.getpid()}.php"
        
        print("📤 Upload de index.php avec colonne Site...")
        sftp.put(local_path, tmp_remote)
        
        print("📦 Déplacement...")
        ssh.exec_command(f"sudo mv {tmp_remote} {remote_path}")
        ssh.exec_command(f"sudo chown www-data:www-data {remote_path}")
        ssh.exec_command(f"sudo chmod 644 {remote_path}")
        
        sftp.close()
        ssh.close()
        
        print("\n✅ Tableau mis à jour avec la colonne Site!")
        
    except Exception as e:
        print(f"❌ Error: {e}")

if __name__ == "__main__":
    main()
