Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1699

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

Dalsi vylepseni na exportu zarizeni.

Zobrazit rozdíly:

freenetis/branches/1.1/application/models/subnet.php
return $subnets;
}
/**
* Get gateway of subnet
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $subnet_id
* @return type
*/
public function get_gateway($subnet_id = NULL)
{
if (!$subnet_id && $this->id)
$subnet_id = $this->id;
return ORM::factory('ip_address')->get_gateway_of_subnet($subnet_id);
}
}
freenetis/branches/1.1/application/controllers/devices.php
if (!$device->id)
Controller::error(RECORD);
$result = array
(
'name' => $device->name,
'type' => $device->type,
'ifaces' => array
(
Iface_Model::TYPE_WIRELESS => array(),
Iface_Model::TYPE_ETHERNET => array(),
Iface_Model::TYPE_PORT => array(),
Iface_Model::TYPE_BRIDGE => array(),
Iface_Model::TYPE_VLAN => array(),
Iface_Model::TYPE_INTERNAL => array(),
Iface_Model::TYPE_VIRTUAL_AP => array()
),
'ip_addresses' => array(),
'gateways' => array()
);
// interfaces of device
$interfaces = array();
// IP addresses of device
$addresses = array();
// gateways of device, probably only one
$gateways = array();
foreach ($device->ifaces as $iface)
{
$result['ifaces'][$iface->type][$iface->name] = array
$interface = array
(
'name' => $iface->name,
'type' => $iface->type,
'mac' => $iface->mac,
'number' => $iface->number,
);
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$result['ifaces'][$iface->type][$iface->name]['wireless'] = array
$interface['wireless'] = array
(
'mode' => $iface->wireless_mode,
'ssid' => $iface->link->wireless_ssid,
......
if ($iface->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$result['ifaces'][$iface->type][$iface->name]['wireless']['clients'] = array();
$interface['wireless']['clients'] = array();
foreach ($iface->link->ifaces as $link_iface)
{
if ($link_iface->id == $iface->id)
continue;
$result['ifaces'][$iface->type][$iface->name]['wireless']['clients'][] = array
$interface['wireless']['clients'][] = array
(
'name' => $link_iface->name,
'mac' => $link_iface->mac,
......
}
}
$interfaces[] = $interface;
foreach ($iface->ip_addresses as $ip_address)
{
$result['ip_addresses'][] = array
// create CIDR format
$cidr = $ip_address->subnet->network_address.'/'.network::netmask2cidr($ip_address->subnet->netmask);
// find broadcast address
$broadcast = long2ip(ip2long($ip_address->subnet->network_address) | ~ip2long($ip_address->subnet->netmask));
$address = array
(
'ip_address' => $ip_address->ip_address,
'iface' => $iface->name
'address' => $ip_address->ip_address,
'netmask' => $ip_address->subnet->netmask,
'network' => $ip_address->subnet->network_address,
'broadcast' => $broadcast,
'cidr' => $cidr,
'interface' => $iface->name
);
if ($ip_address->gateway)
{
}
else
{
// find gateway of subnet
$gateway = $ip_address->subnet->get_gateway();
if ($gateway && $gateway->ip_address)
{
$gateways[] = $gateway->ip_address;
$address['gateway'] = $gateway->ip_address;
}
}
$addresses[] = $address;
}
}
$result = array
(
'name' => $device->name,
'type' => $device->type,
'interfaces' => $interfaces,
'ip' => array
(
'addresses' => $addresses,
'gateways' => array_unique($gateways)
)
);
debug::printr($result);
die();

Také k dispozici: Unified diff