Community discussions

MikroTik App
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Problems with Centos 6 server and API Mikrotik

Sun Feb 26, 2012 2:47 am

Hello, gentlemen ...
Forgive me for bad English, but I am Brazilian and I am using google translator.

Recently set up a server Centos 6 following the following tutorial

http://www.howtoforge.com/perfect-serve ... spconfig-3

This server will host a management system to access the Internet written in PHP / mysql and Mikrotik API to lock / unlock customers.

The whole routine PHP / API was working smoothly using wampp as a development platform (windows), but to put the files in PHP hosting (my server php / mysql centos 6), the functions of adding customers and managing permissions via API not responding. I see through the activity of Winbox login / logoff in RouterOS API commands as though Comm and write do not work.

Someone tell me if you need to do some kind of specific configuration commands for the API to work properly as well as worked in wampp?

Inform the Mikrotik is with the permission of API access enabled and all scripts php / mysql are working properly.

Thanks for help !

A big hug to everyone.
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Sun Feb 26, 2012 3:21 am

Does PHP produce any errors? Have you set your error level to "E_ALL | E_STRICT" (in both environments)? Maybe what was just a notice in WAMPP became important on CentOS.

It's possible that your server firewall is not configured to allow outgoing connections to the router (though PHP should've complained if that's the case, hence making sure you enable error reporting). Try disabling it temporarily to verify and if that's the case, add the "php", "php-cgi" and/or "apache" executables to the list of applications allowed to estabilish outgoing connections.
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Mon Feb 27, 2012 10:35 pm

Does PHP produce any errors? Have you set your error level to "E_ALL | E_STRICT" (in both environments)? Maybe what was just a notice in WAMPP became important on CentOS.

It's possible that your server firewall is not configured to allow outgoing connections to the router (though PHP should've complained if that's the case, hence making sure you enable error reporting). Try disabling it temporarily to verify and if that's the case, add the "php", "php-cgi" and/or "apache" executables to the list of applications allowed to estabilish outgoing connections.


Friend Boen-robot

Your suggestion about CGI reminded me that the server configuration tutorial asks us to uncomment the line (; cgi.fix_pathinfo = 1) in php.ini. I returned the file and commented on it again and the scripts work, but now the values sent on variables are not included in RouterOS.

For example:

This works:
Code:Select all
$ API-> comm ('/queue/simple/add', array ( "name" => "boenrobot" ));
This NOT works:
Code:Select all
$ clientname = "boenrobot"; $ API-> comm ('/queue/simple/add', array ( "name" => $ clientname ));
Can you help me with this problem?
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 12:15 am

Variable names can't have spaces. Turn
Code:Select all
$ clientname
into
Code:Select all
$clientname
(same for the "$ API" part)
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 3:35 pm

Sure,

The variables name havn´t spaces... the spaces in names were created by google translator. I write my messages in notepad and copy/paste on google translator page...

I realized that even writing the values directly in the array, not all the time that the values are dropped in Routeros. if I refresh the page several times, the script includes the values at will. I do not understand why ...

Example...

refresh1 --> Done
refresh2 --> Error
refresh3 --> Error
refresh4 --> Error
refresh5 --> Error
refresh6 --> Done
refresh7 --> Error
refresh8 --> Error
refresh9 --> Done
refresh10 --> Error
...

Understood ??
I'm going crazy with this problem...

Thanks 4 all !!
Brazilian Hugs !
Top
用户头像
janisk
MikroTik Support
MikroTik Support
Posts: 6263
加入: Tue Feb 14, 2006 9:46 am
Location:Riga, Latvia

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 4:18 pm

what error you get in reply? usually !re is quite descriptive
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 4:39 pm

what error you get in reply? usually !re is quite descriptive
This is the "answer" by debug:
Code:Select all
Connection attempt #1 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Connection attempt #2 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Connection attempt #3 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Connection attempt #4 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Connection attempt #5 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Error... An error ocurred [if !done myself message]
After this I try again and debug returs:
Code:Select all
Connection attempt #1 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 0]!done Connection attempt #2 to 192.168.55.1:8728... <<< [6] /login >>> [5/5] bytes read. >>> [5, 1]!done >>> [37/37] bytes read. >>> [37, 1]=ret=333d39b82d8e978ba92bc4f080f08fc7 <<< [6] /login <<< [9] =name=sge <<< [44] =response=00426ccaf36f522ae6422dd4dfb7a34c87 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [17] /queue/simple/add <<< [12] =name=teste5 <<< [32] =target-addresses=192.168.55.213 >>> [5/5] bytes read. >>> [5, 10]!done >>> [8/8] bytes read. >>> [8, 1]=ret=*17 Done ! [if !done myself message]
thereafter I try again other times changing name/addresses values and didn´t work.

