Revize 1323
Přidáno uživatelem Michal Kliment před více než 12 roky(ů)
freenetis/branches/testing/application/controllers/web_interface.php | ||
---|---|---|
*/
|
||
class Web_interface_Controller extends Controller
|
||
{
|
||
|
||
|
||
const MEMBERS_QOS_PARENT = 1;
|
||
const MEMBERS_QOS_ORDINARY = 2;
|
||
const MEMBERS_QOS_ACTIVE = 3;
|
||
const MEMBERS_QOS_HIGH_PRIORITY = 4;
|
||
const MEMBERS_QOS_MEMBERS = 5;
|
||
|
||
const MEMBERS_QOS_PRIORITY_NORMAL = 1;
|
||
const MEMBERS_QOS_PRIORITY_HIGH = 0;
|
||
|
||
const MEMBERS_QOS_PROTOCOL_ALL = 'all';
|
||
|
||
/**
|
||
* Index prints about message
|
||
*/
|
||
... | ... | |
}
|
||
}
|
||
|
||
/**
|
||
* Prints members QoS's data in columns
|
||
*
|
||
* @author Michal Kliment
|
||
* @return type
|
||
*/
|
||
public function members_qos_ceil_rate()
|
||
{
|
||
// qos is not enabled, we ends
|
||
if (!Settings::get('qos_enabled'))
|
||
return;
|
||
|
||
|
||
// finds total qos speed
|
||
$total = network::speed_size(Settings::get('qos_total_speed'),"M");
|
||
|
||
$members_upload_rate = $total['upload'];
|
||
$members_download_rate = $total['download'];
|
||
|
||
// ulogd is enabled
|
||
if (Settings::get('ulogd_enabled'))
|
||
{
|
||
// finds qos speed for active members
|
||
$active = network::speed_size(Settings::get('qos_active_speed'),"M");
|
||
|
||
$members_upload_rate -= $active['upload'];
|
||
$members_download_rate -= $active['download'];
|
||
}
|
||
|
||
$rows = '';
|
||
$i = 4;
|
||
$i = self::MEMBERS_QOS_MEMBERS;
|
||
$total_upload_rate = 0;
|
||
$total_download_rate = 0;
|
||
|
||
$data = array();
|
||
$members_data = array();
|
||
|
||
// finds all members with guaranteed speed
|
||
$members = ORM::factory('member')->get_members_qos_ceil_rate();
|
||
|
||
foreach ($members as $member)
|
||
... | ... | |
$total_upload_rate += $qos_rate['upload'];
|
||
$total_download_rate += $qos_rate['download'];
|
||
|
||
$rows .= "$i\t";
|
||
$rows .= num::decimal_point($qos_ceil['upload'])."M\t";
|
||
$rows .= num::decimal_point($qos_ceil['download'])."M\t";
|
||
$rows .= num::decimal_point($qos_rate['upload'])."M\t";
|
||
$rows .= num::decimal_point($qos_rate['download'])."M\t";
|
||
$rows .= "1\t";
|
||
$rows .= "member_".($i-3)."\n";
|
||
$members_data[$i] = array
|
||
(
|
||
"id" => $i,
|
||
"upload_ceil" => num::decimal_point($qos_ceil['upload'])."M",
|
||
"download_ceil" => num::decimal_point($qos_ceil['download'])."M",
|
||
"upload_rate" => num::decimal_point($qos_rate['upload'])."M",
|
||
"download_rate" => num::decimal_point($qos_rate['download'])."M",
|
||
"parent" => self::MEMBERS_QOS_PARENT,
|
||
"ipset" => "member_".($i-self::MEMBERS_QOS_MEMBERS+1),
|
||
"priority" => self::MEMBERS_QOS_PRIORITY_NORMAL,
|
||
"protocol" => self::MEMBERS_QOS_PROTOCOL_ALL
|
||
);
|
||
|
||
$i++;
|
||
}
|
||
|
||
// deducts qos rate of member with guaranteed speed from total qos rate
|
||
if ($members_upload_rate > $total_upload_rate
|
||
&& $members_download_rate > $total_download_rate)
|
||
{
|
||
$members_upload_rate -= $total_upload_rate;
|
||
$members_download_rate -= $total_download_rate;
|
||
|
||
echo "1\t".$total['upload']."M\t".$total['download']."M\t".$total['upload']."M\t".$total['download']."M\n";
|
||
echo "2\t0M\t0M\t".num::decimal_point($members_upload_rate)."M\t".num::decimal_point($members_download_rate)."M\t1\n";
|
||
|
||
if (Settings::get('ulogd_enabled'))
|
||
echo "3\t0M\t0M\t".$active['upload']."M\t".$active['download']."M\t1\tactive\n";
|
||
|
||
echo $rows;
|
||
}
|
||
else
|
||
|
||
// adds line for parent (total qos rate)
|
||
$data[self::MEMBERS_QOS_PARENT] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_PARENT,
|
||
"upload_ceil" => $total['upload']."M",
|
||
"download_ceil" => $total['download']."M",
|
||
"upload_rate" => $total['upload']."M",
|
||
"download_rate" => $total['download']."M",
|
||
"priority" => self::MEMBERS_QOS_PRIORITY_NORMAL,
|
||
"protocol" => self::MEMBERS_QOS_PROTOCOL_ALL
|
||
);
|
||
|
||
// adds line for ordinary members
|
||
$data[self::MEMBERS_QOS_ORDINARY] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_ORDINARY,
|
||
"upload_ceil" => "0M",
|
||
"download_ceil" => "0M",
|
||
"upload_rate" => num::decimal_point($members_upload_rate)."M",
|
||
"download_rate" => num::decimal_point($members_download_rate)."M",
|
||
"parent" => self::MEMBERS_QOS_PARENT,
|
||
"priority" => self::MEMBERS_QOS_PRIORITY_NORMAL,
|
||
"protocol" => self::MEMBERS_QOS_PROTOCOL_ALL
|
||
);
|
||
|
||
// ulogd is enabled
|
||
if (Settings::get('ulogd_enabled'))
|
||
{
|
||
echo "1\t".$total['upload']."M\t".$total['download']."M\t".$total['upload']."M\t".$total['download']."M\n";
|
||
echo "2\t0M\t0M\t".num::decimal_point($members_upload_rate)."M\t".num::decimal_point($members_download_rate)."M\t1\n";
|
||
|
||
if (Settings::get('ulogd_enabled'))
|
||
echo "3\t0M\t0M\t".$active['upload']."M\t".$active['download']."M\t1\tactive\n";
|
||
// adds line for active members
|
||
$data[self::MEMBERS_QOS_ACTIVE] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_ACTIVE,
|
||
"upload_ceil" => "0M",
|
||
"download_ceil" => "0M",
|
||
"upload_rate" => $active['upload']."M",
|
||
"download_rate" => $active['download']."M",
|
||
"parent" => self::MEMBERS_QOS_PARENT,
|
||
"ipset" => "active",
|
||
"priority" => self::MEMBERS_QOS_PRIORITY_NORMAL,
|
||
"protocol" => self::MEMBERS_QOS_PROTOCOL_ALL
|
||
);
|
||
}
|
||
|
||
$data[self::MEMBERS_QOS_HIGH_PRIORITY] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_HIGH_PRIORITY,
|
||
"upload_ceil" => "0M",
|
||
"download_ceil" => "0M",
|
||
"upload_rate" => "10M",
|
||
"download_rate" => "10M",
|
||
"parent" => self::MEMBERS_QOS_PARENT,
|
||
"priority" => self::MEMBERS_QOS_PRIORITY_HIGH,
|
||
"protocol" => self::MEMBERS_QOS_PROTOCOL_ALL,
|
||
"ipset" => "priority"
|
||
);
|
||
|
||
// adds lines with qos rates of member with guaranteed speed
|
||
$data = arr::merge($data, $members_data);
|
||
|
||
// definition of columns
|
||
$columns = array
|
||
(
|
||
"id",
|
||
"upload_ceil",
|
||
"download_ceil",
|
||
"upload_rate",
|
||
"download_rate",
|
||
"priority",
|
||
"protocol",
|
||
"parent",
|
||
"ipset"
|
||
);
|
||
|
||
echo text::print_in_columns($data, $columns);
|
||
}
|
||
|
||
/**
|
||
* Prints ip addresses of members with guaranteed speed
|
||
*
|
||
* @author Michal Kliment
|
||
* @return type
|
||
*/
|
||
public function ip_addresses_qos_ceil_rate()
|
||
{
|
||
// qos is not enabled, we ends
|
||
if (!Settings::get('qos_enabled'))
|
||
return;
|
||
|
||
$data = array();
|
||
|
||
$ips = ORM::factory('member')->get_active_traffic_members_ip_addresses();
|
||
|
||
foreach ($ips as $ip)
|
||
{
|
||
echo "3\t$ip->ip_address\n";
|
||
$data[] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_ACTIVE,
|
||
"ip_address" => $ip->ip_address
|
||
);
|
||
}
|
||
|
||
foreach (explode(",", Settings::get('qos_high_priority_ip_addresses'))
|
||
as $qos_high_priority_ip_address)
|
||
{
|
||
$data[] = array
|
||
(
|
||
"id" => self::MEMBERS_QOS_HIGH_PRIORITY,
|
||
"ip_address" => $qos_high_priority_ip_address
|
||
);
|
||
}
|
||
|
||
$ip_addresses = ORM::factory('ip_address')->get_ip_addresses_qos_ceil_rate();
|
||
|
||
$i = 3;
|
||
$i = self::MEMBERS_QOS_MEMBERS-1;
|
||
$member_id = 0;
|
||
|
||
foreach ($ip_addresses as $ip_address)
|
||
... | ... | |
$i++;
|
||
$member_id = $ip_address->member_id;
|
||
}
|
||
echo "$i\t$ip_address->ip_address\n";
|
||
|
||
$data[] = array
|
||
(
|
||
"id" => $i,
|
||
"ip_address" => $ip_address->ip_address
|
||
);
|
||
}
|
||
|
||
// definition of columns
|
||
$columns = array ("id", "ip_address");
|
||
|
||
echo text::print_in_columns($data, $columns);
|
||
}
|
||
|
||
}
|
Také k dispozici: Unified diff
Commit vylepseni QoSu - na lokale jsem to uz mel hotove nejakou dobu :-)