Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1439

Přidáno uživatelem Ondřej Fibich před asi 12 roky(ů)

Upravy:
- dokonceni rozhrani pro pridani zarizeni bez dialogu #185

Zobrazit rozdíly:

freenetis/branches/network/application/models/iface.php
", $device_id, Iface_Model::TYPE_PORT);
}
/**
* Tries to find best suitable interface for connecting of a new device of user.
*
* @author Ondrej Fibich
* @param integer $user_id User identificator
* @param integer $type Type of interface for connection
* @return object Suitable iface or null
*/
public function get_iface_for_connecting_to_iface($user_id, $type)
{
$can_connect = Iface_Model::get_can_connect_to($type);
$usearch = array(User_Model::ASSOCIATION, $user_id);
if (count($can_connect))
{
// find current user interfaces and select oponent by link
$from_current = $this->db->query("
SELECT i2.*
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 devices d2 ON i2.device_id = d2.id
WHERE i.type = ? AND i2.type IN(" . implode(',', $can_connect) . ") AND
d.user_id = ? AND d2.user_id IN (" . implode(',', $usearch) . ")
ORDER BY d2.user_id
LIMIT 1
", $type, $user_id);
if ($from_current->current())
{
return $from_current->current();
}
// find nearest of org and user (using GPS)
$from_nearest = $this->db->query("
SELECT i2.*
FROM members m
JOIN users u ON u.member_id = m.id
JOIN address_points ap ON m.address_point_id = ap.id
JOIN devices d2 ON d2.user_id <> u.id
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE u.id = ? AND i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap.gps) IS NOT NULL AND X(ap2.gps) IS NOT NULL AND
u.id IN (" . implode(',', $usearch) . ")
ORDER BY SQRT(POW(X(ap.gps) - X(ap2.gps), 2) + POW(Y(ap.gps) - Y(ap2.gps), 2))
LIMIT 1
", $type, $user_id);
if ($from_nearest->current())
{
return $from_nearest->current();
}
// find nearest of all in net (using GPS)
$from_nearest = $this->db->query("
SELECT i2.*
FROM members m
JOIN users u ON u.member_id = m.id
JOIN address_points ap ON m.address_point_id = ap.id
JOIN devices d2 ON d2.user_id <> u.id
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE u.id = ? AND i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap.gps) IS NOT NULL AND X(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(X(ap.gps) - X(ap2.gps), 2) + POW(Y(ap.gps) - Y(ap2.gps), 2))
LIMIT 1
", $type, $user_id);
if ($from_nearest->current())
{
return $from_nearest->current();
}
}
return NULL;
}
}
freenetis/branches/network/application/controllers/device_templates.php
*/
private function validate_form_value(&$vals)
{
$vals[Iface_Model::TYPE_WIRELESS]['has_mac'] = true;
$vals[Iface_Model::TYPE_WIRELESS]['name'] = htmlspecialchars($vals[Iface_Model::TYPE_WIRELESS]['name']);
$vals[Iface_Model::TYPE_WIRELESS]['type'] = Iface_Model::TYPE_WIRELESS;
$vals[Iface_Model::TYPE_WIRELESS]['has_ip'] = Iface_Model::type_has_ip_address(Iface_Model::TYPE_WIRELESS);
$vals[Iface_Model::TYPE_WIRELESS]['has_link'] = Iface_Model::type_has_link(Iface_Model::TYPE_WIRELESS);
$vals[Iface_Model::TYPE_WIRELESS]['has_mac'] = Iface_Model::type_has_mac_address(Iface_Model::TYPE_WIRELESS);
$vals[Iface_Model::TYPE_WIRELESS]['min_count'] = intval($vals[Iface_Model::TYPE_WIRELESS]['min_count']);
$vals[Iface_Model::TYPE_WIRELESS]['max_count'] = intval($vals[Iface_Model::TYPE_WIRELESS]['max_count']);
......
$vals[Iface_Model::TYPE_WIRELESS]['items'] = array();
}
$vals[Iface_Model::TYPE_ETHERNET]['has_mac'] = true;
$vals[Iface_Model::TYPE_ETHERNET]['name'] = htmlspecialchars($vals[Iface_Model::TYPE_ETHERNET]['name']);
$vals[Iface_Model::TYPE_ETHERNET]['type'] = Iface_Model::TYPE_ETHERNET;
$vals[Iface_Model::TYPE_ETHERNET]['has_ip'] = Iface_Model::type_has_ip_address(Iface_Model::TYPE_ETHERNET);
$vals[Iface_Model::TYPE_ETHERNET]['has_link'] = Iface_Model::type_has_link(Iface_Model::TYPE_ETHERNET);
$vals[Iface_Model::TYPE_ETHERNET]['has_mac'] = Iface_Model::type_has_mac_address(Iface_Model::TYPE_ETHERNET);
$vals[Iface_Model::TYPE_ETHERNET]['count'] = intval($vals[Iface_Model::TYPE_ETHERNET]['count']);
$vals[Iface_Model::TYPE_PORT]['has_mac'] = false;
$vals[Iface_Model::TYPE_PORT]['name'] = htmlspecialchars($vals[Iface_Model::TYPE_PORT]['name']);
$vals[Iface_Model::TYPE_PORT]['type'] = Iface_Model::TYPE_PORT;
$vals[Iface_Model::TYPE_PORT]['has_ip'] = Iface_Model::type_has_ip_address(Iface_Model::TYPE_PORT);
$vals[Iface_Model::TYPE_PORT]['has_link'] = Iface_Model::type_has_link(Iface_Model::TYPE_PORT);
$vals[Iface_Model::TYPE_PORT]['has_mac'] = Iface_Model::type_has_mac_address(Iface_Model::TYPE_PORT);
$vals[Iface_Model::TYPE_PORT]['count'] = intval($vals[Iface_Model::TYPE_PORT]['count']);
if (!isset($vals[Iface_Model::TYPE_PORT]['items']))
......
$vals[Iface_Model::TYPE_PORT]['items'][$k]['number'] = intval($v['number']);
}
}
$vals[Iface_Model::TYPE_INTERNAL]['has_mac'] = true;
$vals[Iface_Model::TYPE_INTERNAL]['name'] = htmlspecialchars($vals[Iface_Model::TYPE_INTERNAL]['name']);
$vals[Iface_Model::TYPE_INTERNAL]['type'] = Iface_Model::TYPE_INTERNAL;
$vals[Iface_Model::TYPE_INTERNAL]['has_ip'] = Iface_Model::type_has_ip_address(Iface_Model::TYPE_INTERNAL);
$vals[Iface_Model::TYPE_INTERNAL]['has_link'] = Iface_Model::type_has_link(Iface_Model::TYPE_INTERNAL);
$vals[Iface_Model::TYPE_INTERNAL]['has_mac'] = Iface_Model::type_has_mac_address(Iface_Model::TYPE_INTERNAL);
$vals[Iface_Model::TYPE_INTERNAL]['min_count'] = intval(@$vals[Iface_Model::TYPE_INTERNAL]['min_count']);
$vals[Iface_Model::TYPE_INTERNAL]['max_count'] = intval(@$vals[Iface_Model::TYPE_INTERNAL]['max_count']);
freenetis/branches/network/application/controllers/js.php
}
}
private function _js_devices_add()
private function _js_devices_add($user_id = NULL)
{
$this->address_point_streets();
$this->address_point_gps();
//$this->link_iface();
$im = new Iface_Model();
$subnet = new Subnet_Model();
$device = new Device_Model();
$arr_suggest_connected_to = array();
if (isset($user_id))
{
$arr_suggest_connected_to = array
(
Iface_Model::TYPE_WIRELESS => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_WIRELESS
),
Iface_Model::TYPE_ETHERNET => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_ETHERNET
),
Iface_Model::TYPE_PORT => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_PORT
)
);
}
$this->views['devices_add'] = View::factory('js/devices_add');
$this->views['devices_add']->arr_subnets = $subnet->select_list_by_net();
$this->views['devices_add']->arr_devices = $device->select_list('id', 'name', 'user_id');
$this->views['devices_add']->arr_suggest_connected_to = $arr_suggest_connected_to;
}
private function _js_devices_edit()
freenetis/branches/network/application/views/js/__pieces/ip_address.php
}
});
for(i in options)
for(var i in options)
{
el.append(
$('<option>', {
freenetis/branches/network/application/views/js/devices_add.php
var arr_subnets = '<option value="">---- <?php echo __('Select subnet') ?> ----</option><?php foreach ($arr_subnets as $k => $v): ?><option value="<?php echo $k ?>"><?php echo $v ?></option><?php endforeach; ?>';
var arr_devices = '<option value="">---- <?php echo __('Select device') ?> ----</option><?php foreach ($arr_devices as $k => $v): ?><option value="<?php echo $k ?>"><?php echo $v ?></option><?php endforeach; ?>';
// port modes
var port_modes = new Array();
<?php foreach (Iface_Model::get_port_modes() as $k => $v): ?>
port_modes[<?php echo $k ?>] = '<?php echo $v ?>';
<?php endforeach; ?>
// connecting suggestions
var suggest_connected_to = new Array();
<?php foreach ($arr_suggest_connected_to as $k => $v): if ($arr_suggest_connected_to[$k] != NULL): ?>
suggest_connected_to[<?php echo $k ?>] = {device_id : <?php echo $v->device_id ?>, iface_id : <?php echo $v->id ?>};
<?php endif; endforeach; ?>
function add_detail_to_ip() {}
function add_detail_to_link() {}
function add_detail_to_iface() {}
function select_device_using_map() {}
/**
* On change of connected to device dropdown, select suitable ifaces
......
}
else
{
inputs.removeClass('required');
$(this).parent().parent().find('.error').remove();
inputs.removeClass('required').removeClass('error');
$(this).parent().parent().find('label.error').remove();
}
}
......
}
/**
* Creates form according to device template
*
* @param device_template_value Device template
* Creates a from of group according to data. Form is indexem by global
* couter which initial value is given also by a parameter. The final
* value of the counter is returned.
*
* @param $group Group on which the form is created
* @param data Data (device templates form)
* @param start_index Start index of counter
* @return integer The value of counter after creating
*/
function create_form_from_device_template(device_template_value)
function create_form_of_group($group, data, start_index)
{
var eths = device_template_value[<?php echo Iface_Model::TYPE_ETHERNET ?>];
var wlans = device_template_value[<?php echo Iface_Model::TYPE_WIRELESS ?>];
var ports = device_template_value[<?php echo Iface_Model::TYPE_PORT ?>];
var internals = device_template_value[<?php echo Iface_Model::TYPE_INTERNAL ?>];
var i = 0;
var $table = $('<table>').addClass('extended');
var $tr = $('<tr>');
var $td;
// ethernet
if (eths['count'] > 0)
// header
$tr.html(
$('<th>').css('width', '10px').text('<?php echo __('Use') ?>?')
);
if (data['has_mac'])
{
var $table = $('<table>').addClass('extended');
$table.html(
$('<tr>').html(
$('<th>').css('width', '10px').text('<?php echo __('Use') ?>?')
).append(
$('<th>').text('<?php echo __('MAC') ?>')
).append(
$('<th>').text('<?php echo __('IP address') ?>')
).append(
$('<th>').text('<?php echo __('Subnet') ?>')
).append(
$('<th>').text('<?php echo __('Connected to device') ?>')
)
$tr.append(
$('<th>').text('<?php echo __('MAC') ?>')
);
}
else if (data['type'] == <?php echo Iface_Model::TYPE_PORT ?>)
{
$tr.append(
$('<th>').text('Port')
);
}
if (data['has_ip'])
{
$tr.append(
$('<th>').text('<?php echo __('IP address') ?>')
).append(
$('<th>').text('<?php echo __('Subnet') ?>')
);
}
if (data['has_link'])
{
$tr.append(
$('<th>').text('<?php echo __('Connected to device') ?>')
)
}
for (; i < eths['count']; i++)
$table.html($tr);
// array of default used rows
var used_rows = [];
// indicator of first row of group
var first_row = true;
// body
var count = (data['count'] == undefined) ? data['max_count'] : data['count'];
count += start_index;
for (var i = start_index; i < count; i++)
{
// get current item
var item = false;
if (data['items'] != undefined)
{
// build hiden elements
var iface_hidden_a = new Array();
iface_hidden_a['name[' + i + ']'] = null;
iface_hidden_a['comment[' + i + ']'] = null;
iface_hidden_a['number[' + i + ']'] = null;
iface_hidden_a['port_mode[' + i + ']'] = null;
iface_hidden_a['type[' + i + ']'] = <?php echo Iface_Model::TYPE_ETHERNET ?>;
iface_hidden_a['wireless_mode[' + i + ']'] = null;
iface_hidden_a['wireless_antenna[' + i + ']'] = null;
item = data['items'].shift();
}
// build hidden elements
var iface_hidden_a = new Array();
iface_hidden_a['name[' + i + ']'] = (item.name == undefined) ? null : item.name;
iface_hidden_a['comment[' + i + ']'] = null;
iface_hidden_a['number[' + i + ']'] = null;
iface_hidden_a['port_mode[' + i + ']'] = null;
iface_hidden_a['type[' + i + ']'] = data['type'];
iface_hidden_a['wireless_mode[' + i + ']'] = (item.wireless_mode == undefined) ? null : item.wireless_mode;
iface_hidden_a['wireless_antenna[' + i + ']'] = (item.wireless_antenna == undefined) ? null : item.wireless_antenna;
var iface_hid = create_hidden_inputs(iface_hidden_a);
if (data['has_ip'])
{
var ip_hidden_a = new Array();
ip_hidden_a['dhcp[' + i + ']'] = 0;
ip_hidden_a['gateway[' + i + ']'] = 0;
ip_hidden_a['service[' + i + ']'] = 0;
var ip_hiddden = create_hidden_inputs(ip_hidden_a);
}
if (data['has_link'])
{
var link_hidden_a = new Array();
link_hidden_a['medium[' + i + ']'] = null;
link_hidden_a['bitrate[' + i + ']'] = null;
......
link_hidden_a['wireless_channel[' + i + ']'] = null;
link_hidden_a['wireless_channel_width[' + i + ']'] = null;
link_hidden_a['wireless_polarization[' + i + ']'] = null;
var iface_hid = create_hidden_inputs(iface_hidden_a);
var ip_hiddden = create_hidden_inputs(ip_hidden_a);
var link_hid = create_hidden_inputs(link_hidden_a);
// make HTML
$table.append(
$('<tr>').html(
$('<th>').css('width', '10px').html($('<input>', {
type : 'checkbox',
name : 'use[' + i + ']',
style : 'width: auto;',
change : change_use
}))
).append(
$('<td>').html($('<input>', {
type : 'text',
name : 'mac[' + i + ']',
style : 'width: 9em',
change : use_row
}).addClass('mac_address'))
).append(
iface_hid
).append(
$('<td>').html($('<input>', {
type : 'text',
name : 'ip[' + i + ']',
style : 'width: 8.5em',
change : use_row
}).addClass('ip_address')).append(ip_hiddden).append($('<a>', {
href : '#',
click : add_detail_to_ip,
style : 'margin: 8px 3px',
title : '<?php echo __('Add details to IP address') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/settings.gif')) ?>'))
).append(
$('<td>').html($('<select>', {
name : 'subnet[' + i + ']',
style : 'width: 9em',
change : use_row
}).html(arr_subnets))
).append(
$('<td>').html($('<select>', {
name : 'connected[' + i + ']',
style : 'width: 13em',
change : use_row
}).bind('change', change_connected).html(arr_devices)).append(($('<select>', {
name : 'connected_iface[' + i + ']',
style : 'width: 13em'
}))).append(link_hid).append($('<a>', {
href : '#',
click : add_detail_to_link,
style : 'margin: 8px 3px',
title : '<?php echo __('Add details to link') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/settings.gif')) ?>'))
}
// make HTML
$tr = $('<tr>');
// checked if minimal size
if ((data['min_count'] != undefined) &&
(data['min_count'] > (i - start_index)))
{
used_rows.push('use[' + i + ']');
}
$tr.html(
$('<th>').css('width', '10px').html($('<input>', {
type : 'checkbox',
name : 'use[' + i + ']',
style : 'width: auto;',
change : change_use
}))
);
$td = $('<td>');
if (data['has_mac'])
{
$td.append($('<input>', {
type : 'text',
name : 'mac[' + i + ']',
style : 'width: 9em',
change : use_row
}).addClass('mac_address'));
}
else if (data['type'] == <?php echo Iface_Model::TYPE_PORT ?>)
{
$td.html(
$('<b>').css('fontSize', '110%').text(
'Port ' + item.number + ', <?php echo __('Mode') ?> ' + port_modes[item.port_mode]
)
);
}
$eth_ifaces_group.after(
$('<tr>').addClass('eth-items').html(
$('<td>').attr('colspan', '2').html($table)
)
).show();
$td.append(iface_hid).append($('<a>', {
href : '#',
click : add_detail_to_iface,
style : 'margin: 8px 3px',
title : '<?php echo __('Add details to interface') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/settings.gif')) ?>'));
$tr.append($td);
if (data['has_ip'])
{
$tr.append(
$('<td>').html($('<input>', {
type : 'text',
name : 'ip[' + i + ']',
style : 'width: 8.5em',
change : use_row
}).addClass('ip_address')).append(ip_hiddden).append($('<a>', {
href : '#',
click : add_detail_to_ip,
style : 'margin: 8px 3px',
title : '<?php echo __('Add details to IP address') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/settings.gif')) ?>'))
).append(
$('<td>').html($('<select>', {
name : 'subnet[' + i + ']',
style : 'width: 9em',
change : use_row
}).html(arr_subnets))
);
}
if (data['has_link'])
{
$tr.append(
$('<td>').html($('<select>', {
name : 'connected[' + i + ']',
style : 'width: 13em',
change : use_row
}).bind('change', change_connected).html(arr_devices)).append($('<a>', {
href : '#',
click : select_device_using_map,
style : 'margin: 8px 3px',
title : '<?php echo __('Select device using device map') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/map_icon.gif')) ?>')).append(($('<select>', {
name : 'connected_iface[' + i + ']',
style : 'width: 13em'
}))).append(link_hid).append($('<a>', {
href : '#',
click : add_detail_to_link,
style : 'margin: 8px 3px',
title : '<?php echo __('Add details to link') ?>'
}).html('<?php echo html::image(array('src' => 'media/images/icons/settings.gif')) ?>'))
);
if (first_row)
{
var sug = suggest_connected_to[data['type']];
if (sug != undefined && sug.iface_id != undefined)
{
$tr.find('select[name^="connected"]').val(sug.device_id).trigger('change');
$tr.find('select[name^="connected_iface"]').val(sug.iface_id);
}
first_row = false;
}
}
$table.append($tr);
}
$group.after(
$('<tr>').addClass('eth-items').html(
$('<td>').attr('colspan', '2').html($table)
)
);
// check used options
for (var name in used_rows)
{
$('input[name="' + used_rows[name] + '"]').attr('checked', true).trigger('change');
}
return i;
}
/**
* Creates form according to device template
*
* @param device_template_value Device template
*/
function create_form_from_device_template(device_template_value)
{
var eths = device_template_value[<?php echo Iface_Model::TYPE_ETHERNET ?>];
var wlans = device_template_value[<?php echo Iface_Model::TYPE_WIRELESS ?>];
var ports = device_template_value[<?php echo Iface_Model::TYPE_PORT ?>];
var internals = device_template_value[<?php echo Iface_Model::TYPE_INTERNAL ?>];
var i = 0;
// ethernet
if (eths['count'] > 0)
{
i = create_form_of_group($eth_ifaces_group, eths, i);
$eth_ifaces_group.show();
}
else
{
$eth_ifaces_group.hide();
......
// wireless
if (wlans['max_count'] > 0)
{
i = create_form_of_group($wlan_ifaces_group, wlans, i);
$wlan_ifaces_group.show();
}
else
......
// port
if (ports['count'] > 0)
{
i = create_form_of_group($port_group, ports, i);
$port_group.show();
}
else
......
}
// internal
if (internals['count'] > 0)
if (internals['max_count'] > 0)
{
i = create_form_of_group($internal_group, internals, i);
$internal_group.show();
}
else

Také k dispozici: Unified diff