Community discussions

MikroTik App
 
bderleta
just joined
Topic Author
Posts: 8
Joined: Thu May 04, 2023 3:01 pm

Script with fetch stopped working in 7.13

Thu Dec 28, 2023 3:36 am

Hello,

I can't manage what I'm doing wrong with this one - it just silently exits on the ":local result (/tool fetch..." call without any error when called from WinBox "Run script" button, or scheduler, but works otherwise fine when ran from terminal. This is the behavior under 7.13 and latest 7.14 beta, when downgraded to 7.12.1 - works from scheduler, button or terminal, does not matter. The proper root CA is installed and trusted. Can I ask for some help or advice? I use this one to build allow list for my homelab HTTP server, it's put in scheduler every 12hrs.

Device used - 5009UPr+S+, arm64. I did not find any solution nor hint in existing threads apart from some singular posts about changed fetch behavior in 7.13, but I do not see anything that could cause such problem. As I mentioned, in 7.12 it works well regardless where it's called from, 7.13 onwards - only from terminal.

Both in scheduler and script, policies are enabled: "read", "write" and "test". It is created and run as user with full privileges.
# Updates IP from cloudflare and puts them to address-list "cloudflare" with 1 day timeout
:local result ([/tool fetch check-certificate=yes mode=https output=user url="https://www.cloudflare.com/ips-v4/" as-value])
:if ($result->"status" = "finished") do={
	:local n 0
	:local a 0
	:local recoded
	:log info "cloudflare-update: remote file fetched"
	:for i from=0 to=([:len ($result->"data")] - 1) do={ 
		:local char [:pick ($result->"data") $i]
		:if ($char = "\n") do={:set $char ","}
		:set recoded ($recoded . $char) 
	}        
	:local iplist [:toarray $recoded]
	:foreach ip in=$iplist do={ 
		:do {
			/ip firewall address-list add list=cloudflare address=$ip timeout=86400
			:put "$ip inserted"
			:set n ($n + 1)
			:set a ($a + 1)
		} on-error={
			:foreach elem in=[/ip firewall address-list find list="cloudflare" address=$ip] do={
				/ip firewall address-list set $elem timeout=86400
				:put "$ip updated"
				:set a ($a + 1)
			}
		};
	};
	:log info "cloudflare-update: $a processed ($n new)"
}
 
bderleta
just joined
Topic Author
Posts: 8
Joined: Thu May 04, 2023 3:01 pm

Re: Script with fetch stopped working in 7.13

Thu Dec 28, 2023 4:02 am

Please, close as I can't delete this thread. Upgraded again straight to 7.14beta3 and it works now... I stay puzzled, but I can't debug it any further.

Who is online

Users browsing this forum: verneti and 9 guests