aboutsummaryrefslogtreecommitdiffstats
path: root/update-tunnelbroker
blob: cf8af45cda9bcba5cf1521334be7d6f0dfe7e437 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!rsc
# RouterOS script: update-tunnelbroker
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
#                         Michael Gisbers <michael@gisbers.de>

:global TunnelUrl;
:global TunnelUser;
:global TunnelPass;
:global TunnelId;
:global TunnelInt;

:global CertificateAvailable;

:if ([ / ip cloud get ddns-enabled ] != true) do={
  :error "IP cloud DDNS is not enabled.";
}

# get the last ip address from tunnel interface
:local TunnelLastIp [ / interface 6to4 get [ / interface 6to4 find where name=$TunnelInt ] local-address ];

# Get the current ip address from cloud
/ ip cloud force-update;
:while ([ / ip cloud get status ] != "updated") do={
  :delay 1s;
}
:local TunnelIp [ / ip cloud get public-address ];

:if ($TunnelIp != $TunnelLastIp) do={
  $CertificateAvailable "Starfield Secure Certificate Authority - G2" "starfield";
  :log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $TunnelIp);
  / tool fetch mode=https check-certificate=yes-without-crl \
      ("https://" . $TunnelUrl . "/nic/update\?hostname=" . $TunnelId) \
      user=$TunnelUser password=$TunnelPass keep-result=no;
  / interface 6to4 set [ / interface 6to4 find where name=$TunnelInt ] local-address=$TunnelIp;
} else={
  :log debug "All tunnelbroker configuration is up to date.";
}