Community discussions

MikroTik App
 
Kameric
just joined
Topic Author
Posts: 8
Joined: Wed Mar 19, 2014 9:54 am

Run script with php api

Thu Jun 05, 2014 9:58 am

I have one problem,the script in mikrotik is script that remove address from address list and working great when runing from winbox.But when i run php code:
require('api.php');

$API = new routeros_api();

$API->debug = true;

if ($API->connect('111.111.111.1', 'adop', 'user')) {

$API->write('/system/script/run',false);
$API->write("=.id=*16");


$API->disconnect();

}
count on winbox for this script is say that script is runed and every time i runed this php code count is rising but nothing happend.What is problem,authorisating or somthing???Sorry for bad english
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Run script with php api

Thu Jun 05, 2014 11:55 am

Does the script by any chance use numbers?

I think maybe RouterOS is trying to execute the script as if it was executing API commands... but that means you can't use numbers in your script.
 
Kameric
just joined
Topic Author
Posts: 8
Joined: Wed Mar 19, 2014 9:54 am

Re: Run script with php api

Thu Jun 05, 2014 12:08 pm

Script is:
/ip firewall address-list {
remove [find address=192.168.111.245]
}
and router say when i run php that script is executed but nothing happend;
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Run script with php api

Thu Jun 05, 2014 12:18 pm

Try to do a single read() before you disconnect.

Also, try to linearize the script, e.g.
/ip firewall address-list
remove [find address=192.168.111.245]
 
Kameric
just joined
Topic Author
Posts: 8
Joined: Wed Mar 19, 2014 9:54 am

Re: Run script with php api

Thu Jun 05, 2014 12:33 pm

Thank you for your answers ,but this is what i get from api in browser:
Connection attempt #1 to 192.168.111.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=f5990f4609726bb20a147d7031242c5e <<< [6] /login <<< [11] =name=admin <<< [44] =response=006f848e08707c84cdc832a2777bfc626b >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [18] /system/script/run <<< [8] =.id=*17 Disconnected...

and again counter says one number more but nothing happend;
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Run script with php api

Thu Jun 05, 2014 12:51 pm

Do a read() I tell ya.

If you do one more read(), the end of that output should be more like
<<< [18] /system/script/run <<< [8] =.id=*17 >>> [5/5] bytes read. >>> [5, 5]!done Disconnected... 
 
Kameric
just joined
Topic Author
Posts: 8
Joined: Wed Mar 19, 2014 9:54 am

Re: Run script with php api

Thu Jun 05, 2014 1:11 pm

ok i will do that but i dont understand what mean with this single read(),example??Please;
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Run script with php api

Thu Jun 05, 2014 2:13 pm

$API->write("=.id=*16");

$API->read();
 
Kameric
just joined
Topic Author
Posts: 8
Joined: Wed Mar 19, 2014 9:54 am

Re: Run script with php api

Thu Jun 05, 2014 4:09 pm

i do exactly same but again response from api is:

Connection attempt #1 to 192.168.111.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=1300078c7e914e04a7ac177c14b02981 <<< [6] /login <<< [11] =name=admin <<< [44] =response=007c600f1cfd137f7a9074aa96524f67f8 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [18] /system/script/run <<< [8] =.id=*17 Disconnected...

Who is online

Users browsing this forum: Partial and 21 guests