Very strange. It gives me impression that it only works when it wants.

My code:
Code:Select all
debug = true; if ($API->connect('192.168.55.1', 'sge', 'sge')) { // Change this as necessery $API->comm('/queue/simple/add', array( "name" => "clientname", "target-addresses" => "clienteip" )); echo "
Done !"; } else { echo "

An error occurred"; } echo "

"; ?>
NOTE:I´m using a RB 750GL as testing Router. Her MK version is 5.11. I believe the version of the router that is serving the network is more current.

Do you think that the version influence the functioning of the API?
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 4:52 pm

Looking at the log, it appears you're having some issues with the connection between the server and the router.

The reason could still be in a misconfigured firewall, but if your router is many switches away and/or serving a good number of clients, a more likely cause is that your links are weak (a buggy switch/cable) and/or that the router is simply being overloaded.

Also, as a side note, check in the "Active Users" session that you don't have any hanging connections (you shouldn't have such with 5.*, but just in case...).
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 5:10 pm

Looking at the log, it appears you're having some issues with the connection between the server and the router.

The reason could still be in a misconfigured firewall, but if your router is many switches away and/or serving a good number of clients, a more likely cause is that your links are weak (a buggy switch/cable) and/or that the router is simply being overloaded.

Also, as a side note, check in the "Active Users" session that you don't have any hanging connections (you shouldn't have such with 5.*, but just in case...).
Thanks again...

Look, my connections are:

Internet link -> RB750GL -> Switcher => [server centos and my development machine]

This structure is only for developing, after everything is working perfectly, the server Centos will be connected to Mikrotik serving the entire network. ie, the only currently active connections in RB750GL are my development machine and the server Centos.

I return to say that the Centos firewall is disabled.
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 5:39 pm

Excellent.

左挂connectio唯一可能的问题ns. In the router, check the active users in "/user active". You should only see one or two, and no "api" sessions. If there are more, it means some connections are left hanging for a while. If that's the case, it might be wise to close them explicitly once you're done by sending a "/quit" command and calling the disconnect() function.
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 5:48 pm

Excellent.

左挂connectio唯一可能的问题ns. In the router, check the active users in "/user active". You should only see one or two, and no "api" sessions. If there are more, it means some connections are left hanging for a while. If that's the case, it might be wise to close them explicitly once you're done by sending a "/quit" command and calling the disconnect() function.
Dude...
In /user/active have only my conection using winbox...

Would if I connect the Centos server directly to a port of RB it work?
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 5:51 pm

Excellent.

左挂connectio唯一可能的问题ns. In the router, check the active users in "/user active". You should only see one or two, and no "api" sessions. If there are more, it means some connections are left hanging for a while. If that's the case, it might be wise to close them explicitly once you're done by sending a "/quit" command and calling the disconnect() function.
Dude...
In /user/active have only my conection using winbox...

Would if I connect the Centos server directly to a port of RB it work?
If even that doesn't work, I'm officially out of ideas.
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 5:53 pm

Sure... I'll try and come back with the result:D
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 7:40 pm

Excellent.

左挂connectio唯一可能的问题ns. In the router, check the active users in "/user active". You should only see one or two, and no "api" sessions. If there are more, it means some connections are left hanging for a while. If that's the case, it might be wise to close them explicitly once you're done by sending a "/quit" command and calling the disconnect() function.
Dude...
In /user/active have only my conection using winbox...

Would if I connect the Centos server directly to a port of RB it work?
If even that doesn't work, I'm officially out of ideas.
Unfortunately, it did not work. Anyway, I need a solution only for add/remove clients in the ARP table and /queue/simple, and lock / unlock customers in the queue. Do you indicate some other feature?
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 7:43 pm

You mentioned in the start that it works with Windows... does it work at the very same node? That is, if you plug the windows machine in place of the CentOS (have the Windows machine directly connected to the router board), does it work?

If it does, this might be a PHP bug related to the way it uses sockets on CentOS. Solution: Use another kind of Linux and/or report this to the PHP/CentOS devs.

If even then it doesn't work, this might be a bug in RouterOS that occurs only on that router board. Solution: Upgrade to the latest RouterOS, and if even then it doesn't work, contact support.
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 8:24 pm

You mentioned in the start that it works with WAMP... does it work at the very same node? That is, if you plug the windows machine in place of the CentOS (have the Windows machine directly connected to the router board), does it work?

If it does, this might be a PHP bug related to the way it uses sockets on CentOS. Solution: Use another kind of Linux and/or report this to the PHP/CentOS devs.

