#!/bin/bash
# Comprehensive W90DM test script

IP="41.119.36.159"
USER="admin"
PASS="0penV70penV7"

echo "=========================================="
echo "W90DM Connection Test - $(date)"
echo "=========================================="
echo ""

# Test 1: Port scan
echo "1. Port Scan:"
nmap -p 22,23,80,443,8080,8443 $IP 2>/dev/null | grep -E "(PORT|tcp)"
echo ""

# Test 2: HTTPS response
echo "2. HTTPS Response:"
curl -k -s -I https://$IP/ 2>&1 | head -5
echo ""

# Test 3: API endpoints with auth
echo "3. API Endpoint Tests:"
for endpoint in "/cgi-bin/api/get_handset_list" "/api/v1/handsets" "/cgi-bin/get_handsets.cgi"; do
    echo "  $endpoint:"
    curl -k -s -u "$USER:$PASS" "https://$IP$endpoint" 2>&1 | cut -c1-60
    echo ""
done

# Test 4: Try form-based login
echo "4. Testing Form Login:"
curl -k -s -X POST \
  -d "username=$USER" \
  -d "password=$PASS" \
  -d "submit=Login" \
  -L \
  "https://$IP/login.htm" 2>&1 | grep -oE "<title>[^<]+</title>" || echo "  No title found"
echo ""

echo "=========================================="
echo "Test Complete"
echo "=========================================="
