Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1915

Přidáno uživatelem Michal Kliment před více než 11 roky(ů)

Opravy:
- fixes #548: Naseptavac volnych IP adres u pridavani/editace IP adres

Zobrazit rozdíly:

freenetis/branches/1.1/application/models/ip_address.php
return ($result && $result->current()) ? $result->current() : FALSE;
}
/**
* Returns all free IP addresses similar to given IP address
*
* @author Michal Kliment
* @param type $ip_address_like
* @return type
*/
public function get_free_ip_addresses($ip_address_like)
{
$arr_ip_addresses = array();
$subnet_model = new Subnet_Model();
// split IP address
$ips = explode('.', $ip_address_like);
// take only first 3 numbers
$ips = array_slice($ips, 0, 3);
// join back to IP address
$network_address = implode('.', $ips);
$subnets = $subnet_model
->like('network_address', $network_address)
->find_all();
$ip_queries = array();
foreach ($subnets as $subnet)
{
$network = ip2long($subnet->network_address);
$total_available = (~ip2long($subnet->netmask) & 0xffffffff)-1;
if ($total_available > 1)
{
for ($i = 1; $i <= $total_available; $i++)
$ip_queries[] = "SELECT '".long2ip($network+$i)."' AS ip_address";
}
// for special 1-host subnet (mask /32) add only 1 IP address with network address (#507)
else
{
$ip_queries[] = "SELECT '".long2ip($network)."' AS ip_address";
}
}
if (!count($ip_queries))
return array();
$ip_query = implode("\nUNION\n", $ip_queries);
$ips = $this->db->query("
SELECT ip_address
FROM
(
$ip_query
) AS ip
WHERE ip_address NOT IN
(
SELECT ip_address
FROM ip_addresses
)
AND ip_address LIKE '%$ip_address_like%'
", $this->id);
foreach ($ips as $ip)
$arr_ip_addresses[] = $ip->ip_address;
return $arr_ip_addresses;
}
}
freenetis/branches/1.1/application/models/watcher.php
WHERE type = ? AND fk_id = ?
", array($type, $fk_id));
}
}
?>
}
freenetis/branches/1.1/application/controllers/json.php
*/
public static function send_json_headers()
{
@header('Cache-Control: no-cache, must-revalidate');
/*@header('Cache-Control: no-cache, must-revalidate');
@header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@header('Content-type: application/json');
@header('Content-type: application/json');*/
}
/**
......
echo json_encode($data);
}
/**
* Prints all free IP addresses similar to given IP address
*
* @author Michal Kliment
*/
public function get_free_ip_addresses()
{
$ip_address = $this->input->get('term');
$ip_address_model = new Ip_address_Model();
try
{
$ip_addresses = $ip_address_model->get_free_ip_addresses($ip_address);
}
catch (Exception $e)
{
$ip_addresses = array();
}
echo json_encode($ip_addresses);
}
}
freenetis/branches/1.1/application/controllers/js.php
}
}
private function _js_devices()
{
$this->ip_addresses_complete();
}
private function _js_devices_add($user_id = NULL, $connection_request_id = NULL)
{
$user = new User_Model($user_id);
......
}
}
private function _js_members_add()
private function _js_ip_addresses()
{
$this->ip_addresses_complete();
}
private function _js_members_add()
{
$this->address_point_streets();
$this->address_point_gps();
$this->domicile_toogle();
......
View::factory('js/__pieces/notification_activate')->render();
}
/**
* Adds javascript for IP address adding/editing
*/
private function ip_addresses_complete()
{
$this->views['__pieces_ip_addresses_complete'] =
View::factory('js/__pieces/ip_addresses_complete')->render();
}
}
freenetis/branches/1.1/application/views/js/__pieces/ip_addresses_complete.php
<?php
/**
* Javascript functionality for adding/edditing of IP addresses.
*
* @author Michal Kliment, Ondřej Fibich
*/
// IDE complementation
if (FALSE): ?><script type='text/javascript'><?php endif
?>
$("#ip_address, input.ip_address").live("keydown.autocomplete", function (){
var input = $(this);
input.autocomplete({
source: "<?php echo url_lang::base() ?>json/get_free_ip_addresses",
close: function (event, ui) {
input.trigger('keyup');
}
});
});

Také k dispozici: Unified diff