Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Posted: Mon Oct 28, 2013 12:50 pm
Hi, im here again, and now im trying print again the active connections and ppp's, but now, from 2 routers..
Here is the code:
Here is the code:
php code
<?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; //Conexion a Mikrotik //IP MIKROTIK //Usuario //Password $client = new RouterOS\Client('xxx.xxx.xxx.xxx', 'victor', 'victor'); $client2 = new RouterOS\Client('xxx.xxx.xxx.xxx','victor','victor'); //$client3 = new RouterOS\Client('','',''); //$client4 = new RouterOS\Client('','',''); //$client5 = new RouterOS\Client('','',''); //Reiniciar PPP $remove=new RouterOs\Request("/ppp/active/remove"); $remove->setArgument('numbers', $itemID); // Tabla echo "<table align='center' border='1' id='natlist' bordercolor='black' class='tablesorter'><form action='' method='POST'>"; echo "<thead><tr bgcolor='#D8D8D8'><th align=left size=3>Nombre</th><th align=left size=3>Servicio</th><th size=3>Tiempo Activo</th><th align=left size=3>Direccion</th><th align=left size=3>Reiniciar</th></tr></thead><tbody>"; //Actualizar pagina //echo "<meta http-equiv='refresh' content='30'>"; $ppp1= $client->sendSync(new RouterOS\Request('/ppp/active/print'))->getAllOfType(RouterOS\Response::TYPE_DATA); $ppp2= $client2->sendSync(new RouterOS\Request('/ppp/active/print'))->getAllOfType(RouterOS\Response::TYPE_DATA); $ppps = array_merge_recursive ($ppp1, $ppp2); $interfaceQuery = RouterOS\Query::where('name', $ppps->getArgument('name')); while ($ppp = $ppps->next()) { $interfaceQuery->orWhere('name', $ppp('name')); } $ac1= $client->sendSync(new RouterOS\Request('/interface/pppoe-server/print', $interfaceQuery))->getAllOfType(RouterOS\Response::TYPE_DATA)->toArray(); $ac2= $client2->sendSync(new RouterOS\Request('/interface/pppoe-server/print', $interfaceQuery))->getAllOfType(RouterOS\Response::TYPE_DATA)->toArray(); $activeInterfaces = array_merge_recursive($ac1, $ac2); foreach ($ppps as $ppp) { $id = $ppp('.id'); $service = ''; foreach ($activeInterfaces as $index => $pppInterface) { if ($pppInterface('name') === $ppp('name')) { $service = $pppInterface('service'); break; } } echo "<tr>"; echo "<td>". $ppp('name') ."</td>"; echo "<td>" . $service . "</td>"; echo "<td>" . $ppp('uptime'). "</td>"; echo "<td>". $ppp('address') ."</td>"; echo "<td><button type='submit' value='{$id}' name='act[remove]' >Reiniciar</td></tr>"; } echo "</form></tbody></table>"; ?>