import paramiko

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)
        
        print("🔍 Running scan_loop.php manually...")
        # Run for a short time or catch output immediately
        # It's a loop, so it runs for 20 mins. We can't wait for it.
        # But we can run it and see if it outputs "Starting..." or errors immediately.
        
        # We'll run scan.php directly first since loop calls it
        print("--- TEST DIRECT SCAN ---")
        stdin, stdout, stderr = ssh.exec_command(f"php {REMOTE_BASE}/scripts/scan.php 1")
        print(stdout.read().decode())
        print("ERR:", stderr.read().decode())
        
        print("\n--- TEST SCAN LOOP ---")
        # Run loop for 5 seconds then kill? No, just see if it starts printing logs.
        # It logs to file/stdout.
        
        stdin, stdout, stderr = ssh.exec_command(f"php {REMOTE_BASE}/scripts/scan_loop.php")
        # Read a bit
        import time
        time.sleep(2) 
        if stdout.channel.recv_ready():
            print(stdout.channel.recv(1024).decode())
        if stderr.channel.recv_ready():
             print("ERR:", stderr.channel.recv(1024).decode())
        
        ssh.close()
    except Exception as e:
        print(f"❌ Error: {e}")

if __name__ == "__main__":
    main()
