Community discussions

MikroTik App
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

RouterOS PHP API class

Sun Nov 29, 2009 1:45 pm

I've create Yet Another PHP RouterOS PHP API:
http://svn.osk-net.pl/svn/rosapi/trunk

Documentation:
http://svn.osk-net.pl/svn/rosapi/trunk/ ... ation.html

Doxygen documentation:
http://svn.osk-net.pl/svn/rosapi/trunk/ ... tated.html

SVN:
http://svn.osk-net.pl/svn/rosapi

The main purpose of another RouterOS PHP API class it to simplify configuration update processes. Example: We have about 20 access points and for each of them we have connected about 20 wds links. Using automatic configuration process we can store information about all wds links in one place. It can be MySQL database.

Using set of configuration files router's can be divided into function groups (ie. router, main-access-point, client-access-point, switch) and be configured from central server automatically. ONLY changed configuration will be updated, so in most cases no configuration will change.
Last edited by ayufan on Tue Apr 13, 2010 1:27 pm, edited 5 times in total.
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Mon Nov 30, 2009 11:34 am

 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Tue Dec 01, 2009 12:46 am

Version 0.2.
- added callbacks
- simple btest example using callbacks to run many simultaneous tests
- updated documentation
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Tue Dec 01, 2009 3:57 pm

I've made my http://ayufan.eu/local/src/rosapi/trunk ... xample.php even more powerful. It's script that can run many simultaneous bandwidth-tests. It's supports only transmit mechanism, because there is a bug with btest that you cant specify different receive and transmit limits. It can be used to check network latencies under heavy load. Uses ncurses to show results :)

Syntax is very simple:
php btest_example.php <login>:<password>@<host> <destination1>@<speed>@<protocol>...
<host> - source host from which to run btests
<speed> - maximum speed in format: 1k, 1M, 1G
<protocol> - protocol to be used: it can be tcp:<connection_count> or udp:<packet_size>
  tcp - use tcp with 1 connection
  tcp:20 - use tcp with 20 connections
  udp:1400 - use udp with packet size 1400
Last edited by ayufan on Mon Mar 22, 2010 1:55 pm, edited 3 times in total.
 
Nerr
just joined
Posts: 1
Joined: Mon Mar 22, 2010 7:47 am

Re: RouterOS PHP API class

Mon Mar 22, 2010 7:49 am

great class, thank you
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Mon Mar 22, 2010 1:53 pm

I know that, I use it to, to manage many routerboards :)
Latest version is always on SVN. Check Logs to see what changed.

Updated my original posts and added doxygen documentation.

Kamil
 
cieplik206
Trainer
Trainer
Posts: 290
Joined: Sun Jul 01, 2007 12:25 am
Contact:

Re: RouterOS PHP API class

Wed Mar 24, 2010 12:44 am

Is there no need to logout from API session in your script ?
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Wed Mar 24, 2010 1:54 am

for now there is no disconnect method, php recycles all sockets when finishes.
 
jprepuk
just joined
Posts: 2
Joined: Fri Mar 26, 2010 4:19 pm

Re: RouterOS PHP API class

Fri Mar 26, 2010 5:15 pm

Hi all

Is it possible to use the where section in the command as in the terminal?
/interface/wireless/registration-table/print stats where mac-address=00:0C:42:61:75:23

Thank you

Janos Prepuk
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Mon Mar 29, 2010 6:29 pm

Is it possible to use the where section in the command as in the terminal?
/interface/wireless/registration-table/print stats where mac-address=00:0C:42:61:75:23
http://wiki.mikrotik.com/wiki/API#Queries
 
cieplik206
Trainer
Trainer
Posts: 290
Joined: Sun Jul 01, 2007 12:25 am
Contact:

Re: RouterOS PHP API class

Mon Mar 29, 2010 10:47 pm

for now there is no disconnect method, php recycles all sockets when finishes.

PHP recycles sockets, but i see a long list of active admins in my ROS,
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Mon Mar 29, 2010 11:10 pm

PHP recycles sockets, but i see a long list of active admins in my ROS,
it's a bug. upgrade your ROS to the latest version
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Tue Mar 30, 2010 12:39 pm

I do have the same problem with 3.28. With never versions everything is OK.

If you use connection for example in function:
function do_sth() {
 $conn = RotuerOS::connect("192.168.1.1", "admin", "");
 $conn->getall("/interface/wireless");
}
PHP will automatically close that connection when leaves function.
So there is no need for separate method for disconnect :)
You can also use:
  unset($conn);
Kamil
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Tue Mar 30, 2010 3:02 pm

I do have the same problem with 3.28. With never versions everything is OK.
actually, 3.27 and 3.28 should not have this problem %) AFAIR, 3.24 has it
 
portfire
just joined
Posts: 3
Joined: Tue Apr 27, 2010 4:28 pm

Re: RouterOS PHP API class

Tue Apr 27, 2010 4:49 pm

Hello i use this api but , I can't run the following code;
$conn->getall("/ip/hotspot/active/print");
i want to get online hotspot users list but doesnt work and gives the following error

trap[/ip/hotspot/active/print/getall]: no such command

someone can help me pls.
 
portfire
just joined
Posts: 3
Joined: Tue Apr 27, 2010 4:28 pm

Re: RouterOS PHP API class

Wed Apr 28, 2010 9:46 am

hello i have a problem i use this api class;

