|
17 | 17 | :global LogPrintExit2; |
18 | 18 | :global ParseKeyValueStore; |
19 | 19 |
|
20 | | -:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false || \ |
21 | | - [ $CertificateAvailable "R3" ] = false) do={ |
| 20 | +:if ([ $CertificateAvailable "Starfield Secure Certificate Authority - G2" ] = false) do={ |
22 | 21 | $LogPrintExit2 error $0 ("Downloading required certificate failed.") true; |
23 | 22 | } |
24 | 23 |
|
25 | | -:local PublicAddress; |
26 | | -:do { |
27 | | - :set PublicAddress ([ /tool/fetch check-certificate=yes-without-crl \ |
28 | | - "https://ipv4.showipv6.de/short" output=user as-value ]->"data"); |
29 | | -} on-error={ |
30 | | - $LogPrintExit2 error $0 ("Failed getting public address.") true; |
31 | | -} |
32 | | - |
33 | | -:if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={ |
34 | | - $LogPrintExit2 warning $0 ("Looks like your device does not have the public address. NAT by ISP?") false; |
35 | | -} |
36 | | - |
37 | 24 | :foreach Interface in=[ /interface/6to4/find where comment~"^tunnelbroker" !disabled ] do={ |
| 25 | + :local I 0; |
| 26 | + :local Response ""; |
38 | 27 | :local InterfaceVal [ /interface/6to4/get $Interface ]; |
| 28 | + :local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ]; |
| 29 | + |
| 30 | + :while ($I < 3 && $Response = "") do={ |
| 31 | + :do { |
| 32 | + :set Response ([ /tool/fetch check-certificate=yes-without-crl \ |
| 33 | + ("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \ |
| 34 | + user=($Comment->"user") password=($Comment->"pass") output=user as-value ]->"data"); |
| 35 | + } on-error={ |
| 36 | + :delay 10s; |
| 37 | + :set I ($I + 1); |
| 38 | + } |
| 39 | + } |
39 | 40 |
|
40 | | - :if ($PublicAddress != $InterfaceVal->"local-address") do={ |
41 | | - :local I 0; |
42 | | - :local Success false; |
43 | | - :local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ]; |
| 41 | + :if (!($Response~"^(good|nochg) ")) do={ |
| 42 | + $LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker or unexpected response!") true; |
| 43 | + } |
44 | 44 |
|
45 | | - $LogPrintExit2 info $0 ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress) false; |
46 | | - :while ($I < 3 && $Success = false) do={ |
47 | | - :do { |
48 | | - /tool/fetch check-certificate=yes-without-crl \ |
49 | | - ("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \ |
50 | | - user=($Comment->"user") password=($Comment->"pass") output=none as-value; |
51 | | - :set Success true; |
52 | | - } on-error={ |
53 | | - :delay 10s; |
54 | | - :set I ($I + 1); |
55 | | - } |
56 | | - } |
57 | | - :if ($Success = false) do={ |
58 | | - $LogPrintExit2 error $0 ("Failed sending the local address to tunnelbroker! Wrong credentials?") true; |
| 45 | + :local PublicAddress [ :pick $Response ([ :find $Response " " ] + 1) [ :find $Response "\n" ] ]; |
| 46 | + |
| 47 | + :if ($PublicAddress != $InterfaceVal->"local-address") do={ |
| 48 | + :if ([ :len [ /ip/address find where address~("^" . $PublicAddress . "/") ] ] < 1) do={ |
| 49 | + $LogPrintExit2 warning $0 ("Looks like your device does not have the public address. NAT by ISP?") false; |
59 | 50 | } |
| 51 | + |
| 52 | + $LogPrintExit2 info $0 ("Local address changed, updating tunnel configuration with address: " . $PublicAddress) false; |
60 | 53 | /interface/6to4/set $Interface local-address=$PublicAddress; |
61 | | - } else={ |
62 | | - $LogPrintExit2 debug $0 ("All tunnelbroker configuration is up to date for interface " . $InterfaceVal->"name" . ".") false; |
63 | 54 | } |
64 | 55 | } |
0 commit comments