Here is how I do it: 1. Create table clients where nas info is stored:
Quote:
DROP TABLE IF EXISTS `clients`; CREATE TABLE `clients` ( `cid` int(2) NOT NULL auto_increment, `client` varchar(15) NOT NULL default '0.0.0.0', `secret` varchar(32) NOT NULL default '*', `shortname` varchar(32) NOT NULL default '', `nastype` varchar(32) NOT NULL default '', PRIMARY KEY (`cid`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
1.1. I'm using customized database of freeradius with different module, but you can suit it to your needs. In groups table create field Mikrotik-Rate-Limit and Night-Mikroti-Rate-Limit, Differ your shapes as you want 1:2 or 1:1.5 etc... Add a script that will execute this at a certain time containing:
2. Create php script that gathers MikroTik named NASes/it can be done with 1 script but I prefer 2/ which will be executed right after the table fields change
Quote:
#!/usr/bin/php -q <?php mysql_connect("localhost", "radius", "radpwd") or die("Could not connect: " . mysql_error()); mysql_select_db("radius");
$query = "SELECT client from clients where nastype='MikroTik'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $client = $row[0]; system("/usr/bin/php -q /etc/ppp/temp/shape-mt.php $client"); } mysql_free_result($result); ?>
3. Create shape-mt.php script that handles the shapings:
Quote:
mysql_connect("localhost", "radius", "radpwd") or die("Could not connect: " . mysql_error()); mysql_select_db("radius");
$ras = $argv[1];
$query = "SELECT Framed-User, MikroTik-Rate-Limit from "your online table" INNER JOIN "yourgrouptable" ON "your online table".groupid="yourgroutable".groupid where "Online-Info"='Online' and "NAS"='$ras'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $user = $row[0]; $rate = $row[1]; system("/usr/bin/perl -w /usr/bin/send-speed.pl $ras $user $rate"); } mysql_free_result($result); ?>
4. Executing your perl script for overwriting the dynamic queues:
Quote:
#!/usr/bin/perl
my $host = $ARGV[0]; my $username = $ARGV[1]; my $rate = $ARGV[2]; my $found=0;
$t->cmd("/queue simple set \"<pppoe-$username>\" limit-at=$rate max-limit=$rate");
Do not forget to enable telnet on the MikroTik and you can use pptp-$username if you provide PPTP. If you have any further questions please feel free to ask here!
Joined: Mon Oct 18, 2004 12:07 am Posts: 780
Karma: 0
Location: Cape Town, South Africa
Interesting...
What about just using a radius client, and sending a radius attribute to the MT? One line, one command, no need for all these scripts calling more scripts, calling more scripts
What about just using a radius client, and sending a radius attribute to the MT? One line, one command, no need for all these scripts calling more scripts, calling more scripts
Sending attribute is just when user connects. When user is online/realtime/ you cannot touch his/her queue so I have to make these scripts to gather online users on my MikroTik RASes and apply the new speeds.
Joined: Mon Oct 18, 2004 12:07 am Posts: 780
Karma: 0
Location: Cape Town, South Africa
Quote:
Change of Authorization RADIUS disconnect and Change of Authorization (according to RFC3576) are supported as well. These attributes may be changed by a CoA request from the RADIUS server: * Mikrotik-Group * Mikrotik-Recv-Limit * Mikrotik-Xmit-Limit * Mikrotik-Rate-Limit * Ascend-Data-Rate (only if Mikrotik-Rate-Limit is not present) * Ascend-XMit-Rate (only if Mikrotik-Rate-Limit is not present) * Mikrotik-Mark-Id * Filter-Id * Mikrotik-Advertise-Url * Mikrotik-Advertise-Interval * Session-Timeout * Idle-Timeout * Port-Limit Note that it is not possible to change IP address, pool or routes that way - for such changes a user must be disconnected first.
It has been discussed on these forums before, MT supports CoA (Change of Authorization I believe). You can alter the dynamic queue speed via a radius update message.
Change of Authorization RADIUS disconnect and Change of Authorization (according to RFC3576) are supported as well. These attributes may be changed by a CoA request from the RADIUS server: * Mikrotik-Group * Mikrotik-Recv-Limit * Mikrotik-Xmit-Limit * Mikrotik-Rate-Limit * Ascend-Data-Rate (only if Mikrotik-Rate-Limit is not present) * Ascend-XMit-Rate (only if Mikrotik-Rate-Limit is not present) * Mikrotik-Mark-Id * Filter-Id * Mikrotik-Advertise-Url * Mikrotik-Advertise-Interval * Session-Timeout * Idle-Timeout * Port-Limit Note that it is not possible to change IP address, pool or routes that way - for such changes a user must be disconnected first.
It has been discussed on these forums before, MT supports CoA (Change of Authorization I believe). You can alter the dynamic queue speed via a radius update message.
It has been discussed but PPPoE does not support CoA just PoD.
Users browsing this forum: No registered users and 8 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum