1. Create table clients where nas info is stored:
1.1. I'm using customized database of freeradius with different module, but you can suit it to your needs.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;
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:
#!/bin/sh
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change MikroTik-Rate-Limit back_rate_limit varchar(64) NOT NULL DEFAULT '0';"
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change Night-Mikroti-Rate-Limit Mikroti-Rate-Limit varchar(64) NOT NULL DEFAULT '0';"
/usr/bin/mysql -uradius -ppwd radius -e "alter table "yourgrouptable" change back_rate_limit Night-Mikroti-Rate-Limit varchar(64) NOT NULL DEFAULT '0';"
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
3. Create shape-mt.php script that handles the shapings:#!/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);
?>
4. Executing your perl script for overwriting the dynamic queues: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);
?>
Do not forget to enable telnet on the MikroTik and you can use pptp-$username if you provide PPTP.#!/usr/bin/perl
my $host = $ARGV[0];
my $username = $ARGV[1];
my $rate = $ARGV[2];
my $found=0;
use Data::Dumper;
use Net::Telnet ();
$t = new Net::Telnet (
Host => "$host",
Timeout => 10,
Dump_log => "./xyz",
Prompt => '/\[.+\] > $/');
$t->login("mikrotik-RW-user", "mikroti-password");
$t->cmd("/queue simple set \"<pppoe-$username>\" limit-at=$rate max-limit=$rate");
If you have any further questions please feel free to ask here!