update fix deadcode, security
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\IpPool\Concerns;
|
||||
|
||||
use App\Models\IpPool;
|
||||
use App\Models\ModuleNetwork;
|
||||
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 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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user