The problem is there's some sort of error I can't figure out. /system script print highlights the brace in front of the last else statement but I can't figure out for the life of me what the problem is.
Code: Select all
### Settings ###
[redacted]
### Script Begins ###
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:global ipddns [:resolve $ddnshost]
# All return codes from members.dyndns.org
:global resultcodes {good="Update successful";
nochg="WARNING: Update not needed, repeated attempts may cause you to be blocked.";
badauth="The username and password pair do not match a real user.";
notfqdn="The hostname specified is not a fully-qualified domain name.";
nohost="The hostname specified does not exist in this user account.";
numhost="Too many hosts (more than 20) specified in an update.";
abuse="The hostname specified is blocked for update abuse.";
badagent="The user agent was not sent or HTTP method is not permitted.";
dnserr="DNS error encountered.";
911="There is a problem or scheduled maintenance on our side."
}
# Check ip address and remove subnet.
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynDNS: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
}
# Determine if an update is required.
:if ($ipddns != $ipfresh) do={
:local logname "dyndns.$ddnshost"
:log info ("DynDNS: IP-DynDNS = $ipddns")
:log info ("DynDNS: IP-Fresh = $ipfresh")
:log info "DynDNS: Update IP needed, saving UPDATE...!"
/tool fetch url="https://$ddnsuser:$ddnstoken@members.dyndns.org/v3/update?hostname=$ddnshost&myip=$ipfresh" keep-result=yes dst-path=$logname;
:local result [ /file get [ /file find name="$logname" ] contents ]
/file remove [ /file get [ /file find name="$logname" ]
:put "Server returned: $result";
# Separate return code from IP address
:for i from=0 to=( [:len $result] - 1) do={
:if ( [:pick $result $i] = " ") do={
:set result [:pick $result 0 $i]
}
}
:put "Return code is: $result";
:foreach resultcode,desc in=$resultcodes do={
:if ( $result = $resultcode ) do={
:log info ("DynDNS: $desc")
}
}
:log info ("DynDNS: IP updated to $ipfresh!")
} else={
:log info ("DynDNS: IP-DynDNS = $ipddns")
:log info ("DynDNS: IP-Fresh = $ipfresh")
:log info "DynDNS: no update required"
}