Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1777

Přidáno uživatelem Michal Kliment před téměř 12 roky(ů)

Opravy:

- #411 - Zmena velikosti podsite s vlastnikem podsite
- #413 - Rozkol IP adres a podsite pri zmene velikosti podsite - vyreseno vylepsenym validatorem
- #414 - Upozorneni na znovu najeti zarizeni nefunguje pokud neni dalsi jine zarizeni nefunkcni

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'there are not any unassigned admins' => 'Neexistují nepřiřazení správci',
'there are not any unassigned subnets' => 'Neexistují nepřiřazené podsítě',
'there is already some vlan with this tag' => 'Již existuje nějaký VLAN s tímto tagem.',
'there is at least one ip address of subnet which not belong to subnet range' => 'Existuje alespoň jedna IP adresa podsítě, která nepatří do rozsahu podsítě.',
'third-degree certified engineers' => 'Certifikovaní technici třetího stupně',
'this account does not exist' => 'Tento účet neexistuje.',
'this approval template already contains approval type with the same priority' => 'Tato hlasovací šablona již obsahuje hlasovací typ se stejnou prioritou.',
freenetis/branches/testing/application/models/ip_address.php
}
/**
* Deletes all IP addresses of subnet with owner
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $subnet_id
*/
public function delete_ip_addresses_of_subnet_with_owner($subnet_id)
{
$this->db->query("
DELETE FROM ip_addresses
WHERE subnet_id = ? AND member_id IS NOT NULL
", $subnet_id);
}
/**
* Sets whitelist
*
* @param ineteger $whitelist
......
return $arr_ip;
}
/**
* Returns first IP address of subnet
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $subnet_id
* @return type
*/
public function get_first_ip_address_of_subnet($subnet_id, $without_owner = FALSE)
{
// not return IP addresses with owner
$WHERE = ($without_owner) ? "AND member_id IS NULL" : "";
$result = $this->db->query("
SELECT ip.*
FROM ip_addresses ip
WHERE subnet_id = ? $WHERE
ORDER BY INET_ATON(ip_address)
", array($subnet_id));
return ($result && $result->current()) ? $result->current() : FALSE;
}
/**
* Returns last IP address of subnet
*
* @author Michal Kliment <kliment@freenetis.org>
* @param type $subnet_id
* @return type
*/
public function get_last_ip_address_of_subnet($subnet_id, $without_owner = FALSE)
{
// not return IP addresses with owner
$WHERE = ($without_owner) ? "AND member_id IS NULL" : "";
$result = $this->db->query("
SELECT ip.*
FROM ip_addresses ip
WHERE subnet_id = ? $WHERE
ORDER BY INET_ATON(ip_address) DESC
", array($subnet_id));
return ($result && $result->current()) ? $result->current() : FALSE;
}
}
freenetis/branches/testing/application/controllers/subnets.php
if($form->validate())
{
$form_data = $form->as_array();
if ($subnet_model->subnets_owner->member->id != $form_data['owner_id'])
$ip_address_model = new Ip_address_Model();
try
{
$ip_address_model = new Ip_address_Model();
$subnet_model->transaction_start();
$ip_address_model->delete_ip_addresses_by_subnet_member(
$subnet_id, $subnet_model->subnets_owner->member_id
);
$subnet_model->name = $form_data['name'];
$subnet_model->network_address = $form_data['network_address'];
$subnet_model->netmask = $form_data['netmask'];
$subnet_model->OSPF_area_id = $form_data['OSPF_area_id'];
if ($this->acl_check_edit('Devices_Controller', 'redirect'))
{
$subnet_model->redirect = $form_data['redirect'];
}
$subnet_model->save_throwable();
// deletes all IP addresses with owner
$ip_address_model->delete_ip_addresses_of_subnet_with_owner($subnet_model->id);
// owner has been set and will be changed
if ($subnet_model->subnets_owner->id && $subnet_model->subnets_owner->member_id != $form_data['owner_id'])
{
$member_id = $subnet_model->subnets_owner->member->id;
$count = $ip_address_model->count_all_ip_addresses_by_member_and_subnet(
$member_id, $subnet_model->id
);
if (!$count)
{
Allowed_subnets_Controller::update_enabled(
$member_id, NULL, NULL, array($subnet_model->id)
);
}
}
// owner is set
if ($form_data['owner_id'])
{
{
$subnet_model->subnets_owner->subnet_id = $subnet_model->id;
$subnet_model->subnets_owner->member_id = $form_data['owner_id'];
$subnet_model->subnets_owner->redirect = 0;
$subnet_model->subnets_owner->save();
$subnet_model->subnets_owner->save_throwable();
// find all free IP addresses
$ips = $subnet_model->get_free_ip_addresses();
$ip_address_model = new Ip_address_Model();
foreach ($ips as $ip)
{
$ip_address_model->clear();
......
Allowed_subnets_Controller::update_enabled(
$form_data['owner_id'], array($subnet_model->id)
);
}
else
{
$subnet_model->subnets_owner->delete();
else if ($subnet_model->subnets_owner->id)
{
$subnet_model->subnets_owner->delete_throwable();
}
$member_id = $subnet_model->subnets_owner->member->id;
$count = ORM::factory('ip_address')->count_all_ip_addresses_by_member_and_subnet(
$member_id, $subnet_model->id
);
if ($subnet_model->subnets_owner->member->id && !$count)
{
Allowed_subnets_Controller::update_enabled(
$member_id, NULL, NULL, array($subnet_model->id)
);
}
$subnet_model->transaction_commit();
status::success('Subnet has been successfully updated.');
}
$subnet_model->name = $form_data['name'];
$subnet_model->network_address = $form_data['network_address'];
$subnet_model->netmask = $form_data['netmask'];
$subnet_model->OSPF_area_id = $form_data['OSPF_area_id'];
if ($this->acl_check_edit('Devices_Controller', 'redirect'))
catch (Exception $e)
{
$subnet_model->redirect = $form_data['redirect'];
$subnet_model->transaction_rollback();
status::error('Error - subnet has not been successfully updated.');
}
if ($subnet_model->save())
{
status::success('Subnet has been successfully updated.');
}
$this->redirect('subnets/show/' . $subnet_id);
}
else
{
......
$netip = ip2long($input->value);
$mask = (int) ip2long($_POST['netmask']);
$net_start = ip2long($input->value);
$net_end = $net_start + (~ip2long($netmask) & 0xffffffff) + 1;
$ip_address_model = new Ip_address_Model();
// try to find first IP address of subnet
$first_ip_address = $ip_address_model->get_first_ip_address_of_subnet(
$this->subnet_id, TRUE
);
// first IP address exist
if ($first_ip_address)
{
// trasnsform to long
$first_ip_address = ip2long($first_ip_address->ip_address);
// first IP address is not in subnet range
if ($first_ip_address < $net_start || $first_ip_address > $net_end)
{
$input->add_error('required', __(
'There is at least one ip address of subnet which not belong to subnet range'
));
}
}
// try to find last IP address of subnet
$last_ip_address = $ip_address_model->get_last_ip_address_of_subnet(
$this->subnet_id, TRUE
);
// last IP address exist
if ($last_ip_address)
{
// trasnsform to long
$last_ip_address = ip2long($last_ip_address->ip_address);
// last IP address is not in subnet range
if ($last_ip_address < $net_start || $last_ip_address > $net_end)
{
$input->add_error('required', __(
'There is at least one ip address of subnet which not belong to subnet range'
));
}
}
// default network adress ranges are set
if (($ranges = Settings::get('address_ranges')) != '')
{
$net_start = ip2long($input->value);
$net_end = $net_start + (~ip2long($netmask) & 0xffffffff) + 1;
// transform string to array
$ranges = explode(',', $ranges);
freenetis/branches/testing/application/controllers/ip_addresses.php
try // try to make DB transction
{
$ip_address->transaction_start();
$ip_address->delete_throwable();
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
freenetis/branches/testing/application/controllers/scheduler.php
* following code generate sequence of diffs
* for each diff and host will be sent notification once time
*/
$diffs = array();
$down_diffs = array();
$increase = 3;
$growth = 5;
......
while ($i <= $max_down_diff)
{
$diffs[] = $i;
$down_diffs[] = $i;
$i += $increase;
......
}
}
// maximal value from sequence of diff for which will sent notification
// about hosts which returned from down state
$max_returned_diff = 10;
for($i=0;$i<count($diffs)-1;$i++)
for($i=0;$i<count($down_diffs)-1;$i++)
{
/**
* find all down hosts in interval between this diff and next diff
......
* in this interval)
*/
$down_hosts = $monitor_host_model->get_all_hosts_by_state(
Monitor_host_Model::STATE_DOWN, $diffs[$i], $diffs[$i+1]);
Monitor_host_Model::STATE_DOWN, $down_diffs[$i], $down_diffs[$i+1]);
// for each send e-mail
foreach ($down_hosts as $down_host)
......
$monitor_host_model->update_host_notification_date($down_host->id);
}
}
// maximal value from sequence of diff for which will sent notification
// about hosts which returned from down state
$max_returned_diff = 30;
/**
* following code generate sequence of diffs
* for each diff and host will be sent notification once time
*/
$returned_diffs = array();
// send notification about hosts which returned from down state
if ($diffs[$i] < $max_returned_diff)
{
/**
* find all hosts which returned from down state in interval
* between this diff and next diff (exclude hosts about which
* has been already sent notification in this interval)
*/
$returned_hosts = $monitor_host_model->get_all_hosts_by_state(
Monitor_host_Model::STATE_UP, $diffs[$i], $diffs[$i+1]);
$increase = 3;
$growth = 5;
// for each send e-mail
foreach ($returned_hosts as $returned_host)
{
$email_queue_model->push(
Settings::get('email_default_email'),
Settings::get('monitoring_email_to'),
__('Monitoring notice').': '.__('Host').' '.$returned_host->name.' '.__('is again reachable'),
__('Host').' '
.html::anchor(url_lang::base().'devices/show/'.$returned_host->device_id, $returned_host->name)
.' '.__('is again reachable since').' '.strftime("%c", strtotime($returned_host->state_changed_date))
);
$i = 0;
$monitor_host_model->update_host_notification_date($returned_host->id);
}
$max = 5;
while ($i <= $max_returned_diff)
{
$returned_diffs[] = $i;
$i += $increase;
if ($i >= $max)
{
$increase = $max;
$max *= $growth;
}
}
for($i=0;$i<count($returned_diffs)-1;$i++)
{
/**
* find all hosts which returned from down state in interval
* between this diff and next diff (exclude hosts about which
* has been already sent notification in this interval)
*/
$returned_hosts = $monitor_host_model->get_all_hosts_by_state(
Monitor_host_Model::STATE_UP, $returned_diffs[$i], $returned_diffs[$i+1]);
// for each send e-mail
foreach ($returned_hosts as $returned_host)
{
$email_queue_model->push(
Settings::get('email_default_email'),
Settings::get('monitoring_email_to'),
__('Monitoring notice').': '.__('Host').' '.$returned_host->name.' '.__('is again reachable'),
__('Host').' '
.html::anchor(url_lang::base().'devices/show/'.$returned_host->device_id, $returned_host->name)
.' '.__('is again reachable since').' '.strftime("%c", strtotime($returned_host->state_changed_date))
);
$monitor_host_model->update_host_notification_date($returned_host->id);
}
}
$monitor_host_model->transaction_commit();
}
catch (Exception $e)

Také k dispozici: Unified diff