i want to see online hotspot users list and use following code
$conn->getall("/ip/hotspot/active/print");
but doesnt work and give following error
trap[/ip/hotspot/active/print/getall]: no such command

How can I solve this problem?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Thu Apr 29, 2010 11:50 am

huh... seems like that function appends '/getall' to the command. try
$conn->getall("/ip/hotspot/active");
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: RouterOS PHP API class

Thu Apr 29, 2010 2:19 pm

if you are testing something and get some problems, use python API, as there can everything be done, what can be done using API.

in this case you would know then, that problem is with PHP API, not API itself.
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Thu Apr 29, 2010 7:41 pm

I didn't have any problem with my PHP API class. I have been using it for about 1 year with simple features as well as with differencing synchronization.
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: RouterOS PHP API class

Thu Apr 29, 2010 8:30 pm

ayufan,

I just have to say thank you. This is really great work, with excellent documentation. I'm going to start digging in to use for some upcoming projects.
 
portfire
just joined
Posts: 3
Joined: Tue Apr 27, 2010 4:28 pm

Re: RouterOS PHP API class

Wed May 05, 2010 11:40 am

huh... seems like that function appends '/getall' to the command. try
$conn->getall("/ip/hotspot/active");

this code worked thanks a lot.
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Wed May 05, 2010 1:45 pm

If any of You produce something useful derived from my scripts - please share it with community ;)
I would be very aprreciated.

Kamil
 
User avatar
maximan
Trainer
Trainer
Posts: 543
Joined: Sat May 29, 2004 12:10 am
Location: Rio Cuarto, Argentina
Contact:

Re: RouterOS PHP API class

Sat Jul 17, 2010 2:20 am

the source of class has 404 (not found). Where i can find this php class?

M.
 
ayufan
Member
Member
Topic Author
Posts: 334
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Sun Jul 18, 2010 2:12 am

the source of class has 404 (not found). Where i can find this php class?

M.
Fixed. Try now.
 
tomburger
just joined
Posts: 3
Joined: Sun May 13, 2018 1:25 pm

Re: RouterOS PHP API class

Mon May 14, 2018 3:15 pm

please can I get with this API class values from /interface wireless monitor 0 once ?
i try with $conn->getall("/interface/wireless", false, "monitor 0 once"). but it dosn't work
or I should use another api class?
thanks for advice
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Tue May 15, 2018 7:30 pm

please can I get with this API class values from /interface wireless monitor 0 once ?
i try with $conn->getall("/interface/wireless", false, "monitor 0 once"). but it dosn't work
or I should use another api class?
thanks for advice
The API command should be
/interface/wireless/monitor
=.id=wlan1
 
tomburger
just joined
Posts: 3
Joined: Sun May 13, 2018 1:25 pm

Re: RouterOS PHP API class

Thu May 17, 2018 3:18 pm

The API command should be
/interface/wireless/monitor
=.id=wlan1
This I try, but not work

trap[/interface/wireless/monitor/getall]: no such command
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Thu May 17, 2018 4:24 pm

The command is
/interface/wireless/monitor
not
/interface/wireless/monitor/getall
Looks like you're using wrong method.
 
tomburger
just joined
Posts: 3
Joined: Sun May 13, 2018 1:25 pm

Re: RouterOS PHP API class

Fri Jun 01, 2018 12:35 pm

as described here https://wiki.mikrotik.com/wiki/RouterOS_PHP_class
available methods are:
connect, setTimeout, dispatch, getall, set, reboot, cancel, fetchurl, move, add, remove, unsett, btest, scan

none looks to work with wireless monitor :-(
maybe i must change to another API class, but this class looks good for provisioning with its parser
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Fri Jun 01, 2018 1:44 pm

Or you just do your own method :) For example, making a copy of 'scan' and adjusting it.
 
sjobbe
just joined
Posts: 20
Joined: Mon Jan 03, 2011 11:40 am

Re: RouterOS PHP API class

Thu Jun 21, 2018 1:42 pm

Did this break with the latest update 6.42.4 (2018-Jun-15 14:14)? I have been using it for years and now it fails at login. I do not see in change log anything that would affect this...?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Thu Jun 21, 2018 5:27 pm

No, there were no changes, my API test program still connects to the 6.42.4 router.
 
sjobbe
just joined
Posts: 20
Joined: Mon Jan 03, 2011 11:40 am

Re: RouterOS PHP API class

Mon Jun 25, 2018 8:41 am

Solved: I needed to add "winbox" in "Policies" for my user group that I call API. In the past it was enough to have read, write and api rights for the group. Something has changed in the new version regarding access rights or user groups that caused this.

Winbox has nothing to do with this but hey, now it works.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Mon Jun 25, 2018 11:34 am

Known problem, should be fixed in next version
 
sjobbe
just joined
Posts: 20
Joined: Mon Jan 03, 2011 11:40 am

Re: RouterOS PHP API class

Tue Jun 26, 2018 9:04 am

What about the upcoming 6.43 version? Does this break as the API authentication process seems to have changed? (I do not install/test release candidates)
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Tue Jun 26, 2018 12:00 pm

What about the upcoming 6.43 version? Does this break as the API authentication process seems to have changed? (I do not install/test release candidates)
Yes, you need API Client version that supports 6.43 authentication.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8712
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: RouterOS PHP API class

Mon Aug 31, 2020 4:01 pm

@ayufan, do you have some working repo now? I hope the source code is not lost...

Who is online

Users browsing this forum: No registered users and 7 guests