Revize 1422
Přidáno uživatelem Michal Kliment před asi 12 roky(ů)
freenetis/branches/testing/application/models/device.php | ||
---|---|---|
", array(Config::get('lang')));
|
||
}
|
||
|
||
/**
|
||
* Returns all devices with service flag in given subnets
|
||
*
|
||
* @author Michal Kliment
|
||
* @param type $subnets
|
||
* @return boolean
|
||
*/
|
||
public function get_all_service_devices_of_subnets ($subnets = array())
|
||
{
|
||
if (!is_array($subnets))
|
||
$subnets = array($subnets);
|
||
|
||
if (!count($subnets))
|
||
return FALSE;
|
||
|
||
$where = "AND IFNULL(ip1.subnet_id, ip2.subnet_id) IN (".implode(", ", $subnets).")";
|
||
|
||
return $this->db->query("
|
||
SELECT d.*
|
||
FROM devices d
|
||
JOIN ifaces i ON i.device_id = d.id
|
||
LEFT JOIN vlan_ifaces vi ON vi.iface_id = i.id
|
||
LEFT JOIN ip_addresses ip1 ON ip1.iface_id = i.id
|
||
LEFT JOIN ip_addresses ip2 ON ip2.vlan_iface_id = vi.id
|
||
WHERE IFNULL(ip1.service,ip2.service) = 1
|
||
AND IFNULL(ip1.gateway,ip2.gateway) = 0
|
||
$where
|
||
ORDER BY d.name
|
||
");
|
||
}
|
||
|
||
public function get_all_dependent_subnets ($device_id = NULL, $recursive = TRUE)
|
||
{
|
||
if (!$device_id)
|
||
$device_id = $this->id;
|
||
|
||
return ORM::factory('subnet')
|
||
->get_all_dependent_subnets_by_device($device_id, $recursive);
|
||
}
|
||
|
||
}
|
freenetis/branches/testing/application/models/subnet.php | ||
---|---|---|
* @param type $device_id
|
||
* @return type
|
||
*/
|
||
public function get_all_subnets_by_device ($device_id = NULL)
|
||
public function get_all_subnets_by_device ($device_id = NULL, $gateway = FALSE)
|
||
{
|
||
if (!$device_id)
|
||
$device_id = $this->id;
|
||
|
||
$where = '';
|
||
|
||
if ($gateway)
|
||
$where .= ' AND gateway = 1';
|
||
|
||
return $this->db->query("
|
||
SELECT
|
||
s.*, ip.gateway,
|
||
... | ... | |
LEFT JOIN ifaces i1 ON i1.id = ip.iface_id
|
||
LEFT JOIN vlan_ifaces vi ON vi.id = ip.vlan_iface_id
|
||
LEFT JOIN ifaces i2 ON i2.id = vi.iface_id
|
||
WHERE IFNULL(i1.device_id, i2.device_id) = ?
|
||
WHERE IFNULL(i1.device_id, i2.device_id) = ? $where
|
||
ORDER BY INET_ATON(ip_address)
|
||
", $device_id);
|
||
}
|
||
|
||
/**
|
||
* Returns all dependent subnets of device
|
||
*
|
||
* @author Michal Kliment
|
||
* @param type $device_id
|
||
* @return type
|
||
*/
|
||
public function get_all_dependent_subnets_by_device ($device_id = NULL, $recursive = TRUE)
|
||
{
|
||
$subnets = array();
|
||
|
||
$device_model = new Device_Model();
|
||
|
||
// find all subnets of which device is gateway
|
||
$gateway_subnets = arr::from_objects(
|
||
$this->get_all_subnets_by_device($device_id, TRUE), 'id'
|
||
);
|
||
|
||
$subnets += $gateway_subnets;
|
||
|
||
if ($recursive && count($gateway_subnets))
|
||
{
|
||
// finds all dependent devices of device's subnets
|
||
$dependent_devices = $device_model
|
||
->get_all_service_devices_of_subnets($gateway_subnets);
|
||
|
||
foreach ($dependent_devices as $dependent_device)
|
||
{
|
||
// recursively find dependent subnets of dependent device
|
||
$subnets += $this->get_all_dependent_subnets_by_device($dependent_device->id, $recursive);
|
||
}
|
||
}
|
||
|
||
return $subnets;
|
||
}
|
||
|
||
}
|
freenetis/branches/testing/application/controllers/devices.php | ||
---|---|---|
$view->render(TRUE);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Generates map of devices
|
||
*
|
||
* @author Michal Kliment
|
||
* @param type $device_id
|
||
*/
|
||
public function map($device_id = NULL)
|
||
{
|
||
$devices = array($device_id => $this->_dependent_device($device_id));
|
||
|
||
/**
|
||
*@todo Jeff do it :-)
|
||
*/
|
||
|
||
$view = new View('devices/map');
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Return array with device name and its device's children
|
||
*
|
||
* @author Michal Kliment
|
||
* @param type $device_id
|
||
* @return type
|
||
*/
|
||
private function _dependent_device($device_id)
|
||
{
|
||
$device = new Device_Model($device_id);
|
||
|
||
$result = array
|
||
(
|
||
'name' => $device->name,
|
||
'children' => array()
|
||
);
|
||
|
||
$subnets = $device->get_all_dependent_subnets($device->id, FALSE);
|
||
|
||
$dependent_devices = arr::from_objects($device->get_all_service_devices_of_subnets($subnets), 'name');
|
||
|
||
foreach ($dependent_devices as $dependent_device_id => $dependent_device_name)
|
||
{
|
||
$result['children'][$dependent_device_id] = $this->_dependent_device($dependent_device_id);
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Shows port
|
freenetis/branches/testing/application/views/devices/map.php | ||
---|---|---|
<?php
|
||
/**
|
||
* @todo Jeff do it :-)
|
||
*/
|
||
?>
|
Také k dispozici: Unified diff
Pridany funkce na zjisteni zavislych podsiti k zarizeni.
Pridana zaklady mapy site pomoci podsiti, jejich bran a servisnich adres (zbyva dodelat graficke zobrazeni = dodela Jeff).