Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1872

Přidáno uživatelem Ondřej Fibich před více než 11 roky(ů)

Novinky:
- fixes #505: Podpora pro Prometheus QoS

Zobrazit rozdíly:

freenetis/branches/1.1/application/models/speed_class.php
}
/**
* Get IP addresses and users logins of a the given speed class
*
* @param integer $class_id
* @param boolean $no_association Display devices of the association?
* @return Mysql_Result
*/
public function get_ip_addresses_to_class($class_id, $no_association = TRUE)
{
$assoc = '';
if ($no_association)
{
$assoc = ' AND m.id <> ' . Member_Model::ASSOCIATION;
}
return $this->db->query("
SELECT m.id AS member_id, ip.ip_address, u.login AS user_login
FROM members m
JOIN users u ON u.member_id = m.id
LEFT JOIN devices d ON d.user_id = u.id
LEFT JOIN ifaces i ON i.device_id = d.id
JOIN ip_addresses ip ON ip.iface_id = i.id OR ip.member_id = m.id
WHERE m.speed_class_id = ? $assoc
ORDER BY m.id, ip.id
", $class_id);
}
/**
* Get default speed class for members.
*
* @return Speed_class_Model|null
freenetis/branches/1.1/application/controllers/web_interface.php
// otherwise print number of total pages
return count($data);
}
/**
* Configuration for Prometheus QoS utility.
* This configuration does not includes handlind of upload values of speed,
* it takes just download.
*
* @author Ondřej Fibich
* @see http://freecode.com/projects/prometheus-qos
*/
public function qos_prometheus()
{
$speed_class_model = new Speed_class_Model();
echo "# Prometheus QoS configuration\n";
echo "# generated on " . date('Y-m-d H:i:s') . "\n";
echo "# FreenetIS " . Version::get_version() . "\n\n";
$speed_classes = $speed_class_model->orderby('d_ceil', 'DESC')->find_all();
foreach ($speed_classes as $speed_class)
{
echo "\n######## $speed_class->name ################################\n";
$ips = $speed_class_model->get_ip_addresses_to_class($speed_class->id);
$last_member_id = NULL;
$last_id = NULL;
foreach ($ips as $ip)
{
// last two parts of IP address
$ip_end = mb_substr($ip->ip_address, mb_strpos(
$ip->ip_address, '.',
mb_strpos($ip->ip_address, '.') + 1
) + 1);
// first row
if ($last_id === NULL)
{
$last_id = "$ip->user_login.$ip_end";
}
echo "$ip->ip_address\t$ip->user_login.$ip_end\t\t";
// group same member by comments
if ($last_member_id != $ip->member_id)
{
$min = intval($speed_class->d_rate / 1024); // convert B => kB
$max = intval($speed_class->d_ceil / 1024); // convert B => kB
echo "#via-prometheus-$min-$max\n";
// change member values
$last_member_id = $ip->member_id;
$last_id = "$ip->user_login.$ip_end";
}
else
{
echo "#sharing-$last_id\n";
}
}
}
}
}

Také k dispozici: Unified diff