update-tunnelbroker: move configuration to global-config...

... and get the external ip address from cloud.

Signed-off-by: Michael Gisbers <michael@gisbers.de>
Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Michael Gisbers 2019-01-02 11:25:45 +01:00 committed by Christian Hesse
parent 69e76f5ecc
commit ca16f286ef
2 changed files with 30 additions and 21 deletions

View file

@ -95,6 +95,13 @@
#:global "cert-renew-url" "https://example.com/certificates/"; #:global "cert-renew-url" "https://example.com/certificates/";
:global "cert-renew-pass" "v3ry-s3cr3t"; :global "cert-renew-pass" "v3ry-s3cr3t";
# Configuration for update-tunnelbroker
#:global tunnelurl "ipv4.tunnelbroker.net";
#:global tunneluser "user";
#:global tunnelpass "v3ry-s3cr3t";
#:global tunnelid "user-XXX.tunnel.tserv6.fra1.ipv6.he.net";
#:global tunnelint "tunnelbroker";
# Do *NOT* change these! # Do *NOT* change these!
:global "sent-routeros-update-notification" "-"; :global "sent-routeros-update-notification" "-";
:global "sent-lte-firmware-update-notification" "-"; :global "sent-lte-firmware-update-notification" "-";

View file

@ -1,31 +1,33 @@
#!rsc #!rsc
# RouterOS script: update-tunnelbroker # RouterOS script: update-tunnelbroker
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de> # Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
# Michael Gisbers <michael@gisbers.de>
:local tunnelurl "ipv4.tunnelbroker.net"; :global tunnelurl;
:local tunneluser "user"; :global tunneluser;
:local tunnelpass "v3ry-s3cr3t"; :global tunnelpass;
:local tunnelid "user-XXX.tunnel.tserv6.fra1.ipv6.he.net"; :global tunnelid;
:global tunnelint;
# name of the local tunnel interface :if ([ / ip cloud get ddns-enabled ] != true) do={
:local tunnelint "tunnelbroker"; :error "IP cloud DDNS is not enabled.";
}
# get the last ip address from tunnel interface # get the last ip address from tunnel interface
:local tunnellastip [ / interface 6to4 get [ / interface 6to4 find where name=$tunnelint ] local-address ]; :local tunnellastip [ / interface 6to4 get [ / interface 6to4 find where name=$tunnelint ] local-address ];
# Get the current ip address on interface with default route # Get the current ip address from cloud
:local tunnelip [ / ip route get [ / ip route find where gateway=[ / ip route get [ / ip route find where dynamic=yes and dst-address="0.0.0.0/0" dynamic active=yes ] gateway ] dst-address!="0.0.0.0/0" ] pref-src ]; / ip cloud force-update;
while ([ / ip cloud get status ] != "updated" ) do={
# Did we get an IP address to compare? :delay 1s;
:if ([ :typeof $tunnelip ] = nil) do={ }
:log warning ("No default route? Could not get address, please check."); :local tunnelip [ / ip cloud get public-address ];
} else={
:if ($tunnelip != $tunnellastip) do={ :if ($tunnelip != $tunnellastip) do={
:log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $tunnelip); :log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $tunnelip);
/ tool fetch mode=https address=$tunnelurl user=$tunneluser password=$tunnelpass \ / tool fetch mode=https address=$tunnelurl user=$tunneluser password=$tunnelpass \
src-path=("/nic/update\?hostname=" . $tunnelid) keep-result=no; src-path=("/nic/update\?hostname=" . $tunnelid) keep-result=no;
/ interface 6to4 set [ / interface 6to4 find where name=$tunnelint ] local-address=$tunnelip; / interface 6to4 set [ / interface 6to4 find where name=$tunnelint ] local-address=$tunnelip;
} else={ } else={
:log debug "All tunnelbroker configuration is up to date."; :log debug "All tunnelbroker configuration is up to date.";
}
} }