Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6f7e4d6a

Přidáno uživatelem Michal Kliment před více než 3 roky(ů)

  • ID 6f7e4d6aa44ab18ea756efc7bae2163ddde4ecb2
  • Rodič e0da3ee3

Add gain and azimuth to wireless ifaces (fixes #1166)

Zobrazit rozdíly:

application/controllers/devices.php
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
$im->wireless_antenna_gain = intval($_POST['wireless_antenna_gain'][$i]);
$im->wireless_antenna_azimuth = intval($_POST['wireless_antenna_azimuth'][$i]);
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
}
application/controllers/ifaces.php
->style('width:200px');
$w_form->dropdown('wireless_antenna')
->label('Antenna')
->label('Antenna type')
->options($antennas)
->style('width:200px');
$w_form->input('wireless_antenna_gain')
->label('Antenna gain')
->rules('valid_numeric');
$w_form->input('wireless_antenna_azimuth')
->label('Antenna azimuth')
->rules('valid_numeric|valid_azimuth');
}
// print virtual AP fields only if type is virtual AP
......
{
$iface->wireless_mode = $form_data['wireless_mode'];
$iface->wireless_antenna = $form_data['wireless_antenna'];
$iface->wireless_antenna_gain = $form_data['wireless_antenna_gain'];
if (Iface_Model::wireless_antenna_has_azimuth($form_data['wireless_antenna']))
$iface->wireless_antenna_azimuth = $form_data['wireless_antenna_azimuth'];
}
else if ($iface->type === Iface_Model::TYPE_VIRTUAL_AP)
{
$parent_iface = new Iface_Model($form_data['parent_iface_id']);
$iface->wireless_mode = $parent_iface->wireless_mode;
$iface->wireless_antenna = $parent_iface->wireless_antenna;
$iface->wireless_antenna_gain = $parent_iface->wireless_antenna_gain;
if (Iface_Model::wireless_antenna_has_azimuth($parent_iface->wireless_antenna))
$iface->wireless_antenna_azimuth = $parent_iface->wireless_antenna_azimuth;
}
else if ($iface->type == Iface_Model::TYPE_PORT)
{
......
->selected($iface->wireless_mode);
$w_form->dropdown('wireless_antenna')
->label('Antenna')
->label('Antenna type')
->options($antennas)
->style('width:200px')
->selected($iface->wireless_antenna);
$w_form->input('wireless_antenna_gain')
->label('Antenna gain')
->rules('valid_numeric')
->value($iface->wireless_antenna_gain);
$w_form->input('wireless_antenna_azimuth')
->label('Antenna azimuth')
->rules('valid_numeric|valid_azimuth')
->value($iface->wireless_antenna_azimuth);
}
// print virtual AP fields only if type is virtual AP
......
$iface->wireless_mode = null;
$iface->wireless_antenna = null;
$iface->wireless_antenna_gain = null;
$iface->wireless_antenna_azimuth = null;
$iface->number = null;
$iface->port_mode = null;
......
{
$iface->wireless_mode = $form_data['wireless_mode'];
$iface->wireless_antenna = $form_data['wireless_antenna'];
$iface->wireless_antenna_gain = $form_data['wireless_antenna_gain'];
if (Iface_Model::wireless_antenna_has_azimuth($form_data['wireless_antenna']))
$iface->wireless_antenna_azimuth = $form_data['wireless_antenna_azimuth'];
}
else if ($iface->type === Iface_Model::TYPE_VIRTUAL_AP)
{
$parent_iface = new Iface_Model($form_data['parent_iface_id']);
$iface->wireless_mode = $parent_iface->wireless_mode;
$iface->wireless_antenna = $parent_iface->wireless_antenna;
$iface->wireless_antenna_gain = $parent_iface->wireless_antenna_gain;
if (Iface_Model::wireless_antenna_has_azimuth($parent_iface->wireless_antenna))
$iface->wireless_antenna_azimuth = $parent_iface->wireless_antenna_azimuth;
// delete current
foreach ($iface->ifaces_relationships as $i)
application/helpers/valid.php
{
return preg_match ("/^([0-9]{1,6}-)?([0-9]{2,10})\/[0-9]{4}$/", $str);
}
/**
* Checks whether string is valid azimuth
*
* @author Michal Kliment
* @param string $str
* @return boolean
*/
public static function azimuth($str)
{
return $str >= 0 && $str < 360;
}
} // End valid
application/i18n/cs_CZ/texts.php
'and' => 'a',
'and now, click login' => 'A nyní klikněte na "Přihlásit".',
'antenna' => 'Anténa',
'antenna azimuth' => 'Směr antény',
'antenna gain' => 'Zisk antény',
'antenna type' => 'Typ antény',
'answer' => 'Odpověd',
'answer to this message' => 'Odpovědet na tuto zprávu',
'any' => 'Jakékoliv',
......
'axo count' => 'Počet AXO',
'axo section' => 'AXO sekce',
'axo value' => 'AXO hodnota',
'azimuth' => 'Směr',
'back' => 'Zpět',
'back to account transfers' => 'Zpět na převody účtu',
'back to administration' => 'Zpět na administraci',
......
'from' => 'Od',
'from member' => 'Od člena',
'from2' => 'z',
'gain' => 'Zisk',
'gateway' => 'Brána',
'gateway information' => 'Informace o bráně',
'gateway ip address' => 'IP adresa brány',
......
'without street' => 'Bez ulice',
'wireless' => 'Bezdrátové',
'wireless antenna' => 'Bezdrátová anténa',
'wireless antenna azimuth' => 'Směr bezdrátové antény',
'wireless antenna gain' => 'Zisk bezdrátové antény',
'wireless antenna type' => 'Typ bezdrátové antény',
'wireless interfaces' => 'Bezdrátová rozhraní',
'wireless mode' => 'Bezdrátový mód',
'wireless setting' => 'Bezdrátové nastavení',
application/models/iface.php
self::TYPE_ETHERNET => array(self::TYPE_BRIDGE),
self::TYPE_VIRTUAL_AP => array(self::TYPE_WIRELESS)
);
/**
* Boolean value if wireless antenna type can have azimuth
*
* @var array
*/
private static $wireless_antenna_has_azimuth = array
(
self::WIRELESS_ANTENNA_DIRECTIONAL => TRUE,
self::WIRELESS_ANTENNA_OMNIDIRECTIONAL => FALSE,
self::WIRELESS_ANTENNA_SECTIONAL => TRUE
);
/**
* Tests if type can have link
......
return array();
}
/**
* Tests if wireless antenna can have azimuth
*
* @author Michal Kliment
* @param integer $wireless_antenna
* @return boolean
*/
public static function wireless_antenna_has_azimuth($wireless_antenna)
{
if (isset(self::$wireless_antenna_has_azimuth[$wireless_antenna]))
return self::$wireless_antenna_has_azimuth[$wireless_antenna];
else
return TRUE;
}
/**
* Returns type of current interface
application/views/device_templates/show.php
<tr>
<th><?php echo __('Name') ?></th>
<th><?php echo __('Wireless mode') ?></th>
<th><?php echo __('Wireless antenna') ?></th>
<th><?php echo __('Antenna type') ?></th>
<th><?php echo __('Antenna gain') ?></th>
<th><?php echo __('Antenna azimuth') ?></th>
</tr>
<?php foreach ($ivals[Iface_Model::TYPE_WIRELESS]['items'] as $item): ?>
<tr>
<td><?php echo $item['name'] ?></td>
<td><?php echo Iface_Model::get_wireless_mode(@$item['wireless_mode']) ?></td>
<td><?php echo Iface_Model::get_wireless_antenna(@$item['wireless_antenna']) ?></td>
<td><?php echo @$item['wireless_antenna_gain'] ?></td>
<td><?php echo @$item['wireless_antenna_azimuth'] ?></td>
</tr>
<?php endforeach; ?>
</table>
application/views/devices/add.php
<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>
<th><label><?php echo __('Antenna type') ?>:</label></th>
<td><?php echo form::dropdown('wireless_antenna_input', $wireless_antennas, array(), 'style="width:200px"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Antenna gain') ?>:</label></th>
<td><?php echo form::input('wireless_antenna_gain_input', '', 'class="number"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Antenna azimuth') ?>:</label></th>
<td><?php echo form::input('wireless_antenna_azimuth_input', '', 'class="number azimuth"') ?></td>
</tr>
</table>
<button class="submit" type="button"><?php echo __('Save') ?></button>
</form>
application/views/ifaces/show.php
<?php endif; ?>
<?php if (isset($iface->wireless_antenna)): ?>
<tr>
<th><?php echo __('Wireless antenna') ?></th>
<th><?php echo __('Wireless antenna type') ?></th>
<td><?php echo Iface_Model::get_wireless_antenna($iface->wireless_antenna) ?></td>
</tr>
<?php endif; ?>
<?php if (isset($iface->wireless_antenna_gain)): ?>
<tr>
<th><?php echo __('Wireless antenna gain') ?></th>
<td><?php echo $iface->wireless_antenna_gain ?> dBi</td>
</tr>
<?php endif; ?>
<?php if (isset($iface->wireless_antenna_azimuth)): ?>
<tr>
<th><?php echo __('Wireless antenna azimuth') ?></th>
<td><?php echo $iface->wireless_antenna_azimuth ?>˚</td>
</tr>
<?php endif; ?>
<?php if (intval($iface->link->id) > 0 && Iface_Model::type_has_link($iface->type)): ?>
<tr>
<th colspan="2"><?php echo __('Link') ?></th>
application/views/js/base.php
{
return (value == '' || value.match(/^([0-9]+[k|M|G|T]?)(\/[0-9]+[k|M|G|T]?)?$/i));
}, '<?php echo __('Bad format.') ?>');
$.validator.addMethod('azimuth', function(value)
{
var azimuth = parseInt(value);
return (value == '' || (azimuth >= 0 && azimuth < 360));
}, '<?php echo __('Bad format.') ?>');
// set up for password checker
$.validator.passwordRating.messages = {
application/views/js/device_templates_add.php
}).html(wiface_mode_options).css('margin', '4px 15px')
)
).append(
$('<td>').html($('<label>').text('<?php echo __('Antenna') ?>:')).append(
$('<td>').html(
$('<label>').text('<?php echo __('Antenna') ?>:').css('font-weight', 'bold')
)
).append(
$('<td>').html($('<label>').text('<?php echo __('Type') ?>:')).append(
$('<select>').attr({
'name' : 'values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][' + i + '][wireless_antenna]',
'class' : 'dropdown',
'type' : 'dropdown'
}).html(wiface_antenna_options).css('margin', '4px 15px')
)
).append(
$('<td>').html($('<label>').text('<?php echo __('Gain') ?>:')).append(
$('<input>').attr({
'name' : 'values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][' + i + '][wireless_antenna_gain]',
'class' : 'number',
'type' : 'number'
}).html(wiface_antenna_options).css('margin', '4px 15px')
)
).append(
$('<td>').html($('<label>').text('<?php echo __('Azimuth') ?>:')).append(
$('<input>').attr({
'name' : 'values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][' + i + '][wireless_antenna_azimuth]',
'class' : 'number',
'type' : 'number'
}).html(wiface_antenna_options).css('margin', '4px 15px')
)
));
}
}
......
<?php $i = 0; foreach ($device_template_value[Iface_Model::TYPE_WIRELESS]['items'] as $item): ?>
$('input[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i ?>][name]"]').val('<?php echo $item['name'] ?>');
$('select[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i ?>][wireless_mode]"]').val('<?php echo $item['wireless_mode'] ?>');
$('select[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i++ ?>][wireless_antenna]"]').val('<?php echo $item['wireless_antenna'] ?>');
$('select[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i ?>][wireless_antenna]"]').val('<?php echo $item['wireless_antenna'] ?>');
$('input[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i ?>][wireless_antenna_gain]"]').val('<?php echo @$item['wireless_antenna_gain'] ?>');
$('input[name="values[<?php echo Iface_Model::TYPE_WIRELESS ?>][items][<?php echo $i++ ?>][wireless_antenna_azimuth]"]').val('<?php echo @$item['wireless_antenna_azimuth'] ?>');
<?php endforeach; ?>
// set values of port items
<?php $i = 0; foreach ($device_template_value[Iface_Model::TYPE_PORT]['items'] as $item): ?>
application/views/js/devices_add.php
$('#port_mode_input').val($td.find('input[name^="port_mode["]').val());
$('#wireless_mode_input').val($td.find('input[name^="wireless_mode["]').val());
$('#wireless_antenna_input').val($td.find('input[name^="wireless_antenna["]').val());
$('#wireless_antenna_gain_input').val($td.find('input[name^="wireless_antenna_gain["]').val());
$('#wireless_antenna_azimuth_input').val($td.find('input[name^="wireless_antenna_azimuth["]').val());
// dialog button action submit
$('#dialog_iface_detail form button').unbind('click').click(function ()
......
$td.find('input[name^="port_mode["]').val($('#port_mode_input').val());
$td.find('input[name^="wireless_mode["]').val($('#wireless_mode_input').val());
$td.find('input[name^="wireless_antenna["]').val($('#wireless_antenna_input').val());
$td.find('input[name^="wireless_antenna_gain["]').val($('#wireless_antenna_gain_input').val());
$td.find('input[name^="wireless_antenna_azimuth["]').val($('#wireless_antenna_azimuth_input').val());
// update connected to device
$td.find('select[name^="connected["]').trigger('change', $td.find('select[name^="connected_iface["]').val());
......
$('#port_mode_input').parent().parent().show();
$('#wireless_mode_input').parent().parent().show();
$('#wireless_antenna_input').parent().parent().show();
$('#wireless_antenna_gain_input').parent().parent().show();
$('#wireless_antenna_azimuth_input').parent().parent().show();
switch (parseInt($td.find('input[name^="type["]').val()))
{
......
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
$('#wireless_antenna_gain_input').parent().parent().hide();
$('#wireless_antenna_azimuth_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_PORT ?>:
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
$('#wireless_antenna_gain_input').parent().parent().hide();
$('#wireless_antenna_azimuth_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_INTERNAL ?>:
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
$('#wireless_antenna_gain_input').parent().parent().hide();
$('#wireless_antenna_azimuth_input').parent().parent().hide();
break;
};
......
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;
iface_hidden_a['wireless_antenna_gain[' + i + ']'] = (item.wireless_antenna_gain == undefined) ? null : item.wireless_antenna_gain;
iface_hidden_a['wireless_antenna_azimuth[' + i + ']'] = (item.wireless_antenna_azimuth == undefined) ? null : item.wireless_antenna_azimuth;
var iface_hid = create_hidden_inputs(iface_hidden_a);
if (data['has_ip'])
db_upgrades/upgrade_1.2.0~alpha12.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/
*
*/
/**
* Add gain and azimuth for wireless ifaces
*
* @author Michal Kliment
*/
$upgrade_sql['1.2.0~alpha12'] = array
(
"ALTER TABLE `ifaces`
ADD `wireless_antenna_gain` INT(11) NULL DEFAULT NULL AFTER `wireless_antenna`,
ADD `wireless_antenna_azimuth` INT(11) NULL DEFAULT NULL AFTER `wireless_antenna_gain`;"
);
version.php
* The current version of FreenetIS.
* This value must be changed by developers in a new release of FreenetIS.
*/
define('FREENETIS_VERSION', '1.2.0~alpha11');
define('FREENETIS_VERSION', '1.2.0~alpha12');

Také k dispozici: Unified diff