Community discussions

 
oxigeno20
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Tue May 23, 2006 5:29 pm
Location: Argentina

Some nice examples for make your own PHP Scripts with API

Sat Oct 12, 2013 6:40 am

Hello everybody!!

I want share some post of my blog. (in spanish).

1) Introduction: what i can do with this API?
http://www.tech-nico.com/blog/api-mikro ... roduccion/

2) First Script: Create a script for testing the access of the API to your RouterOS.
http://www.tech-nico.com/blog/api-mikro ... i-con-php/

3) Manage Hotspot > IP-Bindings from your cel phone. (enable, disable and remove)
http://www.tech-nico.com/blog/api-mikro ... o-abierto/

4) create simples queues with validation.
http://www.tech-nico.com/blog/api-mikro ... car-regla/

5) Graph and log a specific pppoe client. Very Nice!!
http://www.tech-nico.com/blog/api-mikro ... ar-el-log/

6) Graphing real time trafic for some interface with highcharts
http://www.tech-nico.com/blog/api-mikro ... harts-php/

7) Enable or disable some ethernet port.
http://www.tech-nico.com/blog/api-mikro ... -ethernet/

I hope that you like it.
Best regards from Argentina!!

Nicolas www.tech-nico.com
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Some nice examples for make your own PHP Scripts with AP

Sat Oct 12, 2013 12:02 pm

I'd like to know what made you choose Denis' client. Thanks.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
oxigeno20
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Tue May 23, 2006 5:29 pm
Location: Argentina

Re: Some nice examples for make your own PHP Scripts with AP

Sat Oct 12, 2013 4:50 pm

The true, i don't know. lol
The first time than i used this was very easy and fast. I can change too the port of API service, adding more security for the scripts.

I am visiting your site now.
Your libraries are new for me!
Can i try and post some examples on my blog using your libraries?
What can you tell me about ?

best regards!
Nicolas
www.tech-nico.com
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Some nice examples for make your own PHP Scripts with AP

Sat Oct 12, 2013 6:00 pm

Can i try and post some examples on my blog using your libraries?
Yes, please!
What can you tell me about ?
It can do everything Denis' client can, and a lot more.
- Of a particular note is the ability to translate shell-like commands into API syntax automatically, so that a user doesn't need to learn a new syntax (assuming they're already familiar with RouterOS' shell syntax).
- Another unique, more niche (but more impressive if you're in the niche) feature is the support for "persistent connections" - the ability to share the TCP connection between PHP requests, resulting in lesser load for the router (though at the expense of the web server).
- In the latest version, there's even file transfer and script execution with variables that can be supplied ala SQL prepared statements (except better).
- Oh, and since the first version, there has also been the ability of an automatic charset conversion that you can optionally enable. It allows you to write out in your native alphabet (accents and all) from Winbox, while also allowing your PHP application to read/write such data correctly as well, even if it uses UTF-8 (as it should).
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
User avatar
ohara
Member
Member
Posts: 371
Joined: Mon Jun 13, 2011 11:30 pm
Location: Warsaw

Re: Some nice examples for make your own PHP Scripts with AP

Sun Oct 13, 2013 7:25 pm

- In the latest version, there's even file transfer and script execution with variables that can be supplied ala SQL prepared statements (except better).
Could you please give me some advice how to run a script? I tried the following, but I am using it wrong?

php code

<?php
namespace PEAR2\Net\RouterOS;
require_once 'src/PEAR2/Autoload.php';
$client = new Client('192.168.1.1', 'api', 'api');
$responses = $client->sendSync(new Request('/system/script/run script1'));
?>
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Some nice examples for make your own PHP Scripts with AP

Sun Oct 13, 2013 7:28 pm

All arguments need to have their names supplied (that's why I always say "shell-like" as opposed to just "shell"; there are a few differences, with this being the most noticeable and inconvenient one). Sadly, the protocol does not (yet) provide any hints that would allow me to automatically infer the possible argument name if not explicitly supplied.

So:
$responses = $client->sendSync(new Request('/system/script/run number=script1')); 
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
User avatar
ohara
Member
Member
Posts: 371
Joined: Mon Jun 13, 2011 11:30 pm
Location: Warsaw

Re: Some nice examples for make your own PHP Scripts with AP

Sun Oct 13, 2013 7:34 pm

Perfect, thanks! I couldn't get it working with Denis' API. Now it works.

Who is online

Users browsing this forum: No registered users and 88 guests