Page 1 of 1

RouterOS PHP API class

Posted: Sun Nov 29, 2009 1:45 pm
by ayufan
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.

Re: RouterOS PHP API class

Posted: Mon Nov 30, 2009 11:34 am
by ayufan

Re: RouterOS PHP API class

Posted: Tue Dec 01, 2009 12:46 am
by ayufan
Version 0.2.
- added callbacks
- simple btest example using callbacks to run many simultaneous tests
- updated documentation

Re: RouterOS PHP API class

Posted: Tue Dec 01, 2009 3:57 pm
by ayufan
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

Re: RouterOS PHP API class

Posted: Mon Mar 22, 2010 7:49 am
by Nerr
great class, thank you

Re: RouterOS PHP API class

Posted: Mon Mar 22, 2010 1:53 pm
by ayufan
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

Re: RouterOS PHP API class

Posted: Wed Mar 24, 2010 12:44 am
by cieplik206
Is there no need to logout from API session in your script ?

Re: RouterOS PHP API class

Posted: Wed Mar 24, 2010 1:54 am
by ayufan
for now there is no disconnect method, php recycles all sockets when finishes.

Re: RouterOS PHP API class

Posted: Fri Mar 26, 2010 5:15 pm
by jprepuk
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

Re: RouterOS PHP API class

Posted: Mon Mar 29, 2010 6:29 pm
by Chupaka
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

Re: RouterOS PHP API class

Posted: Mon Mar 29, 2010 10:47 pm
by cieplik206
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,

Re: RouterOS PHP API class

Posted: Mon Mar 29, 2010 11:10 pm
by Chupaka
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

Re: RouterOS PHP API class

Posted: Tue Mar 30, 2010 12:39 pm
by ayufan
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

Re: RouterOS PHP API class

Posted: Tue Mar 30, 2010 3:02 pm
by Chupaka
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

Re: RouterOS PHP API class

Posted: Tue Apr 27, 2010 4:49 pm
by portfire
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.

Re: RouterOS PHP API class

Posted: Wed Apr 28, 2010 9:46 am
by portfire
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?

Re: RouterOS PHP API class

Posted: Thu Apr 29, 2010 11:50 am
by Chupaka
huh... seems like that function appends '/getall' to the command. try
$conn->getall("/ip/hotspot/active");

Re: RouterOS PHP API class

Posted: Thu Apr 29, 2010 2:19 pm
by janisk
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.

Re: RouterOS PHP API class

Posted: Thu Apr 29, 2010 7:41 pm
by ayufan
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.

Re: RouterOS PHP API class

Posted: Thu Apr 29, 2010 8:30 pm
by dssmiktik
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.

Re: RouterOS PHP API class

Posted: Wed May 05, 2010 11:40 am
by portfire
huh... seems like that function appends '/getall' to the command. try
$conn->getall("/ip/hotspot/active");

this code worked thanks a lot.

Re: RouterOS PHP API class

Posted: Wed May 05, 2010 1:45 pm
by ayufan
If any of You produce something useful derived from my scripts - please share it with community ;)
I would be very aprreciated.

Kamil

Re: RouterOS PHP API class

Posted: Sat Jul 17, 2010 2:20 am
by maximan
the source of class has 404 (not found). Where i can find this php class?

M.

Re: RouterOS PHP API class

Posted: Sun Jul 18, 2010 2:12 am
by ayufan
the source of class has 404 (not found). Where i can find this php class?

M.
Fixed. Try now.

Re: RouterOS PHP API class

Posted: Mon Feb 06, 2017 11:28 pm
by MtHoodlum
Broken again.

Re: RouterOS PHP API class

Posted: Mon May 14, 2018 3:15 pm
by tomburger
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

Re: RouterOS PHP API class

Posted: Tue May 15, 2018 7:30 pm
by Chupaka
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

Re: RouterOS PHP API class

Posted: Thu May 17, 2018 3:18 pm
by tomburger
The API command should be
/interface/wireless/monitor
=.id=wlan1
This I try, but not work

trap[/interface/wireless/monitor/getall]: no such command

Re: RouterOS PHP API class

Posted: Thu May 17, 2018 4:24 pm
by Chupaka
The command is
/interface/wireless/monitor
not
/interface/wireless/monitor/getall
Looks like you're using wrong method.

Re: RouterOS PHP API class

Posted: Fri Jun 01, 2018 12:35 pm
by tomburger
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

Re: RouterOS PHP API class

Posted: Fri Jun 01, 2018 1:44 pm
by Chupaka
Or you just do your own method :) For example, making a copy of 'scan' and adjusting it.

Re: RouterOS PHP API class

Posted: Thu Jun 21, 2018 1:42 pm
by sjobbe
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...?

Re: RouterOS PHP API class

Posted: Thu Jun 21, 2018 5:27 pm
by Chupaka
No, there were no changes, my API test program still connects to the 6.42.4 router.

Re: RouterOS PHP API class

Posted: Mon Jun 25, 2018 8:41 am
by sjobbe
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.

Re: RouterOS PHP API class

Posted: Mon Jun 25, 2018 11:34 am
by Chupaka
Known problem, should be fixed in next version

Re: RouterOS PHP API class

Posted: Tue Jun 26, 2018 9:04 am
by sjobbe
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)

Re: RouterOS PHP API class

Posted: Tue Jun 26, 2018 10:24 am
by xvirus
I need help in building a project. Let me first describe my project -

I want to build a Web application (using php / php framework(laravel) , html, css, javaScript, bootstrarp ) that will help ISP owner to manage their router (most of them use Mikrotik router).

Reason to build this App:

Most ISP provider here use Mikrotik router to manage their internet business. But managing the router using Winbox ( a desktop based windows software that is build to manage Mikrotik router) seems complex to them. Just for creating new ip to assign a new user, blocking a user if he/she do not pay bills and managing bandwidth they need to operate winbox every time which they find difficult. My approach is to build a web application that will ease their work.

The features I want to provide are-

Creating new IP address and addressing them to user (internet user / end user)
Manage bandwidth of an IP address
Block / Lock any particular IP address automatically (in this case any particular user) who have not paid their monthly bill on certain date of a month
Re-enabling blocked IP address on paying their dues automatically
Showing daily graph of bandwidth received and used

Recording client history (client IP address, Monthly rent, Name, Address etc.)

Recording payment history of client
Auto bill calculation / due calculation
Auto sort out of due users of months
I am able to do 6 - 9 features as described but I have no idea how to implement 1 - 5 features !

Problem That I am facing :

a. I don't know how to connect to a MikrotiK router via web application b. If some how i can access to the MikrotiK router using router IP address , I don't know how to create new IP address on that router database c. how to manage bandwidth via web application d. how to block / lock ip address

Re: RouterOS PHP API class

Posted: Tue Jun 26, 2018 12:00 pm
by Chupaka
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.