Community discussions

MikroTik App
 
cyph3r
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 73
Joined: Sun May 25, 2008 12:21 pm
Location: Pakistan
Contact:

PHP API send disconnection random PPTP active users

Sat Dec 20, 2014 10:32 am

Good Morning Friends,

i have multiple mikrotik routers as RRAS, i want to send disconnection through php API.

is there any way to send random disconnection for users to RAS server instead of individual user through mikrotik .id
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: PHP API send disconnection random PPTP active users

Sat Dec 20, 2014 5:10 pm

You want to disconnect a random user?!?

That's an odd request, but OK...

Get a list of all active users, get their count, and use mt_rand(0, $usersCount - 1) to get a random number between 0 and the number of users. Lookup the generated number in the list of users, and disconnect the user corresponding to that number.

When you say RRAS though... That sounds overly generic... In what fashion to users log in? Hotspot? PPPoE?

If it's with hotspot for example, you can do the following (using the PHP client from my signature):
<?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'));

$util->setMenu('/ip hotspot active');

$userIds = $util->getAll(array('.proplist' => '.id'));
$userIdsCount = count($userIds);
if ($userIdsCount > 0) {
    $idToDisconnect = $userIds[mt_rand(0, $userIdsCount - 1)]->getProperty('.id');
    $util->remove($idToDisconnect);
}
The procedure is analogous for other menus, except that the line
$util->setMenu('/ip hotspot active');
needs to instead point at whatever other menu active users are listed in.
 
cyph3r
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 73
Joined: Sun May 25, 2008 12:21 pm
Location: Pakistan
Contact:

Re: PHP API send disconnection random PPTP active users

Thu Dec 25, 2014 1:26 pm

Thanx bro

Who is online

Users browsing this forum: Google [Bot], VirtualEvan and 77 guests