#!/usr/bin/env python3
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('65.75.210.95', username='root', password='%8qd6oJx%PBB', timeout=20)

def run(cmd):
    _, o, e = c.exec_command(cmd, timeout=25)
    return (o.read() + e.read()).decode('utf-8', errors='replace')

print(run("grep -r 'listen 443' /etc/nginx/sites-enabled/ 2>/dev/null | head -20"))
print('---')
print(run("curl -sS -m 15 -w '\\ncode=%{http_code}\\n' -H 'Host: models.hostlanty.com' -X POST 'http://127.0.0.1/mail/send.php' -d 'key=invalid&email=test@example.com&code=123456&type=register'"))
print('---')
print(run("grep api_key /var/www/servidor/mail/config.php | head -1"))
key_line = run("grep \"'api_key'\" /var/www/servidor/mail/config.php")
# extract key safely for test
import re
m = re.search(r"'api_key'\s*=>\s*'([^']+)'", key_line)
if m:
    key = m.group(1)
    print(run(
        f"curl -sS -m 20 -w '\\ncode=%{{http_code}}\\n' -H 'Host: models.hostlanty.com' "
        f"-X POST 'http://127.0.0.1/mail/send.php' "
        f"-d 'key={key}&email=test@example.com&code=123456&type=register'"
    ))
c.close()