If even then it doesn't work, this might be a bug in RouterOS that occurs only on that router board. Solution: Upgrade to the latest RouterOS, and if even then it doesn't work, contact support.
Sure dude....

If I use my scripts in Wampp server on windows, the interaction between PHP/Mikrotik works great. My PHP version, installed on Centos is 5.3.3. The version of Routeros is 5.11 running on RouterBoard 750GL.

The centos I´m using is version 6.
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 8:29 pm

Is Windows using the same PHP version? Again, this is a bug in either PHP or CentOS. So, if the version on CentOS is older than the one on Windows, it might be the cause. Try with PHP 5.3.10.
Top
charlesabrj
刚刚加入了
Topic Author
Posts: 15
加入: Wed Jan 25, 2012 4:44 pm

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 8:33 pm

Is Windows using the same PHP version? Again, this is a bug in either PHP or CentOS. So, if the version on CentOS is older than the one on Windows, it might be the cause. Try with PHP 5.3.10.
In Wampp the php version is 5.3.5 ...
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Tue Feb 28, 2012 8:40 pm

Then upgradeat leastto that (ideally, upgrade to PHP 5.3.10 on both machines).

查看PHP 5.3.4的更新日志,甲型肝炎e been a few stream related bug fixes... it's possible they also affected sockets. In particular, the part
. Fixed forward stream seeking emulation in streams that don't support seeking
in situations where the read operation gives back less data than requested
and when there was data in the buffer before the emulation started. Also
made more consistent its behavior -- should return failure every time less
data than was requested was skipped. (Gustavo)
is probably the root of this here.
Top
spire2z
Long time Member
Long time Member
Posts: 516
加入: Mon Feb 14, 2005 2:48 am

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:13 pm

我认为我有一个nd figured this problem out

I got the same behaviour/problem as the OP describes.

Its actually the php api class script is too fast for the hash.

To solve it edit the script and add:

sleep (2);

on a new line after line 85

Cheers.
Last edited byspire2zon Thu Mar 01, 2012 10:29 pm, edited 1 time in total.
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:28 pm

5.6 (I haven't upgraded yet because I don't need any of the changes, plus I've seen some stability complains here in the forum) running on an x86 PC. My server uses PHP 5.3.8 (I haven't upgraded to 5.3.10, because I'm waiting for PHP 5.4.0, which will come out soon*) on Windows.

But I use my client, not Denis'. My client explicitly closes the connection instead of leaving it hanging. In the case of charlesabrj, we estabilished a hanging connection is not a problem though.

[edit]* Scratch that... it was just released, like minutes ago.[/edit]
Last edited byboen_roboton Fri Mar 02, 2012 12:02 am, edited 5 times in total.
Top
spire2z
Long time Member
Long time Member
Posts: 516
加入: Mon Feb 14, 2005 2:48 am

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:30 pm

I figured it out and edited my post! Must have been at same time you replied!!
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:33 pm

To solve it edit the script and add:

sleep (2);

on a new line after line 85
Eww... that's an ugly solution:?. But I guess I'm biased, because I've solved this in my client in a completely different fashion: a separate loop that gathers all bytes, and is activated even if you request just one byte. This ensures 100% data integrity with minimum delays at the expense of slight performance penalty ("slight" as in "a few nano, micro or at worst, mili seconds") for "short" words.
Last edited byboen_roboton Fri Mar 02, 2012 6:15 pm, edited 3 times in total.
Top
spire2z
Long time Member
Long time Member
Posts: 516
加入: Mon Feb 14, 2005 2:48 am

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:39 pm

Well I don't really care if it works. I think the delay is fine for my purpose.

Now you've got me interested though. I only just started playing with the API today so used the examples on wiki and here I am a few hours later!

What are you using to handle the API connection?
Top
用户头像
boen_robot
Forum Guru
Forum Guru
Posts: 2400
加入: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Problems with Centos 6 server and API Mikrotik

Thu Mar 01, 2012 10:42 pm

Like I said... my client... see my signature (there's alsoa page in the wiki about it). I welcome any feedback you may have about it.

|
|
V
Top
用户头像
janisk
MikroTik Support
MikroTik Support
Posts: 6263
加入: Tue Feb 14, 2006 9:46 am
Location:Riga, Latvia

Re: Problems with Centos 6 server and API Mikrotik

Fri Mar 02, 2012 12:34 pm

AFAIK when using API you have to use MD5 only once to generate response for challenge, for that you have up to 10 seconds or login attempt will fail. Afterwards if you do not use MD5 for something special that only you use, MD5 is not used anymore.
Top

Who is online

Users browsing this forum:4z1st3n,onnylohand 1 guest