<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password'));
$interfaces = $util->setMenu('/interface')->getAll();
?>
<table>
<?php foreach ($interfaces as $interface) { ?>
<tr><td><?php echo $interface('name'); ?></td></tr>
<?php } ?>
</table>
Hi I am just looking for a simple PHP script that can work with my project. I find it hard to use you applicationUsing the API client from my signature:Code: Select all<?php use PEAR2\Net\RouterOS; require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar'; $util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); $interfaces = $util->setMenu('/interface')->getAll(); ?> <table> <?php foreach ($interfaces as $interface) { ?> <tr><td><?php echo $interface('name'); ?></td></tr> <?php } ?> </table>
What part(s) do you find difficult? Disregarding this and any other pre-existing library, what would you find to be the easiest way for a library to do things like (while still allowing all protocol features)? Could you give me some pseudo code?I find it hard to use you application
$trequest2 = new RouterOS\Request('/interface monitor-traffic interface=wlan1 once');
$rx = $client->sendSync($trequest2)->getProperty('rx-bits-per-second');
$tx = $client->sendSync($trequest2)->getProperty("tx-bits-per-second");
echo $rx;
echo $tx;
$trequest2 = new RouterOS\Request('/interface ethernet monitor ether1 once');
$status = $client->sendSync($trequest2)->getProperty('status');
$rate = $client->sendSync($trequest2)->getProperty("rate");
$auto_neg = $client->sendSync($trequest2)->getProperty("auto-negotiation");
echo 'status: '. $status;
echo 'rate: '. $rate;
echo 'auto_neg: '. $auto_neg;
$trequest2 = new RouterOS\Request('/interface monitor-traffic interface=wlan1 once');
$trequest2result = $client->sendSync($trequest2);
$rx = $trequest2result->getProperty('rx-bits-per-second');
$tx = $trequest2result->getProperty("tx-bits-per-second");
echo $rx;
echo $tx;
$trequest2 = new RouterOS\Request('/interface ethernet monitor numbers=ether1 once');
$trequest2result = $client->sendSync($trequest2);
$status = $trequest2result->getProperty('status');
$rate = $trequest2result->getProperty("rate");
$auto_neg = $trequest2result->getProperty("auto-negotiation");
echo 'status: '. $status;
echo 'rate: '. $rate;
echo 'auto_neg: '. $auto_neg;
Yes. Analogously to how you'd get it from CLI, which is at the "/interface" menu. For an even closer analog than with the Client class, you can use the Util class instead, e.g.By the way, Is it possible to see the LINK DOWN value, using your API?
$util = new RouterOS\Util($client);
$linkDowns = $util->setMenu('/interface')->get('ether1', 'link-downs');
echo 'Link downs: ' . $linkDowns;
:local linkDowns [/interface get ether1 link-downs];
:put ("Link downs: " . $linkDowns);
$client = new RouterOS\Client(192.168.88.22, 'admin',"password", null, false, null, NetworkStream::CRYPTO_TLS));
exception 'PEAR2\Net\Transmitter\SocketException' with message 'stream_socket_client(): Could not get peer certificate' in phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/Stream.php(130): PEAR2\Net\Transmitter\TcpClient->createException('stream_socket_c...', 0) #1 [internal function]: PEAR2\Net\Transmitter\Stream->handleError(2, 'stream_socket_c...', 'phar://C:/xampp...', 147, Array) #2 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php(147): stream_socket_client('tls://192.168.88.22...', 0, '', '60', 4, Resource id #15) #3 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('192.168.88.22', 8729, false, NULL, 'admin/pass', 'TLS', Resource id #15) #4 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.88.22', NULL, false, NULL, 'admin/pass', 'TLS', NULL) #5 C:\xampp\htdocs\beam\new\ssl.php(50): PEAR2\Net\RouterOS\Client->__construct('192.168.88.22', 'admin', 'pass', NULL, false, NULL, 'TLS') #6 {main} Next exception 'PEAR2\Net\Transmitter\SocketException' with message 'Failed to initialize socket.' in phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php(157): PEAR2\Net\Transmitter\TcpClient->createException('Failed to initi...', 7, Object(PEAR2\Net\Transmitter\SocketException)) #1 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('192.168.88.22', 8729, false, NULL, 'admin/pass', 'TLS', Resource id #15) #2 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.88.22', NULL, false, NULL, 'admin/pass', 'TLS', NULL) #3 C:\xampp\htdocs\beam\new\ssl.php(50): PEAR2\Net\RouterOS\Client->__construct('192.168.88.22', 'admin', 'pass', NULL, false, NULL, 'TLS') #4 {main} Next exception 'PEAR2\Net\RouterOS\SocketException' with message 'Error connecting to RouterOS' in phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php:150 Stack trace: #0 phar://C:/xampp/htdocs/PEAR2_Net_RouterOS-1.0.0b5.phar/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.88.22', NULL, false, NULL, 'admin/pass', 'TLS', NULL) #1 C:\xampp\htdocs\beam\new\ssl.php(50): PEAR2\Net\RouterOS\Client->__construct('192.168.88.22', 'admin', 'pass', NULL, false, NULL, 'TLS') #2 {main}
Hello, have you created a certificate for api-ssl with subsequent binding to IP services?hello boen_robot, I have a question about your API (which is awesome)
I'm using your API with successes on the IIS server.
At the moment I started a new server on XAMPP. Everything works properly except for connections via api-ssl (regular api works fine)
at the moment of connection
10:02:25 firewall,info input: in:ether1 out:(none), src-mac 02:ab:cd:ef:6b:a9, proto TCP (SYN), 192.168.88.6:56682->192.168.88.22:8729, len 52
$client = new RouterOS\Client('192.168.88.22', 'admin', 'password', null, false, null, NetworkStream::CRYPTO_TLS,
strem_context_create(array('ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'ciphers' => 'ADH'
)))
);
$context = stream_context_create(
array(
'ssl' => array(
'verify_peer' => true
)
)
);
$context = stream_context_create(array('ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'ciphers' => 'ADH'
))
);
View log file XAMPP, after you run your php script. If there is a problem with PHP, Apache - you will see these errors.Firewall on the server is turned off, what's interesting in the logs I see that the XAMPP server wants to connect to RouterI can connect to the router from IIS server so I exclude the problem with its firewall, it seems to me that this is a problem on XAMPP server, or something has to be changed in php.ini or somewhere else.Code: Select all10:02:25 firewall,info input: in:ether1 out:(none), src-mac 02:ab:cd:ef:6b:a9, proto TCP (SYN), 192.168.88.6:56682->192.168.88.22:8729, len 52
Eventually I will send my requests from the XAMPP server to IIS so that IIS will connect via API-SSL and send back results to XAMPP server, but I would prefer to do all this on the XAMPP server
You mean you're changing the very IP you are connecting to? If that's the case, then yes, the only viable option is adding a self-deleting scheduler that will do the change.since I have your attention I have one more question:
I connect the clients SXT via api-ssl, I want to change the pppoe account. The account changes, but the IP address changes as well, and the script starts to hang.
After reaching the timeout, the page is displayed, can I not wait for the answer, just send the new setting and disconnect?
The second option is to send a scheduler that will change pppoe account data, api will disconnect and after a few seconds the scheduler will change the account.
/tool bandwidth-server set enabled=yes
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password'));
$util->setMenu('/tool bandwidth-server')->set(null, array('enabled' => 'true'));