Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1462

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

Upravy:
- pokud odkaz nema titulek, pokusi se vlozit cervene oznacene id z konce odkazu
- odtraneni vsech vecich spojenych s porty
- upravy v pridavani IP address
- jmeno promenne Path c QS je nastavitelna konstantou

Opravy:
- oprava exportu subnetu do CSV
- opraveno zobrazeni presmetrovani
- opraveny chyby v generovani URL cest
- oprava vyplneni ifacu pri nevyplnenem pripojenem zarizeni u formulare pro pridavani zarizeni

Zobrazit rozdíly:

freenetis/branches/network/application/i18n/cs_CZ/texts.php
'add new invoice item' => 'Přidat novou položku faktury',
'add new ip address' => 'Přidat novou IP adresu',
'add new ip address to device' => 'Přidat novou IP adresu k zařízení',
'add new ip address to interface' => 'Přidat novou IP adresu k rozhraní',
'add new items' => 'Přidat nové položky',
'add new key' => 'Přidat nový klíč',
'add new member' => 'Přidat nového člena',
freenetis/branches/network/application/helpers/html.php
{
if ($uri === '')
{
$site_url2 = $site_url = url::base(FALSE);
$site_url_modified = $site_url = url::base(FALSE);
}
else
{
......
{
$site_url = $uri;
}
$site_url2 = $site_url;
$url = 'path_url=' . urlencode(url_lang::current());
if (strpos($uri, 'path_url') === FALSE)
$site_url_modified = $site_url;
if (strpos($site_url_modified, Path::QSNAME . '=') === FALSE)
{
if (strpos($uri, '?') !== FALSE)
$qs_var = Path::QSNAME . '=' . urlencode(url_lang::current());
if (strpos($site_url_modified, '?') !== FALSE)
{
list ($uri, $qs) = explode('?', $uri, 2);
list ($uri_no_qs, $qs) = explode('?', $site_url_modified, 2);
$queries = explode('&', $qs);
array_push($queries, $url);
$url = implode('&', $queries);
array_push($queries, $qs_var);
$qs = implode('&', $queries);
$site_url_modified = $uri_no_qs . '?' . $qs;
}
$site_url2 = $site_url2 . '?' . $url;
else
{
$site_url_modified .= '?' . $qs_var;
}
}
}
// Title empty? Use the parsed URL or ID
if (empty($title))
{
if (mb_eregi('/([0-9]+)$', $site_url, $r))
{
$title = "<span style=\"color: red\">[$r[1]]</span>";
}
else
{
$title = $site_url;
}
}
return
// Parsed URL
'<a href="'.html::specialchars($site_url2, FALSE).'"'
'<a href="'.html::specialchars($site_url_modified, FALSE).'"'
// Attributes empty? Use an empty string
.(empty($attributes) ? '' : html::attributes($attributes)).'>'
// Title empty? Use the parsed URL
.(empty($title) ? $site_url : $title).'</a>';
// title
. $title .'</a>';
}
/**
freenetis/branches/network/application/models/log.php
*
* @author Ondřej Fibich
* @see Scheduler_Controller::logs_partitions_daily()
* @todo delete all old partitions
*/
public function remove_old_partition()
{
freenetis/branches/network/application/controllers/ports.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/
*
*/
/**
* Controller performs actions over ports.
* Port groups devices to segments.
*
* @package Controller
*/
class Ports_Controller extends Controller
{
public $port_nr = NULL;
private $_device_id = NULL;
/**
* Redirect to show all
*/
public function index()
{
url::redirect('ports/show_all');
}
/**
* Function shows all ports.
*
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param integer $page_word
* @param integer $page
*/
public function show_all(
$limit_results = 50, $order_by = 'id',
$order_by_direction = 'ASC', $page_word = null, $page = 1)
{
//---- delete session device ----
$this->session->del('ssDevice_id');
if(!$this->acl_check_view('Devices_Controller', 'port'))
Controller::error(ACCESS);
// get new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
$port_model = new Port_Model();
$total_ports = $port_model->count_all_ports();
if (($sql_offset = ($page - 1) * $limit_results) > $total_ports)
$sql_offset = 0;
$query = $port_model->get_all_ports(
$sql_offset, (int) $limit_results, $order_by, $order_by_direction
);
$grid = new Grid(url_lang::base().'ports', null,array
(
'current' => $limit_results,
'selector_increace' => 10,
'selector_min' => 10,
'selector_max_multiplier' => 5,
'base_url' => Config::get('lang').'/ports/show_all/'
. $limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page',
'total_items' => $total_ports,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
));
if ($this->acl_check_new('Devices_Controller','port'))
{
$grid->add_new_button('ports/add', __('Add new port'));
}
$grid->order_field('id')
->label('ID')
->class('center');
$grid->order_field('name');
$grid->order_field('port_nr')
->label(__('Number'));
$grid->order_field('device_name');
$grid->order_field('link_name');
$grid->order_field('vlan_count')
->label(__('Vlans'))
->class('center');
$actions = $grid->grouped_action_field();
if ($this->acl_check_view('Devices_Controller','port'))
{
$actions->add_action()
->icon_action('show')
->url('ports/show');
}
if ($this->acl_check_edit('Devices_Controller','port'))
{
$actions->add_action()
->icon_action('edit')
->url('ports/edit');
}
if ($this->acl_check_delete('Devices_Controller','port'))
{
$actions->add_action()
->icon_action('delete')
->url('ports/delete')
->class('delete_link');
}
$grid->datasource( $query );
$view = new View('main');
$view->title = __('Ports list');
$view->breadcrumbs = __('Ports');
$view->content = new View('show_all');
$view->content->table = $grid;
$view->content->headline = __('Ports list');
$view->render(TRUE);
}
/**
* Function shows port.
*
* @param integer $port_id
* @return integer unknown_type
*/
public function show($port_id = null)
{
$ssDevice_id = $this->session->get('ssDevice_id');
if (!$port_id || !is_numeric($port_id))
{
Controller::warning(PARAMETER);
}
$port = new Port_Model($port_id);
if (!$port_id || !$port->id)
{
Controller::error(ACCESS);
}
if (!$this->acl_check_view('Devices_Controller', 'port'))
Controller::error(ACCESS);
$vlan_model = new Vlan_Model();
$vlans = $vlan_model->get_all_vlans_by_port($port->id);
$grid_vlans = new Grid('ports', null, array
(
'separator' => '',
'use_paginator' => false,
'use_selector' => false
));
$grid_vlans->field('name')
->label(__('VLAN name'));
$grid_vlans->field('tag_802_1q')
->class('center');
$grid_vlans->callback_field('tagged')
->callback('callback::boolean')
->label('Tagged VLAN')
->class('center');
$actions = $grid_vlans->grouped_action_field();
if ($this->acl_check_view('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('show')
->url('vlans/show')
->class('popup_link');
}
if ($this->acl_check_edit('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('edit')
->url('vlans/edit')
->class('popup_link');
}
if ($this->acl_check_delete('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('delete')
->url('vlans/delete')
->class('delete_link popup_link');
}
$grid_vlans->datasource($vlans);
if (url_lang::current(1) != 'ports')
{
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $port->device->user->member->id,
'ID ' . $port->device->user->member->id . ' - ' . $port->device->user->member->name,
$this->acl_check_view('Members_Controller', 'members', $port->device->user->member->id))
->enable_translation()
->link('users/show_by_member/' . $port->device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $port->device->user->member_id))
->disable_translation()
->link('users/show/' . $port->device->user->id,
$port->device->user->name . ' ' . $port->device->user->surname . ' (' . $port->device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $port->device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $port->device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $port->device->user->member_id))
->disable_translation()
->link('devices/show/' . $port->device->id . '#device_ports_link',
!empty($port->device->name) ? $port->device->name : $device_type,
$this->acl_check_edit('Devices_Controller', 'devices', $port->device->user->member_id))
->enable_translation();
}
else
{
$breadcrumbs = breadcrumbs::add()
->link('ports/show_all', 'Ports',
$this->acl_check_view('Devices_Controller', 'port'));
}
$breadcrumbs->disable_translation()
->text($port->name);
$headline = __('Port detail') . ' - ' . $port->name;
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('ports/show');
$view->content->port = $port;
$view->content->table_vlans = $grid_vlans;
$view->content->headline = $headline;
$view->render(TRUE);
} // end of show
/**
* Function adds new port.
*
* @param integer $device_id
*/
public function add($device_id = NULL)
{
if (!$this->acl_check_new('Devices_Controller', 'port'))
Controller::error(ACCESS);
$form = new Forge();
$form->group('Basic data');
$form->input('port_nr')
->label(__('Port number').':')
->rules('required|valid_numeric')
->callback(array($this, 'valid_port_nr'));
$form->input('name')
->label(__('Port name').':')
->rules('length[3,200]');
$member_id = NULL;
if ($device_id)
{
$device = new Device_Model($device_id);
// record doesn't exist
if (!$device->id)
Controller::error(RECORD);
$member_id = $device->user->member_id;
$this->_device_id = $device->id;
}
else
{
$device_model = new Device_Model();
$arr_devices = array
(
NULL => '----- '.__('select device').' -----'
) + $device_model->select_list('id', 'name');
$form->dropdown('device_id')
->label(__('Device name'))
->options($arr_devices)
->rules('required');
}
if (!$this->acl_check_new('Devices_Controller','port',$member_id))
Controller::Error(ACCESS);
$segment_model = new Link_Model();
$vlan_model = new Vlan_Model();
$arr_segments = array
(
NULL => '----- '.__('select segment').' -----'
) + $segment_model->get_all_links_to_port_dropdown();
$arr_vlans = ORM::factory('vlan')->select_list();
$form->dropdown('segment_id')
->label(__('Segment name'))
->options($arr_segments)
->rules('required')
->add_button('segments');
$modes = arr::merge(array
(
NULL => '----- '.__('Select mode').' -----'
), Port_Model::get_port_modes());
$form->dropdown('mode')
->rules('required')
->options($modes)
->selected(Port_Model::PORT_MODE_ACCESS)
->callback(array($this, 'valid_mode'));
$default_vlan = $vlan_model->get_default_vlan();
$default_vlans = arr::merge(array
(
NULL => '----- '.__('Select port VLAN').' -----'
), $arr_vlans);
$form->dropdown('port_vlan_id')
->options($default_vlans)
->selected($default_vlan->id)
->rules('required')
->label('Port VLAN')
->help('port_vlan')
->callback(array($this, 'valid_port_vlan'))
->add_button('vlans');
$form->dropdown('tagged_vlan_id[]')
->label(__('Tagged VLANs'))
->options($arr_vlans)
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->dropdown('untagged_vlan_id[]')
->label(__('Untagged VLANs'))
->options($arr_vlans)
->selected($default_vlan->id)
->callback(array($this, 'valid_vlans'))
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->submit('Save');
special::required_forge_style($form, ' *', 'required');
if ($form->validate())
{
$form_data = $form->as_array();
$port = new Port_Model();
try
{
$port->transaction_start();
$port->port_nr = $form_data['port_nr'];
$port->name = $form_data['name'];
if ($device_id)
$port->device_id = $device_id;
else
$port->device_id = $form_data['device_id'];
$port->segment_id = $form_data['segment_id'];
$port->mode = $form_data['mode'];
$port->port_vlan_id = $form_data['port_vlan_id'];
$port->save_throwable();
$vlans = new Ports_vlan_Model();
foreach ((array) $form_data['tagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = TRUE;
$vlans->save_throwable();
$vlans->clear();
}
foreach ((array) $form_data['untagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = FALSE;
$vlans->save_throwable();
$vlans->clear();
}
$port->transaction_commit();
status::success('Port has been successfully saved.');
if ($device_id)
$this->redirect('devices/show/'.$port->id);
else
$this->redirect('show', $port->id);
}
catch (Exception $e)
{
$port->transaction_rollback();
status::error('Error - Cannot save port.');
$this->redirect('show_all', $port->id);
}
}
else
{
if ($device_id && $device->id)
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $device->user->member->id,
'ID ' . $device->user->member->id . ' - ' . $device->user->member->name,
$this->acl_check_view('Members_Controller', 'members', $device->user->member->id))
->enable_translation()
->link('users/show_by_member/' . $device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->disable_translation()
->link('users/show/' . $device->user->id,
$device->user->name . ' ' . $device->user->surname . ' (' . $device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $device->user->member_id))
->disable_translation()
->link('devices/show/' . $device->id . '#device_ports_link',
$device->name,
$this->acl_check_edit('Devices_Controller', 'devices', $device->user->member_id))
->enable_translation();
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('ports/show_all', 'Ports',
$this->acl_check_view('Devices_Controller', 'port'));
}
$breadcrumbs->text('Add new port');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = __('Add new port');
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = __('Add new port');
$view->render(TRUE);
}
} // end of add
public function edit($port_id = NULL)
{
// bad parameter
if (!$port_id || !is_numeric($port_id))
Controller::warning (PARAMETER);
$port = new Port_Model($port_id);
// record doesn't exist
if (!$port->id)
Controller::error (RECORD);
// access control
if (!$this->acl_check_new('Devices_Controller', 'port'))
Controller::error(ACCESS);
$form = new Forge();
$form->group('Basic data');
$form->input('port_nr')
->value($port->port_nr)
->label(__('Port number').':')
->rules('required|valid_numeric')
->callback(array($this, 'valid_port_nr'));
$form->input('name')
->value($port->name)
->label(__('Port name').':')
->rules('length[3,200]');
$member_id = NULL;
$device_model = new Device_Model();
$arr_devices = array
(
NULL => '----- '.__('select device').' -----'
) + $device_model->select_list('id', 'name');
$form->dropdown('device_id')
->label(__('Device name'))
->options($arr_devices)
->selected($port->device_id)
->rules('required');
if (!$this->acl_check_new('Devices_Controller','port',$member_id))
Controller::Error(ACCESS);
$segment_model = new Link_Model();
$vlan_model = new Vlan_Model();
$arr_segments = array
(
NULL => '----- '.__('select segment').' -----'
) + $segment_model->get_all_links_to_port_dropdown();
$form->dropdown('segment_id')
->label(__('Segment name'))
->options($arr_segments)
->selected($port->segment_id)
->rules('required')
->add_button('segments');
$modes = arr::merge(array
(
NULL => '----- '.__('Select mode').' -----'
), Port_Model::get_port_modes());
$form->dropdown('mode')
->rules('required')
->options($modes)
->selected($port->mode)
->callback(array($this, 'valid_mode'));
$vlan_model = new Vlan_Model();
$arr_vlans = $vlan_model->select_list();
$default_vlans = arr::merge(array
(
NULL => '----- '.__('Select port VLAN').' -----'
), $arr_vlans);
$form->dropdown('port_vlan_id')
->options($default_vlans)
->selected($port->port_vlan_id)
->rules('required')
->label('Port VLAN')
->help('port_vlan')
->callback(array($this, 'valid_port_vlan'))
->add_button('vlans');
$vlans = $vlan_model->get_all_vlans_by_port($port->id);
$tagged_vlans = $untagged_vlans = array();
foreach ($vlans as $vlan)
{
if ($vlan->tagged)
$tagged_vlans[] = $vlan->id;
else
$untagged_vlans[] = $vlan->id;
}
$form->dropdown('tagged_vlan_id[]')
->label(__('Tagged VLANs'))
->options($arr_vlans)
->selected($tagged_vlans)
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->dropdown('untagged_vlan_id[]')
->label(__('Untagged VLANs'))
->options($arr_vlans)
->selected($untagged_vlans)
->callback(array($this, 'valid_vlans'))
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->submit('Save');
special::required_forge_style($form, ' *', 'required');
if ($form->validate())
{
$form_data = $form->as_array();
try
{
$port->transaction_start();
$port->port_nr = $form_data['port_nr'];
$port->name = $form_data['name'];
$port->device_id = $form_data['device_id'];
$port->segment_id = $form_data['segment_id'];
$port->mode = $form_data['mode'];
$port->port_vlan_id = $form_data['port_vlan_id'];
$port->save_throwable();
$ports_vlans_model = new Ports_vlan_Model();
$ports_vlans = $ports_vlans_model
->where('port_id', $port_id)
->find_all();
foreach ($ports_vlans as $vlan)
$vlan->delete_throwable();
$vlans = new Ports_vlan_Model();
foreach ((array) $form_data['tagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = TRUE;
$vlans->save_throwable();
$vlans->clear();
}
foreach ((array) $form_data['untagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = FALSE;
$vlans->save_throwable();
$vlans->clear();
}
$port->transaction_commit();
status::success('Port has been successfully updated.');
$this->redirect('ports/show/'.$port->id);
}
catch (Exception $e)
{
$port->transaction_rollback();
status::error('Error - Cannot update port.');
$this->redirect('show_all');
}
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $port->device->user->member->id,
'ID ' . $port->device->user->member->id . ' - ' . $port->device->user->member->name,
$this->acl_check_view('Members_Controller', 'members', $port->device->user->member->id))
->enable_translation()
->link('users/show_by_member/' . $port->device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $port->device->user->member_id))
->disable_translation()
->link('users/show/' . $port->device->user->id,
$port->device->user->name . ' ' . $port->device->user->surname . ' (' . $port->device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $port->device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $port->device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $port->device->user->member_id))
->disable_translation()
->link('devices/show/' . $port->device->id . '#device_ports_link',
$port->device->name,
$this->acl_check_edit('Devices_Controller', 'devices', $port->device->user->member_id))
->link('devices/show_port/' . $port->id, $port->name,
$this->acl_check_view('Devices_Controller', 'port' ,$port->device->user->member_id))
->enable_translation()
->text('Edit');
$title = __('Edit port');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $title;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = $title;
$view->render(TRUE);
}
} // end of edit
/**
* Deletes port
*
* @author Michal Kliment
* @param type $port_id
*/
public function delete($port_id = null)
{
// bad parameter
if (!$port_id || !is_numeric ($port_id))
{
Controller::warning(PARAMETER);
}
// get the port
$port = new Port_Model($port_id);
// record doesn't exist
if (!$port->id)
{
Controller::error(RECORD);
}
// access control
if (!$this->acl_check_delete(
'Devices_Controller', 'port', $port->device->user->member_id
))
{
Controller::error(ACCESS);
}
try
{
$port->transaction_start();
$port->delete_throwable();
$port->transaction_commit();
status::success('Port has been successfully deleted.');
}
catch (Exception $e)
{
$port->transaction_rollback();
status::error('Error - cant delete port.');
}
$this->redirect('show_all');
}
/**
* Callback function to validate number of port
*
* @author Michal Kliment
* @param type $input
*/
public function valid_port_nr ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$value = trim($input->value);
if ($value != '' && $this->_device_id)
{
if ((!$this->port_nr || ($this->port_nr && $value != $this->port_nr)) &&
ORM::factory('port')->port_number_exists(
$value, $this->_device_id
))
{
$input->add_error('required', __('Port number already exist.'));
}
}
}
/**
* Callback function to validate tagged and untagged VLANs
*
* @author Michal Kliment
* @param type $input
*/
public function valid_vlans ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$tagged_vlans = (array) @$_POST['tagged_vlan_id'];
$untagged_vlans = (array) @$_POST['untagged_vlan_id'];
// VLAN can be only tagged or untagged
if (count(array_intersect($untagged_vlans, $tagged_vlans)) > 0)
{
$input->add_error('required', __('VLAN can be only tagged or untagged.'));
}
}
/**
* Callback function to validate port VLAN
*
* @author Michal Kliment
* @param type $input
*/
public function valid_port_vlan ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$port_vlan_id = $input->value;
$tagged_vlans = (array) @$_POST['tagged_vlan_id'];
$untagged_vlans = (array) @$_POST['untagged_vlan_id'];
$mode = $_POST['mode'];
switch($mode)
{
// port is in access mode
case Port_Model::PORT_MODE_ACCESS:
if (!in_array($port_vlan_id, $untagged_vlans))
{
$input->add_error('required', __('Port VLAN has to be in untagged VLANs.'));
}
break;
// port is in trunk mode
case Port_Model::PORT_MODE_TRUNK:
if (!in_array($port_vlan_id, $tagged_vlans))
{
$input->add_error('required', __('Port VLAN has to be in tagged VLANs.'));
}
break;
// port is in hybrid unart
case Port_Model::PORT_MODE_HYBRID:
if (!in_array($port_vlan_id, $untagged_vlans))
{
$input->add_error('required', __('Port VLAN has to be in untagged VLANs.'));
}
break;
}
}
/**
* Callback function to validate mode of port
*
* @author Michal Kliment
* @param type $input
*/
public function valid_mode ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$mode = $input->value;
$tagged_vlans = (array) @$_POST['tagged_vlan_id'];
$untagged_vlans = (array) @$_POST['untagged_vlan_id'];
switch($mode)
{
// port is in access mode
case Port_Model::PORT_MODE_ACCESS:
if (count($tagged_vlans) > 0)
{
$input->add_error('required', __('Port with access mode cannot contain tagged VLANs.'));
}
break;
// port is in trunk mode
case Port_Model::PORT_MODE_TRUNK:
if (count($untagged_vlans) > 0)
{
$input->add_error('required', __('Port with trunk mode cannot contain untagged VLANs.'));
}
break;
// port is in hybrid unart
case Port_Model::PORT_MODE_HYBRID:
break;
}
}
}
freenetis/branches/network/application/controllers/ifaces.php
))
{
$grid_ip_addresses->add_new_button(
'ip_addresses/add_to_iface/'.$iface->id, __('Add new IP address')
'ip_addresses/add/'.$iface->device_id.'/'.$iface->id,
'Add new IP address'
);
}
......
$actions = $grid_ip_addresses->grouped_action_field();
if ($this->acl_check_view(
'Devices_Controller','ip_address',$iface->device->user->member_id))
'Devices_Controller', 'ip_address',
$iface->device->user->member_id
))
{
$actions->add_action()
->icon_action('show')
......
}
if ($this->acl_check_edit(
'Devices_Controller','ip_address',$iface->device->user->member_id))
'Devices_Controller', 'ip_address',
$iface->device->user->member_id
))
{
$actions->add_action()
->icon_action('edit')
......
}
if ($this->acl_check_delete(
'Devices_Controller','ip_address',$iface->device->user->member_id))
'Devices_Controller', 'ip_address',
$iface->device->user->member_id
))
{
$actions->add_action()
->icon_action('delete')
......
$detail = '';
switch ($iface->type) {
switch ($iface->type)
{
case Iface_Model::TYPE_WIRELESS:
$detail = new View('ifaces/detail');
$detail->ip_addresses = $grid_ip_addresses;
$detail = new View('ifaces/detail');
$detail->ip_addresses = $grid_ip_addresses;
break;
case Iface_Model::TYPE_ETHERNET:
$detail = new View('ifaces/detail');
$detail->ip_addresses = $grid_ip_addresses;
$detail = new View('ifaces/detail');
$detail->ip_addresses = $grid_ip_addresses;
break;
};
freenetis/branches/network/application/controllers/ip_addresses.php
protected $form;
/**
* @var array
*/
protected $arr_mask_by_id;
/**
* @var array
*/
protected $arr_net_by_id;
/**
* IP address ID
*
* @var integer
......
/**
* Adds new ip address to current interface.
* Adds new ip address to interface which may be selected in parameters.
*
* @param integer $device_id
* @param integer $device_id
*/
public function add($device_id = NULL)
public function add($device_id = NULL, $iface_id = NULL)
{
if (!$this->acl_check_new('Devices_Controller', 'ip_address'))
Controller::error(ACCESS);
$breadcrumbs = breadcrumbs::add();
if ($device_id)
{
......
if (!$device->id)
Controller::error(RECORD);
$arr_ifaces = array
(
NULL => '----- '.__('select interface').' -----'
) + $device->ifaces->select_list();
if (empty($iface_id))
{
$breadcrumbs->link(
'devices/show_all', 'Devices',
$this->acl_check_view('Devices_Controller', 'devices')
)->link(
'devices/show/' . $device->id, $device->name,
$this->acl_check_view('Devices_Controller', 'devices')
)->text('Add new IP address');
$arr_ifaces = array
(
NULL => '----- '.__('Select interface').' -----'
) + $device->ifaces->select_list();
$title = __('Add new IP address to device').' '.$device->name;
$link_back_url = 'devices/show/'.$device->id;
}
else
{
$iface = new Iface_Model($iface_id);
if (!$iface->id)
Controller::error(RECORD);
$iface_name = $iface->name . ' (' . $iface->mac . ')';
$breadcrumbs->link(
'ifaces/show_all', 'Interfaces',
$this->acl_check_view('Devices_Controller', 'ip_address')
)->link(
'ifaces/show/' . $iface->id, $iface_name,
$this->acl_check_view('Devices_Controller', 'iface')
)->text('Add new IP address');
$arr_ifaces = array
(
$iface->id => $iface->mac . ': ' . $iface->name
);
$title = __('Add new IP address to interface').' '.$iface_name;
$link_back_url = 'ifaces/show/'.$device->id;
}
$title = __('Add new IP address to device').' '.$device->name;
$link_back_url = 'devices/show/'.$device->id;
}
else
{
$breadcrumbs->link(
'ip_addresses/show_all', 'IP addresses',
$this->acl_check_view('Devices_Controller', 'ip_address')
)->disable_translation()
->text('Add new IP address');
$concat = "CONCAT(COALESCE(mac, ''), ': ', COALESCE(name, ''))";
$arr_ifaces = array
(
NULL => '----- '.__('select interface').' -----'
NULL => '----- '.__('Select interface').' -----'
) + ORM::factory('iface')->select_list('id', $concat, 'id');
$title = __('Add new IP address');
......
url::redirect($link_back_url);
}
// breadcrumbs menu
$breadcrumbs = breadcrumbs::add()
->link('ip_addresses/show_all', 'IP addresses',
$this->acl_check_view('Devices_Controller', 'ip_address'))
->disable_translation()
->text($title);
$view = new View('main');
$view->title = $title;
$view->breadcrumbs = $breadcrumbs->html();
......
$arr_ifaces = array
(
NULL => '----- '.__('select interface').' -----'
NULL => '----- '.__('Select interface').' -----'
) + $device->ifaces->select_list();
$arr_subnets = array
(
NULL => '----- '.__('select subnet').' -----'
NULL => '----- '.__('Select subnet').' -----'
) + ORM::factory('subnet')->select_list_by_net();
$arr_bool = array
......
}
$linkback = Path::instance()->previous();
if (url::slice(url_lang::uri($linkback),1,1) == 'show')
{
$linkback = 'ip_addresses/show_all';
......
}
}
/**
* Check ifaces
*
* @param object $input
*/
public function check_ifaces($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$method = $this->form->ip_address->method; // <FORM> method = POST, GET, ...
$iface_id = $this->input->$method('iface_id');
$vlan_iface_id = $input->value;
if ($iface_id && $vlan_iface_id)
{
$input->add_error('required', __('Select only one type of iface.'));
}
else if (!$iface_id && !$vlan_iface_id)
{
$input->add_error('required', __('Interface has not been selected.'));
}
}
}
freenetis/branches/network/application/controllers/export.php
*/
public function csv($content = null, $encoding = null, $id = null)
{
$encodings = array
(
'utf-8' => 'UTF-8',
'windows-1250' => 'WINDOWS-1250'
);
$form = new Forge(url::base().url::current(TRUE));
$encodings = array
(
'utf-8' => 'UTF-8',
'windows-1250' => 'WINDOWS-1250'
);
// display form only if required
$form_display = !isset($encodings[$encoding]);
if ($form_display)
{
$form = new Forge();
$form->set_attr('class', 'form nopopup');
$form->dropdown('encoding')
->options($encodings);
->options($encodings)
->selected($encoding);
$form->submit('Submit');
}
// form is validate
if ($form->validate())
// form is validate
if (!$form_display || $form->validate())
{
if ($form_display)
{
$form_data = $form->as_array();
$encoding = $form_data['encoding'];
// each content has specific query
switch ($content)
{
// export for members with filter
case 'members':
}
if (!$this->acl_check_view('Members_Controller', 'members'))
{
Controller::error(ACCESS);
}
// each content has specific query
switch ($content)
{
// export for members with filter
case 'members':
$filter_form = new Filter_form('m');
$filter_form->autoload();
if (!$this->acl_check_view('Members_Controller', 'members'))
{
Controller::error(ACCESS);
}
$member = new Member_Model();
$filter_form = new Filter_form('m');
$filter_form->autoload();
try
{
$items = $member->get_all_members_to_export($filter_form->as_sql());
}
catch (Exception $e)
{
$items = array();
}
$member = new Member_Model();
$filename = __('Members') . '.csv';
try
{
$items = $member->get_all_members_to_export($filter_form->as_sql());
}
catch (Exception $e)
{
$items = array();
}
break;
$filename = __('Members') . '.csv';
// export for items of subnet
case 'subnets':
break;
$subnet_model = new Subnet_Model($id);
if ($subnet_model->id == 0)
{
Controller::error(RECORD);
}
if (!$this->acl_check_view('Devices_Controller', 'subnet'))
{
Controller::error(ACCESS);
}
$items = $subnet_model->get_items_of_subnet($id);
$filename = $subnet_model->name . '.csv';
// export for items of subnet
case 'subnets':
break;
$subnet_model = new Subnet_Model($id);
// auto export for all tables
default:
if ($subnet_model->id == 0)
{
Controller::error(RECORD);
}
if (!$this->acl_check_view('Settings_Controller', 'system'))
{
Controller::error(ACCESS);
}
if (!$this->acl_check_view('Devices_Controller', 'subnet'))
{
Controller::error(ACCESS);
}
if (empty($content))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
$items = $subnet_model->get_items_of_subnet($id);
$filename = $subnet_model->name . '.csv';
$filename = __(utf8::ucfirst($content)) . '.csv';
break;
$content = inflector::singular($content);
// auto export for all tables
default:
if (!Kohana::auto_load($content . '_Model'))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
if (!$this->acl_check_view('Settings_Controller', 'system'))
{
Controller::error(ACCESS);
}
try
{
$all = ORM::factory($content)->find_all();
$items = array();
if (empty($content))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
foreach ($all as $one)
{
$items[] = $one->as_array();
}
$filename = __(utf8::ucfirst($content)) . '.csv';
unset($all);
}
catch (Exception $e)
$content = inflector::singular($content);
if (!Kohana::auto_load($content . '_Model'))
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
}
try
{
$all = ORM::factory($content)->find_all();
$items = array();
foreach ($all as $one)
{
Controller::warning(PARAMETER, __('Bad parameter for export'));
$items[] = $one->as_array();
}
break;
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff