naptr-eduroam.sh 1.6 KB
Newer Older
1
#! /bin/sh
2
3
4
5

# Example script!
# This script looks up radsec srv records in DNS for the one
# realm given as argument, and creates a server template based
kolla's avatar
kolla committed
6
7
# on that. It currently ignores weight markers, but does sort
# servers on priority marker, lowest number first.
8
# For host command this is column 5, for dig it is column 1.
9
10

usage() {
11
    /bin/echo "Usage: ${0} <realm>"
12
    exit 1
13
14
15
16
17
}

test -n "${1}" || usage

REALM="${1}"
18
DIGCMD=$(command -v dig)
19
20
HOSTCMD=$(command -v host)

21
dig_it_srv() {
22
    ${DIGCMD} +short srv $SRV_HOST | sort -n -k1 |
23
    while read line; do
24
	set $line ; PORT=$3 ; HOST=$4
25
	/bin/echo -e "\thost ${HOST%.}:${PORT}"
26
    done
27
28
}

29
dig_it_naptr() {
30
    ${DIGCMD} +short naptr ${REALM} | grep x-eduroam:radius.tls | sort -n -k1 |
31
    while read line; do
32
	set $line ; TYPE=$3 ; HOST=$6
33
34
35
	if [ "$TYPE" = "\"s\"" ]; then
	    SRV_HOST=${HOST%.}
	    dig_it_srv
36
37
	fi
    done
38
39
40
}

host_it_srv() {
41
    ${HOSTCMD} -t srv $SRV_HOST | sort -n -k5 |
42
    while read line; do
43
	set $line ; PORT=$7 ; HOST=$8 
44
	/bin/echo -e "\thost ${HOST%.}:${PORT}"
45
    done
46
47
}

48
host_it_naptr() {
49
    ${HOSTCMD} -t naptr ${REALM} | grep x-eduroam:radius.tls | sort -n -k5 |
50
    while read line; do
51
	set $line ; TYPE=$7 ; HOST=${10}
52
53
54
55
	if [ "$TYPE" = "\"s\"" ]; then
	    SRV_HOST=${HOST%.}
	    host_it_srv
	fi
56
    done
57
58
}

59
if [ -x "${DIGCMD}" ]; then
60
    SERVERS=$(dig_it_naptr)
61
elif [ -x "${HOSTCMD}" ]; then
62
    SERVERS=$(host_it_naptr)
63
else
64
    /bin/echo "${0} requires either \"dig\" or \"host\" command."
65
    exit 1
66
67
fi

68
if [ -n "${SERVERS}" ]; then
69
    /bin/echo -e "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}"
70
    exit 0
71
72
fi

73
exit 0