Revize 1762
Přidáno uživatelem Ondřej Fibich před asi 12 roky(ů)
freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'error - cannot set filter query as default' => 'Chyba - nelze nastavit dotaz filtru jako výchozí.',
|
||
'error - cannot unset filter query as default' => 'Chyba - nelze zrušit dotaz filtru jako výchozí.',
|
||
'error - cannot update access control group' => 'Chyba - nelze aktualizovat přístupovou skupinu uživatelů',
|
||
'error - cannot update allowed subnets of member' => 'Chyba - nelze aktualizovat povolené podsítě člena.',
|
||
'error - cannot update count of allowed subnets' => 'Chyba - nelze aktualizovat počet povolených podsítí.',
|
||
'error - cannot update device admin' => 'Chyba - nelze aktualizovat správce zařízení.',
|
||
'error - cant add contacts' => 'Chyba - nelze přidat kontakt.',
|
freenetis/trunk/kohana/application/vendors/redirection/freenetis-http-302-redirection.py | ||
---|---|---|
connections.open()
|
||
except socket.error, msg:
|
||
connections.close()
|
||
print >> sys.stderr, "Cannot create/bind socket, error (" + msg[0] + "): " + msg[1]
|
||
print >> sys.stderr, "Cannot create/bind socket, error (" + str(msg[0]) + "): " + str(msg[1])
|
||
sys.exit(4)
|
||
|
||
# set signal handlers
|
freenetis/trunk/kohana/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']);
|
||
// 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'));
|
||
|
||
$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;
|
||
// 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);
|
||
|
||
if ($ip->save())
|
||
try
|
||
{
|
||
status::success('IP address is successfully saved.');
|
||
Allowed_subnets_Controller::update_enabled(
|
||
$ip->iface->device->user->member->id, array($ip->subnet_id)
|
||
$ip_address->iface->device->user->member->id, array($ip_address->subnet_id)
|
||
);
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
status::warning('Error - cannot update allowed subnets of member.');
|
||
}
|
||
|
||
$this->redirect($link_back_url);
|
||
// 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);
|
||
}
|
||
}
|
||
}
|
||
|
||
$view = new View('main');
|
||
$view->title = $title;
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
... | ... | |
{
|
||
$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)
|
||
{
|
||
try // try to make DB transction
|
||
{
|
||
$ip_address->transaction_start();
|
||
|
||
$ip_address->delete_ip_address_with_member($form_data['ip_address']);
|
||
... | ... | |
$ip_address->whitelisted = $form_data['whitelisted'];
|
||
$ip_address->member_id = NULL;
|
||
|
||
unset($form_data);
|
||
|
||
$ip_address->save_throwable();
|
||
|
||
$ip_address->transaction_commit();
|
||
... | ... | |
$member_id, $old_subnet_id
|
||
))
|
||
{
|
||
try
|
||
{
|
||
Allowed_subnets_Controller::update_enabled(
|
||
$member_id, NULL, NULL, array($old_subnet_id)
|
||
$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)
|
||
$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)
|
||
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 - Cannot update ip address.');
|
||
$this->redirect('ip_addresses/show/'.$ip_address->id);
|
||
}
|
||
|
||
$this->redirect('ip_addresses/show/'.$ip_address->id);
|
||
usleep($timeout);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$title = __('Edit IP address');
|
||
... | ... | |
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();
|
||
$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.');
|
||
}
|
||
$ip_address->transaction_rollback();
|
||
|
||
$linkback = Path::instance()->previous();
|
||
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Checks validity of ip address.
|
freenetis/trunk/kohana/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();
|
||
|
||
|
||
// 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
|
||
{
|
||
$allowed_subnet_model->transaction_start();
|
||
... | ... | |
{
|
||
if (in_array($allowed_subnet->subnet_id, $to_remove))
|
||
{
|
||
$allowed_subnet->delete();
|
||
$allowed_subnet->delete_throwable();
|
||
continue;
|
||
}
|
||
|
||
... | ... | |
|
||
$enabled++;
|
||
|
||
$allowed_subnet_model->save();
|
||
$allowed_subnet_model->save_throwable();
|
||
}
|
||
|
||
$allowed_subnet_model->transaction_commit();
|
||
|
||
return TRUE; // all OK
|
||
}
|
||
catch (Exception $e)
|
||
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
|
||
{
|
||
$allowed_subnet_model->transaction_rollback();
|
||
|
||
if (++$transaction_attempt_counter >= $max_attempts) // this was last attempt?
|
||
{
|
||
Log::add_exception($e);
|
||
|
||
if ($thow_ex_on_error)
|
||
{
|
||
throw $e;
|
||
}
|
||
else
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
usleep($timeout);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
freenetis/trunk/kohana/application/controllers/devices.php | ||
---|---|---|
|
||
$update_allowed_params = array();
|
||
|
||
// 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
|
||
{
|
||
$dm->transaction_start();
|
||
... | ... | |
|
||
// ifaces //////////////////////////////////////////////////////
|
||
|
||
$update_allowed_params = array();// reset
|
||
$post_use = isset($_POST['use']) ? $_POST['use'] : array();
|
||
|
||
foreach ($post_use as $i => $v)
|
||
... | ... | |
}
|
||
|
||
// done
|
||
unset($form_data);
|
||
$dm->transaction_commit();
|
||
|
||
//Update allowed subnets after transaction is successfully commited
|
||
$error_added = TRUE; // throw error?
|
||
|
||
foreach ($update_allowed_params as $params)
|
||
{
|
||
try
|
||
{
|
||
Allowed_subnets_Controller::update_enabled(
|
||
$params['member_id'],
|
||
$params['to_enable']
|
||
$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.');
|
||
}
|
||
}
|
||
|
||
status::success('Device has been successfully saved.');
|
||
url::redirect('devices/show/'.$dm->id);
|
||
}
|
||
catch (Exception $e)
|
||
catch (Exception $e) // failed => rollback and wait 100ms before next attempt
|
||
{
|
||
$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);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (isset($user_id))
|
||
{
|
||
... | ... | |
$linkback = 'devices/show_all';
|
||
}
|
||
|
||
if ($device->delete())
|
||
// 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_subnets_Controller::update_enabled($mid, NULL, NULL, $subnets);
|
||
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);
|
||
}
|
||
else
|
||
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);
|
||
}
|
||
|
||
// redirect
|
||
url::redirect($linkback);
|
||
usleep($timeout);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Generate export of device
|
freenetis/trunk/kohana/application/libraries/Settings.php | ||
---|---|---|
'allowed_subnets_update_interval' => 60,
|
||
// default count of allowed subnets
|
||
'allowed_subnets_default_count' => 1,
|
||
// if a deadlock came in, whole transaction may be executed again
|
||
// this property sets the max count of repeats of execution. (#284)
|
||
'db_trans_deadlock_repeats_count' => 4,
|
||
// if repeats (previous variable) are set as greater than 1, this
|
||
// timeout in ms defines time to next repeat of execution. (#284)
|
||
'db_trans_deadlock_repeats_timeout' => 100,
|
||
// default value for prefix of subject of notification
|
||
// e-mails to members
|
||
'email_subject_prefix' => 'FreenetIS',
|
Také k dispozici: Unified diff
Opravy:
- merge #399: chybne vypsani chybove hlasky u skriptu pro presmerovani
- fixes #254: deadlock