Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1836

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

Upravy:

- fixes #468 - Chybejici omezeni vice bran na podsiti (snad vsude)

Zobrazit rozdíly:

freenetis/branches/1.1/application/i18n/cs_CZ/texts.php
'subnet count' => 'Počet podsítí',
'subnet not exists' => 'Podsíť neexistuje',
'subnet does not exists' => 'Podsíť neexistuje',
'subnet has already have gateway' => 'Podsíť již má bránu.',
'subnet has been successfully assigned to cloud' => 'Podsíť byla uspěšně přidána do oblasti',
'subnet has been successfully removed from cloud' => 'Podsíť byla úspěšně odstraněna z oblasti',
'subnet has been successfully disabled' => 'Podsíť byla úspěšně zakázána.',
freenetis/branches/1.1/application/models/subnet.php
return ($result->count() > 0 ? $result->current()->subnet_id : NULL);
}
/**
* Returns all subnets with existing gateway
*
* @author Michal Kliment
* @return Mysql_Result
*/
public function get_all_subnets_with_gateway()
{
return $this->db->query("
SELECT s.*
FROM subnets s
JOIN ip_addresses ip ON ip.subnet_id = s.id AND ip.gateway = 1
");
}
}
freenetis/branches/1.1/application/controllers/ip_addresses.php
$grid->add_new_button('ip_addresses/add', __('Add new IP address'));
}
$grid->order_callback_field('ip_address')
->label('IP address')
->callback('callback::ip_address_field');
$grid->order_field('ip_address')
->label('IP address');
$grid->order_link_field('subnet_id')
->link('subnets/show', 'subnet_name')
->label('Subnet');
$grid->order_callback_field('gateway')
->label('Gateway')
->help(help::hint('gateway'))
->callback('boolean')
->class('center');
$grid->order_callback_field('service')
->label('Service')
->help(help::hint('service'))
->callback('boolean')
->class('center');
$grid->order_callback_field('whitelisted')
->label('Whitelist')
->help(help::hint('Whitelist'))
->callback('whitelisted_field')
->class('center');
$grid->order_callback_field('device_name')
->label('Device name')
->callback('callback::device_field');
$actions = $grid->grouped_action_field();
if ($this->acl_check_view('Devices_Controller','ip_address'))
{
$actions->add_action('id')
->icon_action('show')
->url('ip_addresses/show')
->class('popup_link');
}
if ($this->acl_check_edit('Devices_Controller','ip_address'))
{
$actions->add_action('id')
->icon_action('edit')
->url('ip_addresses/edit');
->url('ip_addresses/edit')
->class('popup_link');
}
if ($this->acl_check_delete('Devices_Controller','ip_address'))
......
->label('IP address')
->rules('required|valid_ip_address')
->callback(array($this, 'valid_ip'))
->style('width:200px');
->style('width:200px');
$this->form->dropdown('subnet_id')
->label('Select subnet name')
......
$this->form->dropdown('gateway')
->label(__('Gateway').': '.help::hint('gateway'))
->options(arr::rbool())
->selected('0');
->selected('0')
->callback(array($this, 'valid_gateway'));
$this->form->dropdown('service')
->label(__('Service').': '.help::hint('service'))
......
Controller::error(RECORD);
$this->ip_address_id = $ip_address_id;
$device = $ip_address->iface->device;
$arr_ifaces = array
......
$this->form->dropdown('gateway')
->label(__('Gateway').': '.help::hint('gateway'))
->options(arr::rbool())
->selected($ip_address->gateway);
->selected($ip_address->gateway)
->callback(array($this, 'valid_gateway'));
$this->form->dropdown('service')
->label(__('Service').': '.help::hint('service'))
......
}
/**
* Callback function to validate if subnet has gateway
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $input
*/
public function valid_gateway($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$subnet_id = (int) $this->input->post('subnet_id');
if ($input->value && $subnet_id)
{
$subnet = new Subnet_Model($subnet_id);
// find gateway of subnet
$gateway = $subnet->get_gateway();
// gateway already exists
if ($gateway && $gateway->id && $this->ip_address_id != $gateway->id)
{
$input->add_error('required', __('Subnet has already have gateway.'));
}
}
}
/**
* Checks ip address if matches subnet and mask.
*
* @param string $ip
freenetis/branches/1.1/application/controllers/js.php
$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_gateway_subnets = arr::from_objects($subnet->get_all_subnets_with_gateway());
$this->views['devices_add']->arr_devices = $device->select_list_device_with_user($user_id);
$this->views['devices_add']->connection_request_model = ($cr_model->loaded) ? $cr_model : NULL;
}
freenetis/branches/1.1/application/controllers/devices.php
if (isset($_POST['ip'][$i]) && valid::ip_address($_POST['ip'][$i]))
{
$subnet_id = intval($_POST['subnet'][$i]);
$gateway = ($_POST['gateway'][$i] == 1);
// ip address is gatewayof subnet
if ($gateway)
{
$subnet = new Subnet_Model($subnet_id);
$gateway = $subnet->get_gateway();
// subnet has already have gateway
if ($gateway && $gateway->id)
throw new Exception(__('Error').': '.__('Subnet has already have gateway'));
}
// save IP address
$ipm = new Ip_address_Model();
$ipm->iface_id = $im->id;
$ipm->subnet_id = intval($_POST['subnet'][$i]);
$ipm->subnet_id = $subnet_id;
$ipm->member_id = NULL;
$ipm->ip_address = htmlspecialchars($_POST['ip'][$i]);
$ipm->dhcp = ($_POST['dhcp'][$i] == 1);
$ipm->gateway = ($_POST['gateway'][$i] == 1);
$ipm->gateway = $gateway;
$ipm->service = ($_POST['service'][$i] == 1);
$ipm->save_throwable();
freenetis/branches/1.1/application/views/js/devices_add.php
var subnets_options = '<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 devices_options = '<option value="">---- <?php echo __('Select device') ?> ----</option><?php foreach ($arr_devices as $k_u => $v_u): ?><optgroup label="<?php echo $k_u ?>"><?php foreach ($v_u as $k => $v): ?><option value="<?php echo $k ?>"><?php echo $v ?></option><?php endforeach; ?></optgroup><?php endforeach; ?>';
// subnets with gateway
var gateway_subnets = [<?php echo implode(', ',array_keys($arr_gateway_subnets)) ?>];
// port modes asociative array
var port_modes = new Array();
<?php foreach (Iface_Model::get_port_modes() as $k => $v): ?>
......
// dialog button action submit
$('#dialog_ip_address_detail form button').unbind('click').click(function ()
{
{
if ($('#dialog_ip_address_detail form').valid())
{
// fill in hidden fields
......
alert('<?php echo __('Some IP addresses are same, please change them') ?>!');
isValid = false;
}
var gateway = $(v).parent().children('input[name^="gateway["]').val();
var subnet_id = $(v).parent().children('select[name^="subnet["]').val();
// subnet has already have gateway
if (in_array(subnet_id, gateway_subnets) && gateway == 1)
{
alert('<?php echo __('Subnet has already have gateway') ?>');
isValid = false;
}
}
});
// check if all MAC addresses are unique
......
}
}
});
// send form
return isValid;
}

Také k dispozici: Unified diff