-
Notifications
You must be signed in to change notification settings - Fork 0
/
freedns-update.rsc
executable file
·53 lines (45 loc) · 1.83 KB
/
freedns-update.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!rsc by RouterOS
# RouterOS script: freedns-update
#
# update http://freedns.afraid.org if public IP changed
# https://github.com/martindb/routeros/blob/main/doc/freedns-update.md
:local 0 "freedns-update";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global CurrentIp;
:global FreeDnsKey;
:global SendNotification;
:global SymbolForNotification;
:global LogPrint;
:global ParseKeyValueStore;
:global IsFullyConnected;
$LogPrint debug $0 "Init";
:if ([:typeof $FreeDnsKey] != "str") do={
$LogPrint warning $0 ("FreeDnsKey not defined/loaded") true;
}
:if ([ $IsFullyConnected ] = false) do={
$LogPrint debug $0 ("System is not fully connected, not updating.");
:return false;
}
:foreach Interface in=[/interface/find where comment~"freedns" !disabled] do={
:local InterfaceVal [/interface/get $Interface];
:local inter ($InterfaceVal->"name");
:local NewIp [/ip/address/get [/ip/address/find interface=$inter] address];
$LogPrint debug $0 ("Interface $inter - NewIp: $NewIp - CurrentIp: $CurrentIp");
:if ($NewIp != $CurrentIp) do={
$LogPrint info $0 ("$inter ip changed ($CurrentIp -> $NewIp)");
:do {
/tool/fetch url=("http://freedns.afraid.org/dynamic/update.php?$FreeDnsKey") keep-result=no;
:local Comment [$ParseKeyValueStore ($InterfaceVal->"comment")];
:local Notify ($Comment->"notify");
:if ($Notify = true) do={
$SendNotification ([$SymbolForNotification "warning-sign"] . "New public IP") ("The public ip of $inter changed from $CurrentIp to $NewIp");
}
:set $CurrentIp $NewIp;
} on-error={
$LogPrint warning $0 ("Unable to update FreeDNS IP for $inter");
$SendNotification ([$SymbolForNotification "cross-mark"] . "FreeDNS error") ("$0: Unable to update FreeDNS IP for $inter");
}
};
};
$LogPrint debug $0 "End";