mirror of
https://github.com/rekryt/iplist.git
synced 2025-10-13 16:59:36 +03:00
feat: exclude local ip-s
This commit is contained in:
@@ -53,14 +53,14 @@ final class Site {
|
|||||||
$ip6 = array_merge($ip6, $ipv6results);
|
$ip6 = array_merge($ip6, $ipv6results);
|
||||||
}
|
}
|
||||||
|
|
||||||
$newIp4 = SiteFactory::normalize(array_diff($ip4, $this->ip4));
|
$newIp4 = SiteFactory::normalize(array_diff($ip4, $this->ip4), true);
|
||||||
$this->cidr4 = SiteFactory::normalize(IP4Helper::processCIDR($newIp4, $this->cidr4));
|
$this->cidr4 = SiteFactory::normalize(IP4Helper::processCIDR($newIp4, $this->cidr4), true);
|
||||||
|
|
||||||
$newIp6 = SiteFactory::normalize(array_diff($ip6, $this->ip6));
|
$newIp6 = SiteFactory::normalize(array_diff($ip6, $this->ip6), true);
|
||||||
$this->cidr6 = SiteFactory::normalize(IP6Helper::processCIDR($newIp6, $this->cidr6));
|
$this->cidr6 = SiteFactory::normalize(IP6Helper::processCIDR($newIp6, $this->cidr6), true);
|
||||||
|
|
||||||
$this->ip4 = SiteFactory::normalize(array_merge($this->ip4, $ip4));
|
$this->ip4 = SiteFactory::normalize(array_merge($this->ip4, $ip4), true);
|
||||||
$this->ip6 = SiteFactory::normalize(array_merge($this->ip6, $ip6));
|
$this->ip6 = SiteFactory::normalize(array_merge($this->ip6, $ip6), true);
|
||||||
|
|
||||||
$this->saveConfig();
|
$this->saveConfig();
|
||||||
App::getLogger()->debug('Reloaded for ' . $this->name);
|
App::getLogger()->debug('Reloaded for ' . $this->name);
|
||||||
@@ -85,20 +85,27 @@ final class Site {
|
|||||||
|
|
||||||
if (isset($this->external->ip4)) {
|
if (isset($this->external->ip4)) {
|
||||||
foreach ($this->external->ip4 as $url) {
|
foreach ($this->external->ip4 as $url) {
|
||||||
$this->ip4 = SiteFactory::normalize(array_merge($this->ip4, explode("\n", file_get_contents($url))));
|
$this->ip4 = SiteFactory::normalize(
|
||||||
|
array_merge($this->ip4, explode("\n", file_get_contents($url))),
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->external->ip6)) {
|
if (isset($this->external->ip6)) {
|
||||||
foreach ($this->external->ip6 as $url) {
|
foreach ($this->external->ip6 as $url) {
|
||||||
$this->ip6 = SiteFactory::normalize(array_merge($this->ip6, explode("\n", file_get_contents($url))));
|
$this->ip6 = SiteFactory::normalize(
|
||||||
|
array_merge($this->ip6, explode("\n", file_get_contents($url))),
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->external->cidr4)) {
|
if (isset($this->external->cidr4)) {
|
||||||
foreach ($this->external->cidr4 as $url) {
|
foreach ($this->external->cidr4 as $url) {
|
||||||
$this->cidr4 = SiteFactory::normalize(
|
$this->cidr4 = SiteFactory::normalize(
|
||||||
array_merge($this->cidr4, explode("\n", file_get_contents($url)))
|
array_merge($this->cidr4, explode("\n", file_get_contents($url))),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,7 +113,8 @@ final class Site {
|
|||||||
if (isset($this->external->cidr6)) {
|
if (isset($this->external->cidr6)) {
|
||||||
foreach ($this->external->cidr6 as $url) {
|
foreach ($this->external->cidr6 as $url) {
|
||||||
$this->cidr6 = SiteFactory::normalize(
|
$this->cidr6 = SiteFactory::normalize(
|
||||||
array_merge($this->cidr6, explode("\n", file_get_contents($url)))
|
array_merge($this->cidr6, explode("\n", file_get_contents($url))),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,21 +57,43 @@ class SiteFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$domains = self::normalize($domains);
|
$domains = self::normalize($domains);
|
||||||
$ip4 = self::normalize($ip4);
|
$ip4 = self::normalize($ip4, true);
|
||||||
$ip6 = self::normalize($ip6);
|
$ip6 = self::normalize($ip6, true);
|
||||||
$cidr4 = self::normalize(IP4Helper::processCIDR($ip4, self::normalize($cidr4)));
|
$cidr4 = self::normalize(IP4Helper::processCIDR($ip4, self::normalize($cidr4)), true);
|
||||||
$cidr6 = self::normalize(IP6Helper::processCIDR($ip6, self::normalize($cidr6)));
|
$cidr6 = self::normalize(IP6Helper::processCIDR($ip6, self::normalize($cidr6)), true);
|
||||||
|
|
||||||
return new Site($name, $domains, $dns, $timeout, $ip4, $ip6, $cidr4, $cidr6, $external);
|
return new Site($name, $domains, $dns, $timeout, $ip4, $ip6, $cidr4, $cidr6, $external);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
|
* @param bool $excludeLocalIPs
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function normalize(array $array): array {
|
public static function normalize(array $array, bool $excludeLocalIPs = false): array {
|
||||||
return array_values(
|
return array_values(
|
||||||
array_unique(array_filter($array, fn(string $item) => !str_starts_with($item, '#') && strlen($item) > 0))
|
array_unique(
|
||||||
|
array_filter(
|
||||||
|
$array,
|
||||||
|
fn(string $item) => !str_starts_with($item, '#') &&
|
||||||
|
strlen($item) > 0 &&
|
||||||
|
(!$excludeLocalIPs ||
|
||||||
|
(!str_starts_with($item, '10.') &&
|
||||||
|
!str_starts_with($item, '172.16.') &&
|
||||||
|
!str_starts_with($item, '192.168.') &&
|
||||||
|
!str_starts_with($item, 'fd')))
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $array
|
||||||
|
* @param bool $excludeLocalIPs
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function normalizeArray(array $array, bool $excludeLocalIPs = false): array {
|
||||||
|
sort($array);
|
||||||
|
return SiteFactory::normalize($array, $excludeLocalIPs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user