Revize 1523
Přidáno uživatelem Ondřej Fibich před asi 12 roky(ů)
freenetis/branches/network/application/models/iface.php | ||
---|---|---|
* @param integer $type Type of interface for connection
|
||
* @param array $gps location of device - default member AP [optional]
|
||
* @param string $filter_sql Filter SQL
|
||
* @param integer $wmode Wireless mode of interface which try to connect [optional]
|
||
* @return object Suitable iface or null
|
||
*/
|
||
public function get_iface_for_connecting_to_iface($user_id, $type,
|
||
$gps = array(), $filter_sql = '')
|
||
$gps = array(), $filter_sql = '', $wmode = NULL)
|
||
{
|
||
$can_connect = self::get_can_connect_to($type);
|
||
$user = new User_Model($user_id);
|
||
... | ... | |
$where = 'WHERE ' . $filter_sql;
|
||
}
|
||
|
||
// select oposite mode
|
||
if ($wmode == Iface_Model::WIRELESS_MODE_AP)
|
||
{
|
||
$wmode = Iface_Model::WIRELESS_MODE_CLIENT;
|
||
}
|
||
else
|
||
{
|
||
$wmode = Iface_Model::WIRELESS_MODE_AP;
|
||
}
|
||
|
||
if ($user->id && count($can_connect))
|
||
{
|
||
$usearch = array(User_Model::ASSOCIATION, $user->id);
|
||
... | ... | |
FROM devices d
|
||
JOIN ifaces i ON i.device_id = d.id
|
||
JOIN links l ON i.link_id = l.id
|
||
JOIN ifaces i2 ON i2.link_id = l.id AND i2.id <> i.id
|
||
JOIN ifaces i2 ON i2.link_id = l.id AND i2.id <> i.id AND
|
||
(
|
||
i2.type NOT IN(?, ?) OR
|
||
(
|
||
i2.type IN(?, ?) AND i2.wireless_mode = ?
|
||
)
|
||
)
|
||
LEFT JOIN ip_addresses ip ON ip.iface_id = i2.id
|
||
JOIN devices d2 ON i2.device_id = d2.id
|
||
JOIN address_points ap2 ON ap2.id = d2.address_point_id
|
||
... | ... | |
$where
|
||
ORDER BY user
|
||
LIMIT 1
|
||
", $type, $user->id);
|
||
", array
|
||
(
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP,
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP,
|
||
$wmode, $type, $user->id
|
||
));
|
||
|
||
if ($from_current->current())
|
||
{
|
||
... | ... | |
ap2.gps, d2.name AS device_name, ap2.street_id AS street,
|
||
ap2.town_id AS town, ap2.street_number
|
||
FROM devices d2
|
||
JOIN ifaces i2 ON i2.device_id = d2.id
|
||
JOIN ifaces i2 ON i2.device_id = d2.id AND
|
||
(
|
||
i2.type NOT IN(?, ?) OR
|
||
(
|
||
i2.type IN(?, ?) AND i2.wireless_mode = ?
|
||
)
|
||
)
|
||
LEFT JOIN ip_addresses ip2 ON ip2.iface_id = i2.id
|
||
JOIN address_points ap2 ON d2.address_point_id = ap2.id
|
||
WHERE i2.type IN(" . implode(',', $can_connect) . ") AND
|
||
... | ... | |
ap2.gps, d2.name AS device_name, ap2.street_id AS street,
|
||
ap2.town_id AS town, ap2.street_number
|
||
FROM devices d2
|
||
JOIN ifaces i2 ON i2.device_id = d2.id
|
||
JOIN ifaces i2 ON i2.device_id = d2.id AND
|
||
(
|
||
i2.type NOT IN(?, ?) OR
|
||
(
|
||
i2.type IN(?, ?) AND i2.wireless_mode = ?
|
||
)
|
||
)
|
||
LEFT JOIN ip_addresses ip2 ON ip2.iface_id = i2.id
|
||
JOIN address_points ap2 ON d2.address_point_id = ap2.id
|
||
WHERE i2.type IN(" . implode(',', $can_connect) . ") AND
|
||
... | ... | |
) i
|
||
ORDER BY i.priority DESC
|
||
LIMIT 1
|
||
")->current();
|
||
", array
|
||
(
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP,
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP, $wmode,
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP,
|
||
self::TYPE_WIRELESS, self::TYPE_VLAN_AP, $wmode
|
||
))->current();
|
||
}
|
||
|
||
return NULL;
|
freenetis/branches/network/application/controllers/ifaces.php | ||
---|---|---|
{
|
||
if (count($ips) != 0)
|
||
{
|
||
status::warning('Interface still has at least one ip address.');
|
||
status::warning('Interface still has at least one IP address.');
|
||
}
|
||
else if (count($vlan_ifaces) != 0)
|
||
{
|
freenetis/branches/network/application/controllers/json.php | ||
---|---|---|
$user_id = $this->input->get('user_id');
|
||
$gpsx = $this->input->get('gpsx');
|
||
$gpsy = $this->input->get('gpsy');
|
||
$wmode = $this->input->get('wmode');
|
||
$gps = array();
|
||
|
||
if ($user_id)
|
||
... | ... | |
echo json_encode(array
|
||
(
|
||
Iface_Model::TYPE_WIRELESS => $im->get_iface_for_connecting_to_iface(
|
||
$user_id, Iface_Model::TYPE_WIRELESS, $gps, $filter->as_sql()
|
||
$user_id, Iface_Model::TYPE_WIRELESS, $gps, $filter->as_sql(), $wmode
|
||
),
|
||
Iface_Model::TYPE_ETHERNET => $im->get_iface_for_connecting_to_iface(
|
||
$user_id, Iface_Model::TYPE_ETHERNET, $gps, $filter->as_sql()
|
||
... | ... | |
{
|
||
$device_id = (int) $this->input->get('data');
|
||
$itype = $this->input->get('itype');
|
||
$wmode = $this->input->get('wmode');
|
||
$ifaces = array();
|
||
$arr_ifaces = array();
|
||
$concat = 'CONCAT(IFNULL(mac, \'- \'),\': \',IFNULL(name,\'\'))';
|
||
|
||
if ($device_id)
|
||
if ($device_id && is_numeric($itype))
|
||
{
|
||
if (is_numeric($itype))
|
||
$itypes = Iface_Model::get_can_connect_to($itype);
|
||
|
||
if (count($itypes))
|
||
{
|
||
$itypes = Iface_Model::get_can_connect_to($itype);
|
||
|
||
if (count($itypes))
|
||
if (is_numeric($wmode) && ($itype == Iface_Model::TYPE_WIRELESS))
|
||
{
|
||
// select oposite mode
|
||
if ($wmode == Iface_Model::WIRELESS_MODE_AP)
|
||
{
|
||
$wmode = Iface_Model::WIRELESS_MODE_CLIENT;
|
||
}
|
||
else
|
||
{
|
||
$wmode = Iface_Model::WIRELESS_MODE_AP;
|
||
}
|
||
|
||
$ifaces = ORM::factory('iface')
|
||
->where('device_id', $device_id)
|
||
->where('wireless_mode', $wmode)
|
||
->in('type', $itypes)
|
||
->select_list('id', $concat);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$ifaces = ORM::factory('iface')
|
||
->where('device_id', $device_id)
|
||
->select_list('id', $concat);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (is_numeric($itype))
|
||
{
|
||
$itypes = Iface_Model::get_can_connect_to($itype);
|
||
|
||
if (count($itypes))
|
||
else
|
||
{
|
||
$ifaces = ORM::factory('iface')
|
||
->where('device_id', $device_id)
|
||
->in('type', $itypes)
|
||
->select_list('id', $concat);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$ifaces = ORM::factory('iface')
|
||
->select_list('id', $concat);
|
||
}
|
||
}
|
||
|
||
foreach ($ifaces as $id => $name)
|
freenetis/branches/network/application/controllers/devices.php | ||
---|---|---|
);
|
||
|
||
// wireless modes
|
||
$arr_wireless_modes = array
|
||
(
|
||
NULL => '----- '.__('Select mode').' -----'
|
||
) + Iface_Model::get_wireless_modes();
|
||
$arr_wireless_modes = Iface_Model::get_wireless_modes();
|
||
|
||
// wireless antenna types
|
||
$arr_wireless_antennas = array
|
||
... | ... | |
|
||
if (isset($_POST['connected_iface'][$i]))
|
||
{
|
||
// connected iface
|
||
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
|
||
// restrict blank fields
|
||
if (!(Iface_Model::type_has_ip_address($im->type) &&
|
||
Iface_Model::type_has_mac_address($im->type) &&
|
||
empty($im->mac) && (
|
||
!isset($_POST['ip'][$i]) ||
|
||
empty($_POST['ip'][$i]) ||
|
||
!valid::ip_address($_POST['ip'][$i])
|
||
)))
|
||
{
|
||
// connected iface
|
||
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
|
||
|
||
// save link
|
||
if ($im->type != Iface_Model::TYPE_INTERNAL && $im_connect_to->id)
|
||
{
|
||
$lm = new Link_Model($_POST['link_id'][$i]);
|
||
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
|
||
$lm->medium = intval($_POST['medium'][$i]);
|
||
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
|
||
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
|
||
$lm->duplex = ($_POST['duplex'][$i] == 1);
|
||
// save link
|
||
if (Iface_Model::type_has_link($im->type) &&
|
||
$im_connect_to && $im_connect_to->id)
|
||
{
|
||
$lm = new Link_Model($_POST['link_id'][$i]);
|
||
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
|
||
$lm->medium = intval($_POST['medium'][$i]);
|
||
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
|
||
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
|
||
$lm->duplex = ($_POST['duplex'][$i] == 1);
|
||
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
}
|
||
|
||
$lm->save_throwable();
|
||
$im->link_id = $lm->id;
|
||
$im_connect_to->link_id = $lm->id;
|
||
$im_connect_to->save_throwable();
|
||
}
|
||
|
||
$lm->save_throwable();
|
||
$im->link_id = $lm->id;
|
||
$im_connect_to->link_id = $lm->id;
|
||
$im_connect_to->save_throwable();
|
||
}
|
||
}
|
||
|
freenetis/branches/network/application/views/devices/add.php | ||
---|---|---|
</tr>
|
||
<tr>
|
||
<th><label><?php echo __('Port mode') ?>:</label></th>
|
||
<td><?php echo form::dropdown('port_mode_input', $port_modes, 'style="width:200px"') ?></td>
|
||
<td><?php echo form::dropdown('port_mode_input', $port_modes, array(), 'style="width:200px"') ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><label><?php echo __('Wireless mode') ?>:</label></th>
|
||
<td><?php echo form::dropdown('wireless_mode_input', $wireless_modes, 'style="width:200px"') ?></td>
|
||
<td><?php echo form::dropdown('wireless_mode_input', $wireless_modes, array(), 'style="width:200px"') ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><label><?php echo __('Wireless antenna') ?>:</label></th>
|
||
<td><?php echo form::dropdown('wireless_antenna_input', $wireless_antennas, 'style="width:200px"') ?></td>
|
||
<td><?php echo form::dropdown('wireless_antenna_input', $wireless_antennas, array(), 'style="width:200px"') ?></td>
|
||
</tr>
|
||
</table>
|
||
<button class="submit" type="button"><?php echo __('Save') ?></button>
|
freenetis/branches/network/application/views/js/devices_add.php | ||
---|---|---|
$td.find('input[name^="wireless_mode["]').val($('#wireless_mode_input').val());
|
||
$td.find('input[name^="wireless_antenna["]').val($('#wireless_antenna_input').val());
|
||
|
||
// update connected to device
|
||
$td.find('select[name^="connected["]').trigger('change', $td.find('select[name^="connected_iface["]').val());
|
||
|
||
//set texts
|
||
if (parseInt($td.find('input[name^="type["]').val()) == <?php echo Iface_Model::TYPE_PORT ?>)
|
||
{
|
||
... | ... | |
map_a.attr('href', rtrim(parts[0], '0123456789/') + '/' + value + '?' + parts[1]);
|
||
}
|
||
|
||
var wmode = $(this).parent().parent().find('input[name^="wireless_mode["]').val();
|
||
|
||
$.getJSON('<?php echo url_lang::base() ?>json/get_ifaces', {
|
||
data: value, itype: $ety.val()
|
||
data: value, itype: $ety.val(), wmode: wmode
|
||
}, function (data)
|
||
{
|
||
var options = ['<option value="">---- <?php echo __('Select interface') ?> ---</option>'];
|
||
|
||
|
||
for (var i in data)
|
||
{
|
||
options.push('<option value="');
|
||
options.push(data[i].id);
|
||
options.push('"');
|
||
|
||
if (iface_id == data[i].id)
|
||
if (iface_id == data[i].id || data.length == 1)
|
||
{
|
||
options.push(' selected="selected"');
|
||
}
|
||
... | ... | |
qs.push('user_id=' + $('#user_id').val());
|
||
qs.push('gpsx=' + $('#gpsx').val());
|
||
qs.push('gpsy=' + $('#gpsy').val());
|
||
qs.push('wmode=' + $(e).parent().parent().find('input[name^="wireless_mode["]').val());
|
||
qs.push($(e).parent().parent().find('input[name^="_device_filter["]').val());
|
||
|
||
$.ajax({
|
||
... | ... | |
html_buffer.push(i);
|
||
html_buffer.push(']" style="width: 16em"');
|
||
|
||
if (first_row)
|
||
if (first_row && data['type'] != '<?php echo Iface_Model::TYPE_PORT ?>')
|
||
{
|
||
html_buffer.push(' class="connected_first_' + data['type'] + '"');
|
||
}
|
||
... | ... | |
html_buffer.push(i);
|
||
html_buffer.push(']" style="width: 16em"');
|
||
|
||
if (first_row)
|
||
if (first_row && data['type'] != '<?php echo Iface_Model::TYPE_PORT ?>')
|
||
{
|
||
html_buffer.push(' class="connected_iface_first_' + data['type'] + '"');
|
||
}
|
freenetis/branches/network/application/views/js/ifaces_add.php | ||
---|---|---|
|
||
$connected_to_iface.html('<option value=""><?php echo __('Loading data, please wait') ?>...</option>');
|
||
|
||
var wmode = <?php if ($itype == Iface_Model::TYPE_WIRELESS): ?>$('#wireless_mode').val();<?php else: ?>null<?php endif; ?>;
|
||
|
||
if (!wmode)
|
||
{
|
||
wmode = '<?php echo Iface_Model::WIRELESS_MODE_CLIENT ?>';
|
||
}
|
||
|
||
$.getJSON('<?php echo url_lang::base() ?>json/get_ifaces', {
|
||
data: val, itype: '<?php echo $itype ?>'
|
||
data: val, itype: '<?php echo $itype ?>', wmode: wmode
|
||
}, function (data)
|
||
{
|
||
var options = ['<option value="">---- <?php echo __('Select interface') ?> ---</option>'];
|
||
... | ... | |
options.push(data[i].id);
|
||
options.push('"');
|
||
|
||
if (((data.length == 1) && (iface_id == undefined)) ||
|
||
((iface_id != undefined) && (iface_id == data[i].id)))
|
||
if (((data.length == 1) && !iface_id) ||
|
||
(iface_id && (iface_id == data[i].id)))
|
||
{
|
||
options.push(' selected="selected"');
|
||
}
|
||
... | ... | |
}
|
||
});
|
||
|
||
// change ifaces on selecting different mode
|
||
$('#wireless_mode').change(function ()
|
||
{
|
||
$('#connected_to').trigger('change', $('#connected_to_interface').val());
|
||
});
|
||
|
||
// on change of connected to iface
|
||
$('#connected_to_interface').change(function ()
|
||
{
|
Také k dispozici: Unified diff
Upravy:
- omezeni pripojeni k u pridavani zarizeni (pokud se jedna o bezdratove kontroluje spravne strany AP
client)
reseni nevyplnenych udaju a ulozeni linky