import paramiko
import sys
import os

HOST = "135.125.102.180"
USER = "ubuntu"
PASS = "BotPascal2026!"

def main():
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username=USER, password=PASS, banner_timeout=30)
        
        print("--- 1. SPAM.CSV PERMS ---")
        stdin, stdout, stderr = ssh.exec_command("ls -l /var/www/html/repondeur_mail_grok/data/spam.csv")
        print(stdout.read().decode())
        
        print("--- 2. API: get_spam_keywords ---")
        # Run php to simulate API call
        cmd = 'php -r "$_GET[\'action\']=\'get_spam_keywords\'; include(\'/var/www/html/repondeur_mail_grok/public/action.php\');"'
        stdin, stdout, stderr = ssh.exec_command(cmd)
        print(stdout.read().decode())
        print("\n")
        
        print("--- 3. API: preview_spam_matches ---")
        cmd = 'php -r "$_GET[\'action\']=\'preview_spam_matches\'; include(\'/var/www/html/repondeur_mail_grok/public/action.php\');"'
        stdin, stdout, stderr = ssh.exec_command(cmd)
        print(stdout.read().decode())
        
        ssh.close()
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()
