Page 1 of 1

Run script with php api

Posted: Thu Jun 05, 2014 9:58 am
by Kameric
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

Re: Run script with php api

Posted: Thu Jun 05, 2014 11:55 am
by boen_robot
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.

Re: Run script with php api

Posted: Thu Jun 05, 2014 12:08 pm
by Kameric
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;

Re: Run script with php api

Posted: Thu Jun 05, 2014 12:18 pm
by boen_robot
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]

Re: Run script with php api

Posted: Thu Jun 05, 2014 12:33 pm
by Kameric
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;

Re: Run script with php api

Posted: Thu Jun 05, 2014 12:51 pm
by boen_robot
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... 

Re: Run script with php api

Posted: Thu Jun 05, 2014 1:11 pm
by Kameric
ok i will do that but i dont understand what mean with this single read(),example??Please;

Re: Run script with php api

Posted: Thu Jun 05, 2014 2:13 pm
by boen_robot
$API->write("=.id=*16");

$API->read();

Re: Run script with php api

Posted: Thu Jun 05, 2014 4:09 pm
by Kameric
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...