Итерация 2: сканирование сети
- Phinx миграции: network_ranges, scan_jobs, discovered_hosts, audit_log - Models: NetworkRange, ScanJob, DiscoveredHost - Repositories с CRUD для всех сущностей - NetworkScanner: ping sweep + TCP connect + ARP table + reverse DNS - PingScanner, TcpPortScanner (curl_multi для параллелизма), ArpTableReader - HostFingerprintService: vendor detection + confidence scoring - ScanJobRunner + CLI worker (bin/run-scan-worker.php) - Discovery UI: управление диапазонами, запуск скана, таблица находок - NetworkRangeController с валидацией CIDR - Обновлён public/index.php с DI конфигурацией для новых сервисов
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Domovoy\Models;
|
||||
|
||||
class DiscoveredHost
|
||||
{
|
||||
public ?int $id = null;
|
||||
public ?int $scanJobId = null;
|
||||
public string $ipAddress = '';
|
||||
public ?string $macAddress = null;
|
||||
public ?string $hostname = null;
|
||||
public ?string $vendor = null;
|
||||
public ?string $detectedOs = null;
|
||||
/** @var int[] */
|
||||
public array $openPorts = [];
|
||||
/** @var string[] */
|
||||
public array $protocols = [];
|
||||
public array $fingerprint = [];
|
||||
public int $confidence = 50;
|
||||
public string $status = 'new';
|
||||
public ?string $matchedDeviceId = null;
|
||||
public ?\DateTimeImmutable $firstSeen = null;
|
||||
public ?\DateTimeImmutable $lastSeen = null;
|
||||
public ?\DateTimeImmutable $createdAt = null;
|
||||
public ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$obj = new self();
|
||||
$obj->id = (int)$data['id'];
|
||||
$obj->scanJobId = $data['scan_job_id'] !== null ? (int)$data['scan_job_id'] : null;
|
||||
$obj->ipAddress = $data['ip_address'];
|
||||
$obj->macAddress = $data['mac_address'] ?? null;
|
||||
$obj->hostname = $data['hostname'] ?? null;
|
||||
$obj->vendor = $data['vendor'] ?? null;
|
||||
$obj->detectedOs = $data['detected_os'] ?? null;
|
||||
$obj->openPorts = json_decode($data['open_ports_json'] ?? '[]', true);
|
||||
$obj->protocols = json_decode($data['protocols_json'] ?? '[]', true);
|
||||
$obj->fingerprint = json_decode($data['fingerprint_json'] ?? '{}', true);
|
||||
$obj->confidence = (int)$data['confidence'];
|
||||
$obj->status = $data['status'];
|
||||
$obj->matchedDeviceId = $data['matched_device_id'] ?? null;
|
||||
$obj->firstSeen = new \DateTimeImmutable($data['first_seen']);
|
||||
$obj->lastSeen = new \DateTimeImmutable($data['last_seen']);
|
||||
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
|
||||
$obj->updatedAt = new \DateTimeImmutable($data['updated_at']);
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Domovoy\Models;
|
||||
|
||||
class NetworkRange
|
||||
{
|
||||
public ?int $id = null;
|
||||
public string $name = '';
|
||||
public string $cidr = '';
|
||||
public bool $enabled = true;
|
||||
public ?\DateTimeImmutable $createdAt = null;
|
||||
public ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$obj = new self();
|
||||
$obj->id = (int)$data['id'];
|
||||
$obj->name = $data['name'];
|
||||
$obj->cidr = $data['cidr'];
|
||||
$obj->enabled = (bool)$data['enabled'];
|
||||
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
|
||||
$obj->updatedAt = new \DateTimeImmutable($data['updated_at']);
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Domovoy\Models;
|
||||
|
||||
class ScanJob
|
||||
{
|
||||
public ?int $id = null;
|
||||
public string $type = '';
|
||||
public string $status = 'pending';
|
||||
public ?int $networkRangeId = null;
|
||||
public ?string $deviceId = null;
|
||||
public ?\DateTimeImmutable $startedAt = null;
|
||||
public ?\DateTimeImmutable $finishedAt = null;
|
||||
public ?string $errorMessage = null;
|
||||
public ?string $resultJson = null;
|
||||
public ?string $createdBy = null;
|
||||
public ?\DateTimeImmutable $createdAt = null;
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
$obj = new self();
|
||||
$obj->id = (int)$data['id'];
|
||||
$obj->type = $data['type'];
|
||||
$obj->status = $data['status'];
|
||||
$obj->networkRangeId = $data['network_range_id'] !== null ? (int)$data['network_range_id'] : null;
|
||||
$obj->deviceId = $data['device_id'] ?? null;
|
||||
$obj->startedAt = $data['started_at'] !== null ? new \DateTimeImmutable($data['started_at']) : null;
|
||||
$obj->finishedAt = $data['finished_at'] !== null ? new \DateTimeImmutable($data['finished_at']) : null;
|
||||
$obj->errorMessage = $data['error_message'] ?? null;
|
||||
$obj->resultJson = $data['result_json'] ?? null;
|
||||
$obj->createdBy = $data['created_by'] ?? null;
|
||||
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user