Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1416

Přidáno uživatelem Michal Kliment před asi 12 roky(ů)

Optimalizace presmerovani pro propojeni s Mikrotikem:
- pridana podpora strankovani (Mikrotik neumi stahnout a pracovat soubory >= 4096kb
- pridana funkce unallowed_ip_addresses ktera vraci vsechny IP adresy s nastavenym presmerovanim => lepsi stahovat cca 3% IP adres nez 97%, ne?

Zobrazit rozdíly:

freenetis/branches/testing/application/models/subnet.php
) AS subnet_range
FROM subnets
WHERE redirect = 1
ORDER BY INET_ATON(network_address)
");
}
freenetis/branches/testing/application/models/ip_address.php
WHERE m.ignore_whitelist = 1
)
)
ORDER BY INET_ATON(ip_address)
");
}
/**
* Same as previous method, but return unallowed ip addresses
*
* @author Michal Kliment
* @see Web_interface_Controller#unallowed_ip_addresses
* @return type
*/
public function get_unallowed_ip_addresses()
{
return $this->db->query("
SELECT ip_address
FROM ip_addresses ip
JOIN messages_ip_addresses mip ON mip.ip_address_id = ip.id
JOIN messages m ON mip.message_id = m.id
WHERE IFNULL(ip.whitelisted,0) = 0 OR m.ignore_whitelist = 1
GROUP BY ip.id
ORDER BY INET_ATON(ip_address)
");
}
/**
* Function gets all ip address of interfaces of devices of users of given member.
*
* @param integer $member_id
freenetis/branches/testing/application/controllers/web_interface.php
* @author Jiri Svitak
* @return unknown_type
*/
public function redirected_ranges()
public function redirected_ranges($paginator = FALSE, $page = NULL)
{
$ranges = ORM::factory('subnet')->get_redirected_ranges();
$items = array();
foreach ($ranges as $range)
$items[] = $range->subnet_range;
// stupid mikrotik cannot handle file >= 4096kB
if ($paginator)
{
echo "$range->subnet_range\n";
echo $this->paginator(4096, $items, $page);
}
else
{
echo implode("\n", $items)."\n";
}
}
/**
......
* @author Jiri Svitak
* @return unknown_type
*/
public function allowed_ip_addresses()
public function allowed_ip_addresses($paginator = FALSE, $page = NULL)
{
$ips = ORM::factory('ip_address')->get_allowed_ip_addresses();
$ip_adresses = ORM::factory('ip_address')->get_allowed_ip_addresses();
foreach ($ips as $ip)
$items = array();
foreach ($ip_adresses as $ip_adress)
$items[] = $ip_adress->ip_address;
// stupid mikrotik cannot handle file >= 4096kB
if ($paginator)
{
echo "$ip->ip_address\n";
echo $this->paginator(4096, $items, $page);
}
else
{
echo implode("\n", $items)."\n";
}
}
/**
* Prints all unallowed ip addresses, otherwise same as previous method
*
* @author Michal Kliments
* @param type $paginator
* @param type $page
*/
public function unallowed_ip_addresses($paginator = FALSE, $page = NULL)
{
$ip_adresses = ORM::factory('ip_address')->get_unallowed_ip_addresses();
$items = array();
foreach ($ip_adresses as $ip_adress)
$items[] = $ip_adress->ip_address;
// stupid mikrotik cannot handle file >= 4096kB
if ($paginator)
{
echo $this->paginator(4096, $items, $page);
}
else
{
echo implode("\n", $items)."\n";
}
}
public function self_cancelable_ip_addresses()
/**
* @author Michal Kliment
*/
public function self_cancelable_ip_addresses($paginator = FALSE, $page = NULL)
{
$ips = ORM::factory('ip_address')->get_ip_addresses_with_self_cancel();
$ip_adresses = ORM::factory('ip_address')->get_ip_addresses_with_self_cancel();
foreach ($ips as $ip)
$items = array();
foreach ($ip_adresses as $ip_adress)
$items[] = $ip_adress->ip_address;
// stupid mikrotik cannot handle file >= 4096kB
if ($paginator)
{
echo "$ip->ip_address\n";
echo $this->paginator(4096, $items, $page);
}
else
{
echo implode("\n", $items)."\n";
}
}
/**
......
$monitor_host_model->update_host($ip, Monitor_host_Model::get_state($states[$i]), $lats[$i]);
}
}
/**
* It creates pagination of results, it is used for buffering result
* for smaller parts, e.g. Mikrotik cannot handle file >= 4096 kB
*
* @author Michal Kliment
* @param type $delimeter_size
* @param type $items
* @param type $page
* @return string
*/
private function paginator($delimeter_size, $items, $page = NULL)
{
$data = array();
$current_page = 1;
// data for first page
$data[$current_page] = '';
foreach ($items as $item)
{
// overflow data of current page
if (strlen($data[$current_page]) + strlen($item) +1 >= $delimeter_size)
{
// we want current page => return it
if ($page && $page == $current_page)
{
return $data[$current_page];
}
// otherwise create new page
$current_page++;
$data[$current_page] = '';
}
// store data to current page
$data[$current_page] .= "$item\n";
}
// we want last page => return it
if ($page)
{
return $data[$current_page];
}
// otherwise print number of total pages
return count($data);
}
}

Také k dispozici: Unified diff