Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1632

Přidáno uživatelem Ondřej Fibich před asi 12 roky(ů)

Opravy:

- oprava MySQL funkce pro ulogd
- smazani ulogd MySQL funkci pri nepovolení ulogu
- zprovoznění a optimalizace provozu
- zprovozneni znaceni aktivnich clenu v ulogu a napojení do QoSu
- oprava kontroly prav v databazi (nefungovalo u roota s pravy *.*)

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/help.php
'ulogd_active' => 'Jedná se o seznam (z pohledu typu provozu) příliš aktivních členů. Tento seznam se používá například pro vyhodnocování QoSu pro členy (členové z tohoto seznamu jsou mírně znevýhodněni oproti ostatním členům), aktualizuje při každé aktualizaci ulogd, viz. Nastavení - Logování - Ulogd - Interval aktualizace.',
'ulogd_active_button' => 'Určuje, zda-li byl člen označen jako Aktivní = příliš aktivní z pohledu provozu. Členové ze seznamu aktivních členů jsou například mírně znevýhodněni oproti ostatním členům u vyhodnocování QoSu pro členy. Viz. Nastavení - Logování - Aktivní členové',
'ulogd_active_count' => 'Množství členů, z jehož se bude počítat průměr. Členové, kteří dosáhnou tohotu průměru, budou označeni jako příliš aktivní. Může být zadán absolutně (číslem) nebo relativně (v procentech). Výchozí hodnota je 10&#37.',
'ulogd_active_min' => 'Členové, kteří sice dosáhnou průměru, ale nedosáhnou této minimální hodnoty, nebudou označeni jako aktivní.',
'ulogd_active_min' => 'Členové, kteří sice dosáhnou průměru, ale nedosáhnou této minimální hodnoty, nebudou označeni jako aktivní. (např 1GB)',
'ulogd_active_type' => 'Typ provozu, podle kterého se mají hledat příliš aktivní členové. Možné hodnoty jsou: upload, download nebo obojí.',
'ulogd_order' => 'Jde o pořadí položky podle zvoleného řazení. Ve výchozím stavu se řadí podle stejného typu provozu jako se hledají aktivní členové. Viz Nastavení - Logování - Aktivní členové - Typ provozu.',
'ulogd_update_interval' => 'Interval aktualizace ulogd v sekundách. Po uplynutí této doby se zaktualizují počítadla provozu členů a najdou se příliš aktivní členové. Výchozí hodnota je 1800 sekund (30 minut).',
freenetis/branches/testing/application/i18n/en_US/help.php
'ulogd_active' => 'This is a list (in terms of type of operation) very active members. This list is used for example to evaluate QoSu for members (members of this list are slightly disadvantaged compared to other members), updated with each update ulogd see. Settings - Logging - Ulogd - Update interval.',
'ulogd_active_button' => 'Determines whether a member has been designated as Active = very active in terms of traffic. Members from the list of active members as slightly disadvantaged compared to other members of the evaluation QoSu for members. See. Settings - Logging - Active Members',
'ulogd_active_count' => 'Number of members, whose average will be calculated. Members who achieve this average will be identified as very active. Can be specified in absolute terms (number) or relatively (in percentage). The default value is 10&#37.',
'ulogd_active_min' => 'Members who do reach the average, but do not reach this minimum value will be marked as active.',
'ulogd_active_min' => 'Members who do reach the average, but do not reach this minimum value will be marked as active. (e.g. 1GB)',
'ulogd_active_type' => 'Type of operation by which to search for very active members. Possible values ​​are: upload, download or both.',
'ulogd_order' => 'This is the order of items according to the selected ordering. By default, ranked according to the same type of operation as they are looking for active members. See Options - Logging - Active members - type of operation.',
'ulogd_update_interval' => 'Ulogd update interval in seconds. After this time, to revise the counter service members and there will be very active members. The default value is 1800 seconds (30 minutes).',
freenetis/branches/testing/application/models/members_traffic.php
*/
public function avg_daily_traffics($day = NULL, $type = NULL)
{
if (!$day)
$day = date('Y-m-d');
$result = $this->db->query("
SELECT
AVG(upload) AS upload,
AVG(download) AS download,
AVG(upload+download) AS total
IFNULL(AVG(upload+local_upload), 0) AS upload,
IFNULL(AVG(download+local_download), 0) AS download,
IFNULL(AVG(upload+local_upload+download+local_download), 0) AS total
FROM members_traffics
WHERE day = ?
", $day);
if ($result && ($result = $result->current()))
{
return ($type && property_exists($result, $type)) ? $result->$type : $result;
}
else
{
return NULL;
}
}
/**
* Update active members
*
* @author Michal Kliment
* @param type $avg
* @param type $limit
* @param type $type
* @param double $avg
* @param integer $limit
* @param string $type
* @param string $day
* @return boolean
*/
public function update_active_members($avg, $limit, $type)
public function update_active_members($avg, $limit, $type, $day)
{
if ($type == 'total')
{
$type = '('
.$this->db->escape_column ('upload').'+'
.$this->db->escape_column ('download').')';
$type = '(upload+local_upload+download+local_download)';
}
else if ($type == 'upload')
{
$type = '(upload+local_upload)';
}
else
$type = $this->db->escape_column ($type);
{
$type = '(download+local_download)';
}
try
{
$this->transaction_start();
$this->db->query("UPDATE members_traffics SET active = 0");
$this->db->query("
UPDATE members_traffics
SET active = 0
WHERE day = ?
", $day);
$this->db->query("
UPDATE members_traffics
SET active = 1
WHERE $type >= ? AND member_id IN
WHERE day = ? AND $type >= ? AND member_id IN
(
SELECT id
FROM members
......
)
ORDER BY $type DESC
LIMIT ?
", array($avg, $limit));
", array($day, $avg, $limit));
$this->transaction_commit();
freenetis/branches/testing/application/models/member.php
/**
* Returns IP addresses of the most traffic-active members
*
* @param string $day
* @see Web_interface_Controller#active_traffic_members_ip_addresses
* @author Michal Kliment
* @return Mysql_Result
*/
public function get_active_traffic_members_ip_addresses()
public function get_active_traffic_members_ip_addresses($day)
{
return $this->db->query("
SELECT ip.ip_address
FROM
(
SELECT member_id FROM members_traffics
WHERE active = 1
) AS t
JOIN users u ON u.member_id = t.member_id
SELECT DISTINCT ip.ip_address
FROM members_traffics mt
JOIN users u ON u.member_id = mt.member_id
JOIN devices d ON d.user_id = u.id
LEFT JOIN ifaces i ON i.device_id = d.id
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
WHERE ip.ip_address IS NOT NULL
");
WHERE mt.active = 1 AND mt.day = ? AND ip.ip_address IS NOT NULL
", $day);
}
/**
......
) AS q
GROUP BY id
ORDER BY id DESC
", Member_Model::TYPE_APPLICANT );
", self::TYPE_APPLICANT );
}
/**
......
SELECT IFNULL(COUNT(*), 0) AS count
FROM members m
WHERE m.type = ?
", Member_Model::TYPE_APPLICANT)->current()->count;
", self::TYPE_APPLICANT)->current()->count;
}
/**
......
$where
GROUP BY m.id
ORDER BY $order_by
", array(Account_attribute_Model::CREDIT, Member_Model::ASSOCIATION));
", array(Account_attribute_Model::CREDIT, self::ASSOCIATION));
}
/**
......
public function update_lock_status()
{
$this->db->query("UPDATE members SET locked = 0");
$this->db->query("UPDATE members SET locked = 1 where type = 15");
$this->db->query("UPDATE members SET locked = 1 where type = " . self::TYPE_FORMER);
$this->db->query("
UPDATE members m,
(
......
public function count_all_members_to_ulogd()
{
$result = $this->db->query("
SELECT COUNT(m.id) AS total_members_count
SELECT COUNT(m.id) AS total
FROM members m
WHERE m.type <> 15 AND (m.qos_rate IS NULL OR m.qos_rate = 0) AND m.id NOT IN
(
SELECT mi.member_id
FROM membership_interrupts mi
JOIN members_fees mf ON mi.members_fee_id = mf.id
WHERE mf.activation_date <= CURDATE() AND CURDATE() <= mf.deactivation_date
)
");
WHERE m.type <> ? AND
(m.qos_rate IS NULL OR m.qos_rate = 0 OR LENGTH(m.qos_rate) = 0) AND
m.id NOT IN
(
SELECT mi.member_id
FROM membership_interrupts mi
JOIN members_fees mf ON mi.members_fee_id = mf.id
WHERE mf.activation_date <= CURDATE() AND CURDATE() <= mf.deactivation_date
)
", self::TYPE_FORMER);
return ($result && $result->current()) ? $result->current()->total_members_count : 0;
return ($result && $result->current()) ? $result->current()->total : 0;
}
/**
......
public function get_members_qos_ceil_rate ()
{
return $this->db->query("
SELECT
id,
IF(qos_ceil<>'',qos_ceil,'0') AS qos_ceil,
IF(qos_rate<>'',qos_rate,'0') AS qos_rate
SELECT id,
IF(qos_ceil IS NOT NULL AND qos_ceil <> '', qos_ceil, '0') AS qos_ceil,
IF(qos_rate IS NOT NULL AND qos_rate <> '', qos_rate, '0') AS qos_rate
FROM members m
WHERE qos_ceil OR qos_rate
WHERE (qos_ceil IS NOT NULL AND qos_ceil <> '') OR
(qos_rate IS NOT NULL AND qos_rate <> '')
ORDER BY m.id
");
}
freenetis/branches/testing/application/models/ulog2_ct.php
LEFT JOIN ifaces i ON ip.iface_id = i.id
LEFT JOIN devices d ON i.device_id = d.id
LEFT JOIN users u ON d.user_id = u.id
WHERE ip.ip_address = _ip_address;
WHERE INET_ATON(ip.ip_address) = INET_ATON(_ip_address);
INSERT INTO ip_addresses_traffics (ip_address, download, upload, local_download, local_upload, member_id)
VALUES(_ip_address, _download, _upload, _local_download, _local_upload, _member_id)
......
}
/**
* Destroy function to ulogd
*
* @author Michal Kliment
*/
public static function destroy_functions()
{
$db = Database::instance();
$db->query("DROP FUNCTION IF EXISTS `UPDATE_CT`");
$db->query("DROP FUNCTION IF EXISTS `insert_rand`");
$db->query("DROP FUNCTION IF EXISTS `ip2str`");
$db->query("DROP FUNCTION IF EXISTS `swap_endian`");
}
/**
* Checks pre requirements for ulogd
*
* @author Michal Kliment
freenetis/branches/testing/application/controllers/web_interface.php
return;
// finds total qos speed
$total = network::speed_size(Settings::get('qos_total_speed'),"M");
$total = network::speed_size(Settings::get('qos_total_speed'), "M");
$members_upload_rate = $total['upload'];
$members_download_rate = $total['download'];
......
if (Settings::get('ulogd_enabled'))
{
// finds qos speed for active members
$active = network::speed_size(Settings::get('qos_active_speed'),"M");
$active = network::speed_size(Settings::get('qos_active_speed'), "M");
$members_upload_rate -= $active['upload'];
$members_download_rate -= $active['download'];
......
$data = array();
$ips = ORM::factory('member')->get_active_traffic_members_ip_addresses();
$ips = ORM::factory('member')->get_active_traffic_members_ip_addresses(date('Y-m-d'));
foreach ($ips as $ip)
{
freenetis/branches/testing/application/controllers/scheduler.php
$ulogd_active_count = Settings::get('ulogd_active_count');
// count is in percents
if (substr($ulogd_active_count, -1) == "%")
if (substr($ulogd_active_count, -1) == '%')
{
// finds total members to ulogd
$total = ORM::factory('member')->count_all_members_to_ulogd();
// calculates count of active members from percents
$ulogd_active_count = (int) round(
((int) substr($ulogd_active_count, 0, -1)) / 100 * $total
);
}
// finding of avarage
$avg = $members_traffic_model->avg_daily_traffics(
date('Y-m-d'), Settings::get('ulogd_active_type')
......
if (($ulogd_active_min = Settings::get('ulogd_active_min')) != '')
{
$min = intval($ulogd_active_min);
$min = doubleval($ulogd_active_min);
switch (substr($ulogd_active_min, -2, 1))
{
......
// updates active members
$members_traffic_model->update_active_members(
$avg, $ulogd_active_count,
Settings::get('ulogd_active_type')
Settings::get('ulogd_active_type'),
date('Y-m-d')
);
// updates variable
freenetis/branches/testing/application/controllers/settings.php
{
Ulog2_ct_Model::create_functions();
}
else
{
Ulog2_ct_Model::destroy_functions();
}
$issaved = true;
freenetis/branches/testing/system/libraries/ORM.php
if ($permissions == NULL)
{
$db_name = Config::get('db_name');
$permissions = array();
foreach ($this->db->query("SHOW GRANTS FOR CURRENT_USER") as $row)
{
$values = array_values(arr::from_object ($row));
if (($pos = strpos($values[0], ' ON `'.Config::get('db_name').'`.*')) === FALSE)
if ((($pos = strpos($values[0], ' ON `'.$db_name.'`.*')) === FALSE) &&
($pos = strpos($values[0], ' ON *.*')) === FALSE)
{
continue;
}
if (($permissions = substr($values[0], 6, $pos-6)) == 'ALL PRIVILEGES')
{
return true;
$permissions = arr::tolower (explode(", ", $permissions));
}
$permissions = arr::tolower (explode(', ', $permissions));
break;
}
}
return ($permissions == 'ALL PRIVILEGES'
|| in_array (strtolower($permission), $permissions));
return (
$permissions == 'ALL PRIVILEGES' ||
in_array (strtolower($permission), $permissions)
);
}
/**

Také k dispozici: Unified diff