Итерация 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
+68 -1
View File
@@ -58,12 +58,56 @@ $containerBuilder->addDefinitions([
PDO::ATTR_EMULATE_PREPARES => false,
]);
},
// Repositories
\Domovoy\Repositories\UserRepository::class => function ($c) {
return new \Domovoy\Repositories\UserRepository($c->get(PDO::class));
},
\Domovoy\Repositories\NetworkRangeRepository::class => function ($c) {
return new \Domovoy\Repositories\NetworkRangeRepository($c->get(PDO::class));
},
\Domovoy\Repositories\ScanJobRepository::class => function ($c) {
return new \Domovoy\Repositories\ScanJobRepository($c->get(PDO::class));
},
\Domovoy\Repositories\DiscoveredHostRepository::class => function ($c) {
return new \Domovoy\Repositories\DiscoveredHostRepository($c->get(PDO::class));
},
\Domovoy\Repositories\AuditLogRepository::class => function ($c) {
return new \Domovoy\Repositories\AuditLogRepository($c->get(PDO::class));
},
// Discovery services
\Domovoy\Services\Discovery\PingScanner::class => function () {
return new \Domovoy\Services\Discovery\PingScanner();
},
\Domovoy\Services\Discovery\TcpPortScanner::class => function () {
return new \Domovoy\Services\Discovery\TcpPortScanner();
},
\Domovoy\Services\Discovery\ArpTableReader::class => function () {
return new \Domovoy\Services\Discovery\ArpTableReader();
},
\Domovoy\Services\Discovery\HostFingerprintService::class => function () {
return new \Domovoy\Services\Discovery\HostFingerprintService();
},
\Domovoy\Services\Discovery\NetworkScanner::class => function ($c) {
return new \Domovoy\Services\Discovery\NetworkScanner(
$c->get(\Domovoy\Services\Discovery\PingScanner::class),
$c->get(\Domovoy\Services\Discovery\TcpPortScanner::class),
$c->get(\Domovoy\Services\Discovery\ArpTableReader::class),
$c->get(\Domovoy\Services\Discovery\HostFingerprintService::class),
$c->get(\Domovoy\Repositories\DiscoveredHostRepository::class)
);
},
// Job runner
\Domovoy\Services\Jobs\ScanJobRunner::class => function ($c) {
return new \Domovoy\Services\Jobs\ScanJobRunner(
$c->get(\Domovoy\Repositories\ScanJobRepository::class),
$c->get(\Domovoy\Services\Discovery\NetworkScanner::class)
);
},
// Auth
\Domovoy\Services\AuthService::class => function ($c) {
return new \Domovoy\Services\AuthService($c->get(\Domovoy\Repositories\UserRepository::class));
},
// Controllers
\Domovoy\Controllers\AuthController::class => function ($c) {
return new \Domovoy\Controllers\AuthController($c->get(\Domovoy\Services\AuthService::class));
},
@@ -73,6 +117,18 @@ $containerBuilder->addDefinitions([
\Domovoy\Controllers\DashboardController::class => function () {
return new \Domovoy\Controllers\DashboardController();
},
\Domovoy\Controllers\DiscoveryController::class => function ($c) {
return new \Domovoy\Controllers\DiscoveryController(
$c->get(\Domovoy\Repositories\NetworkRangeRepository::class),
$c->get(\Domovoy\Repositories\ScanJobRepository::class),
$c->get(\Domovoy\Repositories\DiscoveredHostRepository::class)
);
},
\Domovoy\Controllers\NetworkRangeController::class => function ($c) {
return new \Domovoy\Controllers\NetworkRangeController(
$c->get(\Domovoy\Repositories\NetworkRangeRepository::class)
);
},
]);
$container = $containerBuilder->build();
@@ -85,15 +141,26 @@ $app->addBodyParsingMiddleware();
$app->add(new \Domovoy\Middleware\AuthMiddleware());
$app->addErrorMiddleware(true, true, true);
// Routes
// Public routes
$app->get('/login', [\Domovoy\Controllers\AuthController::class, 'loginForm'])->setName('login');
$app->post('/login', [\Domovoy\Controllers\AuthController::class, 'login'])->setName('login.post');
$app->get('/setup', [\Domovoy\Controllers\SetupController::class, 'form'])->setName('setup');
$app->post('/setup', [\Domovoy\Controllers\SetupController::class, 'create'])->setName('setup.post');
// Protected routes
$app->group('', function (\Slim\Routing\RouteCollectorProxy $group) {
$group->get('/dashboard', [\Domovoy\Controllers\DashboardController::class, 'index'])->setName('dashboard');
$group->post('/logout', [\Domovoy\Controllers\AuthController::class, 'logout'])->setName('logout');
// Discovery
$group->get('/discovery', [\Domovoy\Controllers\DiscoveryController::class, 'index'])->setName('discovery');
$group->post('/discovery/scan', [\Domovoy\Controllers\DiscoveryController::class, 'startScan'])->setName('discovery.scan');
$group->post('/discovery/hosts/ignore', [\Domovoy\Controllers\DiscoveryController::class, 'ignoreHost'])->setName('discovery.hosts.ignore');
// Network ranges CRUD
$group->post('/discovery/ranges/create', [\Domovoy\Controllers\NetworkRangeController::class, 'create'])->setName('discovery.ranges.create');
$group->post('/discovery/ranges/toggle', [\Domovoy\Controllers\NetworkRangeController::class, 'toggle'])->setName('discovery.ranges.toggle');
$group->post('/discovery/ranges/delete', [\Domovoy\Controllers\NetworkRangeController::class, 'delete'])->setName('discovery.ranges.delete');
});
$app->run();