1
0
mirror of https://github.com/eworm-de/routeros-scripts.git synced 2024-05-11 05:55:19 +00:00
eworm-de-routeros-scripts/update-tunnelbroker
Christian Hesse ceaa83b83e global-functions: merge $LogAnd{Error,Put} to $LogPrintExit ...
... and fix logging.

Logging with severity from variable (:log $severity ...) is not
possible, this is considered a syntax error. Also the 'workaround' with
parsing code failed with missing message in log.

The reliable code is a lot longer, so merge the two functions to save a
lot of duplicate code.
2020-02-26 14:19:54 +01:00

37 lines
1.4 KiB
Plaintext

#!rsc
# RouterOS script: update-tunnelbroker
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
# Michael Gisbers <michael@gisbers.de>
:global CertificateAvailable;
:global ParseKeyValueStore;
:global LogPrintExit;
:if ([ / ip cloud get ddns-enabled ] != true) do={
$LogPrintExit error "IP cloud DDNS is not enabled." true;
}
# Get the current ip address from cloud
/ ip cloud force-update;
:while ([ / ip cloud get status ] != "updated") do={
:delay 1s;
}
:local PublicAddress [ / ip cloud get public-address ];
:foreach Interface in=[ / interface 6to4 find where comment~"^tunnelbroker" !disabled ] do={
:local InterfaceVal [ / interface 6to4 get $Interface ];
:if ($PublicAddress != $InterfaceVal->"local-address") do={
:local Comment [ $ParseKeyValueStore ($InterfaceVal->"comment") ];
$CertificateAvailable "Starfield Secure Certificate Authority - G2";
:log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $PublicAddress);
/ tool fetch check-certificate=yes-without-crl \
("https://ipv4.tunnelbroker.net/nic/update\?hostname=" . $Comment->"id") \
user=($Comment->"user") password=($Comment->"pass") output=none;
/ interface 6to4 set $Interface local-address=$PublicAddress;
} else={
:log debug ("All tunnelbroker configuration is up to date for interface " . $InterfaceVal->"name" . ".");
}
}