import paramiko

c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('160.187.143.253', username='root', password=';ur7n)LC1BQ;')

def r(cmd):
    print(f"Executing: {cmd}")
    try:
        _, so, se = c.exec_command(cmd, timeout=30)
        stdout = so.read().decode('utf-8', 'replace').strip()
        stderr = se.read().decode('utf-8', 'replace').strip()
        if stdout: print(f"STDOUT:\n{stdout}")
        if stderr: print(f"STDERR:\n{stderr}")
        return stdout
    except Exception as e: 
        return str(e)

r('sudo -u postgres psql -d jumpadb -c "SELECT email, licenses FROM users WHERE email = \'keanu@pc24.id\';"')
r('sudo -u postgres psql -d jumpadb -c "SELECT t.name, t.licenses FROM tenants t JOIN users u ON u.tenant_id = t.id WHERE u.email = \'keanu@pc24.id\';"')
r('sudo -u postgres psql -d jumpadb -c "SELECT key, module FROM system_features WHERE key LIKE \'%microphone%\';"')

c.close()
