1 |
douglas |
933 |
#!/bin/sh |
2 |
|
|
# DHCP Client Exit Hooks |
3 |
douglas |
847 |
# |
4 |
|
|
# Douglas Thrift |
5 |
|
|
# |
6 |
|
|
# $Id$ |
7 |
|
|
|
8 |
douglas |
1407 |
tunnelbroker() |
9 |
|
|
{ |
10 |
|
|
local pass=`python -c "import getpass, hashlib; print hashlib.md5(getpass.getpass('tunnelbroker pass: ')).hexdigest()"` |
11 |
|
|
read -p 'tunnelbroker user_id: ' -r user_id |
12 |
|
|
read -p 'tunnelbroker tunnel_id: ' -r tunnel_id |
13 |
|
|
export CURL_CA_BUNDLE=`mktemp -t dhclient` |
14 |
|
|
cat >$CURL_CA_BUNDLE <<-EOF |
15 |
|
|
-----BEGIN CERTIFICATE----- |
16 |
|
|
MIICsTCCAhoCCQC8IBpX67SYlzANBgkqhkiG9w0BAQQFADCBnDELMAkGA1UEBhMC |
17 |
|
|
VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExEDAOBgNVBAcTB0ZyZW1vbnQxIDAeBgNV |
18 |
|
|
BAoTF0h1cnJpY2FuZSBFbGVjdHJpYywgTExDMQ0wCwYDVQQLEwRJUFY2MRkwFwYD |
19 |
|
|
VQQDExB0dW5uZWxicm9rZXIubmV0MRowGAYJKoZIhvcNAQkBFgtpbmZvQGhlLm5l |
20 |
|
|
dDAeFw0wNzA3MTEwMTM1MzFaFw0xNzA3MDgwMTM1MzFaMIGcMQswCQYDVQQGEwJV |
21 |
|
|
UzETMBEGA1UECBMKQ2FsaWZvcm5pYTEQMA4GA1UEBxMHRnJlbW9udDEgMB4GA1UE |
22 |
|
|
ChMXSHVycmljYW5lIEVsZWN0cmljLCBMTEMxDTALBgNVBAsTBElQVjYxGTAXBgNV |
23 |
|
|
BAMTEHR1bm5lbGJyb2tlci5uZXQxGjAYBgkqhkiG9w0BCQEWC2luZm9AaGUubmV0 |
24 |
|
|
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXJHwlKn5pdUqFAZGGYI8sluS+ |
25 |
|
|
luS2NiihelZTXAGkE8hrlkS3Xj3AYLknddWgcoTXVMlI9LK0tEQMPZBIV/QXjXHq |
26 |
|
|
HvhOb4hoT14w+VbySPRXGDqUiakJYBnNFZiIR8OA51AwM9+pUZGkNEAJYMXE+Th8 |
27 |
|
|
euta8zxjPS0kEgjGbwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAFVFliiWM802HDqY |
28 |
|
|
loveIJOZdcnXhpQuYmnDgHHC9PAadOVcYzdkkmBoQ1APSfugkHEc7zc/vzjiMlVs |
29 |
|
|
62PFaqFxi692CknGCnwyCn+Hm/PFWx+YnOyNLCji2oOYbTZre97n5iZKrOk/hJZO |
30 |
|
|
y7bsxRNdmUWgy0urugi331F9y7cf |
31 |
|
|
-----END CERTIFICATE----- |
32 |
|
|
EOF |
33 |
|
|
curl -4 "https://tunnelbroker.net/ipv4_end.php?ipv4b=AUTO&pass=$pass&user_id=$user_id&tunnel_id=$tunnel_id" |
34 |
|
|
echo |
35 |
|
|
rm $CURL_CA_BUNDLE |
36 |
|
|
unset CURL_CA_BUNDLE |
37 |
|
|
if ! grep -q "^gifconfig_${tunnelbroker_gif:=gif0}=\"$new_ip_address $tunnelbroker_server\"$" /etc/rc.conf; then |
38 |
|
|
sed -Ee "s/^(gifconfig_$tunnelbroker_gif=\").*( $tunnelbroker_server\")$/\1$new_ip_address\2/" -i '' /etc/rc.conf |
39 |
|
|
ifconfig $tunnelbroker_gif tunnel $new_ip_address $tunnelbroker_server |
40 |
|
|
fi |
41 |
|
|
} |
42 |
douglas |
847 |
|
43 |
douglas |
1407 |
dns() |
44 |
|
|
{ |
45 |
|
|
read -p 'dns key: ' -r key |
46 |
|
|
read -p 'dns secret: ' -r secret |
47 |
douglas |
935 |
nsupdate -d <<-EOF |
48 |
|
|
key $key $secret |
49 |
|
|
update delete $hostname A |
50 |
douglas |
1410 |
update add $hostname 300 A $new_ip_address |
51 |
douglas |
935 |
send |
52 |
|
|
EOF |
53 |
douglas |
1407 |
} |
54 |
|
|
|
55 |
|
|
case ${reason:=RENEW} in |
56 |
|
|
BOUND|RENEW|REBIND|REBOOT) |
57 |
|
|
case `hostname -s` in |
58 |
|
|
justonenight) |
59 |
|
|
hostname='ellwoodbeach.douglasthrift.net' |
60 |
|
|
tunnelbroker_server='66.220.18.42' |
61 |
|
|
;; |
62 |
|
|
backhome) |
63 |
|
|
hostname='mustang.douglasthrift.net' |
64 |
douglas |
1410 |
tunnelbroker_server='66.220.18.42' |
65 |
douglas |
1407 |
;; |
66 |
|
|
esac |
67 |
|
|
|
68 |
|
|
: ${new_ip_address:=`host -t a $hostname | cut -d ' ' -f 4`} |
69 |
|
|
|
70 |
|
|
[ -n "$tunnelbroker_server" ] && tunnelbroker |
71 |
|
|
|
72 |
|
|
dns |
73 |
douglas |
933 |
;; |
74 |
|
|
esac |