aboutsummaryrefslogblamecommitdiffstats
path: root/update-tunnelbroker
blob: fccd41c2b91dd5590a5cf6da7b53feecbb8afbcf (plain) (tree)
1
2
3
4
5
6
7
8
9
10
     
                                      
                                                         
                                                              
 



                   
 
                             

                                                  


                                                                                                           




                                                    
 
                                     
                                                                                  
                                                                                                 

                                                                        

                                                                                               
 
#!rsc
# RouterOS script: update-tunnelbroker
# 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 CertificateAvailable;

: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 from cloud
/ ip cloud force-update;
while ([ / ip cloud get status ] != "updated" ) do={
  :delay 1s;
}
:local tunnelip [ / ip cloud get public-address ];

: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.";
}