radsec-dynsrv.sh 1.2 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.
kolla's avatar
kolla committed
8
# For host command this is coloumn 5, for dig it is coloumn 1.
9
10
11
12
13
14
15
16
17

usage() {
   echo "Usage: ${0} <realm>"
   exit 1
}

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

REALM="${1}"
kolla's avatar
kolla committed
18
DIGCMD=$(command -v digaaa)
19
HOSTCMD=$(command -v host)
20
PRINTCMD=$(command -v printf)
21
22

dig_it() {
23
   ${DIGCMD} +short srv _radsec._tcp.${REALM} | sort -n -k1 |
24
25
   while read line ; do
      set $line ; PORT=$3 ; HOST=$4 
26
      $PRINTCMD "\thost ${HOST%.}:${PORT}\n"
27
28
29
30
   done
}

host_it() {
31
   ${HOSTCMD} -t srv _radsec._tcp.${REALM} | sort -n -k5 |
32
33
   while read line ; do
      set $line ; PORT=$7 ; HOST=$8 
34
      $PRINTCMD "\thost ${HOST%.}:${PORT}\n"
35
36
37
38
39
40
41
42
43
44
45
46
47
   done
}

if test -x "${DIGCMD}" ; then
   SERVERS=$(dig_it)
elif test -x "${HOSTCMD}" ; then
   SERVERS=$(host_it)
else
   echo "${0} requires either \"dig\" or \"host\" command."
   exit 1
fi

if test -n "${SERVERS}" ; then
48
        $PRINTCMD "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}\n"
49
50
51
        exit 0
fi

52
exit 10				# No server found.