array(), 'ips' => array()); } if($type == ZoneTypeEnum::ADDON) { $serviceid = hostingaddon::factory($relid)->hostingid; } else { $serviceid = $relid; } $out['pools'] = IPManagerIntegration::getIPPoolsForService($serviceid); $out['all_ips'] = $out['ips'] = $client->getIPsForService($serviceid); } else { $out['pools'] = IPManagerIntegration::getIPPoolsForClient($clientid); $out['all_ips'] = $out['ips'] = $client->getClientIPs(); } foreach($out['pools'] as $pk => $pool) { $empty_pool = true; foreach($out['ips'] as $k => $ip) { $ip = new IP($ip); if($ip->isInNetwork($pool['pool'], $pool['mask'])) { unset($out['ips'][$k]); $empty_pool = false; } } if($empty_pool && !self::isSubnetCustomIPEnabled()) { unset($out['pools'][$pk]); } } return $out; } public static function validateIfClientCanUseIP($clientid, $type, $relid, $ip, $zone_create = false) { $ip = new IP($ip); if(!$ip->isValid()) { throw new ValidationException('Invalid IP', 1); } if(( $zone_create === FALSE && self::isCustomIPEnabled() ) || ($zone_create === TRUE && self::isCustomIPEnabledForZoneCreate()) ) { return true; } $ip_array = self::getIPsArray($clientid, $type, $relid); if( !self::isSubnetCustomIPEnabled() ) { if(!in_array((string)$ip, $ip_array['all_ips'])) { throw new ValidationException("You cannot use IP that do not belongs to you", 301); } return true; } if(in_array((string)$ip, $ip_array['ips'])) { return true; } foreach($ip_array['pools'] as $pool) { if($ip->isInNetwork($pool['pool'], $pool['mask'])) { return true; } } throw new ValidationException("You cannot use IP that does not belong to subnet", 302); } }