Community discussions

MikroTik App
 
elico
Member Candidate
Member Candidate
Topic Author
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

using fetch tool on ppp on-up script

Mon Jan 18, 2021 2:44 pm

I have a nice setup with pppoe/l2tp/pptp server it works great of course.
I wanted to trigger a remote api call using "/tool fetch" however it doesn't work.

I am trying to run the next:
/tool fetch address=192.168.200.80 host=192.168.200.80 mode=http src-path=login output=none;
:log info "#####$user LOGIN";
But for some reason both the tool fetch and the log are not working one after the other.
The log by itself works and then I am adding the fetch and it stops works.

Is there any way to run the fetch tool in "On Up" script?

What are my options to run a fetch tool?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7041
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: using fetch tool on ppp on-up script

Tue Jan 19, 2021 10:56 am

ppp on-up script has limited permissions.
You need to add a script with "dont-require-permissions" set to yes and execute it from ppp on-up.
 
elico
Member Candidate
Member Candidate
Topic Author
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: using fetch tool on ppp on-up script

Tue Jan 19, 2021 7:10 pm

My main concern is the user variable.
I need it for the fetch script.

What are my options?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7041
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: using fetch tool on ppp on-up script

Wed Jan 20, 2021 10:13 am

If a script is executed from PPP on-up, then the user variable will be available.
 
elico
Member Candidate
Member Candidate
Topic Author
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: using fetch tool on ppp on-up script

Wed Jan 20, 2021 4:26 pm

@mrz, I am trying to figure out how to do that but can't.
I have the next in the ppp on-up script:
:log info "****** $user Connected";
/system script run test;
and in the test script:
:log info "#####$user Connected";
The logs shows:
****** eliezer Connected
##### Connected
So it's not accessible directly.
There are other issues.
Let say I have used a variable, a global variable is too wide.
Would a local variable work?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7041
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: using fetch tool on ppp on-up script  [SOLVED]

Thu Jan 21, 2021 10:17 am

Add a script in system scripts menu
/system script add name=myScript source={ :log info "****** $user Connected"; }

Then set:
on-up=myScript
 
elico
Member Candidate
Member Candidate
Topic Author
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: using fetch tool on ppp on-up script

Sun Jan 24, 2021 7:56 am

Thanks, Eventually I managed to make it work with the next is my script:
:do {
	:local Url ("http://ngtech.co.il/index.html");
	/tool fetch url=$Url keep-result=no;
	:log info "*****$user Connected";
} on-error={
	:log info "Error";
}

:log info "#####$user Connected";
The on-error is called on a 404 so it's a bit weird for me.

By the way a selection can be added to the winbox menu to select a script or write one.

Who is online

Users browsing this forum: marcelofares, rextended and 21 guests