Итерация 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:
2026-05-26 07:41:23 +08:00
parent e7732f5cee
commit 177e44f015
22 changed files with 1477 additions and 1 deletions
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateNetworkRanges extends AbstractMigration
{
public function change(): void
{
$table = $this->table('network_ranges');
$table
->addColumn('name', 'string', ['limit' => 255, 'null' => false])
->addColumn('cidr', 'string', ['limit' => 45, 'null' => false])
->addColumn('enabled', 'boolean', ['null' => false, 'default' => true])
->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addColumn('updated_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addIndex(['cidr'], ['unique' => true])
->create();
}
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateScanJobs extends AbstractMigration
{
public function change(): void
{
$table = $this->table('scan_jobs');
$table
->addColumn('type', 'string', ['limit' => 50, 'null' => false])
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'pending'])
->addColumn('network_range_id', 'integer', ['null' => true])
->addColumn('device_id', 'string', ['limit' => 36, 'null' => true])
->addColumn('started_at', 'datetime', ['null' => true])
->addColumn('finished_at', 'datetime', ['null' => true])
->addColumn('error_message', 'text', ['null' => true])
->addColumn('result_json', 'text', ['null' => true])
->addColumn('created_by', 'string', ['limit' => 36, 'null' => true])
->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addIndex(['status'])
->addIndex(['type'])
->create();
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateDiscoveredHosts extends AbstractMigration
{
public function change(): void
{
$table = $this->table('discovered_hosts');
$table
->addColumn('scan_job_id', 'integer', ['null' => true])
->addColumn('ip_address', 'string', ['limit' => 45, 'null' => false])
->addColumn('mac_address', 'string', ['limit' => 17, 'null' => true])
->addColumn('hostname', 'string', ['limit' => 255, 'null' => true])
->addColumn('vendor', 'string', ['limit' => 255, 'null' => true])
->addColumn('detected_os', 'string', ['limit' => 255, 'null' => true])
->addColumn('open_ports_json', 'text', ['null' => true])
->addColumn('protocols_json', 'text', ['null' => true])
->addColumn('fingerprint_json', 'text', ['null' => true])
->addColumn('confidence', 'integer', ['null' => false, 'default' => 50])
->addColumn('status', 'string', ['limit' => 20, 'null' => false, 'default' => 'new'])
->addColumn('matched_device_id', 'integer', ['null' => true])
->addColumn('first_seen', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addColumn('last_seen', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addColumn('updated_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addIndex(['ip_address'])
->addIndex(['mac_address'])
->addIndex(['status'])
->create();
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateAuditLog extends AbstractMigration
{
public function change(): void
{
$table = $this->table('audit_log');
$table
->addColumn('user_id', 'string', ['limit' => 36, 'null' => true])
->addColumn('action', 'string', ['limit' => 100, 'null' => false])
->addColumn('entity_type', 'string', ['limit' => 50, 'null' => true])
->addColumn('entity_id', 'string', ['limit' => 36, 'null' => true])
->addColumn('details_json', 'text', ['null' => true])
->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addIndex(['action'])
->addIndex(['entity_type', 'entity_id'])
->addIndex(['created_at'])
->create();
}
}