30 lines
680 B
PHP
30 lines
680 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LayLink\Agent;
|
|
|
|
use LayLink\Auth\PolicyChecker;
|
|
|
|
final class TargetConnector
|
|
{
|
|
public function __construct(private readonly array $nodeConfig)
|
|
{
|
|
}
|
|
|
|
public function isAllowed(string $host, int $port): bool
|
|
{
|
|
if (!in_array($port, $this->nodeConfig['allowed_ports'] ?? [], true)) {
|
|
return false;
|
|
}
|
|
|
|
foreach ($this->nodeConfig['allowed_cidrs'] ?? [] as $cidr) {
|
|
if (is_string($cidr) && PolicyChecker::cidrContains($cidr, $host)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return in_array($host, $this->nodeConfig['allowed_hosts'] ?? [], true);
|
|
}
|
|
}
|