2024-03-07 10:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2024-03-07 10:42:16 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2024-03-07 10:14:03 +00:00
|
|
|
use App\Models\Project as ModelsProject;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class Domains extends Controller
|
|
|
|
{
|
|
|
|
public function domains(Request $request)
|
|
|
|
{
|
|
|
|
$teamId = get_team_id_from_token();
|
|
|
|
if (is_null($teamId)) {
|
2024-03-07 11:27:23 +00:00
|
|
|
return invalid_token();
|
2024-03-07 10:14:03 +00:00
|
|
|
}
|
|
|
|
$projects = ModelsProject::where('team_id', $teamId)->get();
|
|
|
|
$domains = collect();
|
|
|
|
$applications = $projects->pluck('applications')->flatten();
|
2024-03-07 10:42:16 +00:00
|
|
|
$settings = InstanceSettings::get();
|
2024-03-07 10:14:03 +00:00
|
|
|
if ($applications->count() > 0) {
|
|
|
|
foreach ($applications as $application) {
|
|
|
|
$ip = $application->destination->server->ip;
|
|
|
|
$fqdn = str($application->fqdn)->explode(',')->map(function ($fqdn) {
|
|
|
|
return str($fqdn)->replace('http://', '')->replace('https://', '')->replace('/', '');
|
|
|
|
});
|
2024-03-07 10:49:15 +00:00
|
|
|
if ($ip === 'host.docker.internal') {
|
|
|
|
if ($settings->public_ipv4) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $settings->public_ipv4,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($settings->public_ipv6) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $settings->public_ipv6,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if (!$settings->public_ipv4 && !$settings->public_ipv6) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $ip,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
2024-03-07 11:36:49 +00:00
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $ip,
|
|
|
|
]);
|
2024-03-07 10:49:15 +00:00
|
|
|
}
|
2024-03-07 10:14:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$services = $projects->pluck('services')->flatten();
|
|
|
|
if ($services->count() > 0) {
|
|
|
|
foreach ($services as $service) {
|
|
|
|
$service_applications = $service->applications;
|
|
|
|
if ($service_applications->count() > 0) {
|
|
|
|
foreach ($service_applications as $application) {
|
|
|
|
$fqdn = str($application->fqdn)->explode(',')->map(function ($fqdn) {
|
|
|
|
return str($fqdn)->replace('http://', '')->replace('https://', '')->replace('/', '');
|
|
|
|
});
|
2024-03-07 10:49:15 +00:00
|
|
|
if ($ip === 'host.docker.internal') {
|
|
|
|
if ($settings->public_ipv4) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $settings->public_ipv4,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($settings->public_ipv6) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $settings->public_ipv6,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if (!$settings->public_ipv4 && !$settings->public_ipv6) {
|
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $ip,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
2024-03-07 11:36:49 +00:00
|
|
|
$domains->push([
|
|
|
|
'domain' => $fqdn,
|
|
|
|
'ip' => $ip,
|
|
|
|
]);
|
2024-03-07 10:49:15 +00:00
|
|
|
}
|
2024-03-07 10:14:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$domains = $domains->groupBy('ip')->map(function ($domain) {
|
|
|
|
return $domain->pluck('domain')->flatten();
|
2024-03-07 10:25:15 +00:00
|
|
|
})->map(function ($domain, $ip) {
|
|
|
|
return [
|
|
|
|
'ip' => $ip,
|
|
|
|
'domains' => $domain,
|
|
|
|
];
|
|
|
|
})->values();
|
2024-03-07 10:14:03 +00:00
|
|
|
|
|
|
|
return response()->json($domains);
|
|
|
|
}
|
|
|
|
}
|