import requests
import sys
import urllib3
urllib3.disable_warnings()

BASE = 'https://dexshellx.com'

print('=== STEP 1: Check Domain ===')
try:
    r = requests.get(BASE, timeout=15, allow_redirects=True, verify=False)
    print(f'Status: {r.status_code}')
    print(f'Final URL: {r.url}')
    ct = r.headers.get('Content-Type', '')
    print(f'Content-Type: {ct}')
    print(f'Content preview:\n{r.text[:300]}')
    print()
except Exception as e:
    print(f'ERROR reaching domain: {e}')
    sys.exit(1)

print('=== STEP 2: Check Login Page ===')
try:
    r2 = requests.get(BASE + '/dex/login', timeout=15, verify=False)
    print(f'Login page status: {r2.status_code}')
    print(f'Login page URL: {r2.url}')
    print(f'Content preview:\n{r2.text[:500]}')
except Exception as e:
    print(f'ERROR: {e}')

print()
print('=== STEP 3: Try Login ===')
session = requests.Session()
session.verify = False
session.headers.update({
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
})

try:
    # GET homepage first to get cookie
    session.get(BASE + '/', timeout=10)
    session.get(BASE + '/dex/login', timeout=10)
    
    login_data = {
        'user': 'slex',
        'pass': 'pppp0000',
        'language': 'en_US'
    }
    r3 = session.post(BASE + '/dex/login', data=login_data, timeout=15, allow_redirects=True)
    print(f'Login status: {r3.status_code}')
    print(f'Final URL after login: {r3.url}')
    
    if '/login' not in r3.url:
        print('✅ LOGIN SUCCESSFUL!')
    else:
        print('❌ Login failed - still on login page')
    
    print(f'Content preview:\n{r3.text[:400]}')
except Exception as e:
    print(f'ERROR during login: {e}')
