Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1840

Přidáno uživatelem Michal Kliment před více než 11 roky(ů)

Upravy:

- #465 - Optimalizace reloadu DHCP zaznamu (zohlednovani expirace DHCP u exportu)

Zobrazit rozdíly:

freenetis/branches/1.1/application/models/device.php
), 'stdClass', FALSE);
}
/**
* Test if given IP address belongs to device
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $ip_address
* @param type $device_id
* @return boolean
*/
public function is_ip_address_of_device($ip_address, $device_id = NULL)
{
if (!$device_id && $this->id)
$device_id = $this->id;
$result = $this->db->query("
SELECT COUNT(*) AS count
FROM ip_addresses ip
JOIN ifaces i ON ip.iface_id = i.id
WHERE ip.ip_address = ? AND i.device_id = ?
", array($ip_address, $device_id));
if ($result && $result->current() && $result->current()->count > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
}
freenetis/branches/1.1/application/models/subnet.php
}
/**
* Sets subnets of device as (not) expired
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $device_id ID of device
* @param type $flag sexpired (1) or not (0) [optional]
*/
public function set_expired_subnets_of_device($device_id, $flag = 1)
{
$this->db->query("
UPDATE subnets s
JOIN ip_addresses ip ON ip.subnet_id = s.id AND ip.gateway = 1
JOIN ifaces i ON ip.iface_id = i.id
SET s.dhcp_expired = ?
WHERE s.dhcp > 0 AND i.device_id = ?
", array($flag, $device_id));
}
/**
* Check if any of device subnet on that the device is gateway is expired
*
* @param int $device_id
freenetis/branches/1.1/application/controllers/devices.php
$device = new Device_Model($device_id);
// user is not logged
if (!$this->user_id)
// device doesn't exist
if (!$device->id)
{
// device doesn't exist
if (!$device->id)
// user is not logged
if (!$this->user_id)
{
@header('HTTP/1.0 404 Not found');
die();
}
$ip_addresses = array();
foreach ($device->ifaces as $iface)
else
{
foreach ($iface->ip_addresses as $ip_address)
{
$ip_addresses[] = $ip_address->ip_address;
}
Controller::error(RECORD);
}
}
// is it device itself?
if (!in_array(server::remote_addr(), $ip_addresses))
{
@header('HTTP/1.0 403 Forbidden');
die();
}
// it is device itself?
$from_device = $device->is_ip_address_of_device(server::remote_addr());
if ($from_device)
{
// update access time of device
try
{
......
}
else
{
// device doesn't exist
if (!$device->id)
Controller::error(RECORD);
if (!$this->acl_check_view(get_class($this), 'devices', $device->user->member_id))
Controller::error(ACCESS);
}
......
if (!isset($formats[$format]) || !isset($outputs[$output]))
Controller::error(RECORD);
// it is device itself?
if ($from_device)
{
// generating of DHCP server's config
if (strstr($format, 'dhcp') !== FALSE)
{
$subnet_model = new Subnet_Model();
// no change
if (!$subnet_model->is_any_subnet_of_device_expired($device_id))
{
if (!text::starts_with($format, 'mikrotik'))
{
@header('HTTP/1.0 304 Not Modified');
}
die();
}
}
}
// get full export of device
$device_export = $device->get_export();
// it is device itself?
if ($from_device)
{
// generating of DHCP server's config
if (strstr($format, 'dhcp') !== FALSE)
{
// update DHCP expire flag
$subnet_model->set_expired_subnets_of_device($device_id, 0);
}
}
if ($output == 'file')
if ($output == 'file')
{
switch ($format)
{
......
$view->render(TRUE);
}
// form to choose format and output
else
else if (!$from_device)
{
$title = __('Export of device');

Také k dispozici: Unified diff