ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/VPN/mpd-up.sh
Revision: 856
Committed: 2006-08-08T03:28:50-07:00 (18 years, 10 months ago) by douglas
Content type: text/x-sh
Original Path: FreeBSDAdmin/VPN/mpd-nsupdate-up.sh
File size: 1587 byte(s)
Log Message:
Woo!

File Contents

# User Rev Content
1 douglas 856 #!/usr/local/bin/bash
2     # MPD Interface Up
3     #
4     # Douglas Thrift
5     #
6     # $Id$
7    
8     shopt -s extglob
9    
10     root=`dirname $0`
11     interface=`grep -E '^(pptp|ng)[0-9]$' <<<$1`
12     local_ip=`grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' <<<$3`
13     remote_ip=`grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' <<<$4`
14     authname=$5
15    
16     function usage()
17     {
18     echo -e "Usage: `basename $0` \e[1minterface\e[0m inet \e[1mlocal-ip remote-ip authname\e[0m [dns1 \e[1mserver-ip\e[0m] [dns2 \e[1mserver-ip\e[0m]"
19     exit 1
20     }
21    
22     for (( index = 6; index <= $#; ++index )); do
23     case $(eval "echo \"\${$index}\"") in
24     (dns@(1|2))
25     eval "declare \${$index}=\$(grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' <<<\${$((++index))})"
26     if eval "[[ -z \$$(eval "echo \${$((index - 1))}") ]]"; then
27     usage
28     fi
29     ;;
30     (*)
31     usage
32     ;;
33     esac
34     done
35    
36     if [[ -z $interface ]] || [[ $2 != inet ]] || [[ -z $local_ip ]] || [[ -z $remote_ip ]] || [[ -z $authname ]]; then
37     usage
38     fi
39    
40     if grep -Eq '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.4$' <<<$remote_ip; then
41     hostname='unplugged.douglasthrift.net.'
42     else
43     hostname=`sed -E 's/^[0-9]{1,3}\.[0-9]{1,3}\.([0-9]{1,3})\.([0-9]{1,3})$/vpn-\1-\2.douglasthrift.net./' <<<$remote_ip`
44     fi
45    
46     reverse=`sed -E 's/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/\4.\3.\2.\1.in-addr.arpa./' <<<$remote_ip`
47    
48     source $root/mpd-nsupdate-common.sh
49    
50     nsupdate <<EOF
51     key $name $secret
52     update delete $hostname IN A
53     update add $hostname 300 IN A $remote_ip
54     send
55     update delete $reverse IN PTR
56     update add $reverse 300 IN PTR $hostname
57     send
58     EOF
59    
60     echo $hostname $reverse > ~/.mpd-nsupdate.$interface

Properties

Name Value
svn:executable *
svn:keywords Id