Revize 202
Přidáno uživatelem Michal Kliment před více než 15 roky(ů)
freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'id' => 'ID',
|
||
'iface name' => 'Název rozhraní',
|
||
'iface' => 'Rozhraní',
|
||
'iface has not been selected' => 'Rozhraní nebylo vybráno.',
|
||
'ifaces' => 'Rozhraní',
|
||
'in database can be only one infrastructure account' => 'V databázi může být pouze jeden účet infrastruktury.',
|
||
'in database can be only one master bank account' => 'V databázi může být pouze jeden hlavní bankovní účet',
|
||
... | ... | |
'select device' => 'Vyber zařízení',
|
||
'select interface' => 'Vyber rozhraní',
|
||
'select only one subnet' => 'Vyberte jen jednu podsíť.',
|
||
'select only one type of iface' => 'Vyberte jen jeden typ rozhraní.',
|
||
'select port' => 'Vyber port',
|
||
'select segment' => 'Vyber segment',
|
||
'select subnet name' => 'Vyber jméno podsítě',
|
freenetis/trunk/kohana/application/models/ip_address.php | ||
---|---|---|
<?php
|
||
class Ip_address_Model extends ORM {
|
||
|
||
<?php
|
||
class Ip_address_Model extends ORM {
|
||
|
||
protected $belongs_to = array('iface','subnet','vlan_iface');
|
||
|
||
public $arr_sql = array('segment_name'=>'s.name','device_name'=>'d.name','user'=>'concat(u.name,\' \',u.surname)');
|
||
|
||
public function count_all_ip_addresses($filter_values = array())
|
||
{
|
||
$where = '';
|
||
if(count($filter_values)>0) $where .= 'where ';
|
||
foreach ($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='where ') $where .= ' and ';
|
||
$where .= $this->get_sql($key).' like \'%'.trim($value).'%\' collate utf8_general_ci';
|
||
}
|
||
}
|
||
|
||
$ip_addresses = self::$db->query('select ip.id, ip.IP_address, f.MAC, s.name as segment_name, d.name as device_name, concat(u.name,\' \',u.surname) as user_name from ip_addresses ip
|
||
left join ifaces f on ip.iface_id = f.id
|
||
left join segments s on f.segment_id = s.id
|
||
left join devices d on f.device_id = d.id
|
||
left join users u on d.user_id = u.id '.$where);
|
||
return count($ip_addresses);
|
||
}
|
||
|
||
public function get_all_ip_addresses($limit_from = 0, $limit_results = 50, $order_by = 'ip_addresses.id', $order_by_direction = 'ASC', $filter_values = array())
|
||
|
||
public function count_all_ip_addresses()
|
||
{
|
||
$where = '';
|
||
if(count($filter_values)>0) $where .= 'where ';
|
||
foreach ($filter_values as $key => $value)
|
||
{
|
||
if($key!='submit')
|
||
{
|
||
if($where!='where ') $where .= ' and ';
|
||
$where .= $this->get_sql($key).' like \'%'.trim($value).'%\' collate utf8_general_ci';
|
||
}
|
||
}
|
||
|
||
if ($order_by=='IP_address') $order_by = 'str2ip(IP_address)';
|
||
|
||
return self::$db->query('select ip.id, ip.IP_address, f.MAC, s.name as segment_name, d.name as device_name, concat(u.name,\' \',u.surname) as user_name from ip_addresses ip
|
||
left join ifaces f on ip.iface_id = f.id
|
||
left join segments s on f.segment_id = s.id
|
||
left join devices d on f.device_id = d.id
|
||
left join users u on d.user_id = u.id '
|
||
.$where.' order by '.$this->get_sql($order_by).' '.$order_by_direction.' limit '.$limit_from.','.$limit_results);
|
||
return self::$db->count_records('ip_addresses');
|
||
}
|
||
|
||
public function get_all_ip_addresses($limit_from = 0, $limit_results = 50, $order_by = 'ip_addresses.id', $order_by_direction = 'ASC')
|
||
{
|
||
return self::$db->query(' SELECT ifaces.name AS iface_name, vlan_ifaces.name AS vlan_iface_name,subnets.name as subnet_name, ip_addresses.* FROM ip_addresses
|
||
LEFT JOIN ifaces ON ifaces.id = ip_addresses.iface_id
|
||
LEFT JOIN vlan_ifaces ON vlan_ifaces.id = ip_addresses.VLAN_iface_id
|
||
LEFT JOIN subnets ON subnets.id=ip_addresses.subnet_id
|
||
ORDER BY '.$order_by.' '.$order_by_direction.' LIMIT '.$limit_from.','.$limit_results);
|
||
}
|
||
|
||
private function get_sql($key = NULL)
|
||
{
|
||
return (isset($this->arr_sql[$key])) ? $this->arr_sql[$key] : $key;
|
||
}
|
||
|
||
/**
|
||
* Returns count of records matching the given ip address. Used for test of existing ip address.
|
||
* @param $ip ip address
|
||
* @return unknown_type count of found ip addresses
|
||
*/
|
||
public function get_count($ip)
|
||
{
|
||
return self::$db->where('ip_address', $ip)->count_records('ip_addresses');
|
||
}
|
||
}
|
||
|
||
?>
|
||
}
|
||
|
||
?>
|
freenetis/trunk/kohana/application/controllers/vlan_ifaces.php | ||
---|---|---|
if(!$this->acl_check_view('Devices_Controller','vlan_iface',$member_id)) Controller::error(1);
|
||
|
||
$this->session->set('ssVlan_iface_id',$vlan_iface->id);
|
||
$this->session->del('ssIface_id');
|
||
|
||
//----------- list of IP ADDRESSES ---------------
|
||
$ip_model = new Ip_address_Model();
|
||
... | ... | |
//----- end EDIT --------------------------------------------------------------
|
||
//=============================================================================
|
||
}
|
||
?>
|
||
?>
|
freenetis/trunk/kohana/application/controllers/ip_addresses.php | ||
---|---|---|
protected $form;
|
||
protected $arr_mask_by_id;
|
||
protected $arr_net_by_id;
|
||
protected $ip_address_id;
|
||
|
||
function index()
|
||
{
|
||
... | ... | |
$url_array = explode('/', trim(url::current(), '/'));
|
||
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
|
||
unset($url_array);
|
||
|
||
//$query = $ip_model->select(array('ifaces.name as iface_name', 'vlan_ifaces.name as vlan_iface_name', 'ip_addresses.*'))->join('ifaces', 'ifaces.id = ip_addresses.iface_id')->join('vlan_ifaces', 'vlan_ifaces.id = ip_addresses.VLAN_iface_id')->orderby($order_by,$order_by_direction)->limit($limit_results,$sql_offset)->find_all();
|
||
/*$db = new Database;
|
||
$query = $db->query('SELECT ifaces.name AS iface_name, vlan_ifaces.name AS vlan_iface_name, ip_addresses.* FROM ip_addresses LEFT JOIN ifaces ON ifaces.id = ip_addresses.iface_id LEFT JOIN vlan_ifaces ON vlan_ifaces.id = ip_addresses.VLAN_iface_id ORDER BY id ASC LIMIT 0, 50');
|
||
*/
|
||
|
||
$filter=new Table_Form(url_lang::base()."ip_addresses/show_all", "get", array(
|
||
|
||
$query = $ip_model->get_all_ip_addresses($sql_offset, (int)$limit_results, $order_by, $order_by_direction);
|
||
|
||
$total_ip = $ip_model->count_all_ip_addresses();
|
||
|
||
new Table_Form_Item('text','IP_address','IP address'),
|
||
new Table_Form_Item('text','MAC','MAC'),
|
||
"tr",
|
||
new Table_Form_Item('text','segment_name','Segment name'),
|
||
new Table_Form_Item('text','device_name','Device name'),
|
||
"tr",
|
||
new Table_Form_Item('text','user','User'),
|
||
"tr",
|
||
"td",
|
||
new Table_Form_Item('submit','submit','Filter')
|
||
)
|
||
);
|
||
|
||
|
||
$query = $ip_model->get_all_ip_addresses($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values());
|
||
$total_ip = $ip_model->count_all_ip_addresses($filter->values());
|
||
|
||
$sql_offset = ($sql_offset>$total_ip) ? 0 : $sql_offset;
|
||
|
||
$grid = new Grid(url_lang::base().'ip_addresses', url_lang::lang('texts.IP addresses list'),array(
|
||
... | ... | |
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results,
|
||
'query_string' => $this->input->get()
|
||
//'query_string' => $this->input->get()
|
||
));
|
||
|
||
if ($this->acl_check_new('Devices_Controller','ip_address'))
|
||
$grid->add_new_button(url_lang::base().'ip_addresses/add', url_lang::lang('texts.Add new IP address'));
|
||
$grid->order_field('id')->label('ID')->class('center');
|
||
$grid->order_field('IP_address')->label(url_lang::lang('texts.ip addresses'));
|
||
//$grid->order_field('subnet_name')->label(url_lang::lang('texts.Subnet name'));
|
||
$grid->order_field('MAC')->label(url_lang::lang('texts.MAC'));
|
||
$grid->order_field('segment_name')->label(url_lang::lang('texts.Segment name'));
|
||
$grid->order_field('device_name')->label(url_lang::lang('texts.Device name'));
|
||
$grid->order_field('user_name')->label(url_lang::lang('texts.User'));
|
||
//$grid->order_field('vlan_iface_name')->label(url_lang::lang('texts.VLAN interface name'));
|
||
$grid->order_field('IP_address')->label(url_lang::lang('texts.ip addresses'));
|
||
$grid->order_field('iface_name')->label(url_lang::lang('texts.Interface name'));
|
||
$grid->order_field('vlan_iface_name')->label(url_lang::lang('texts.VLAN interface name'));
|
||
$grid->order_field('subnet_name')->label(url_lang::lang('texts.Subnet name'));
|
||
if ($this->acl_check_view('Devices_Controller','ip_address'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Show'))->url(url_lang::base().'ip_addresses/show')->action(url_lang::lang('texts.Show'))->class('center');
|
||
if ($this->acl_check_edit('Devices_Controller','ip_address'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Edit'))->url(url_lang::base().'ip_addresses/edit')->action(url_lang::lang('texts.Edit'))->class('center');
|
||
// to do - set access control
|
||
if ($this->acl_check_delete('Devices_Controller','ip_address'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'ip_addresses/delete')->action(url_lang::lang('texts.Delete'))->class('center');
|
||
$grid->datasource( $query );
|
||
... | ... | |
$view->header->title = url_lang::lang('texts.IP addresses list');
|
||
$view->header->menu = Controller::render_menu();
|
||
$view->content = new View('show_all');
|
||
$view->content->table = $filter->view.$grid;
|
||
$view->content->table = $grid;
|
||
$view->content->headline = '';
|
||
$view->footer = new View('base/footer');
|
||
$view->render(TRUE);
|
||
... | ... | |
{
|
||
$ip_address = new Ip_address_Model($ip_address_id);
|
||
|
||
$member_id = $ip_address->iface->device->user->member_id;
|
||
if ($ip_address->iface_id)
|
||
$member_id = $ip_address->iface->device->user->member_id;
|
||
else $member_id = $ip_address->vlan_iface->iface->device->user->member_id;
|
||
|
||
if (!isset($ip_address_id) || $ip_address->id == 0) {
|
||
Controller::warning(1);
|
||
... | ... | |
function add()
|
||
{
|
||
//---- Get variable for narrow selecting of selectbox ----
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
$ssIface_id = $this->session->get('ssIface_id');
|
||
$ssVlan_iface_id = $this->session->get('ssVlan_iface_id');
|
||
|
||
//---- Set global parameters for valid callback function ----
|
||
$this->iface_type = $this->input->post('iface_type');
|
||
$this->subnet_id = $this->input->post('subnet_id');
|
||
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
$ssIface_id = $this->session->get('ssIface_id');
|
||
$ssVlan_iface_id = $this->session->get('ssVlan_iface_id');
|
||
|
||
$this->form=$form = new Forge(url_lang::base()."ip_addresses/add/", '', 'POST', array('id' => 'article_form'));
|
||
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
$this->form = new Forge(url_lang::base()."ip_addresses/add", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$iface_model = new Iface_Model();
|
||
$vlan_iface_model = new Vlan_iface_Model();
|
||
|
||
$member_id = NULL;
|
||
$arr_ifaces = array();
|
||
$arr_vlan_ifaces = array();
|
||
|
||
if ($ssVlan_iface_id) {
|
||
$ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all_by_id($ssVlan_iface_id);
|
||
$default = 'VLAN';
|
||
if ($ssIface_id)
|
||
{
|
||
$ifaces = $iface_model->find_all_by_id($ssIface_id);
|
||
$vlan_ifaces = array();
|
||
$member_id = $ifaces->current()->device->user->member_id;
|
||
}
|
||
elseif ($ssIface_id) {
|
||
$ifaces = $iface_model->orderby('name')->find_all_by_id($ssIface_id);
|
||
$default = 'iface';
|
||
foreach($ifaces as $iface) $member_id = $iface->device->user->member_id;
|
||
else if ($ssVlan_iface_id)
|
||
{
|
||
$ifaces = array();
|
||
$vlan_ifaces = $vlan_iface_model->find_all_by_id($ssVlan_iface_id);
|
||
$member_id = $vlan_ifaces->current()->iface->device->user->member_id;
|
||
}
|
||
else {
|
||
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
|
||
else
|
||
{
|
||
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
|
||
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
|
||
|
||
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
|
||
$arr_vlan_ifaces[0] = '----- '.url_lang::lang('texts.select vlan interface').' -----';
|
||
}
|
||
|
||
|
||
if (!$this->acl_check_new('Devices_Controller', 'ip_address',$member_id)) Controller::error(1);
|
||
|
||
foreach ($ifaces as $iface) {
|
||
$arr_ifaces[$iface->id] = $iface->name;
|
||
}
|
||
|
||
foreach ($vlan_ifaces as $vlan_iface) {
|
||
$arr_vlan_ifaces[$vlan_iface->id] = $vlan_iface->name;
|
||
}
|
||
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model
|
||
->select("id","name","network_address as net_str",
|
||
"inet_aton(network_address) as net",
|
||
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
|
||
->orderby('name')->find_all();
|
||
$arr_subnets_netnames[]=$arr_subnets_names[] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
$arr_subnets_ids[]=$arr_subnets_masks[]=$arr_subnets_nets[]=0;
|
||
foreach ($subnets as $subnet) {
|
||
$arr_subnets_names[$subnet->id] = $subnet->name . ": ". $subnet->net_str."/".$subnet->mask;
|
||
$this->arr_mask_by_id[$subnet->id]=$subnet->mask;
|
||
$this->arr_net_by_id[$subnet->id]=$subnet->net;
|
||
$arr_subnets_nets[] = $subnet->net;
|
||
$arr_subnets_masks[] = $subnet->mask;
|
||
$arr_subnets_netnames[] = $subnet->net_str."/".$subnet->mask.": ".$subnet->name ;
|
||
$arr_subnets_ids[]=$subnet->id;
|
||
->orderby('net')->find_all();
|
||
|
||
$arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
|
||
foreach ($subnets as $subnet)
|
||
{
|
||
$arr_subnets[$subnet->id] = $subnet->net_str.'/'.$subnet->mask.': '.$subnet->name;
|
||
}
|
||
|
||
array_multisort($arr_subnets_nets, SORT_NUMERIC, SORT_ASC,
|
||
$arr_subnets_masks, SORT_NUMERIC, SORT_ASC,
|
||
$arr_subnets_ids, SORT_NUMERIC, SORT_ASC,
|
||
$arr_subnets_netnames, SORT_STRING, SORT_ASC);
|
||
|
||
$arr_subnets_ips=array_combine($arr_subnets_ids, $arr_subnets_netnames);
|
||
//$form->group('')->label(url_lang::lang('texts.IP addresses'));
|
||
//$form->radio('iface_type')->label(url_lang::lang('texts.IP address').':')->rules('required|length[3,250]');
|
||
|
||
if (!$ssIface_id && !$ssVlan_iface_id) {
|
||
$form->radio('iface_type')->label(url_lang::lang('texts.Interface type').':')->options(array('iface'=>url_lang::lang('texts.Basic').' ','VLAN'=>url_lang::lang('texts.VLAN')))->default('iface')->onchange('ajax_get_ifaces(this.value)');
|
||
}
|
||
else {
|
||
$form->hidden('iface_type')->value($default);
|
||
}
|
||
$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name').':')
|
||
->options($arr_ifaces)
|
||
->rules('required');
|
||
//->class('ajax')->callback(array($this, 'callback_iface_selected'));
|
||
$form->input('IP_address')->label(url_lang::lang('texts.IP address').':')
|
||
if (count($arr_ifaces))
|
||
$this->form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name').':')->options($arr_ifaces)->selected($ssIface_id);
|
||
|
||
if (count($arr_vlan_ifaces))
|
||
$this->form->dropdown('vlan_iface_id')->label(url_lang::lang('texts.VLAN interface name').':')->options($arr_vlan_ifaces)->selected($ssVlan_iface_id)->callback(array($this, 'check_ifaces'));
|
||
|
||
$this->form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required')
|
||
->callback(array($this, 'valid_ip'));
|
||
|
||
|
||
$form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name').':')
|
||
->options($arr_subnets_names);
|
||
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name').':')
|
||
->options($arr_subnets)
|
||
->rules('required');
|
||
//->class('ajax')->onchange('ajax_get_subnet(this.value)');
|
||
$form->group('')->label(url_lang::lang('texts.or'));
|
||
$form->dropdown('subnet_id2')->label(url_lang::lang('texts.Select subnet IP').':')
|
||
->options($arr_subnets_ips);
|
||
|
||
/**
|
||
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
|
||
... | ... | |
$form->input('subnet_ospf_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit')->callback(array($this, 'callback_subnet_selected'));
|
||
*/
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($form->validate())
|
||
if($this->form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
$form_data = $this->form->as_array();
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
... | ... | |
|
||
$ip = new Ip_address_Model();
|
||
|
||
if ($form_data['iface_type'] == 'iface') {
|
||
if (isset($form_data['iface_id']))
|
||
$ip->iface_id = $form_data['iface_id'];
|
||
$ip->vlan_iface_id = null;
|
||
}
|
||
else {
|
||
$ip->iface_id = null;
|
||
$ip->vlan_iface_id = $form_data['iface_id'];
|
||
}
|
||
|
||
if (isset($form_data['vlan_iface_id']))
|
||
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
|
||
|
||
$ip->IP_address = $form_data['IP_address'];
|
||
|
||
if ($subnet_id = $form_data['subnet_id']) {
|
||
$ip->subnet_id = $subnet_id;
|
||
}
|
||
$ip->subnet_id = $form_data['subnet_id'];
|
||
/**
|
||
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
|
||
else {
|
||
... | ... | |
if ($ip->save())
|
||
{
|
||
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
|
||
if ((bool)$ip->vlan_iface_id) url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
|
||
elseif ($ssIface_id) url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
|
||
if ((bool)$ssVlan_iface_id) url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
|
||
else if ($ssIface_id) url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
|
||
else url::redirect(url_lang::base().'ip_addresses/show_all');
|
||
exit;
|
||
}
|
||
... | ... | |
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('form');
|
||
$view->content->form = $form->html();
|
||
$view->content->form = $this->form->html();
|
||
$view->content->link_back = $link_back;
|
||
$view->content->headline = url_lang::lang('texts.Create new IP address');
|
||
|
||
... | ... | |
* @param $ip_address_id id of ipaddress to edit
|
||
* @return unknown_type
|
||
*/
|
||
function edit($ip_address_id = null)
|
||
/*function edit($ip_address_id = null)
|
||
{
|
||
//---- Get variable for narrow selecting of selectbox ----
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
... | ... | |
if($ip_address->iface->id) $member_id = $ip_address->iface->device->user->member_id;
|
||
else if ($ip_address->vlan_iface->id) $member_id = $ip_address->vlan_iface->iface->device->user->member_id;
|
||
|
||
$this->ip_address_id = $ip_address_id;
|
||
|
||
if (!$this->acl_check_edit('Devices_Controller', 'ip_address', $member_id)) Controller::error(1);
|
||
|
||
$form = new Forge(url_lang::base()."ip_addresses/edit/".$ip_address_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form = $form = new Forge(url_lang::base()."ip_addresses/edit/".$ip_address_id, '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
|
||
... | ... | |
$selected = $ip_address->iface_id;
|
||
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
|
||
}
|
||
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
|
||
//$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
|
||
}
|
||
|
||
foreach ($ifaces as $iface) {
|
||
$arr_ifaces[$iface->id] = $iface->name;
|
||
}
|
||
|
||
/*$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model->select('id','name')->orderby('name')->find_all();
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model->select('id','name')->orderby('name')->find_all();
|
||
$arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
foreach ($subnets as $subnet) {
|
||
$arr_subnets[$subnet->id] = $subnet->name;
|
||
}
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model
|
||
->select("id","name","network_address as net_str",
|
||
"inet_aton(network_address) as net",
|
||
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
|
||
->orderby('net')->find_all();
|
||
|
||
$arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
|
||
foreach ($subnets as $subnet)
|
||
{
|
||
$arr_subnets[$subnet->id] = $subnet->net_str.'/'.$subnet->mask.': '.$subnet->name;
|
||
}
|
||
|
||
|
||
|
||
$form->group('')->label(url_lang::lang('texts.IP addresses'));
|
||
|
||
if (!$ssIface_id && !$ssVlan_iface_id)
|
||
... | ... | |
$form->hidden('iface_type')->value($default);
|
||
}
|
||
|
||
|
||
|
||
$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name'))->options($arr_ifaces)->rules('required');
|
||
// old version not functional - callback function callback_iface_selected not defined
|
||
//$form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name'))->options($arr_ifaces)->rules('required')->selected($selected)->class('ajax')->callback(array($this, 'callback_iface_selected'));
|
||
|
||
// new version, not functional, problems with somewhere in callback, cannot debug
|
||
$form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required|valid_ip')->value($ip_address->IP_address)->callback(array($this, 'valid_ip'));
|
||
//$form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required|valid_ip')->value($ip_address->IP_address)->callback(array($this, 'valid_ip'));
|
||
// old version, functional
|
||
//$form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->value($ip_address->IP_address)->rules('required|valid_ip');
|
||
$form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->value($ip_address->IP_address)->rules('required|valid_ip')->callback(array($this, 'valid_ip'));
|
||
|
||
$form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name'))->options($arr_subnets)->rules('required')->selected($ip_address->subnet_id);
|
||
//$form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name'))->options($arr_subnets)->rules('required')->selected($ip_address->subnet_id);
|
||
$form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name'))->options($arr_subnets)->rules('required')->selected($ip_address->subnet_id);
|
||
|
||
/*$form->input('subnet_name')->label(url_lang::lang('texts.Subnet name').':')->rules('length[3,250]');
|
||
$form->input('subnet_network_address')->label(url_lang::lang('texts.Subnet network address').':')->rules('length[3,250]');
|
||
$form->input('subnet_netmask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('length[3,250]');
|
||
*/
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($form->validate())
|
||
{
|
||
... | ... | |
exit;
|
||
}
|
||
|
||
} else { //not valid
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
// end validate --------------------------------------------------
|
||
|
||
|
||
if ($ssVlan_iface_id) $link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$ssVlan_iface_id, url_lang::lang('texts.Back to VLAN interface parameters'));
|
||
elseif ($ssIface_id) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$ssIface_id, url_lang::lang('texts.Back to interface parameters'));
|
||
else $link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
|
||
|
||
|
||
|
||
$view = new View('template');
|
||
|
||
$view->header = new View('base/header');
|
||
... | ... | |
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
|
||
} // end of edit function
|
||
*/
|
||
|
||
|
||
function edit($ip_address_id = NULL)
|
||
{
|
||
$ip_address = new Ip_address_Model($ip_address_id);
|
||
|
||
if (!isset($ip_address_id) || $ip_address->id == 0) {
|
||
Controller::warning(1);
|
||
}
|
||
|
||
$this->form = new Forge(url_lang::base()."ip_addresses/edit/".$ip_address_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$iface_model = new Iface_Model();
|
||
$vlan_iface_model = new Vlan_iface_Model();
|
||
|
||
$member_id = NULL;
|
||
$arr_ifaces = array();
|
||
$arr_vlan_ifaces = array();
|
||
|
||
$iface_selected = $ip_address->iface_id;
|
||
$vlan_iface_selected = $ip_address->vlan_iface_id;
|
||
|
||
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
|
||
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
|
||
|
||
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
|
||
$arr_vlan_ifaces[0] = '----- '.url_lang::lang('texts.select vlan interface').' -----';
|
||
|
||
//if (!$this->acl_check_new('Devices_Controller', 'ip_address',$member_id)) Controller::error(1);
|
||
|
||
foreach ($ifaces as $iface) {
|
||
$arr_ifaces[$iface->id] = $iface->name;
|
||
}
|
||
|
||
foreach ($vlan_ifaces as $vlan_iface) {
|
||
$arr_vlan_ifaces[$vlan_iface->id] = $vlan_iface->name;
|
||
}
|
||
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model
|
||
->select("id","name","network_address as net_str",
|
||
"inet_aton(network_address) as net",
|
||
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
|
||
->orderby('net')->find_all();
|
||
|
||
$arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
|
||
foreach ($subnets as $subnet)
|
||
{
|
||
$arr_subnets[$subnet->id] = $subnet->net_str.'/'.$subnet->mask.': '.$subnet->name;
|
||
}
|
||
|
||
$this->form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name').':')->options($arr_ifaces)->selected($iface_selected);
|
||
|
||
$this->form->dropdown('vlan_iface_id')->label(url_lang::lang('texts.VLAN interface name').':')->options($arr_vlan_ifaces)->selected($vlan_iface_selected)->callback(array($this, 'check_ifaces'));
|
||
|
||
$this->form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required')
|
||
->callback(array($this, 'valid_ip'));
|
||
|
||
|
||
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name').':')
|
||
->options($arr_subnets)
|
||
->rules('required');
|
||
//->class('ajax')->onchange('ajax_get_subnet(this.value)');
|
||
|
||
/**
|
||
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
|
||
* @todo Proper Ajax should be implemented - see http://learn.kohanaphp.com/2008/06/17/jquery-and-kohana-unobtrusive-ajax/
|
||
*
|
||
$form->group('')->label(url_lang::lang('texts.Subnet data'));
|
||
$form->input('subnet_name')->label(url_lang::lang('texts.Subnet name').':')->rules('required|length[3,250]')->callback(array($this, 'callback_subnet_selected'));
|
||
$form->input('subnet_network_address')->label(url_lang::lang('texts.Subnet network address').':')->rules('required|valid_ip')->callback(array($this, 'callback_subnet_selected'));
|
||
$form->input('subnet_netmask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('required')->callback(array($this, 'callback_subnet_selected'));
|
||
$form->input('subnet_ospf_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit')->callback(array($this, 'callback_subnet_selected'));
|
||
*/
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate())
|
||
{
|
||
$form_data = $this->form->as_array();
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
$ip = new Ip_address_Model();
|
||
|
||
if (isset($form_data['iface_id']))
|
||
$ip->iface_id = $form_data['iface_id'];
|
||
|
||
if (isset($form_data['vlan_iface_id']))
|
||
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
|
||
|
||
$ip->IP_address = $form_data['IP_address'];
|
||
|
||
$ip->subnet_id = $form_data['subnet_id'];
|
||
/**
|
||
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
|
||
else {
|
||
$subnet = new Subnet_Model();
|
||
|
||
$subnet->name = $form_data['subnet_name'];
|
||
$subnet->network_address = $form_data['subnet_network_address'];
|
||
$subnet->netmask = $form_data['subnet_netmask'];
|
||
$subnet->OSPF_area_id = $form_data['subnet_ospf_area_id'];
|
||
|
||
if ($subnet->save()) $ip->subnet_id = $subnet->id;
|
||
|
||
}
|
||
*/
|
||
unset($form_data);
|
||
|
||
if ($ip->save())
|
||
{
|
||
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
|
||
if ((bool)$ssVlan_iface_id) url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
|
||
else if ($ssIface_id) url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
|
||
else url::redirect(url_lang::base().'ip_addresses/show_all');
|
||
exit;
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
//$form->IP_address->value("ahoj"); //demo of how to fill a field after validation error
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
if ($vlan_iface_selected) $link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$vlan_iface_selected, url_lang::lang('texts.Back to VLAN interface parameters'));
|
||
elseif ($iface_selected) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$iface_selected, url_lang::lang('texts.Back to interface parameters'));
|
||
else $link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
|
||
|
||
|
||
$view = new View('template');
|
||
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('form');
|
||
$view->content->form = $this->form->html();
|
||
$view->content->link_back = $link_back;
|
||
$view->content->headline = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
|
||
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
} // end of add functi
|
||
|
||
/**
|
||
* to do - comment
|
||
* @param $acc_id
|
||
* @return unknown_type
|
||
*/
|
||
function delete($acc_id = NULL)
|
||
function delete($ip_address_id = NULL)
|
||
{
|
||
// to do - correct access control for this action
|
||
//if (!$this->gacl_class->acl_check('freenetis', 'delete_own', 'all', $_SESSION['username'],get_class($this),'delete_accounts')) Controller::error(1);
|
||
|
||
$ip_address = new Ip_address_Model($ip_address_id);
|
||
|
||
if (isset($acc_id))
|
||
if ($ip_address->id) // IP adress exists
|
||
{
|
||
// identify the owner of IP_address
|
||
if ($ip_address->iface_id) $member_id = $ip_address->iface->device->user->member_id;
|
||
else $member_id = $ip_address->vlan_iface->iface->device->user->member_id;
|
||
|
||
if (!$this->acl_check_delete('Devices_Controller', 'ip_address',$member_id)) Controller::error(1);
|
||
|
||
$ssIface_id = $this->session->get('ssIface_id');
|
||
$ssVlan_iface_id = $this->session->get('ssVlan_iface_id');
|
||
$model_ip = new Ip_address_Model($acc_id);
|
||
$iface = $model_ip->iface_id;
|
||
$model_ip->delete();
|
||
|
||
$ip_address->delete();
|
||
$this->session->set_flash('message', url_lang::lang('texts.IP address has been deleted.'));
|
||
//url::redirect(url_lang::base().'ifaces/show/'.(int)$iface);
|
||
|
||
if ($ssVlan_iface_id)
|
||
$link_back = url_lang::base().'vlan_ifaces/show/'.$ssVlan_iface_id;
|
||
elseif ($ssIface_id)
|
||
... | ... | |
else
|
||
$link_back = url_lang::base().'ip_addresses/show_all';
|
||
url::redirect($link_back);
|
||
|
||
}
|
||
|
||
else
|
||
{
|
||
Controller::warning(1);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
... | ... | |
function valid_ip($input)
|
||
{
|
||
$method=$this->form->IP_address->method; // <FORM> method = POST, GET, ...
|
||
$ip=ip2long($this->input->$method('IP_address')); // Submitted values
|
||
$ip=ip2long($this->input->$method('IP_address')); // Submitted values;
|
||
|
||
$subnet_id=$this->input->$method('subnet_id');
|
||
$subnet_id2=$this->input->$method('subnet_id2');
|
||
|
||
if ($subnet_id==0 && $subnet_id2==0) { // subnet was not selected
|
||
if ($ip > 0) // try to find a subnet matching to the ip
|
||
$input->add_error('required', url_lang::lang('texts.Subnet has not been selected.'));
|
||
else
|
||
$input->add_error('required', url_lang::lang('texts.Invalid IP address'));
|
||
|
||
if ($ip <= 0)
|
||
{ // invalid IP adress
|
||
$input->add_error('required', url_lang::lang('texts.Invalid IP address'));
|
||
return false;
|
||
}
|
||
|
||
$subnet_model = new Subnet_Model();
|
||
$subnet = $subnet_model->
|
||
select("inet_aton(network_address) as net", "32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")->
|
||
where('id',$subnet_id)->
|
||
find();
|
||
|
||
$this->check_ip($ip, $subnet->net, $subnet->mask, $input);
|
||
|
||
} else if ($subnet_id==0) $subnet_id=$subnet_id2;
|
||
else if ($subnet_id2==0);
|
||
else if ($subnet_id != $subnet_id2)
|
||
$input->add_error('required', url_lang::lang('texts.Select only one subnet.'));
|
||
|
||
$subnet=$this->arr_net_by_id[$subnet_id];
|
||
$mask=$this->arr_mask_by_id[$subnet_id];
|
||
|
||
if ($ip > 0 )
|
||
$this->check_ip($ip, $subnet, $mask, $input);
|
||
else
|
||
$input->add_error('required', url_lang::lang('texts.IP address is required.'));
|
||
|
||
|
||
// checks if exists this ip
|
||
$ip_model = new Ip_address_Model();
|
||
if ($ip_model->get_count($this->input->$method('IP_address')) > 0)
|
||
|
||
$ips = $ip_model->where('IP_address',$input->value)->find_all();
|
||
|
||
foreach ($ips as $ip)
|
||
{
|
||
$input->add_error('required', url_lang::lang('texts.IP address already exists.'));
|
||
if ($this->ip_address_id != $ip->id) // only for edit: check if ip_address is not still same
|
||
$input->add_error('required', url_lang::lang('texts.IP address already exists.'));
|
||
}
|
||
} // end of valid_ip
|
||
|
||
... | ... | |
{
|
||
$mask=0xffffffff<<(32-$mask) & 0xffffffff;
|
||
//printf(" ip=%lx, net=%lx, mask=%lx, AND=%lx", $ip, $net, $mask, $ip & $mask);
|
||
if (($ip & $mask) != $net)
|
||
if (($ip & $mask) != $net)
|
||
{
|
||
$input->add_error('required', url_lang::lang('texts.IP address does not match the subnet/mask.'));
|
||
}
|
||
else if ($ip==$net || $ip==($net | ~$mask))
|
||
$input->add_error('required', url_lang::lang('texts.Invalid IP address'));
|
||
}
|
||
|
||
function check_ifaces($input)
|
||
{
|
||
$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', url_lang::lang('texts.Select only one type of iface.'));
|
||
else if (!$iface_id && !$vlan_iface_id)
|
||
$input->add_error('required', url_lang::lang('texts.Iface has not been selected.'));
|
||
}
|
||
|
||
/**
|
||
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
|
||
|
freenetis/trunk/kohana/application/libraries/MY_Controller.php | ||
---|---|---|
|
||
|
||
/**
|
||
* Function checks access rights for
|
||
* -currently logged user (stored in $_SESSION['username'])
|
||
* -view operation in controller name passed in $axo_section, identified by $axo_value.
|
||
* Fuction checks access rights
|
||
* Return true if currently logged user (stored in $_SESSION['username']) may view own $axo_value object in $axo_section (and in variable $member_id is his own id of member)
|
||
* or if currently logged user may view all $axo_value object in $axo_section else return false
|
||
*
|
||
* @param $axo_section
|
||
* @param $axo_value
|
||
* @param $member_id
|
||
* @return unknown_type
|
||
* @param $axo_section group of objects to view
|
||
* @param $axo_value object to view
|
||
* @param $member_id optional variable, id of other member who is being showed by logged member
|
||
* @return boolean returns true if member has enough access rights
|
||
*/
|
||
public function acl_check_view($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
... | ... | |
if ($this->gacl_class->acl_check('freenetis', 'new_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
return $return;
|
||
}
|
||
|
||
public function acl_check_delete($axo_section, $axo_value, $member_id = NULL)
|
||
{
|
||
$return = false;
|
||
if (!isset($this->gacl_class)) $this->phpgacl_init();
|
||
if($member_id==$_SESSION['member_id'])
|
||
{
|
||
if ($this->gacl_class->acl_check('freenetis', 'delete_own', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
}
|
||
if ($this->gacl_class->acl_check('freenetis', 'delete_all', 'all', $_SESSION['username'],$axo_section,$axo_value)) $return = true;
|
||
return $return;
|
||
}
|
||
|
||
/* public function do_something(){
|
||
//method available in all controllers
|
freenetis/trunk/kohana/system/libraries/Database.php | ||
---|---|---|
foreach ($fields as $field => $match)
|
||
{
|
||
$field = (strpos($field, '.') !== FALSE) ? $this->config['table_prefix'].$field : $field;
|
||
$this->where[] = $this->driver->like($field, $match, 'AND ', count($this->where));
|
||
$this->where[] = $this->driver->like($field, $match, 'AND ', count($this->where)).' collate utf8_general_ci';
|
||
}
|
||
|
||
return $this;
|
Také k dispozici: Unified diff
Upraven kontroler pro IP adresy, zbyva dodelat funkci pro editaci. Mensi
uprava systemove databazove funkce like() - nyni porovnava podle
utf8_general_ci, tedy bez diakritiky.