Revize 1438
Přidáno uživatelem Michal Kliment před více než 12 roky(ů)
freenetis/branches/network/application/models/device.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Returns all devices of segment
|
||
* Returns all devices of link
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $segment_id
|
||
* @return MySQL_Iterator object
|
||
*/
|
||
public function get_all_devices_of_segment($segment_id)
|
||
public function get_all_devices_of_link($link_id)
|
||
{
|
||
return $this->db->query("
|
||
SELECT
|
||
... | ... | |
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
|
||
LEFT JOIN users u ON d.user_id = u.id
|
||
LEFT JOIN members m ON u.member_id = m.id
|
||
WHERE i.segment_id = ?
|
||
WHERE i.link_id = ?
|
||
GROUP BY d.id
|
||
", $segment_id);
|
||
", $link_id);
|
||
}
|
||
|
||
/**
|
freenetis/branches/network/application/models/iface.php | ||
---|---|---|
i.mac, i.name, i.comment, i.type, i.number, i.port_mode, l.bitrate,
|
||
cd.id AS connected_to_device_id, cd.name AS connected_to_device_name,
|
||
COUNT(*) AS connected_to_devices_count,
|
||
GROUP_CONCAT(cd.name SEPARATOR ', \\n') AS connected_to_devices
|
||
GROUP_CONCAT(cd.name SEPARATOR ', \\n') AS connected_to_devices,
|
||
l.wireless_norm, l.wireless_frequency, i.wireless_mode,
|
||
l.wireless_channel_width, l.wireless_ssid, ir.parent_iface_id,
|
||
pi.name AS parent_name, v.tag_802_1q
|
||
FROM ifaces i
|
||
LEFT JOIN ifaces_relationships ir ON ir.iface_id = i.id
|
||
LEFT JOIN ifaces pi ON ir.parent_iface_id = pi.id
|
||
LEFT JOIN links l ON i.link_id = l.id
|
||
LEFT JOIN ifaces ci ON ci.link_id = l.id AND ci.id <> i.id AND
|
||
(
|
||
... | ... | |
)
|
||
)
|
||
LEFT JOIN devices cd ON ci.device_id = cd.id
|
||
LEFT JOIN ifaces_vlans iv ON iv.iface_id = i.id
|
||
LEFT JOIN vlans v ON iv.vlan_id = v.id
|
||
WHERE i.device_id = ? $where
|
||
GROUP BY i.id
|
||
ORDER BY i.number, i.type, i.name
|
freenetis/branches/network/application/controllers/devices.php | ||
---|---|---|
$subnet_model = new Subnet_Model();
|
||
$ip_address_model = new Ip_address_Model();
|
||
$iface_model = new Iface_Model();
|
||
$vlan_iface_model = new Vlan_iface_Model();
|
||
$wireless_iface_model = new Wireless_iface_Model();
|
||
$device_model = new Device_Model();
|
||
|
||
// definition of array for data
|
||
$device_ifaces = array
|
||
(
|
||
Iface_Model::TYPE_WIRELESS => array(),
|
||
Iface_Model::TYPE_ETHERNET => array()
|
||
Iface_Model::TYPE_WIRELESS => array(),
|
||
Iface_Model::TYPE_ETHERNET => array(),
|
||
Iface_Model::TYPE_VLAN => array(),
|
||
);
|
||
$device_wireless_ifaces = array();
|
||
$device_wireless_iface_devices = array();
|
||
$device_vlan_ifaces = array();
|
||
$device_ip_addresses = array();
|
||
$device_subnets = array();
|
||
$device_subnet_ip_addresses = array();
|
||
... | ... | |
$device_ifaces[$iface->type][] = $iface;
|
||
|
||
if ($iface->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$device_wireless_ifaces[$iface->id] = $wireless_iface_model->get_wireless_iface($iface->id);
|
||
{
|
||
$link_devices = $device_model->get_all_devices_of_link($iface->link_id);
|
||
|
||
$segment_devices = $device_model->get_all_devices_of_segment($iface->segment_id);
|
||
|
||
$device_wireless_iface_devices[$iface->id] = array();
|
||
foreach ($segment_devices as $segment_device)
|
||
foreach ($link_devices as $link_device)
|
||
{
|
||
if ($segment_device->id != $device->id)
|
||
$device_wireless_iface_devices[$iface->id][] = $segment_device;
|
||
}
|
||
if ($link_device->id != $device->id)
|
||
$device_wireless_iface_devices[$iface->id][] = $link_device;
|
||
}
|
||
}
|
||
}
|
||
|
||
// device's vlan interfaces
|
||
$vlan_ifaces = $vlan_iface_model->get_all_vlan_ifaces_by_device_id($device->id);
|
||
foreach ($vlan_ifaces as $vlan_iface)
|
||
$device_vlan_ifaces[] = $vlan_iface;
|
||
|
||
// device's ip addresses
|
||
$ip_addresses = $ip_address_model->get_ip_addresses_of_device($device->id);
|
||
|
||
... | ... | |
$view->qos_ip_addresses = $qos_ip_addresses;
|
||
$view->device_members = $device_members;
|
||
$view->device_ifaces = $device_ifaces;
|
||
$view->device_vlan_ifaces = $device_vlan_ifaces;
|
||
$view->device_ip_addresses = $device_ip_addresses;
|
||
$view->device_gateways = $device_gateways;
|
||
$view->device_wireless_ifaces = $device_wireless_ifaces;
|
||
$view->device_wireless_iface_devices = $device_wireless_iface_devices;
|
||
$view->dns_servers = $form_data["dns_servers"];
|
||
$view->render(TRUE);
|
freenetis/branches/network/application/views/device_templates/mikrotik.php | ||
---|---|---|
/interface wireless
|
||
<?php foreach ($device_ifaces[Iface_Model::TYPE_WIRELESS] as $iface_id => $iface)
|
||
{
|
||
if ($device_wireless_ifaces[$iface->id]->norm)
|
||
if ($iface->wireless_norm)
|
||
{
|
||
$norm = $device_wireless_ifaces[$iface->id]->norm;
|
||
if ($device_wireless_ifaces[$iface->id]->frequence!="")
|
||
$frequence = " frequency=".$device_wireless_ifaces[$iface->id]->frequence;
|
||
$norm = $iface->wireless_norm;
|
||
if ($iface->wireless_frequency !="")
|
||
$frequency = " frequency=".$iface->wireless_frequency;
|
||
}
|
||
else
|
||
{
|
||
$norm = Wireless_segment_Model::NORM_802_11_A;
|
||
$frequence = "";
|
||
$norm = Link_Model::NORM_802_11_A;
|
||
$frequency = "";
|
||
}
|
||
?>
|
||
set <?php echo $iface_id ?> arp=enabled disabled=no mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>" <?php
|
||
switch ($device_wireless_ifaces[$iface->id]->wmode)
|
||
switch ($iface->wireless_mode)
|
||
{
|
||
case Wireless_iface_Model::WIRELESS_MODE_AP:
|
||
case Iface_Model::WIRELESS_MODE_AP:
|
||
echo "mode=ap-bridge ";
|
||
break;
|
||
case Wireless_iface_Model::WIRELESS_MODE_CLIENT:
|
||
case Iface_Model::WIRELESS_MODE_CLIENT:
|
||
echo "mode=station ";
|
||
break;
|
||
}
|
||
switch ($norm)
|
||
{
|
||
case Wireless_segment_Model::NORM_802_11_B:
|
||
case Link_Model::NORM_802_11_B:
|
||
echo " band=2ghz-b ";
|
||
break;
|
||
case Wireless_segment_Model::NORM_802_11_G:
|
||
case Link_Model::NORM_802_11_G:
|
||
echo " band=2ghz-onlyg ";
|
||
break;
|
||
case Wireless_segment_Model::NORM_802_11_B_G:
|
||
case Link_Model::NORM_802_11_B_G:
|
||
echo " band=2ghz-b/g ";
|
||
break;
|
||
case Wireless_segment_Model::NORM_802_11_A:
|
||
case Wireless_segment_Model::NORM_802_11_N:
|
||
case Link_Model::NORM_802_11_A:
|
||
case Link_Model::NORM_802_11_N:
|
||
echo " band=5ghz-a ";
|
||
break;
|
||
}
|
||
if ($device_wireless_ifaces[$iface->id]->channel_width!="")
|
||
echo "channel-width=".$device_wireless_ifaces[$iface->id]->channel_width."mhz ";
|
||
?>country="czech republic" default-authentication=yes<?php echo $frequence ?> ssid="<?php echo $device_wireless_ifaces[$iface->id]->ssid ?>"
|
||
if ($iface->wireless_channel_width != "")
|
||
echo "channel-width=".$iface->wireless_channel_width."mhz ";
|
||
?>country="czech republic" default-authentication=yes<?php echo $frequency ?> ssid="<?php echo $iface->wireless_ssid ?>"
|
||
<?php } ?>
|
||
/interface wireless access-list
|
||
<?php foreach ($device_ifaces[Iface_Model::TYPE_WIRELESS] as $iface_id => $iface): ?>
|
||
... | ... | |
set <?php echo $iface_id ?> arp=enabled auto-negotiation=yes disabled=no full-duplex=yes mac-address=<?php echo $iface->mac ?> name="<?php echo $iface->name ?>"
|
||
<?php endforeach ?>
|
||
/interface vlan
|
||
<?php foreach ($device_vlan_ifaces as $device_vlan_iface): ?>
|
||
add arp=enabled disabled=no interface="<?php echo $device_vlan_iface->iface_name ?>" name="<?php echo $device_vlan_iface->name ?>" vlan-id=<?php echo $device_vlan_iface->tag_802_1q ?>
|
||
<?php foreach ($device_ifaces[Iface_Model::TYPE_VLAN] as $iface_id => $iface): ?>
|
||
add arp=enabled disabled=no interface="<?php echo $iface->parent_name ?>" name="<?php echo $iface->name ?>" vlan-id=<?php echo $iface->tag_802_1q ?>
|
||
<?php endforeach ?>
|
||
/ip address
|
||
<?php foreach ($device_ip_addresses as $device_ip_address): ?>
|
||
... | ... | |
set allow-remote-requests=yes servers=<?php echo $dns_servers ?>
|
||
/ip pool
|
||
<?php foreach ($dhcp_subnets as $dhcp_subnet): ?>
|
||
add name="<?php echo $dhcp_subnet->iface !='' ? $dhcp_subnet->iface : $dhcp_subnet->vlan_iface ?>" ranges=<?php echo $dhcp_subnet->subnet_range_start ?>-<?php echo $dhcp_subnet->subnet_range_end ?>
|
||
add name="<?php echo $dhcp_subnet->iface ?>" ranges=<?php echo $dhcp_subnet->subnet_range_start ?>-<?php echo $dhcp_subnet->subnet_range_end ?>
|
||
<?php endforeach ?>
|
||
/ip dhcp-server
|
||
<?php foreach ($dhcp_subnets as $dhcp_subnet): ?>
|
||
add address-pool="<?php echo $dhcp_subnet->iface !='' ? $dhcp_subnet->iface : $dhcp_subnet->vlan_iface ?>" authoritative=after-2sec-delay bootp-support=static disabled=no interface="<?php echo $dhcp_subnet->iface !='' ? $dhcp_subnet->iface : $dhcp_subnet->vlan_iface ?>" lease-time=3d name="<?php echo $dhcp_subnet->iface !='' ? $dhcp_subnet->iface : $dhcp_subnet->vlan_iface ?>"
|
||
add address-pool="<?php $dhcp_subnet->iface ?>" authoritative=after-2sec-delay bootp-support=static disabled=no interface="<?php echo $dhcp_subnet->iface ?>" lease-time=3d name="<?php echo $dhcp_subnet->iface ?>"
|
||
<?php endforeach ?>
|
||
/ip dhcp-server config
|
||
set store-leases-disk=5m
|
Také k dispozici: Unified diff
Oprava exportu zarizeni s novou strukturou datebaze site.