aboutsummaryrefslogtreecommitdiffstats
path: root/update-tunnelbroker
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2019-01-03 17:45:43 +0100
committerGravatar Christian Hesse <mail@eworm.de>2019-01-04 12:35:34 +0100
commit870f00bb36f5af3088344371764da48bbde9651a (patch)
tree4e41839d17515cf05cb563fbb4dee92970889941 /update-tunnelbroker
parent7d06a7e8c2b66a12db65130bddb3578b3f04468f (diff)
global: variable names are CamelCase
___ _ ___ __ / _ )(_)__ _ / _/__ _/ /_ / _ / / _ `/ / _/ _ `/ __/ /____/_/\_, / /_/ \_,_/\__/ _ __ /___/ _ __ | | / /___ __________ (_)___ ____ _/ / | | /| / / __ `/ ___/ __ \/ / __ \/ __ `/ / | |/ |/ / /_/ / / / / / / / / / / /_/ /_/ |__/|__/\__,_/_/ /_/ /_/_/_/ /_/\__, (_) /____/ RouterOS has some odd behavior when it comes to variable names. Let's have a look at the interfaces: [admin@MikroTik] > / interface print where name=en1 Flags: D - dynamic, X - disabled, R - running, S - slave # NAME TYPE ACTUAL-MTU L2MTU 0 RS en1 ether 1500 1598 That looks ok. Now we use a script: { :local interface "en1"; / interface print where name=$interface; } And the result... [admin@MikroTik] > { :local interface "en1"; {... / interface print where name=$interface; } Flags: D - dynamic, X - disabled, R - running, S - slave # NAME TYPE ACTUAL-MTU L2MTU 0 RS en1 ether 1500 1598 ... still looks ok. We make a little modification to the script: { :local name "en1"; / interface print where name=$name; } And the result: [admin@MikroTik] > { :local name "en1"; {... / interface print where name=$name; } Flags: D - dynamic, X - disabled, R - running, S - slave # NAME TYPE ACTUAL-MTU L2MTU 0 RS en1 ether 1500 1598 1 S en2 ether 1500 1598 2 S en3 ether 1500 1598 3 S en4 ether 1500 1598 4 S en5 ether 1500 1598 5 R br-local bridge 1500 1598 Ups! The filter has no effect! That happens whenever the variable name ($name) matches the property name (name=). And another modification: { :local type "en1"; / interface print where name=$type; } And the result: [admin@MikroTik] > { :local type "en1"; {... / interface print where name=$type; } Flags: D - dynamic, X - disabled, R - running, S - slave # NAME TYPE ACTUAL-MTU L2MTU Ups! Nothing? Even if the variable name ($type) matches whatever property name (type=) things go wrong. The answer from MikroTik support (in Ticket#2019010222000454): > This is how scripting works in RouterOS and we will not fix it. To get around this we use variable names in CamelCase. Let's hope Mikrotik never ever introduces property names in CamelCase... *fingers crossed*
Diffstat (limited to 'update-tunnelbroker')
-rw-r--r--update-tunnelbroker26
1 files changed, 13 insertions, 13 deletions
diff --git a/update-tunnelbroker b/update-tunnelbroker
index fccd41c..cf8af45 100644
--- a/update-tunnelbroker
+++ b/update-tunnelbroker
@@ -3,11 +3,11 @@
# 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 TunnelUrl;
+:global TunnelUser;
+:global TunnelPass;
+:global TunnelId;
+:global TunnelInt;
:global CertificateAvailable;
@@ -16,22 +16,22 @@
}
# 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 from cloud
/ ip cloud force-update;
-while ([ / ip cloud get status ] != "updated" ) do={
+:while ([ / ip cloud get status ] != "updated") do={
:delay 1s;
}
-:local tunnelip [ / ip cloud get public-address ];
+:local TunnelIp [ / ip cloud get public-address ];
-:if ($tunnelip != $tunnellastip) do={
+:if ($TunnelIp != $TunnelLastIp) do={
$CertificateAvailable "Starfield Secure Certificate Authority - G2" "starfield";
- :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 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;
+ ("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.";
}