Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1450

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

Upravy:
- neotestovane ukladani zarizeni (#185)
- vyplnovani linku ve formulari pro pridani zarizeni (#185)
- kontrola zda neexistuje jiz IP v adrese a dalsi validatory pro pridani zarizeni (#185)

Zobrazit rozdíly:

freenetis/branches/network/application/helpers/valid.php
return TRUE;
}
/**
* Checks ip address if matches subnet and mask.
*
* @param long $ip
* @param integer $net
* @param integer $mask
* @return bool
*/
public static function ip_check_subnet($ip, $net, $mask)
{
$mask = 0xffffffff << (32 - $mask) & 0xffffffff;
if (($ip & $mask) != (int) $net)
{
return false; // IP address does not match the subnet/mask
}
else if ($ip == $net || ($ip == ($net | ~$mask)) && ~$mask != 0)
{
return false; // Invalid IP address
}
return true;
}
/**
* Validates a credit card number using the Luhn (mod10) formula.
freenetis/branches/network/application/controllers/ip_addresses.php
'filter' => $filter_form
));
if ($this->acl_check_new('Devices_Controller','ip_address'))
if ($this->acl_check_new('Devices_Controller', 'ip_address'))
{
$grid->add_new_button('ip_addresses/add', __('Add new IP address'));
}
freenetis/branches/network/application/controllers/json.php
echo json_encode($contacts);
}
/**
* Performs action of ip_address_check jQuery frm validator.
*
* @author Ondrej Fibich
*/
public function ip_address_check()
{
$edit_id = intval($this->input->get('ip_address_id', 0));
$subnet_id = intval($this->input->get('subnet_id'), 0);
$ip_str = trim($this->input->get('ip_address'));
if (!$subnet_id && !$ip_str)
{
die(json_encode(array('state' => true)));
}
$ip_model = new Ip_address_Model();
$subnet_model = new Subnet_Model($subnet_id);
if (!$subnet_model || !$subnet_model->id)
{
die(json_encode(array
(
'state' => false,
'message' => __('Subnet not exists.')
)));
}
$subnet = $subnet_model->get_net_and_mask_of_subnet();
// checks mask
if (!valid::ip_check_subnet(ip2long($ip_str), $subnet->net + 0, $subnet->mask))
{
die(json_encode(array
(
'state' => false,
'message' => __('IP address does not match the subnet/mask.')
)));
}
// checks if exists this ip in database
$ips = $ip_model->where(array
(
'ip_address' => $ip_str,
'member_id' => NULL
))->find_all();
foreach ($ips as $ip)
{
// only for edit: check if ip_address is not still same
if ($edit_id && ($edit_id != $ip->id))
{
die(json_encode(array
(
'state' => false,
'message' => __('IP address already exists.')
)));
}
}
echo json_encode(array('state' => true));
}
/**
* Callback AJAX function to filter's whisper for iface MAC address
*
......
}
/**
* Callback AJAX function to return link by iface id
*
* @author Ondřej Fibich
*/
public function get_links_by_iface()
{
$iface = new Iface_Model($this->input->get('iface_id'));
if ($iface->id && $iface->link_id)
{
die(json_encode($iface->link->as_array()));
}
else
{
die(json_encode(null));
}
}
/**
* Callback AJAX function to return links by given iface's type
*
* @TODO
freenetis/branches/network/application/controllers/devices.php
Controller::error(ACCESS);
}
$user_model = new User_Model();
$device_model = new Device_Model();
// if the device is added to given user, then only one user will be to select
// $selected_device = 0;
$selected_engineer = $this->session->get('user_id');
$gpsx = '';
......
if (isset($user_id))
{
$user = new User_Model($user_id);
$user_model = new User_Model($user_id);
if ($user->id == 0)
if (!$user_model->id)
{
Controller::error(RECORD);
}
if (!$this->acl_check_new('Devices_Controller', 'devices', $user->member_id))
Controller::error(ACCESS);
$selected = $user_model->id;
$selected_country_id = $user_model->member->address_point->country_id;
$selected_street_id = $user_model->member->address_point->street_id;
$selected_street_number = $user_model->member->address_point->street_number;
$selected_town_id = $user_model->member->address_point->town_id;
$gps = $user_model->member->address_point->get_gps_coordinates();
$selected = $user->id;
$selected_country_id = $user->member->address_point->country_id;
$selected_street_id = $user->member->address_point->street_id;
$selected_street_number = $user->member->address_point->street_number;
$selected_town_id = $user->member->address_point->town_id;
$gps = $user->member->address_point->get_gps_coordinates();
$link_model = new Link_Model();
// $found_segment = $link_model->get_link_of_user($user->id);
if ($gps)
{
$gpsx = gps::real2degrees($gps->gpsx, FALSE);
$gpsy = gps::real2degrees($gps->gpsy, FALSE);
}
// if ($found_segment)
// {
// $selected_device = $found_segment->device_id;
// }
$found_engineer = ORM::factory('device_engineer')->get_engineer_of_user($user_model->id);
$device_engineer_model = new Device_engineer_Model();
$found_engineer = $device_engineer_model->get_engineer_of_user($user->id);
if ($found_engineer)
{
$selected_engineer = $found_engineer->id;
}
$arr_users[$user->id] = $user->surname.' '.$user->name.' - '.$user->login;
$arr_users[$user_model->id] = $user_model->get_name_with_login();
}
else
{
if (!$this->acl_check_new('Devices_Controller', 'devices'))
Controller::error(ACCESS);
$user_model = new User_Model();
$selected = 0;
$selected_country_id = Settings::get('default_country');
$selected_street_id = 0;
$selected_street_number = '';
$selected_town_id = 0;
$arr_users_first = array(NULL => '----- '.__('select user').' -----');
$arr_users = $arr_users_first + $user_model->select_list_grouped();
$arr_users = array
(
NULL => '----- '.__('select user').' -----'
) + $user_model->select_list_grouped();
}
// enum types for device
......
$types[NULL] = '----- '.__('select type').' -----';
asort($types);
// enum types for wireless setting
$arr_modes = $enum_type_model->get_values(Enum_type_Model::MODE_TYPE_ID);
$arr_modes[0] = '----- '.__('select').' -----';
asort($arr_modes);
$arr_norms = $enum_type_model->get_values(Enum_type_Model::NORM_TYPE_ID);
$arr_norms[0] = '----- '.__('select').' -----';
asort($arr_norms);
$arr_antennas = $enum_type_model->get_values(Enum_type_Model::ANTENNA_TYPE_ID);
$arr_antennas[0] = '----- '.__('select').' -----';
asort($arr_antennas);
$arr_polarizations = $enum_type_model->get_values(Enum_type_Model::POLARIZATION_TYPE_ID);
$arr_polarizations[0] = '----- '.__('select').' -----';
asort($arr_polarizations);
// all device templates
$device_templates = array
(
NULL => '----- '.__('Select template').' -----'
) + ORM::factory('device_template')->select_list();
// subnets
$subnet_model = new Subnet_Model();
$subnets = $subnet_model->get_all_subnets_order_by_net();
$arr_subnets_netnames[] = $arr_subnets_names[] = '----- '.__('select subnet').' -----';
$arr_subnets_ids[] = $arr_subnets_masks[] = $arr_subnets_nets[] = 0;
$wmodes = array
(
NULL => '----- '.__('Select mode').' -----'
) + Iface_Model::get_wireless_modes();
$itypes = array
(
NULL => '----- '.__('Select type').' -----'
) + Iface_Model::get_necessary_types();
$wantennas = array
(
NULL => '----- '.__('Select antenna').' -----'
) + Iface_Model::get_wireless_antennas();
$this->arr_mask_by_id = array();
$this->arr_net_by_id = array();
foreach ($subnets as $subnet)
{
$arr_subnets_names[$subnet->id] = $subnet->net_str."/".$subnet->mask.": ".$subnet->name;
$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;
}
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);
// connected to devices
$concat = 'CONCAT(id, IF(name IS NOT NULL, CONCAT(\' - \', name), \'\'))';
$arr_devices = array
(
NULL => '----- '.__('select device').' -----'
) + $device_model->select_list('id', $concat);
// country
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
// streets
$street_model = new Street_Model();
$arr_streets = array
(
NULL => '----- '.__('without street').' -----'
) + $street_model->select_list('id', 'street');
) + ORM::factory('street')->select_list('id', 'street');
// towns
$town_model = new Town_Model();
$arr_towns = array
(
NULL => '----- '.__('select town').' -----'
) + $town_model->select_list_with_quater();
// ports
$port_modes = array
(
NULL => '----- '.__('select mode').' -----'
) + Iface_Model::get_port_modes();
// link mediums
$link_mediums = array
(
NULL => '----- '.__('select medium').' -----'
) + Link_Model::get_medium_types();
) + ORM::factory('town')->select_list_with_quater();
// list of engineers
if ($this->acl_check_edit('Devices_Controller', 'main_engineer'))
......
// name is not required, it is useful to name routers, access points, etc. only
$group_device->input('name')
->label('Device name')
->value(($user_id) ? $user->surname : '')
->value(($user_id) ? $user_model->surname : '')
->rules('required|length[2,200]')
->style('width: 520px');
......
if (!empty($user_id))
{
$group_address->visible(!$user->id);
$group_address->visible(!$user_model->id);
}
$group_address->dropdown('town_id')
......
$form->group('Wireless interfaces');
$form->group('Ports');
$form->group('Internal interfaces');
// // adding interface
// $group_inface = $form->group('Interface');
//
// $group_inface->dropdown('itype')
// ->label('Type')
// ->options($itypes)
// ->callback(array($this, 'valid_itype'));
//
// $group_inface->input('iname')
// ->label('Name');
//
// $group_inface->input('mac')
// ->label('MAC')
// ->rules('valid_mac_address')
// ->callback(array($this, 'valid_mac'));
//
// $group_inface->dropdown('port_mode')
// ->label('Port mode')
// ->options($port_modes);
//
// $group_inface->input('number')
// ->rules('valid_numeric')
// ->label('Port number');
//
// $group_inface->dropdown('wireless_mode')
// ->label('Wireless mode')
// ->options($wmodes)
// ->callback(array($this, 'valid_mode'));
//
// $group_inface->dropdown('wireless_antenna')
// ->label('Wireless antenna')
// ->options($wantennas);
//
// $group_ip_address = $form->group('IP address');
//
// $group_ip_address->input('ip_address')
// ->label('IP address')
// ->rules('valid_ip_address')
// ->callback(array($this, 'valid_ip'));
//
// $group_ip_address->dropdown('subnet_id')
// ->label('Select subnet name')
// ->options($arr_subnets_names)
// ->callback(array($this, 'valid_subnet'))
// ->add_button('subnets');
//
// $group_ip_address->dropdown('service')
// ->label(__('Service') . ':&nbsp;' . help::hint('service'))
// ->options($yes_no_option);
//
// $group_ip_address->dropdown('gateway')
// ->label(__('Gateway') . ':&nbsp;' . help::hint('gateway'))
// ->options($yes_no_option);
//
// $group_connected_to = $form->group('Connected to device');
//
// $group_connected_to->dropdown('connected_to_device_id')
// ->label('Connected to device')
// ->options($arr_devices)
// ->selected($selected_device);
//
// $group_connected_to->dropdown('connected_to_device_iface_id')
// ->label('Interface of connection')
// ->options(array());
//
// $group_connected_to->input('link_medium')
// ->label('Interface of connection')
// ->options($link_mediums);
//
// $group_connected_to->input('link_name')
// ->label('Name of link');
//
// $group_connected_to->dropdown('duplex')
// ->label('Duplex')
// ->options($yes_no_option);
// submit button
$form->submit('Confirm');
......
if($form->validate())
{
$form_data = $form->as_array();
$dm = new Device_Model();
// gps
$gpsx = NULL;
$gpsy = NULL;
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
try
{
$gpsx = doubleval($form_data['gpsx']);
$gpsy = doubleval($form_data['gpsy']);
$dm->transaction_start();
// device //////////////////////////////////////////////////////
$dm->user_id = $form_data['user_id'];
if (gps::is_valid_degrees_coordinate($form->gpsx->value))
if (!isset($user_id))
{
$gpsx = gps::degrees2real($form->gpsx->value);
$user_model = new User_Model($dm->user_id);
}
if (gps::is_valid_degrees_coordinate($form->gpsy->value))
if (empty($form_data['name']))
{
$gpsy = gps::degrees2real($form->gpsy->value);
$dm->name = $user_model->login.'_'.$types[$form_data['type']];
}
}
// device model
$dm = new Device_Model();
$dm->user_id = $form_data['user_id'];
// access rights
if (!isset($user_id))
$user = new User_Model($dm->user_id);
if (empty($form_data['name']))
{
$dm->name = $user->login.'_'.$types[$form_data['type']];
}
else
{
$dm->name = $form_data['name'];
}
$dm->trade_name = $form_data['trade_name'];
$dm->type = $form_data['type'];
$dm->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
if ($this->acl_check_new(get_class($this), 'login'))
{
$dm->login = $form_data['login'];
}
if ($this->acl_check_new(get_class($this), 'password'))
{
$dm->password = $form_data['login_password'];
}
$dm->price = $form_data['price'];
$dm->payment_rate = $form_data['payment_rate'];
$dm->buy_date = date('Y-m-d', $form_data['buy_date']);
$dm->comment = $form_data['comment'];
else
{
$dm->name = $form_data['name'];
}
$address_point_model = new Address_point_Model();
$ap = $address_point_model->get_address_point(
$form_data['country_id'], $form_data['town_id'],
$form_data['street_id'], $form_data['street_number'],
$gpsx, $gpsy
);
$dm->trade_name = htmlspecialchars($_POST['trade_name']);
$dm->type = $form_data['type'];
$dm->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
// add address point if there is no such
if (!$ap->id)
{
$ap->save();
}
// add GPS
if (!empty($gpsx) && !empty($gpsy))
{ // save
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
}
else
{ // delete gps
$ap->gps = '';
$ap->save();
}
if ($this->acl_check_new(get_class($this), 'login'))
{
$dm->login = $form_data['login'];
}
$dm->address_point_id = $ap->id;
if ($this->acl_check_new(get_class($this), 'password'))
{
$dm->password = $form_data['login_password'];
}
$device_saved = $dm->save();
// device engineer model
$device_engineer = new Device_engineer_Model();
$device_engineer->device_id = $dm->id;
$device_engineer->user_id = $form_data['first_engineer_id'];
$device_engineer_saved = $device_engineer->save();
$iface_model_saved = TRUE;
$ip_address_saved = TRUE;
// if ($form_data['itype'])
// {
// $iname = trim($form_data['iname']);
// if ($iname == '')
// $iname = Iface_Model::get_default_name ($form_data['itype']);
//
// $segment_id = intval($form_data['segment_id']);
// $segment_id = ($segment_id > 0) ? $segment_id : NULL;
//
// // interface model
// $iface_model = new Iface_Model();
// $iface_model->device_id = $dm->id;
// $iface_model->segment_id = $segment_id;
// $iface_model->mac = $form_data['mac'];
// $iface_model->name = $iname;
// $iface_model->type = $form_data['itype'];
// $iface_model_saved = $iface_model->save();
//
// if ($iface_model->type == Iface_Model::TYPE_WIRELESS)
// {
// $iface_model->wireless_mode = $form_data['wireless_mode'];
// $iface_model->wireless_antenna = $form_data['wireless_antenna'];
// $iface_model->wireless_ = $form_data['wireless_antenna'];
// }
//
// if ($form_data['ip_address'] != '')
// {
// // ip address model
// $ip_address_model = new Ip_address_Model();
// $ip_address_model->iface_id = $iface_model->id;
// $ip_address_model->subnet_id = $form_data['subnet_id'];
// $ip_address_model->ip_address = $form_data['ip_address'];
// $ip_address_model->dhcp = NULL;
// $ip_address_saved = $ip_address_model->save();
//
// Allowed_subnets_Controller::update_enabled(
// $user->member_id, array($ip_address_model->subnet_id)
// );
// }
// }
unset($form_data);
$dm->price = $form_data['price'];
$dm->payment_rate = $form_data['payment_rate'];
$dm->buy_date = date('Y-m-d', $form_data['buy_date']);
$dm->comment = $form_data['comment'];
// has been everything saved successfully?
if ($device_saved && $device_engineer_saved && $iface_model_saved &&
$ip_address_saved)
{
// address point ///////////////////////////////////////////////////
// gps
$gpsx = NULL;
$gpsy = NULL;
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
{
$gpsx = doubleval($form_data['gpsx']);
$gpsy = doubleval($form_data['gpsy']);
if (gps::is_valid_degrees_coordinate($form->gpsx->value))
{
$gpsx = gps::degrees2real($form->gpsx->value);
}
if (gps::is_valid_degrees_coordinate($form->gpsy->value))
{
$gpsy = gps::degrees2real($form->gpsy->value);
}
}
$address_point_model = new Address_point_Model();
$ap = $address_point_model->get_address_point(
$form_data['country_id'], $form_data['town_id'],
$form_data['street_id'], $form_data['street_number'],
$gpsx, $gpsy
);
// add address point if there is no such
if (!$ap->id)
{
$ap->save_throwable();
}
// add GPS
if (!empty($gpsx) && !empty($gpsy))
{ // save
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
}
else
{ // delete gps
$ap->gps = '';
$ap->save_throwable();
}
$dm->address_point_id = $ap->id;
$dm->save_throwable();
// device engineer ////////////////////////////////////////////
$device_engineer = new Device_engineer_Model();
$device_engineer->device_id = $dm->id;
$device_engineer->user_id = $form_data['first_engineer_id'];
$device_engineer->save();
// ifaces //////////////////////////////////////////////////////
$post_use = $_POST['use'];
$post_use = $_POST['use'];
foreach ($post_use as $i => $v)
{
// skip not used
if ($v != 1)
{
continue;
}
// save iface
$im = new Iface_Model();
$im->device_id = $dm->id;
$im->name = htmlspecialchars($_POST['name'][$i]);
$im->comment = htmlspecialchars($_POST['comment'][$i]);
$im->type = intval($_POST['type'][$i]);
if ($im->type == Iface_Model::TYPE_PORT)
{
$im->number = intval($_POST['number'][$i]);
$im->port_mode = intval($_POST['port_mode'][$i]);
}
else
{
$im->mac = intval($_POST['mac'][$i]);
}
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
}
// connected iface
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
// save link
if ($im->type != Iface_Model::TYPE_INTERNAL && $im_connect_to->id)
{
$lm = new Link_Model($_POST['link_id'][$i]);
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
$lm->medium = intval($_POST['medium'][$i]);
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
$lm->bitrate = network::str2bytes($_POST['link_comment'][$i]);
$lm->duplex = ($_POST['duplex'][$i] == 1);
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
}
$lm->save_throwable();
$im->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
$im->save_throwable();
// save IP address
$ipm = new Ip_address_Model();
$ipm->iface_id = $im->id;
$ipm->subnet_id = intval($_POST['subnet_id'][$i]);
$ipm->member_id = NULL;
$ipm->ip_address = htmlspecialchars($_POST['ip_address'][$i]);
$ipm->dhcp = ($_POST['dhcp'][$i] == 1);
$ipm->gateway = ($_POST['gateway'][$i] == 1);
$ipm->service = ($_POST['service'][$i] == 1);
$ipm->save_throwable();
// allowed subnet to added IP
Allowed_subnets_Controller::update_enabled(
$dm->user->member_id, array($ipm->subnet_id)
);
}
// done
unset($form_data);
$dm->transaction_commit();
status::success('Device has been successfully saved.');
}
catch (Exception $e)
{
$dm->transaction_rollback();
status::error('Device has not been successfully saved.');
}
url::redirect('devices/show/'.$dm->id);
}
......
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $user->member->id,
'ID ' . $user->member->id . ' - ' . $user->member->name,
$this->acl_check_view('Members_Controller', 'members', $user->member->id))
->link('members/show/' . $user_model->member->id,
'ID ' . $user_model->member->id . ' - ' . $user_model->member->name,
$this->acl_check_view('Members_Controller', 'members', $user_model->member->id))
->enable_translation()
->link('users/show_by_member/' . $user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $user->member_id))
->link('users/show_by_member/' . $user_model->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $user_model->member_id))
->disable_translation()
->link('users/show/' . $user->id,
$user->name . ' ' . $user->surname . ' (' . $user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $user->member_id))
->link('users/show/' . $user_model->id,
$user_model->name . ' ' . $user_model->surname . ' (' . $user_model->login . ')',
$this->acl_check_view('Users_Controller', 'users', $user_model->member_id))
->enable_translation()
->link('devices/show_by_user/' . $user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $user->member_id))
->link('devices/show_by_user/' . $user_model->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $user_model->member_id))
->text('Add new whole device');
}
else
......
{
Ip_addresses_Controller::show($ip_address_id);
}
/**
* Function checks validity of ip address.
*
* @param $input ip address to validate
*/
public function valid_ip($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($this->input->post('subnet_id') && trim($input->value) == '')
{
$input->add_error('required', __('This information is required.'));
}
//$method=$form->ip_address->method; // <FORM> method = POST, GET, ...
// ip2long??? why? half of all ipv4 addresses cannot be added (jsvitak)
$ip = ip2long($this->input->post('ip_address')); // Submitted values
$subnet_id = $this->input->post('subnet_id');
// checks if exists this ip in database
$ip_model = new Ip_address_Model();
if ($ip_model->where('ip_address', $this->input->post('ip_address'))->count_all() > 0)
{
$input->add_error('required', __('IP address already exists.'));
}
}
/**
* Functions validate wireless settings when "add_wireless" checkbox is checked.
*
* @param object $input
*/
public function valid_mode($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if (!$input->value && $this->input->post('add_wireless'))
{
$input->add_error('required', __('Value has not been entered.'));
}
}
/**
* Functions validate norm
*
* @param object $input
*/
public function valid_norm($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if (!$input->value && $this->input->post('add_wireless'))
{
$input->add_error('required', __('Value has not been entered.'));
}
}
/**
* Functions validate antenna
*
* @param object $input
*/
public function valid_antenna($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if (!$input->value && $this->input->post('add_wireless'))
{
$input->add_error('required', __('Value has not been entered.'));
}
}
/**
* Functions validate polarization
*
* @param object $input
*/
public function valid_polarization($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if (!$input->value && $this->input->post('add_wireless'))
{
$input->add_error('required', __('Value has not been entered.'));
}
}
/**
* Callback function to validate type of interface
*
* @author Michal Kliment
* @param type $input
*/
public function valid_itype ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($this->input->post('mac')!= '' && trim($input->value) == '')
{
$input->add_error('required', __('This information is required.'));
}
}
/**
* Callback function to validate MAC address
*
* @author Michal Kliment
* @param type $input
*/
public function valid_mac ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($this->input->post('itype') && trim($input->value) == '')
{
$input->add_error('required', __('This information is required.'));
}
}
/**
* Callback function to validate subnet
*
* @author Michal Kliment
* @param type $input
*/
public function valid_subnet ($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($this->input->post('ip_address') != '' && !$input->value)
{
$input->add_error('required', __('This information is required.'));
}
}
/**
* Create grids of interfaces and ip addresses of given device.
*
* @param Device_Model $device
......
if ($this->acl_check_new(get_class($this), 'ip_address', $member_id))
{
$grids['ip_addresses']->add_new_button(
'ip_addresses/add/'.$device->id, 'Add new ip address',
array
'ip_addresses/add/'.$device->id, 'Add new ip address', array
(
'title' => __('Add new ip address'),
'class' => 'popup_link'
......
$grids['ports']->callback_field('connected_to_device')
->callback('callback::connected_to_device');
/*$grid_ports->field('vlan_count')
->label('Vlans')
->class('center');*/
$actions = $grids['ports']->grouped_action_field();
if ($this->acl_check_view(get_class($this),'port',$member_id))
freenetis/branches/network/application/views/js/devices_add.php
options.push('<option value="' + val.id + '">' + val.name + '</option>');
});
$eif.html(options.join(''));
$eif.html(options.join('')).trigger('change');
});
}
/**
* On change of connected iface to device dropdown, set link
*/
function change_connected_iface()
{
var iface_id = $(this).val();
var $p = $(this).parent().parent();
var made = false;
if (parseInt(iface_id))
{
$.ajax({
method: 'get',
dataType: 'json',
async: 'false',
url: '<?php echo url_lang::base(); ?>json/get_links_by_iface?iface_id=' + iface_id,
success: function (v)
{
if (v && parseInt(v.id))
{
made = true;
$p.find('input[name^="link_id"]').val(v.id);
$p.find('input[name^="medium"]').val(v.medium);
$p.find('input[name^="link_name"]').val(v.name);
$p.find('input[name^="link_comment"]').val(v.comment);
$p.find('input[name^="bitrate"]').val(v.bitrate);
$p.find('input[name^="duplex"]').val(v.duplex);
$p.find('input[name^="wireless_ssid"]').val(v.wireless_ssid);
$p.find('input[name^="wireless_norm"]').val(v.wireless_norm);
$p.find('input[name^="wireless_frequency"]').val(v.wireless_frequency);
$p.find('input[name^="wireless_channel"]').val(v.wireless_channel);
$p.find('input[name^="wireless_channel_width"]').val(v.wireless_channel_width);
$p.find('input[name^="wireless_polarization"]').val(v.wireless_polarization);
}
}
});
}
if (made)
{
var type = $p.find('input[name^="type"]').val();
$p.find('input[name^="link_id"]').val(null);
$p.find('input[name^="medium"]').val((type == <?php echo Iface_Model::TYPE_WIRELESS ?>) ? <?php echo Link_Model::AIR ?> : <?php echo Link_Model::CABLE ?>);
$p.find('input[name^="link_name"]').val((type == <?php echo Iface_Model::TYPE_WIRELESS ?>) ? '<?php echo network::str2bytes(Link_Model::get_wireless_max_bitrate(Link_Model::NORM_802_11_G) . 'M') ?>' : '<?php echo network::str2bytes('100M') ?>');
$p.find('input[name^="link_comment"]').val($('#link_comment_input').val());
$p.find('input[name^="bitrate"]').val($('#bitrate_input').val() + $('#bitrate_unit_input').val());
$p.find('input[name^="duplex"]').val(0);
$p.find('input[name^="wireless_ssid"]').val(null);
$p.find('input[name^="wireless_norm"]').val((type == <?php echo Iface_Model::TYPE_WIRELESS ?>) ? '<?php echo Link_Model::NORM_802_11_G ?>' : null);
$p.find('input[name^="wireless_frequency"]').val(null);
$p.find('input[name^="wireless_channel"]').val(null);
$p.find('input[name^="wireless_channel_width"]').val(null);
$p.find('input[name^="wireless_polarization"]').val(null);
}
}
/**
* On any change in row select use button
*/
function use_row()
......
* On change of use of row - change all fields to required or otherwise
*/
function change_use()
{
var inputs = $(this).parent().parent().find('input.mac_address');
{
if ($(this).is(':checked'))
{
inputs.each(function ()
$(this).parent().parent().find('input.mac_address').each(function ()
{
if (!$(this).hasClass('required'))
{
......
}
else
{
inputs.removeClass('required').removeClass('error');
$(this).parent().parent().find('input, select').removeClass('required').removeClass('error');
$(this).parent().parent().find('label.error').remove();
}
}
......
if (data['has_link'])
{
var link_hidden_a = new Array();
link_hidden_a['link_id[' + i + ']'] = null;
link_hidden_a['medium[' + i + ']'] = (data['type'] == <?php echo Iface_Model::TYPE_WIRELESS ?>) ? <?php echo Link_Model::AIR ?> : <?php echo Link_Model::CABLE ?>;
link_hidden_a['bitrate[' + i + ']'] = (data['type'] == <?php echo Iface_Model::TYPE_WIRELESS ?>) ? '<?php echo network::str2bytes(Link_Model::get_wireless_max_bitrate(Link_Model::NORM_802_11_G) . 'M') ?>' : '<?php echo network::str2bytes('100M') ?>';
link_hidden_a['duplex[' + i + ']'] = 0;
......
name : 'ip[' + i + ']',
style : 'width: 8.5em',
change : use_row
}).addClass('ip_address')).append(ip_hiddden).append($('<a>', {
}).addClass('ip_address').addClass('ip_address_check')).append(ip_hiddden).append($('<a>', {
href : '#',
click : add_detail_to_ip,
title : '<?php echo __('Add details to IP address') ?>'
......
title : '<?php echo __('Select device using device map') ?>'
}).addClass('device_add_detail_button').html('<?php echo html::image(array('src' => 'media/images/icons/map_icon.gif')) ?>')).append($('<br>')).append($('<select>', {
name : 'connected_iface[' + i + ']',
style : 'width: 13em'
style : 'width: 13em',
change : change_connected_iface
})).append(link_hid).append($('<a>', {
href : '#',
click : add_detail_to_link,
......
var internals = device_template_value[<?php echo Iface_Model::TYPE_INTERNAL ?>];
var i = 0;
// trade name
$eth_ifaces_group.before($('<input>', {
name: 'trade_name',
type: 'hidden',
value: $('#device_template_id').text()
}));
// ethernet
if (eths['count'] > 0)
{
......
{
if ($(this).validate().form())
{
// enable previously disabled fields
$this.find('input').removeAttr('readonly');
$this.find('select').removeAttr('disabled');
freenetis/branches/network/application/views/js/base.php
$.validator.addMethod('ip_address', function(value)
{
value = value.replace(new RegExp("\\n", "g" ), ",");
value = value.replace(new RegExp("\\n", "g"), ",");
return value == '' || value.match(/^(((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9]),?)+$/g);
}, '<?php echo __('Invalid IP address') ?>');
$.validator.addMethod('ip_address_check', function(value, element)
{
var ret = false;
var subnet_id = $(element).parent().find('select[name^="subnet"]').val();
$.ajax({
url: '<?php echo url_lang::base() ?>json/ip_address_check',
async: false,
dataType: 'json',
data: {ip_address: value, subnet_id: subnet_id},
success: function(result)
{
if(result.state)
{
ret = true;
}
else
{
$.validator.messages.ip_address_check = result.message;
}
}
});
return ret;
}, '<?php echo __('IP address already exists.') ?>');
$.validator.addMethod('cidr', function(value)
{
var result = value.match(/^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9][0-9])|[0-9])\/((3[0-2])|(2[0-9])|(1[0-9])|([0-9]))$/);
if (!result)
return false;
var s = value.split("/");
var s = value.split('/');
return ((ip2long(s[0]) & (0xffffffff<<(32-s[1]) & 0xffffffff)) == ip2long(s[0]));
}, '<?php echo __('Invalid IP address') ?>');

Také k dispozici: Unified diff