init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user