blob: a203370de48d994a380cfffa86e4b2510dce8964 [file] [log] [blame]
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001#!/bin/bash
2
3# Autodiscover XML Debug Script
4# Usage: ./view_autodiscover.sh [OPTIONS] [email@domain.com]
5
6# Function to display help
7show_help() {
8 cat << EOF
9Autodiscover XML Debug Script
10
11Usage: $0 [OPTIONS] [email@domain.com]
12
13OPTIONS:
14 -h, --help Show this help message
15 -d, --domain FQDN Override autodiscover domain (default: autodiscover.DOMAIN)
16 Example: -d mail.example.com
17
18EXAMPLES:
19 $0 user@example.com
20 Test autodiscover for user@example.com using autodiscover.example.com
21
22 $0 -d mail.example.com user@example.com
23 Test autodiscover for user@example.com using mail.example.com
24
25 $0 -d localhost:8443 user@example.com
26 Test autodiscover using localhost:8443 (useful for development)
27
28EOF
29 exit 0
30}
31
32# Initialize variables
33EMAIL=""
34DOMAIN_OVERRIDE=""
35
36# Parse command line arguments
37while [[ $# -gt 0 ]]; do
38 case $1 in
39 -h|--help)
40 show_help
41 ;;
42 -d|--domain)
43 DOMAIN_OVERRIDE="$2"
44 shift 2
45 ;;
46 -*)
47 echo "Error: Unknown option $1"
48 echo "Use -h or --help for usage information"
49 exit 1
50 ;;
51 *)
52 EMAIL="$1"
53 shift
54 ;;
55 esac
56done
57
58# Check if xmllint is available
59if ! command -v xmllint &> /dev/null; then
60 echo "WARNING: xmllint not found. Output will not be formatted."
61 echo "Install with: apt install libxml2-utils (Debian/Ubuntu) or yum install libxml2 (CentOS/RHEL)"
62 echo ""
63 USE_XMLLINT=false
64else
65 USE_XMLLINT=true
66fi
67
68# Get email address from user input if not provided
69if [ -z "$EMAIL" ]; then
70 read -p "Enter email address to test: " EMAIL
71fi
72
73# Validate email format
74if [[ ! "$EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
75 echo "Error: Invalid email address format"
76 exit 1
77fi
78
79# Extract domain from email
80EMAIL_DOMAIN="${EMAIL#*@}"
81
82# Determine autodiscover URL
83if [ -n "$DOMAIN_OVERRIDE" ]; then
84 AUTODISCOVER_URL="https://${DOMAIN_OVERRIDE}/Autodiscover/Autodiscover.xml"
85 echo "Testing Autodiscover for: $EMAIL"
86 echo "Override domain: $DOMAIN_OVERRIDE"
87else
88 AUTODISCOVER_URL="https://autodiscover.${EMAIL_DOMAIN}/Autodiscover/Autodiscover.xml"
89 echo "Testing Autodiscover for: $EMAIL"
90fi
91
92echo "URL: $AUTODISCOVER_URL"
93echo "============================================"
94echo ""
95
96# Make the request
97RESPONSE=$(curl -k -s -X POST "$AUTODISCOVER_URL" \
98 -H "Content-Type: text/xml" \
99 -d "<?xml version=\"1.0\" encoding=\"utf-8\"?>
100<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/request/2006\">
101 <Request>
102 <EMailAddress>$EMAIL</EMailAddress>
103 <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
104 </Request>
105</Autodiscover>")
106
107# Check if response is empty
108if [ -z "$RESPONSE" ]; then
109 echo "Error: No response received from server"
110 exit 1
111fi
112
113# Format and display output
114if [ "$USE_XMLLINT" = true ]; then
115 echo "$RESPONSE" | xmllint --format - 2>&1
116else
117 echo "$RESPONSE"
118fi
119
120echo ""
121echo "============================================"
122echo "Response length: ${#RESPONSE} bytes"