Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1405

Přidáno uživatelem Ondřej Fibich před více než 12 roky(ů)

Upravy:
- pocatek #185 (Nova struktura databaze pro sit), editace struktury zasazenych ORM modelu.

Zobrazit rozdíly:

freenetis/branches/network/application/helpers/callback.php
*/
public function port_mode_field($item, $name)
{
echo Port_Model::get_mode($item->mode);
echo Port_Model::get_port_mode($item->mode);
}
/**
......
switch ($item->type)
{
// interface
case Segment_Model::IFACE:
case Link_Model::IFACE:
echo html::anchor('ifaces/show/'.$item->id, $item->name);
break;
// port
case Segment_Model::PORT:
case Link_Model::PORT:
echo html::anchor('ports/show/'.$item->id, $item->name);
break;
......
switch ($item->type)
{
// interface
case Segment_Model::IFACE:
case Link_Model::IFACE:
echo __('Interface');
break;
// port
case Segment_Model::PORT:
case Link_Model::PORT:
echo __('Port');
break;
......
*/
public static function segment_medium_field ($item, $name)
{
echo Segment_Model::get_medium_type($item->medium);
echo Link_Model::get_medium_type($item->medium);
}
/**
freenetis/branches/network/application/models/vlan_iface.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* VLAN iface
*
* @package Model
*
* @property integer $id
* @property integer $vlan_id
* @property Vlan_Model $vlan
* @property integer $iface_id
* @property Iface_Model $iface
* @property integer $name
* @property ORM_Iterator $ip_addresses
*/
class Vlan_iface_Model extends ORM
{
protected $belongs_to = array('iface', 'vlan');
protected $has_many = array('ip_addresses');
protected $has_one = array('ip_address');
/**
* Function counts all records.
*
* @return integer
*/
public function count_all_vlan_ifaces()
{
return $this->db->count_records('vlan_ifaces');
}
/**
* Returns all VLAN interfaces which belong to device
*
* @author Michal Kliment
* @param integer $device_id
* @return Mysql_Result
*/
public function get_all_vlan_ifaces_by_device_id ($device_id, $order_by = 'tag_802_1q')
{
if (!$this->has_column($order_by))
$order_by = 'tag_802_1q';
return $this->db->query("
SELECT vi.*, vi.id AS vlan_iface_id, vi.name AS vlan_iface_name,
v.id AS vlan_id, v.name AS vlan_name,
v.tag_802_1q, i.id AS iface_id, i.name AS iface_name
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
WHERE i.device_id = ?
ORDER BY tag_802_1q
", array($device_id));
}
/**
* Returns all VLAN interface of device
*
* @author Michal Kliment
* @param int $device_id
* @return Mysql_Result
*/
public function get_all_vlan_ifaces_with_ip_addresses_by_device_id ($device_id)
{
return $this->db->query("
SELECT
vi.*,
vi.id AS vlan_iface_id,
vi.name AS vlan_iface_name,
v.id AS vlan_id,
v.name AS vlan_name,
v.tag_802_1q,
i.id AS iface_id,
i.name AS iface_name,
ip.id AS ip_address_id,
ip.ip_address,
32-log2((~INET_ATON(s.netmask) & 0xffffffff) + 1) AS subnet_range
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip ON vi.id = ip.vlan_iface_id
LEFT JOIN subnets s ON ip.subnet_id = s.id
WHERE i.device_id = ?
ORDER BY tag_802_1q
", array ($device_id));
}
/**
* Returns all vlan ifaces of iface
*
* @author Michal Kliment
* @param integer $iface_id
* @return Mysql_Result
*/
public function get_all_vlan_ifaces_of_iface ($iface_id)
{
return $this->db->query("
SELECT id, name
FROM vlan_ifaces
WHERE iface_id = ?
ORDER BY id ASC
", array($iface_id));
}
}
freenetis/branches/network/application/models/port.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Port
*
* @package Model
*
* @property integer $id
* @property integer $device_id
* @property Device_Model $device
* @property integer $segment_id
* @property Device_Model $segment
* @property integer $port_nr
* @property string $name
* @property ORM_Iterator $vlans
* @property integer $mode
* @property integer $port_vlan_id
* @property Vlan_Model $port_vlan
*/
class Port_Model extends ORM
{
/**
* Const for mode access
*/
const MODE_ACCESS = 1;
/**
* Const for mode trunk
*/
const MODE_TRUNK = 2;
/**
* Const for mode hybrid
*/
const MODE_HYBRID = 3;
/**
* Human format for modes
* @var array
*/
private static $modes = array
(
self::MODE_ACCESS => 'Access',
self::MODE_TRUNK => 'Trunk',
self::MODE_HYBRID => 'Hybrid'
);
protected $belongs_to = array('segment', 'device', 'port_vlan' => 'vlan');
protected $has_and_belongs_to_many = array('vlans');
/**
* Return human format for given const of mode
*
* @author Michal Kliment
* @param type $mode
* @return boolean
*/
public static function get_mode($mode)
{
if (isset(self::$modes[$mode]))
return __(self::$modes[$mode]);
else
return FALSE;
}
/**
* Return human format for modes
*
* @author Michal Kliment
* @return type
*/
public static function get_modes()
{
return array_map('__', self::$modes);
}
/**
* Gets count of ports of device
*
* @param integer $device_id
* @return integer
*/
public function count_ports_of_device($device_id)
{
return $this->db->where('device_id', $device_id)->count_records('ports');
}
/**
* Gets count off all ports
*
* @return integer
*/
public function count_all_ports()
{
return $this->db->count_records('ports');
}
/**
* Gets all ports
*
* @param integer $limit_from
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @return Mysql_Result
*/
public function get_all_ports(
$limit_from = 0, $limit_results = 50,
$order_by = 'ports.id', $order_by_direction = 'ASC')
{
// order by direction check
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'asc';
}
// query
return $this->db->query("
SELECT devices.name as device_name,segments.name as segment_name,
IFNULL(ports_vlans.vlan_count,0) AS vlan_count, ports.id,ports.name,
ports.port_nr
FROM ports
LEFT JOIN devices ON devices.id = ports.device_id
LEFT JOIN segments ON segments.id = ports.segment_id
LEFT JOIN (
SELECT COUNT(*) as vlan_count,port_id
FROM ports_vlans
GROUP BY port_id
) ports_vlans ON ports_vlans.port_id=ports.id
ORDER BY " . $this->db->escape_column($order_by) . " $order_by_direction
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
");
}
/**
* Gets ports of device
*
* @param integer $device_id
* @return integer
*/
public function get_ports_of_device($device_id)
{
return $this->db->query("
SELECT
p.id AS port_id, p.name AS port_name,
d.name as device_name, p.segment_id, s.name as segment_name,
IFNULL(pv.vlan_count,0) AS vlan_count, p.id, p.name,
p.port_nr, s.bitrate, p.mode
FROM ports p
LEFT JOIN devices d ON d.id = p.device_id
LEFT JOIN segments s ON s.id = p.segment_id
LEFT JOIN (
SELECT COUNT(*) as vlan_count,port_id
FROM ports_vlans
GROUP BY port_id
) pv ON pv.port_id = p.id
WHERE device_id = ?
ORDER BY port_nr ASC
", $device_id);
}
/**
* Function deletes port and vlan relation from pivot table.
*
* @param integer $port_id
*/
public function delete_from_pivot_table($port_id)
{
$this->db->query("
DELETE FROM ports_vlans
WHERE port_id = ?
", $port_id);
}
/**
* Checks whether exists port number in device
*
* @author Michal Kliment
* @param integer $port_nr
* @param integer $device_id
* @return boolean
*/
public function port_number_exists ($port_nr, $device_id)
{
$result = $this->db->query("
SELECT COUNT(*) AS total
FROM ports p
WHERE p.port_nr = ? AND p.device_id = ?
", array($port_nr, $device_id));
if ($result && $result->current())
return (bool) $result->current()->total;
else
return false;
}
}
freenetis/branches/network/application/models/wireless_segment.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Wireless segment
*
* @package Model
* @author Michal Kliment
*
* @property integer $id
* @property integer $segment_id
* @property Segment_Model $segment
* @property string $ssid
* @property integer $norm
* @property integer $frequence
* @property integer $channel
* @property integer $channel_width
* @property integer $polarization
*/
class Wireless_segment_Model extends ORM
{
// constants of norms
const NORM_802_11_A = 1;
const NORM_802_11_B = 2;
const NORM_802_11_G = 3;
const NORM_802_11_N = 4;
const NORM_802_11_B_G = 5;
// constants of polarizations
const POLARIZATION_HORIZONTAL = 1;
const POLARIZATION_VERTICAL = 2;
const POLARIZATION_CIRCULAR = 3;
const POLARIZATION_BOTH = 4;
const POLARIZATION_HORIZONTAL_VERTICAL = 5;
/**
* Array of norms, keys of array are equal to constants of norms
* @var array
*/
private static $norms = array
(
self::NORM_802_11_A => '802.11a',
self::NORM_802_11_B => '802.11b',
self::NORM_802_11_G => '802.11g',
self::NORM_802_11_N => '802.11n',
self::NORM_802_11_B_G => '802.11b/g'
);
/**
* Array of polarizations, keys of array are equal to constants of polarizations
* @var array
*/
private static $polarizations = array
(
self::POLARIZATION_HORIZONTAL => 'horizontal',
self::POLARIZATION_VERTICAL => 'vertical',
self::POLARIZATION_CIRCULAR => 'circular',
self::POLARIZATION_BOTH => 'both',
self::POLARIZATION_HORIZONTAL_VERTICAL => 'horizontal and vertical'
);
/**
* Array of max bitrates
* @var array
*/
private static $max_bitrates = array
(
self::NORM_802_11_A => 54,
self::NORM_802_11_B => 11,
self::NORM_802_11_G => 54,
self::NORM_802_11_N => 600,
self::NORM_802_11_B_G => 54
);
/**
* Returns norm name by given norm id
*
* @author
* @param integer $norm
* @return string
*/
public function get_norm ($norm = NULL)
{
if (!$norm && isset($this))
$norm = $this->norm;
if (array_key_exists($norm, self::$norms))
return self::$norms[$norm];
else
return NULL;
}
/**
* Returns all norm names
*
* @author Michal Kliment
* @return array
*/
public function get_norms ()
{
return self::$norms;
}
/**
* Returns polarization name by given polarization id
*
* @author Michal Kliment
* @param integer $polarization
* @return string
*/
public function get_polarization ($polarization = NULL)
{
if (!$polarization)
$polarization = $this->polarization;
if (array_key_exists($polarization, self::$polarizations))
return url_lang::lang('texts.'.self::$polarizations[$polarization]);
else
return NULL;
}
/**
* Returns all polarization names
*
* @author Michal Kliment
* @return array
*/
public function get_polarizations ()
{
return array_map('__', self::$polarizations);
}
/**
* Returns max bitrate of norm
*
* @author Michal Kliment
* @param integer $norm
* @return integer
*/
public function get_max_bitrate ($norm = NULL)
{
if (!$norm)
$norm = $this->norm;
if (array_key_exists($norm, self::$max_bitrates))
return self::$max_bitrates[$norm];
else
return NULL;
}
/**
* Returns all max bitrates of norms
*
* @author Michal Kliment
* @param integer $norm
* @return integer
*/
public function get_max_bitrates ()
{
return self::$max_bitrates;
}
}
freenetis/branches/network/application/models/segment.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Segment
*
* @package Model
*
* @property integer $id
* @property string $name
* @property integer $medium_id
* @property integer $bitrate
* @property integer $duplex
* @property string $comment
* @property blob $gps
* @property Wireless_segment_Model $wireless
* @property ORM_Iterator $ifaces
* @property ORM_Iterator $ports
*/
class Segment_Model extends ORM
{
// mediums
const ROAMING = 1;
const AIR = 2;
const CABLE = 3;
const SINGLE_FIBER = 4;
const MULTI_FIBER = 5;
const IFACE = 1;
const PORT = 2;
/**
* Medium types
*
* @var array
*/
private static $medium_types = array
(
self::ROAMING => 'roaming',
self::AIR => 'air',
self::CABLE => 'cable',
self::SINGLE_FIBER => 'fiber optical single-mode',
self::MULTI_FIBER => 'fiber optical multi-mode'
);
protected $has_many = array('ifaces', 'ports');
protected $has_one = array('wireless' => 'wireless_segment');
/**
* Counts all segments
*
* @param array $filter_values
* @return integer
*/
public function count_all_segments($filter_sql = '')
{
$where = '';
// filter
if ($filter_sql != '')
$where = "WHERE $filter_sql";
// query
return $this->db->query("
SELECT COUNT(*) AS total
FROM
(
SELECT s.id, s.name, medium_id AS medium, s.duplex, s.comment,
s.bitrate, (SELECT COUNT(*) FROM ifaces WHERE segment_id = s.id) +
(SELECT COUNT(*) FROM ports WHERE segment_id = s.id) as items_count,
IFNULL(ws.ssid,'') AS ssid, ws.norm
FROM segments s
LEFT JOIN enum_types e ON s.medium_id = e.id
LEFT JOIN (
SELECT *
FROM translations
WHERE lang = ?
) f ON e.value = f.original_term
LEFT JOIN wireless_segments ws ON ws.segment_id = s.id
) s
$where
", Config::get('lang'))->current()->total;
}
/**
* Gets all segments
*
* @param integer $limit_from
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param array $filter_values
* @return Mysql_Result
*/
public function get_all_segments(
$limit_from = 0, $limit_results = 20,
$order_by = 'id', $order_by_direction = 'asc',
$filter_sql = '')
{
$where = '';
if ($filter_sql != '')
$where = "WHERE $filter_sql";
// query
return $this->db->query("
SELECT * FROM
(
SELECT s.id, s.name, medium_id AS medium, s.duplex, s.comment,
s.bitrate, (SELECT COUNT(*) FROM ifaces WHERE segment_id = s.id) +
(SELECT COUNT(*) FROM ports WHERE segment_id = s.id) as items_count,
IFNULL(ws.ssid,'') AS ssid, ws.norm
FROM segments s
LEFT JOIN enum_types e ON s.medium_id = e.id
LEFT JOIN (
SELECT *
FROM translations
WHERE lang = ?
) f ON e.value = f.original_term
LEFT JOIN wireless_segments ws ON ws.segment_id = s.id
) s
$where
ORDER BY " . $this->db->escape_column($order_by) . " $order_by_direction
LIMIT " .intval($limit_from) . ", " . intval($limit_results) . "
", Config::get('lang'));
}
/**
* Function tries to find segment where user's device is connected to. Used in devices/add.
*
* @param integer $user_id
* @return Database_Result
*/
public function get_segment_of_user($user_id)
{
$result = $this->db->query("
SELECT DISTINCT s.id, s.name
FROM segments s
JOIN ifaces i ON i.segment_id = s.id
JOIN devices d ON d.id = i.device_id
WHERE d.user_id = ?
", $user_id);
if ($result && $result->count() > 0)
{
return $result->current();
}
return null;
}
/**
* Returns roaming segment
*
* @author Michal Kliment
* @return integer
*/
public function get_roaming ()
{
$roaming = $this->where('medium_id', self::ROAMING)->find();
return ($roaming && $roaming->id) ? $roaming->id : NULL;
}
/**
* get segment by IP address
*
* @param integer $ip_address
* @return Segment_Model
*/
public function get_by_ip_address ($ip_address)
{
$result = $this->db->query("
SELECT s.* FROM
(
SELECT IFNULL(i1.segment_id,i2.segment_id) AS segment_id
FROM ip_addresses ip
LEFT JOIN ifaces i1 ON ip.iface_id = i1.id
LEFT JOIN vlan_ifaces vi ON ip.vlan_iface_id = vi.id
LEFT JOIN ifaces i2 ON vi.iface_id = i2.id
WHERE ip.ip_address = ?
) AS q
JOIN segments s ON q.segment_id = s.id
", array($ip_address));
if ($result && $result->count() > 0)
{
$result->current();
}
return null;
}
/**
* Returns all segments to dropdown as array
*
* @author Michal Kliment
* @return array
*/
public function get_all_segments_to_dropdown ()
{
return $this->select_list('id', 'name');
}
/**
* Returns all segments to dropdown as array
*
* @author Michal Kliment
* @return array
*/
public function get_all_segments_to_iface_dropdown ()
{
$segments = $this->db->query("
SELECT s.id, s.name
FROM segments s
WHERE medium_id = ? OR medium_id = ? OR medium_id = ?
ORDER BY s.name
", array(self::AIR, self::CABLE, self::ROAMING));
$arr_segments = array();
foreach ($segments as $segment)
{
$arr_segments[$segment->id] = $segment->name;
}
return $arr_segments;
}
/**
* Returns all segments to dropdown as array
*
* @author Michal Kliment
* @return array
*/
public function get_all_segments_to_port_dropdown ()
{
$segments = $this->db->query("
SELECT s.id, s.name
FROM segments s
WHERE medium_id = ? OR medium_id = ?
OR medium_id = ? OR medium_id = ?
ORDER BY s.name
", array(self::SINGLE_FIBER, self::MULTI_FIBER,
self::CABLE, self::ROAMING));
$arr_segments = array();
foreach ($segments as $segment)
$arr_segments[$segment->id] = $segment->name;
return $arr_segments;
}
/**
* Returns medium type by medium type id
*
* @author Michal Kliment
* @param integer $type_id
* @return string
*/
public static function get_medium_type ($medium_type_id)
{
if (isset(self::$medium_types[$medium_type_id]))
return url_lang::lang('texts.'.self::$medium_types[$medium_type_id]);
else
return NULL;
}
/**
* Returns medium types
*
* @author Michal Kliment
* @return array
*/
public static function get_medium_types ()
{
$medium_types = array();
foreach (self::$medium_types as $medium_type_id => $medium_type)
$medium_types[$medium_type_id] = url_lang::lang('texts.'.$medium_type);
return $medium_types;
}
/**
* Returns all items (interfaces and ports) which belong to given segment
*
* @author Michal Kliment
* @param integer $segment_id
* @return Mysql_Result
*/
public function get_items ($segment_id = NULL)
{
if (!$segment_id)
$segment_id = $this->id;
return $this->db->query("
SELECT q.*, d.name AS device_name, m.name AS member_name,
m.id AS member_id, wi.wmode
FROM
(
SELECT id, device_id, mac, name, ? AS type
FROM ifaces i
WHERE i.segment_id = ?
UNION
SELECT id, device_id, NULL AS mac, name, ? AS type
FROM ports p
WHERE p.segment_id = ?
) AS q
JOIN devices d ON q.device_id = d.id
JOIN users u ON d.user_id = u.id
JOIN members m ON u.member_id = m.id
LEFT JOIN wireless_ifaces wi ON wi.iface_id = q.id AND q.type = ?
ORDER BY wi.wmode
", self::IFACE, $segment_id, self::PORT, $segment_id, self::IFACE);
}
/**
* Returns all segments according to given type of iface
*
* @author Michal Kliment
* @param integer $type
* @return array
*/
public function get_all_segments_by_iface_type ($type)
{
switch ($type)
{
case Iface_Model::TYPE_WIRELESS:
$medium_id = self::AIR;
break;
case Iface_Model::TYPE_ETHERNET:
$medium_id = self::CABLE;
break;
default:
return array();
break;
}
return $this->where('medium_id', $medium_id)
->orwhere('medium_id', self::ROAMING)
->select_list('id','name');
}
}
freenetis/branches/network/application/models/wireless_iface.php
<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/
/**
* Wireless iface
*
* @package Model
* @author Michal Kliment
*
* @property integer $id
* @property integer $iface_id
* @property integer $wmode
* @property integer $antenna
* @property Iface_Model $iface
*/
class Wireless_iface_Model extends ORM
{
/** AP mode of wireless iface */
const MODE_AP = 1;
/** Client mode of wireless iface */
const MODE_CLIENT = 2;
/**
* Models of wirelless iface
*
* @var array
*/
private static $modes = array
(
self::MODE_AP => 'AP',
self::MODE_CLIENT => 'client'
);
/** Directional type of antenna */
const ANTENNA_DIRECTIONAL = 1;
/** Omnidirectional type of antenna */
const ANTENNA_OMNIDIRECTIONAL = 2;
/** Sectional type of antenna */
const ANTENNA_SECTIONAL = 3;
/**
* Antenas types array
*
* @var array
*/
private static $antennas = array
(
self::ANTENNA_DIRECTIONAL => 'Directional',
self::ANTENNA_OMNIDIRECTIONAL => 'Omnidirectional',
self::ANTENNA_SECTIONAL => 'Sectional'
);
protected $belongs_to = array('iface');
/**
* Returns mode of current wireless interface
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_mode ($mode = NULL)
{
if (!$mode && isset($this))
$mode = $this->wmode;
if (array_key_exists($mode, self::$modes))
return __(self::$modes[$mode]);
else
return NULL;
}
/**
* Returns all modes of wireless interfaces
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_modes ()
{
return array_map('__', self::$modes);
}
/**
* Returns antenna of current wireless interface
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_antenna ($antenna = NULL)
{
if (!$antenna)
$antenna = $this->antenna;
if (array_key_exists($antenna, self::$antennas))
return __(self::$antennas[$antenna]);
else
return NULL;
}
/**
* Returns all antennas of wireless interfaces
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_antennas ()
{
return array_map('__', self::$antennas);
}
/**
* Counts items by wireless mode and segment
*
* @author Michal Kliment
* @param integer $mode
* @param integer $segment_id
* @return mixed
*/
public function count_items_by_mode_and_segment ($mode, $segment_id, $iface_id = NULL)
{
$where = '';
if ($iface_id)
$where = 'AND i.id <> '.intval($iface_id);
$result = $this->db->query("
SELECT COUNT(*) AS total
FROM wireless_ifaces wi
LEFT JOIN ifaces i on wi.iface_id = i.id
WHERE wi.wmode = ? AND i.segment_id = ? $where
", array($mode, $segment_id));
if ($result && $result->current())
return (bool) $result->current()->total;
else
return false;
}
/**
* Return wireless iface belongs to iface
*
* @author Michal Kliment
* @param type $iface_id
* @return boolean
*/
public function get_wireless_iface ($iface_id)
{
$result = $this->db->query("
SELECT wi.*, ws.*
FROM ifaces i
LEFT JOIN wireless_ifaces wi ON wi.iface_id = i.id
LEFT JOIN segments s ON i.segment_id = s.id
LEFT JOIN wireless_segments ws ON ws.segment_id = s.id
WHERE i.id = ? AND i.type = ?
", $iface_id, Iface_Model::TYPE_WIRELESS);
if ($result && $result->current())
return $result->current();
else
return false;
}
}
freenetis/branches/network/application/models/device.php
/**
* Device is own by user and located at specified address point.
* Each device has many ifaces and ports.
* Each device has many ifaces.
*
* @package Model
*
......
* @property User_Model $user
* @property Address_point_Model $address_point
* @property ORM_Iterator $ifaces
* @property ORM_Iterator $ports
* @property ORM_Iterator $device_admins
* @property ORM_Iterator $device_engineers
*/
class Device_Model extends ORM
{
// type constants of devices (not all of them)
const TYPE_PC = 7;
const TYPE_CLIENT = 8;
const TYPE_AP = 62;
protected $has_many = array
(
'ifaces', 'ports',
'devices' => 'device_admins'
);
protected $has_many = array('ifaces');
protected $belongs_to = array('address_point', 'user');
protected $has_and_belongs_to_many = array
(
'device_admins' => 'user',
......
JOIN segments s ON i.segment_id = s.id
", array
(
Segment_Model::IFACE,
Link_Model::IFACE,
$device_id,
Segment_Model::PORT,
Link_Model::PORT,
$device_id
));
}
freenetis/branches/network/application/models/iface.php
*/
/**
* Ifaces
* An interface may be assigned to several IP addresses (commonly just one),
* and belongs to a device. Two interfaces may be connected using a segment.
*
* Interface is specified by a type:
*
* - wireless (wifi device in mode of AP/client and with specifications: antena, ..)
* - ethernet
* - port (link layer - without MAC)
* - bridge
* - VLAN
* - internal (special type of interface for configuration of switches)
*
* @package Model
*
* @property integer $id
* @property integer $type
* @property integer $device_id
* @property integer $segment_id
* @property integer $link_id
* @property string $mac
* @property string $name
* @property integer $number
* @property string $comment
* @property Segment_Model $segment
* @property integer $wireless_mode
* @property integer $wireless_antenna
* @property integer $port_mode
* @property Link_Model $link
* @property Device_Model $device
* @property Wireless_iface_Model $wireless
* @property ORM_Iterator $vlan_ifaces
* @property ORM_Iterator $iface_vlans
* @property ORM_Iterator $ip_addresses
* @property ORM_Iterator $parents
* @property ORM_Iterator $childrens
*/
class Iface_Model extends ORM
{
protected $belongs_to = array('link', 'device');
protected $has_many = array(
'iface_vlans', 'ip_addresses',
'parents' => 'ifaces_relationships',
'childrens' => 'ifaces_relationships'
);
/** Wireless type of iface */
const TYPE_WIRELESS = 1;
/** Ethernet type of iface */
const TYPE_ETHERNET = 2;
/** Interface is port (link layer - without MAC) */
const TYPE_PORT = 3;
/** Bridge interface */
const TYPE_BRIDGE = 4;
/** Virtual interface */
const TYPE_VLAN = 5;
/** Special type of interface for configuration of switches */
const TYPE_INTERNAL = 6;
/** AP mode of wireless iface */
const WIRELESS_MODE_AP = 1;
/** Client mode of wireless iface */
const WIRELESS_MODE_CLIENT = 2;
/** Directional type of antenna */
const WIRELESS_ANTENNA_DIRECTIONAL = 1;
/** Omnidirectional type of antenna */
const WIRELESS_ANTENNA_OMNIDIRECTIONAL = 2;
/** Sectional type of antenna */
const WIRELESS_ANTENNA_SECTIONAL = 3;
/** Const for mode access */
const PORT_MODE_ACCESS = 1;
/** Const for mode trunk */
const PORT_MODE_TRUNK = 2;
/** Const for mode hybrid */
const PORT_MODE_HYBRID = 3;
/**
* Name of iface types
*
......
*/
private static $types = array
(
self::TYPE_WIRELESS => 'Wireless',
self::TYPE_ETHERNET => 'Ethernet'
self::TYPE_WIRELESS => 'Wireless',
self::TYPE_ETHERNET => 'Ethernet',
self::TYPE_PORT => 'Port',
self::TYPE_BRIDGE => 'Bridge',
self::TYPE_VLAN => 'VLAN',
self::TYPE_INTERNAL => 'Internal'
);
/**
......
*/
private static $default_names = array
(
self::TYPE_WIRELESS => 'wlan',
self::TYPE_ETHERNET => 'eth'
self::TYPE_WIRELESS => 'wlan',
self::TYPE_ETHERNET => 'eth',
self::TYPE_PORT => 'port',
self::TYPE_BRIDGE => 'bridge',
self::TYPE_VLAN => 'vlan',
self::TYPE_INTERNAL => 'internal'
);
protected $belongs_to = array('segment', 'device');
protected $has_many = array('vlan_ifaces', 'ip_addresses');
protected $has_one = array('wireless' => 'wireless_iface');
/**
* Get count of ifaces of device
* Models of wirelless iface
*
* @var array
*/
private static $wireless_modes = array
(
self::WIRELESS_MODE_AP => 'AP',
self::WIRELESS_MODE_CLIENT => 'client'
);
/**
* Antenas types array
*
* @var array
*/
private static $wireless_antennas = array
(
self::WIRELESS_ANTENNA_DIRECTIONAL => 'Directional',
self::WIRELESS_ANTENNA_OMNIDIRECTIONAL => 'Omnidirectional',
self::WIRELESS_ANTENNA_SECTIONAL => 'Sectional'
);
/**
* Human format for modes
*
* @param integer $device_id
* @return integer
* @var array
*/
public function count_ifaces_of_device($device_id)
private static $port_modes = array
(
self::PORT_MODE_ACCESS => 'Access',
self::PORT_MODE_TRUNK => 'Trunk',
self::PORT_MODE_HYBRID => 'Hybrid'
);
/**
* Returns type of current interface
*
* @author Michal Kliment
* @param integer $type
* @return string
*/
public function get_type($type = NULL)
{
return $this->db->where('device_id', $device_id)->count_records('ifaces');
if (empty($type) && $this->id)
{
$type = $this->type;
}
if (is_numeric($type) && array_key_exists($type, self::$types))
{
return __(self::$types[$type]);
}
return NULL;
}
/**
* Gets count of wireless settings of iface
*
* @author Ondřej Fibich
* @param integer $iface_id
* @return integer
* Returns all types of interfaces
*
* @author Michal Kliment
* @return array
*/
public function count_ws_of_iface($iface_id = NULL)
public function get_types()
{
if ($iface_id === NULL && $this->id)
return array_map('__', self::$types);
}
/**
* Returns default name of current type of interface
*
* @author Michal Kliment
* @param integer $type
* @return string
*/
public function get_default_name($type = NULL)
{
if (empty($type) && $this->id)
{
$iface_id = $this->id;
$type = $this->type;
}
return $this->db->query("
SELECT COUNT(*) AS count
FROM wireless_ifaces
WHERE iface_id = ?
", $iface_id)->current()->count;
if (!empty($type) && array_key_exists($type, self::$default_names))
{
return self::$default_names[$type];
}
return NULL;
}
/**
* Returns all default names of interfaces
*
* @author Michal Kliment
* @return array
*/
public function get_default_names()
{
return self::$default_names;
}
/**
* Returns mode of current wireless interface
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_wireless_mode($mode = NULL)
{
if (!$mode && isset($this))
{
$mode = $this->wireless_mode;
}
if (array_key_exists($mode, self::$wireless_modes))
{
return __(self::$wireless_modes[$mode]);
}
return NULL;
}
/**
* Returns all modes of wireless interfaces
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_wireless_modes()
{
return array_map('__', self::$wireless_modes);
}
/**
* Returns antenna of current wireless interface
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_wireless_antenna($antenna = NULL)
{
if (!$antenna)
{
$antenna = $this->wireless_antenna;
}
if (array_key_exists($antenna, self::$wireless_antennas))
{
return __(self::$wireless_antennas[$antenna]);
}
return NULL;
}
/**
* Returns all antennas of wireless interfaces
*
* @author Michal Kliment
* @param integer $mode
* @return string
*/
public function get_wireless_antennas()
{
return array_map('__', self::$wireless_antennas);
}
/**
* Return human format for given const of mode
*
* @author Michal Kliment
* @param integer $mode
* @return boolean
*/
public static function get_port_mode($mode)
{
if (isset(self::$port_modes[$mode]))
return __(self::$port_modes[$mode]);
else
return FALSE;
}
/**
* Return human format for modes
*
* @author Michal Kliment
* @return array
*/
public static function get_port_modes()
{
return array_map('__', self::$port_modes);
}
/**
* Get count of ifaces of device
*
* @param integer $device_id
* @return integer
*/
public function count_ifaces_of_device($device_id)
{
return $this->db->where('device_id', $device_id)->count_records('ifaces');
}
/**
* Function gets all interfaces.
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff