Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c2e44ab0

Přidáno uživatelem Michal Kliment před asi 9 roky(ů)

Release 1.0.12

Zobrazit rozdíly:

application/controllers/allowed_subnets.php
* @author Michal Kliment
* @param integer $member_id
* @param string | array $to_enable
* @return void
* @param string | array $to_disable
* @param string | array $to_remove
* @param boolean $thow_ex_on_error Trow an exception if an error occure?
* @return boolean State of operation.
*/
public static function update_enabled(
$member_id, $to_enable = array(), $to_disable = array(),
$to_remove = array())
$to_remove = array(), $thow_ex_on_error = FALSE)
{
// bad parameter
if (!$member_id)
......
// finds all allowed subnet of member
$allowed_subnet_model = new Allowed_subnet_Model();
try
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// try to delete
while (TRUE)
{
$allowed_subnet_model->transaction_start();
$allowed_subnets = $allowed_subnet_model->where('member_id', $member->id)
->where('member_id', $member->id)
->orderby(array('enabled' => 'desc', 'last_update' => 'desc'))
->find_all();
try
{
$allowed_subnet_model->transaction_start();
$arr_subnets = array();
$allowed_subnets = $allowed_subnet_model->where('member_id', $member->id)
->where('member_id', $member->id)
->orderby(array('enabled' => 'desc', 'last_update' => 'desc'))
->find_all();
// to_enabled have the hightest priority
foreach ($allowed_subnets as $allowed_subnet)
{
if (in_array($allowed_subnet->subnet_id, $to_remove))
$arr_subnets = array();
// to_enabled have the hightest priority
foreach ($allowed_subnets as $allowed_subnet)
{
$allowed_subnet->delete();
continue;
if (in_array($allowed_subnet->subnet_id, $to_remove))
{
$allowed_subnet->delete_throwable();
continue;
}
if (!in_array($allowed_subnet->subnet_id, $to_enable) &&
!in_array($allowed_subnet->subnet_id, $to_disable))
{
$arr_subnets[] = $allowed_subnet->subnet_id;
}
}
if (!in_array($allowed_subnet->subnet_id, $to_enable) &&
!in_array($allowed_subnet->subnet_id, $to_disable))
$arr_subnets = arr::merge($to_enable, $arr_subnets, $to_disable);
// maximum count of allowed subnets (0 = unlimited)
$max_enabled = ($member->allowed_subnets_count->count) ?
$member->allowed_subnets_count->count : count($arr_subnets);
$enabled = 0;
foreach ($arr_subnets as $subnet)
{
$arr_subnets[] = $allowed_subnet->subnet_id;
}
}
if (!$subnet)
continue;
$arr_subnets = arr::merge($to_enable, $arr_subnets, $to_disable);
if ($aid = $allowed_subnet_model->exists($member->id, $subnet))
{
$allowed_subnet_model->where('id', $aid)->find();
}
else
{
$allowed_subnet_model->clear();
$allowed_subnet_model->member_id = $member->id;
$allowed_subnet_model->subnet_id = $subnet;
}
// maximum count of allowed subnets (0 = unlimited)
$max_enabled = ($member->allowed_subnets_count->count) ?
$member->allowed_subnets_count->count : count($arr_subnets);
$allowed_subnet_model->enabled = ($enabled < $max_enabled);
$enabled = 0;
foreach ($arr_subnets as $subnet)
{
if (!$subnet)
continue;
$enabled++;
if ($aid = $allowed_subnet_model->exists($member->id, $subnet))
{
$allowed_subnet_model->where('id', $aid)->find();
}
else
{
$allowed_subnet_model->clear();
$allowed_subnet_model->member_id = $member->id;
$allowed_subnet_model->subnet_id = $subnet;
$allowed_subnet_model->save_throwable();
}
$allowed_subnet_model->enabled = ($enabled < $max_enabled);
$allowed_subnet_model->transaction_commit();
return TRUE; // all OK
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
$allowed_subnet_model->transaction_rollback();
$enabled++;
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
if ($thow_ex_on_error)
{
throw $e;
}
else
{
return FALSE;
}
}
$allowed_subnet_model->save();
usleep($timeout);
}
$allowed_subnet_model->transaction_commit();
}
catch (Exception $e)
{
$allowed_subnet_model->transaction_rollback();
Log::add_exception($e);
}
}
application/controllers/approval_types.php
status::success('Approval type has been successfully added.');
// classic adding
if (!$this->popup)
{
url::redirect('approval_types/show/'.$at->id);
}
$this->redirect('approval_types/show/', $at->id);
}
// headline
application/controllers/aro_groups.php
$count = $model_groups_aro_map->count_rows_by_group_id($group->id);
if ($group->id == 21)
if ($group->id == Aro_group_Model::ALL)
{
$rows[$i + 1] = '<tr><td style="width:400px">'
. $ret . __('' . $group->name)
......
if (!$group->id)
Controller::error(RECORD);
// cannot delete group with some childrens
if (!$group->is_deletable())
{
status::warning('Cannot delete group - this group is protected against deletion');
url::redirect('aro_groups/show_all');
}
// cannot delete group with some childrens
if ($group->count_childrens())
{
status::warning('Cannot delete group - it has at least one children group');
url::redirect('access_rights/show_groups');
url::redirect('aro_groups/show_all');
}
$group->transaction_start();
application/controllers/contacts.php
Controller::error(RECORD);
}
$this->_contact_id = NULL;
$contact_model = new Contact_Model($contact_id);
$country_model = new Country_Model();
......
if ($form->validate())
{
if ($contact_model->value != $form->value->value &&
$contact_model->find_contact_id(
$contact_model->type, $form->value->value
))
{
status::warning('Contact is already in database');
}
else
{
$issaved = TRUE;
$contact_model->value = $form->value->value;
$issaved = $issaved && $contact_model->save();
if ($issaved)
if ($contact_model->save())
{
status::success('Additional contacts have been successfully updated');
}
......
{
status::error('Error - cant update additional contacts');
}
}
$this->redirect('contacts/show_by_user/',$user_id);
}
......
$contact_model = new Contact_Model();
// search for contacts
$contact_id = $contact_model->find_contact_id(
$type, trim($input->value)
);
$duplicip_contacts = $contact_model->find_contacts($type, trim($input->value));
if ($contact_id && $contact_id != $this->_contact_id)
foreach ($duplicip_contacts as $c)
{
$contact_model = ORM::factory('contact', $contact_id);
if ($contact_model->count_all_users_contacts_relation() > 0)
if ($c->id && ($c->id != $this->_contact_id))
{
if ($contact_model->count_all_users_contacts_relation($c->id) > 0)
{
$input->add_error('required', __('Contact is already in database'));
break;
}
}
}
}
}
}
application/controllers/device_templates.php
// parse values
$this->validate_form_value($vals);
$default = isset($form_data['default']);
$default = isset($form_data['default']) && $form_data['default'];
// model
$device_template_model = new Device_template_Model();
application/controllers/devices.php
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric');
->rules('valid_numeric')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
$dm = new Device_Model();
$update_allowed_params = array();
try
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// try to delete
while (TRUE)
{
$dm->transaction_start();
// device //////////////////////////////////////////////////////
$dm->user_id = $form_data['user_id'];
if (!isset($user_id))
try
{
$um = new User_Model($dm->user_id);
}
$dm->transaction_start();
if (empty($form_data['device_name']))
{
$dm->name = $um->login.'_'.$types[$form_data['device_type']];
}
else
{
$dm->name = $form_data['device_name'];
}
$device_template = new Device_template_Model($form_data['device_template_id']);
// device //////////////////////////////////////////////////////
$device = new Device_Model();
$device->user_id = $form_data['user_id'];
if ($device_template && $device_template->id)
{
$dm->trade_name = $device_template->name;
}
$dm->type = $form_data['device_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'];
}
if (!isset($user_id))
{
$um = new User_Model($device->user_id);
}
$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['device_comment'];
if (empty($form_data['device_name']))
{
$device->name = $um->login.'_'.$types[$form_data['device_type']];
}
else
{
$device->name = $form_data['device_name'];
}
// address point ///////////////////////////////////////////////////
$device_template = new Device_template_Model($form_data['device_template_id']);
// gps
$gpsx = NULL;
$gpsy = NULL;
if ($device_template && $device_template->id)
{
$device->trade_name = $device_template->name;
}
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
{
$gpsx = doubleval($form_data['gpsx']);
$gpsy = doubleval($form_data['gpsy']);
$device->type = $form_data['device_type'];
$device->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
if (gps::is_valid_degrees_coordinate($form_data['gpsx']))
if ($this->acl_check_new(get_class($this), 'login'))
{
$gpsx = gps::degrees2real($form_data['gpsx']);
$device->login = $form_data['login'];
}
if (gps::is_valid_degrees_coordinate($form_data['gpsy']))
if ($this->acl_check_new(get_class($this), 'password'))
{
$gpsy = gps::degrees2real($form_data['gpsy']);
$device->password = $form_data['login_password'];
}
}
$address_point_model = new Address_point_Model();
$device->price = $form_data['price'];
$device->payment_rate = $form_data['payment_rate'];
$device->buy_date = date('Y-m-d', $form_data['buy_date']);
$device->comment = $form_data['device_comment'];
$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
);
// address point ///////////////////////////////////////////////////
// add address point if there is no such
if (!$ap->id)
{
$ap->save_throwable();
}
// gps
$gpsx = NULL;
$gpsy = NULL;
// add GPS
if (!empty($gpsx) && !empty($gpsy))
{ // save
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
}
else
{ // delete gps
$ap->gps = '';
$ap->save_throwable();
}
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
{
$gpsx = doubleval($form_data['gpsx']);
$gpsy = doubleval($form_data['gpsy']);
$dm->address_point_id = $ap->id;
$dm->save_throwable();
if (gps::is_valid_degrees_coordinate($form_data['gpsx']))
{
$gpsx = gps::degrees2real($form_data['gpsx']);
}
// 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 //////////////////////////////////////////////////////
if (gps::is_valid_degrees_coordinate($form_data['gpsy']))
{
$gpsy = gps::degrees2real($form_data['gpsy']);
}
}
$post_use = isset($_POST['use']) ? $_POST['use'] : array();
foreach ($post_use as $i => $v)
{
// skip not used
if ($v != 1)
$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)
{
continue;
$ap->save_throwable();
}
// 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]);
// add GPS
if (!empty($gpsx) && !empty($gpsy))
{ // save
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
}
else
{
$im->mac = htmlspecialchars($_POST['mac'][$i]);
{ // delete gps
$ap->gps = '';
$ap->save_throwable();
}
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
}
// can autosave?
$autosave_may = TRUE;
if (isset($_POST['connected_iface'][$i]))
$device->address_point_id = $ap->id;
$device->save_throwable();
// device engineer ////////////////////////////////////////////
$device_engineer = new Device_engineer_Model();
$device_engineer->device_id = $device->id;
$device_engineer->user_id = $form_data['first_engineer_id'];
$device_engineer->save();
// ifaces //////////////////////////////////////////////////////
$update_allowed_params = array();// reset
$post_use = isset($_POST['use']) ? $_POST['use'] : array();
foreach ($post_use as $i => $v)
{
// restrict blank fields
if (!(Iface_Model::type_has_ip_address($im->type) &&
Iface_Model::type_has_mac_address($im->type) &&
empty($im->mac) && (
!isset($_POST['ip'][$i]) ||
empty($_POST['ip'][$i]) ||
!valid::ip_address($_POST['ip'][$i])
)))
// skip not used
if ($v != 1)
{
continue;
}
// save iface
$im = new Iface_Model();
$im->device_id = $device->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 = htmlspecialchars($_POST['mac'][$i]);
}
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
// connected iface
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
}
// save link
if (Iface_Model::type_has_link($im->type) &&
$im_connect_to && $im_connect_to->id)
// can autosave?
$autosave_may = TRUE;
if (isset($_POST['connected_iface'][$i]))
{
// restrict blank fields
if (!(Iface_Model::type_has_ip_address($im->type) &&
Iface_Model::type_has_mac_address($im->type) &&
empty($im->mac) && (
!isset($_POST['ip'][$i]) ||
empty($_POST['ip'][$i]) ||
!valid::ip_address($_POST['ip'][$i])
)))
{
// disable autosave
$autosave_may = FALSE;
$roaming = new Link_Model();
$link_id = $_POST['link_id'][$i];
$roaming_id = $roaming->get_roaming();
$roaming = $roaming->find($roaming_id);
$name = $_POST['link_name'][$i];
$medium = $_POST['medium'][$i];
// don not connect to roaming
if ($link_id == $roaming_id)
// connected iface
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
// save link
if (Iface_Model::type_has_link($im->type) &&
$im_connect_to && $im_connect_to->id)
{
$link_id = NULL;
// fix name
if (trim($name) == trim($roaming->name))
// disable autosave
$autosave_may = FALSE;
$roaming = new Link_Model();
$link_id = $_POST['link_id'][$i];
$roaming_id = $roaming->get_roaming();
$roaming = $roaming->find($roaming_id);
$name = $_POST['link_name'][$i];
$medium = $_POST['medium'][$i];
// don not connect to roaming
if ($link_id == $roaming_id)
{
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$name = __('air') . ' ';
}
else
{
$name = __('cable') . ' ';
}
if ($im_connect_to->type == Iface_Model::TYPE_WIRELESS &&
$im_connect_to->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$name .= $im_connect_to->device->name;
$name .= ' - ' . $dm->name;
}
else
{
$name .= $dm->name . ' - ';
$name .= $im_connect_to->device->name;
}
// fix medium
if ($medium == Link_Model::MEDIUM_ROAMING)
$link_id = NULL;
// fix name
if (trim($name) == trim($roaming->name))
{
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
$name = __('air') . ' ';
}
else
{
$name = __('cable') . ' ';
}
if ($im_connect_to->type == Iface_Model::TYPE_WIRELESS &&
$im_connect_to->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$name .= $im_connect_to->device->name;
$name .= ' - ' . $device->name;
}
else
{
$medium = Link_Model::MEDIUM_CABLE;
$name .= $device->name . ' - ';
$name .= $im_connect_to->device->name;
}
// fix medium
if ($medium == Link_Model::MEDIUM_ROAMING)
{
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
}
else
{
$medium = Link_Model::MEDIUM_CABLE;
}
}
}
}
}
$lm = new Link_Model($link_id);
$lm->name = htmlspecialchars($name);
$lm->medium = intval($medium);
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
$lm->bitrate = network::str2bytes($_POST['bitrate'][$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();
// restrict count of connected devices to link
$max = Link_Model::get_max_ifaces_count($im->type);
if ($lm->id != $roaming_id &&
$max <= 2) // delete connected (port, eth)
{
foreach ($lm->ifaces as $i_del)
$lm = new Link_Model($link_id);
$lm->name = htmlspecialchars($name);
$lm->medium = intval($medium);
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
$lm->duplex = ($_POST['duplex'][$i] == 1);
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$i_del->link_id = null;
$i_del->save_throwable();
$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();
// restrict count of connected devices to link
$max = Link_Model::get_max_ifaces_count($im->type);
if ($lm->id != $roaming_id &&
$max <= 2) // delete connected (port, eth)
{
foreach ($lm->ifaces as $i_del)
{
$i_del->link_id = null;
$i_del->save_throwable();
}
}
$im->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
$im->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
}
}
// autosave (add) link
if (isset($_POST['link_autosave'][$i]) &&
$_POST['link_autosave'][$i] && $autosave_may)
{
$lm = new Link_Model();
$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['bitrate'][$i]);
$lm->duplex = ($_POST['duplex'][$i] == 1);
if ($im->type == Iface_Model::TYPE_WIRELESS)
// autosave (add) link
if (isset($_POST['link_autosave'][$i]) &&
$_POST['link_autosave'][$i] && $autosave_may)
{
$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 = new Link_Model();
$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['bitrate'][$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;
}
$lm->save_throwable();
$im->link_id = $lm->id;
$im->save_throwable();
if (isset($_POST['ip'][$i]) && valid::ip_address($_POST['ip'][$i]))
{
// save IP address
$ipm = new Ip_address_Model();
$ipm->iface_id = $im->id;
$ipm->subnet_id = intval($_POST['subnet'][$i]);
$ipm->member_id = NULL;
$ipm->ip_address = htmlspecialchars($_POST['ip'][$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
$update_allowed_params[] = array
(
'member_id' => $device->user->member_id,
'to_enable' => array($ipm->subnet_id)
);
}
}
// done
$dm->transaction_commit();
//Update allowed subnets after transaction is successfully commited
$error_added = TRUE; // throw error?
$im->save_throwable();
if (isset($_POST['ip'][$i]) && valid::ip_address($_POST['ip'][$i]))
foreach ($update_allowed_params as $params)
{
// save IP address
$ipm = new Ip_address_Model();
$ipm->iface_id = $im->id;
$ipm->subnet_id = intval($_POST['subnet'][$i]);
$ipm->member_id = NULL;
$ipm->ip_address = htmlspecialchars($_POST['ip'][$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
$update_allowed_params[] = array
(
'member_id' => $dm->user->member_id,
'to_enable' => array($ipm->subnet_id)
);
try
{
Allowed_subnets_Controller::update_enabled(
$params['member_id'], $params['to_enable'],
array(), array(), $error_added
);
}
catch (Exception $e)
{
$error_added = FALSE;
status::warning('Error - cannot update allowed subnets of member.');
}
}
}
// done
unset($form_data);
$dm->transaction_commit();
//Update allowed subnets after transaction is successfully commited
foreach ($update_allowed_params as $params)
status::success('Device has been successfully saved.');
url::redirect('devices/show/'.$device->id);
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
Allowed_subnets_Controller::update_enabled(
$params['member_id'],
$params['to_enable']
);
$dm->transaction_rollback();
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
status::error('Device has not been successfully saved.');
break;
}
usleep($timeout);
}
status::success('Device has been successfully saved.');
url::redirect('devices/show/'.$dm->id);
}
catch (Exception $e)
{
$dm->transaction_rollback();
Log::add_exception($e);
status::error('Device has not been successfully saved.');
}
}
if (isset($user_id))
......
{
$selected_engineer = $found_engineer->id;
}
$arr_users[$um->id] = $um->get_name_with_login();
}
else
{
......
$selected_street_id = 0;
$selected_street_number = '';
$selected_town_id = 0;
$arr_users = array
(
NULL => '----- '.__('select user').' -----'
) + $um->select_list_grouped();
}
$arr_users = array
(
NULL => '----- '.__('select user').' -----'
) + $um->select_list_grouped();
// enum types for device
$enum_type_model = new Enum_type_Model();
$types = $enum_type_model->get_values(Enum_type_Model::DEVICE_TYPE_ID);
......
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric');
->rules('valid_numeric')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
$group_payment->input('payment_rate')
->label('Monthly payment rate')
->rules('valid_numeric')
->value($device->payment_rate ? $device->payment_rate : '');
->value($device->payment_rate ? $device->payment_rate : '')
->callback(array($this, 'valid_repayment'));
$group_payment->date('buy_date')
->label('Buy date')
......
$linkback = 'devices/show_all';
}
if ($device->delete())
{
Allowed_subnets_Controller::update_enabled($mid, NULL, NULL, $subnets);
status::success('Device has been successfully deleted.');
}
else
{
status::error('Error - cant delete device.');
}
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// redirect
url::redirect($linkback);
// try to delete
while (TRUE)
{
try // try to make DB transction
{
$device->transaction_start();
$device->delete_throwable();
$device->transaction_commit();
try
{
Allowed_subnets_Controller::update_enabled($mid, NULL, NULL, $subnets, TRUE);
}
catch (Exception $e)
{
status::warning('Error - cannot update allowed subnets of member.');
}
// redirect
status::success('Device has been successfully deleted.');
$this->redirect($linkback);
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
$device->transaction_rollback();
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
status::error('Error - cant delete device.');
$this->redirect($linkback);
}
usleep($timeout);
}
}
}
/**
......
return $filter_form;
}
/**
* Validate repayment of device
*
* @param Form_Field $input
*/
public function valid_repayment($input = NULL)
{
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
$price = $this->input->post('price');
$rate = $input->value;
if (!empty($price) && doubleval($rate) <= 0)
{
$input->add_error('required', __('Must be greater than zero'));
}
}
}
application/controllers/ifaces.php
if ($this->acl_check_new(get_class($this), 'iface', $member_id))
{
$grid->add_new_button(
'ifaces/add/' . $device->id, 'Add new interface'
'ifaces/add/' . $iface->device->id, 'Add new interface'
);
}
......
$grid->datasource($vlans);
$detail = $grid;
break;
case Iface_Model::TYPE_INTERNAL:
$detail = new View('ifaces/detail');
$detail->ip_addresses = $grid_ip_addresses;
break;
};
$view->content->iface = $iface;
......
->label('VLAN')
->options($vlan_ifaces)
->rules('required')
->add_button('vlans')
->style('width:200px');
$vlan_form->dropdown('parent_iface_id')
......
->label('VLAN')
->options($vlans)
->selected($vlan_id)
->add_button('vlans')
->style('width:200px');
$vlan_form->dropdown('parent_iface_id')
......
try
{
$iface->transaction_start();
$old_type = $iface->type;
$iface->name = $form_data['name'];
$iface->type = $form_data['itype'];
......
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
// disconnect
else if (isset($_POST['change_link']) && $_POST['change_link'])
{
$iface->link_id = null;
}
// do not changes link commonly, but if type changed we must
// look if the current link can be used on new type
// this code resolves (#310)
else if ($old_type != $iface->type)
{
$mediums = $iface->get_types_has_link_with_medium($iface->type);
if ($iface->link_id &&
!array_key_exists($iface->link->medium, $mediums))
{
$iface->link_id = null;
}
}
}
else
{
application/controllers/ip_addresses.php
) + ORM::factory('iface')->select_list_grouped_by_device($device->id);
$title = __('Add new IP address to device').' '.$device->name;
$link_back_url = 'devices/show/'.$device->id;
$linkback = 'devices/show/'.$device->id;
}
else
{
......
);
$title = __('Add new IP address to interface').' '.strval($iface);
$link_back_url = 'ifaces/show/'.$device->id;
$linkback = 'ifaces/show/'.$iface->id;
}
}
......
) + ORM::factory('iface')->select_list_grouped_by_device();
$title = __('Add new IP address');
$link_back_url = 'ip_addresses/show_all';
$linkback = 'ip_addresses/show_all';
}
$this->form = new Forge();
......
{
$form_data = $this->form->as_array();
$ip = new Ip_address_Model();
$ip_address = new Ip_address_Model();
$ip->delete_ip_address_with_member($form_data['ip_address']);
$ip->iface_id = $form_data['iface_id'];
$ip->ip_address = $form_data['ip_address'];
$ip->subnet_id = $form_data['subnet_id'];
$ip->gateway = $form_data['gateway'];
$ip->service = $form_data['service'];
$ip->whitelisted = Ip_address_Model::NO_WHITELIST;
$ip->member_id = NULL;
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// try to delete
while (TRUE)
{
try // try to make DB transction
{
$ip_address->transaction_start();
$ip_address->delete_ip_address_with_member($form_data['ip_address']);
$ip_address->iface_id = $form_data['iface_id'];
$ip_address->ip_address = $form_data['ip_address'];
$ip_address->subnet_id = $form_data['subnet_id'];
$ip_address->gateway = $form_data['gateway'];
$ip_address->service = $form_data['service'];
$ip_address->whitelisted = Ip_address_Model::NO_WHITELIST;
$ip_address->member_id = NULL;
$ip_address->save_throwable();
$ip_address->transaction_commit();
unset($form_data);
try
{
Allowed_subnets_Controller::update_enabled(
$ip_address->iface->device->user->member->id, array($ip_address->subnet_id)
);
}
catch (Exception $e)
{
status::warning('Error - cannot update allowed subnets of member.');
}
if ($ip->save())
{
status::success('IP address is successfully saved.');
Allowed_subnets_Controller::update_enabled(
$ip->iface->device->user->member->id, array($ip->subnet_id)
);
// redirect
status::success('IP address is successfully saved.');
$this->redirect($linkback);
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
$ip_address->transaction_rollback();
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
status::error('Error - cant add ip address.');
$this->redirect($linkback);
}
usleep($timeout);
}
}
$this->redirect($link_back_url);
}
$view = new View('main');
......
{
$form_data = $this->form->as_array();
try
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// try to delete
while (TRUE)
{
$ip_address->transaction_start();
$ip_address->delete_ip_address_with_member($form_data['ip_address']);
$old_subnet_id = $ip_address->subnet_id;
$ip_address->iface_id = $form_data['iface_id'];
$ip_address->ip_address = $form_data['ip_address'];
$ip_address->subnet_id = $form_data['subnet_id'];
$ip_address->gateway = $form_data['gateway'];
$ip_address->service = $form_data['service'];
$ip_address->whitelisted = $form_data['whitelisted'];
$ip_address->member_id = NULL;
unset($form_data);
$ip_address->save_throwable();
$ip_address->transaction_commit();
$member_id = $device->user->member_id;
// this block of code cannot be in database transation otherwise
// you will get error
// subnet has been changed and ip address was the only one of this member
// from this subnet -> deletes subnet from allowed subnets of member
if ($old_subnet_id != $ip_address->subnet_id &&
!$ip_address->count_all_ip_addresses_by_member_and_subnet(
$member_id, $old_subnet_id
))
try // try to make DB transction
{
Allowed_subnets_Controller::update_enabled(
$member_id, NULL, NULL, array($old_subnet_id)
);
$ip_address->transaction_start();
$ip_address->delete_ip_address_with_member($form_data['ip_address']);
$old_subnet_id = $ip_address->subnet_id;
$ip_address->iface_id = $form_data['iface_id'];
$ip_address->ip_address = $form_data['ip_address'];
$ip_address->subnet_id = $form_data['subnet_id'];
$ip_address->gateway = $form_data['gateway'];
$ip_address->service = $form_data['service'];
$ip_address->whitelisted = $form_data['whitelisted'];
$ip_address->member_id = NULL;
$ip_address->save_throwable();
$ip_address->transaction_commit();
$member_id = $device->user->member_id;
// this block of code cannot be in database transation otherwise
// you will get error
// subnet has been changed and ip address was the only one of this member
// from this subnet -> deletes subnet from allowed subnets of member
if ($old_subnet_id != $ip_address->subnet_id &&
!$ip_address->count_all_ip_addresses_by_member_and_subnet(
$member_id, $old_subnet_id
))
{
try
{
Allowed_subnets_Controller::update_enabled(
$member_id, NULL, NULL,
array($old_subnet_id), TRUE
);
}
catch (Exception $e)
{
status::warning('Error - cannot update allowed subnets of member.');
}
}
try
{
Allowed_subnets_Controller::update_enabled(
$member_id, array($ip_address->subnet_id), array(),
array(), TRUE
);
}
catch (Exception $e)
{
status::warning('Error - cannot update allowed subnets of member.');
}
status::success('IP address has been successfully updated.');
$this->redirect('ip_addresses/show/'.$ip_address->id);
}
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
$ip_address->transaction_rollback();
Allowed_subnets_Controller::update_enabled(
$member_id, array($ip_address->subnet_id)
);
status::success('IP address has been successfully updated.');
}
catch (Exception $e)
{
$ip_address->transaction_rollback();
Log::add_exception($e);
status::error('Error - Cannot update ip address.');
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
Log::add_exception($e);
status::error('Error - Cannot update ip address.');
$this->redirect('ip_addresses/show/'.$ip_address->id);
}
usleep($timeout);
}
}
$this->redirect('ip_addresses/show/'.$ip_address->id);
}
else
{
......
Controller::error(ACCESS);
}
// success
if ($ip_address->delete())
// link back
$linkback = Path::instance()->previous();
if (url::slice(url_lang::uri($linkback), 0, 2) == 'ip_addresses/show')
{
$linkback = 'ip_addresses/show_all';
}
// gets number of maximum of acceptable repeating of operation
// after reaching of deadlock and time of waiting between
// other attempt to make transaction (#254)
$transaction_attempt_counter = 0;
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
// try to delete
while (TRUE)
{
try // try to make DB transction
{
$ip_address->transaction_start();
if ($ip_address->subnet->subnets_owner->id)
{
$ip_address->member_id = $ip_address->subnet->subnets_owner->member->id;
$ip_address->iface_id = NULL;
$ip_address->save_throwable();
}
else
$ip_address->delete_throwable();
$ip_address->transaction_commit();
// ip address was the only one of this member
// from this subnet -> deletes subnet from allowed subnets of member
if (!$ip_address->count_all_ip_addresses_by_member_and_subnet(
$member_id, $subnet_id
))
{
try
{
Allowed_subnets_Controller::update_enabled(
$member_id, NULL, NULL, array($subnet_id)
$member_id, NULL, NULL, array($subnet_id), TRUE
);
}
catch (Exception $e)
{
status::warning('Error - cannot update allowed subnets of member.');
}
}
// redirect
status::success('IP address has been successfully deleted.');
$this->redirect($linkback);
}
else
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
{
status::error('Error - cant delete ip address.');
}
$linkback = Path::instance()->previous();
$ip_address->transaction_rollback();
if (url::slice(url_lang::uri($linkback),0,2) == 'ip_addresses/show')
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
{
$linkback = 'ip_addresses/show_all';
Log::add_exception($e);
status::error('Error - cant delete ip address.');
$this->redirect($linkback);
}
$this->redirect($linkback);
usleep($timeout);
}
}
}
/**
application/controllers/js.php
$this->views['devices_add']->arr_devices = $device->select_list_device_with_user($user_id);
}
private function _js_devices_add_simple()
{
$this->address_point_streets();
$this->address_point_gps();
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff