#!/usr/bin/env python3
import sys
import time

import paramiko

sys.stdout.reconfigure(encoding="utf-8", errors="replace")
time.sleep(20)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("192.168.10.156", username="torbatyaruser", password="Moli@5404", timeout=30, allow_agent=False, look_for_keys=False)
url = (
    "https://auth.torbatyar.ir/realms/superapp/protocol/openid-connect/auth"
    "?client_id=superapp-frontend"
    "&redirect_uri=https%3A%2F%2Ftorbatyar.ir%2Fauth%2Fcallback"
    "&response_type=code&scope=openid"
)
cmd = (
    "curl -sk -m 25 --resolve auth.torbatyar.ir:443:192.168.10.156 "
    f"'{url}' | tr -d '\\r' | grep -oE 'data-identity-api=\"[^\"]+\"' | head -n 5; "
    "echo ---; "
    "curl -sk -m 10 -o /dev/null -w auth=%{http_code} --resolve auth.torbatyar.ir:443:192.168.10.156 https://auth.torbatyar.ir/"
)
_, stdout, stderr = c.exec_command(cmd, timeout=60, get_pty=True)
print((stdout.read() + stderr.read()).decode("utf-8", "replace"))
c.close()
