Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1772

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

Zobrazit rozdíly:

freenetis/branches/1.1/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/1.1/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/1.1/application/controllers/subnets.php
{
if ($ip->iface_id)
{
$id = $ip->id;
$member_id = $ip->iface->device->user->member_id;
$member_name = $ip->iface->device->user->member->name;
}
else
{
$id = NULL;
$member_id = $ip->member_id;
$member_name = $ip->member->name;
}
$ip_addresses[ip2long($ip->ip_address)-$network] = arr::to_object(array
(
'id' => $ip->id,
'id' => $id,
'device_id' => $ip->iface->device_id,
'device_name' => $ip->iface->device->name,
'device_type' => $enum_type_model->get_value($ip->iface->device->type),
......
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'];
$subnet_model->dhcp = $form_data['dhcp'];
$subnet_model->qos = $form_data['qos'];
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'];
$subnet_model->dhcp = $form_data['dhcp'];
$subnet_model->qos = $form_data['qos'];
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/1.1/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

Také k dispozici: Unified diff