Community discussions

MUM Europe 2020
 
ayufan
Member
Member
Topic Author
Posts: 331
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.
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
ayufan
Member
Member
Topic Author
Posts: 331
Joined: Sun Jun 03, 2007 9:35 pm
Contact:

Re: RouterOS PHP API class

Mon Nov 30, 2009 11:34 am

hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
ayufan
Member
Member
Topic Author
Posts: 331
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
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
ayufan
Member
Member
Topic Author
Posts: 331
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.
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
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: 331
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
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
cieplik206
Trainer
Trainer
Posts: 286
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 ?
https://www.wispcasts.com - Mikrotik Video Tutorials.

The best place where you can improve your skills!

Facebook - F/wispcasts
Twitter - @wispcasts
 
ayufan
Member
Member
Topic Author
Posts: 331
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.
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
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: 8320
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
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
cieplik206
Trainer
Trainer
Posts: 286
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,
https://www.wispcasts.com - Mikrotik Video Tutorials.

The best place where you can improve your skills!

Facebook - F/wispcasts
Twitter - @wispcasts
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8320
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
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
ayufan
Member
Member
Topic Author
Posts: 331
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
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8320
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
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
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: 8320
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");
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
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: 331
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.
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
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.
Doug
 
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: 331
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
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
User avatar
maximan
Trainer
Trainer
Posts: 549
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.
MKE Solutions > Professional Support IT (Spanish / English)
FastNetMon / FNM Manager: DDoS Detection Tools.
 
ayufan
Member
Member
Topic Author
Posts: 331
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.
hAP AC, TP-Link Archer C7 v2, RB951G, RB450G, RPI2, RPI zero
 
MtHoodlum
just joined
Posts: 14
Joined: Fri Sep 07, 2012 2:09 am

Re: RouterOS PHP API class

Mon Feb 06, 2017 11:28 pm

Broken again.
 
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: 8320
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
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
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: 8320
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.
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
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: 8320
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.
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
sjobbe
just joined
Posts: 18
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: 8320
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.
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
sjobbe
just joined
Posts: 18
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: 8320
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
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
sjobbe
just joined
Posts: 18
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)
 
xvirus
just joined
Posts: 1
Joined: Tue Jun 26, 2018 10:01 am
Location: Dhaka, Bangladesh
Contact:

Re: RouterOS PHP API class

Tue Jun 26, 2018 10:24 am

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
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8320
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.
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.

Who is online

Users browsing this forum: No registered users and 6 guests