aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Michael Gisbers <michael@gisbers.de>2019-01-02 11:25:45 +0100
committerGravatar Christian Hesse <mail@eworm.de>2019-01-02 15:02:42 +0100
commitca16f286efd21a8c0d627a85679f6995af26889f (patch)
tree32f4265aed13187b796e176b05b47c3750d3885c
parent69e76f5eccd130bf432caa0ba1153d20783d37ba (diff)
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>
-rw-r--r--global-config7
-rw-r--r--update-tunnelbroker40
2 files changed, 28 insertions, 19 deletions
diff --git a/global-config b/global-config
index bd3250f..cba5e27 100644
--- a/global-config
+++ b/global-config
@@ -95,6 +95,13 @@
#:global "cert-renew-url" "https://example.com/certificates/";
: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!
:global "sent-routeros-update-notification" "-";
:global "sent-lte-firmware-update-notification" "-";
diff --git a/update-tunnelbroker b/update-tunnelbroker
index 05a4a8e..ee8e0e8 100644
--- a/update-tunnelbroker
+++ b/update-tunnelbroker
@@ -1,31 +1,33 @@
#!rsc
# RouterOS script: update-tunnelbroker
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
+# Michael Gisbers <michael@gisbers.de>
-:local tunnelurl "ipv4.tunnelbroker.net";
-:local tunneluser "user";
-:local tunnelpass "v3ry-s3cr3t";
-:local tunnelid "user-XXX.tunnel.tserv6.fra1.ipv6.he.net";
+:global tunnelurl;
+:global tunneluser;
+:global tunnelpass;
+:global tunnelid;
+:global tunnelint;
-# name of the local tunnel interface
-:local tunnelint "tunnelbroker";
+: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 on interface with default route
-: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 ];
+# 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 ];
-# Did we get an IP address to compare?
-:if ([ :typeof $tunnelip ] = nil) do={
- :log warning ("No default route? Could not get address, please check.");
-} else={
- :if ($tunnelip != $tunnellastip) do={
- :log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $tunnelip);
- / tool fetch mode=https address=$tunnelurl user=$tunneluser password=$tunnelpass \
+:if ($tunnelip != $tunnellastip) do={
+ :log info ("Local address changed, sending UPDATE to tunnelbroker! New address: " . $tunnelip);
+ / tool fetch mode=https address=$tunnelurl user=$tunneluser password=$tunnelpass \
src-path=("/nic/update\?hostname=" . $tunnelid) 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.";
- }
+ / interface 6to4 set [ / interface 6to4 find where name=$tunnelint ] local-address=$tunnelip;
+} else={
+ :log debug "All tunnelbroker configuration is up to date.";
}