routeros-scripts/update-tunnelbroker

38 lines
1.3 KiB
Plaintext
Raw Normal View History

#!rsc
2018-07-05 13:29:26 +00:00
# RouterOS script: update-tunnelbroker
2019-01-01 20:19:19 +00:00
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
# Michael Gisbers <michael@gisbers.de>
2018-07-05 13:29:26 +00:00
:global tunnelurl;
:global tunneluser;
:global tunnelpass;
:global tunnelid;
:global tunnelint;
2018-07-05 13:29:26 +00:00
:global CertificateAvailable;
:if ([ / ip cloud get ddns-enabled ] != true) do={
:error "IP cloud DDNS is not enabled.";
}
2018-07-05 13:29:26 +00:00
# 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 ];
2018-07-05 13:29:26 +00:00
: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.";
2018-07-05 13:29:26 +00:00
}