Files
portal-api/app/Http/Controllers/Api/Admin/IpPool/Concerns/ReadsIpPoolUsage.php
T
baodev0 0b08689ea4 feat: harden admin auth and ticket workflows
- add rotating admin refresh tokens and password gates\n- expand ticket galleries, exports, and client resources\n- improve IP allocation auditing and dashboard data\n- enforce encrypted client access tokens on public routes
2026-10-16 17:00:55 +07:00

52 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\IpPool\Concerns;
use App\Models\IpPool;
use App\Models\ModuleNetwork;
use App\Services\IpPool\IpPoolDashboard;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
trait ReadsIpPoolUsage
{
/**
* Service IDs already tied to an IP — either directly via ip_pools.service_id,
* or indirectly via a VM (module_vmware) sitting on that IP. Used by the admin
* form to disable services that are already in use on another IP.
*/
public function usedServices(): JsonResponse
{
$direct = IpPool::whereNotNull('service_id')
->select(['id as ip_pool_id', 'service_id']);
$viaVm = DB::table('ip_pools as ip')
->join('module_ip_address as mia', function ($join) {
$join->on('mia.ip', '=', 'ip.ip_address')
->on('mia.module_network_id', '=', 'ip.module_network_id');
})
->join('module_vmware as mv', 'mv.module_ip_address', '=', 'mia.id')
->whereNotNull('mv.service_id')
->select(['ip.id as ip_pool_id', 'mv.service_id']);
$used = $direct->toBase()->union($viaVm)->get()->unique(fn ($row) => "{$row->service_id}-{$row->ip_pool_id}")->values();
return response()->json(['error' => false, 'data' => $used]);
}
public function dashboard(IpPoolDashboard $dashboard): JsonResponse
{
return response()->json(['error' => false, 'data' => $dashboard->build()]);
}
public function networks(): JsonResponse
{
$networks = ModuleNetwork::select(['id', 'name', 'type', 'network', 'module_host_id'])
->with(['host:id,name,module_datacenter_id', 'host.datacenter:id,name'])
->orderBy('name')
->get();
return response()->json(['error' => false, 'data' => $networks]);
}
}