/
DATKAI
/
ITCUP
Обзор
Документация
Войти
/
DATKAI
/
ITCUP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Console/Commands/VpnStatusCommand.php
63 строки
2 KB
ITCUP Admin
feat(vpn): этап 3 — маршрутизация site-to-site + этап 4 — мониторинг
22 апр 2026, 08:13
22 апр 2026, 08:13
96a4d88
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use App\Models\VpnClient; use App\Models\VpnService; use App\Services\Vpn\VpnManager; use Illuminate\Console\Command; class VpnStatusCommand extends Command { protected $signature = 'itcup:vpn-status'; protected $description = 'Обновляет статус управляемых VPN-сервисов и peer-ов (handshake, bytes)'; public function handle(VpnManager $manager): int { $services = VpnService::whereIn('role', ['hub', 'client']) ->where('is_active', true) ->get(); if ($services->isEmpty()) { return self::SUCCESS; } foreach ($services as $service) { $res = $manager->status($service); if (($res['state'] ?? '') !== 'up' || empty($res['peers'])) { continue; } // Сопоставляем peer-ов по публичному ключу foreach ($res['peers'] as $peer) { $pubKey = $peer['public_key'] ?? null; if (!$pubKey) continue; // Ищем VpnClient с таким public_key в credentials $client = $service->clients() ->get() ->first(fn (VpnClient $c) => ($c->credentials['public_key'] ?? null) === $pubKey); if (!$client) continue; $update = [ 'rx_bytes' => $peer['rx_bytes'] ?? 0, 'tx_bytes' => $peer['tx_bytes'] ?? 0, 'last_endpoint' => $peer['endpoint'] ?: null, ]; if (!empty($peer['last_handshake'])) { $update['last_handshake_at'] = \Carbon\Carbon::createFromTimestamp($peer['last_handshake']); } $client->update($update); } $this->line("✓ {$service->name}: " . count($res['peers']) . ' peer-ов обновлено'); } return self::SUCCESS; } }