Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/DomainsController.php
Show All 15 Lines | class DomainsController extends Controller | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
$list = []; | $list = []; | ||||
foreach ($user->domains() as $domain) { | foreach ($user->domains() as $domain) { | ||||
if (!$domain->isPublic()) { | if (!$domain->isPublic()) { | ||||
$list[] = $domain->toArray(); | $data = $domain->toArray(); | ||||
$data = array_merge($data, self::domainStatuses($domain)); | |||||
$list[] = $data; | |||||
} | } | ||||
} | } | ||||
return response()->json($list); | return response()->json($list); | ||||
} | } | ||||
/** | /** | ||||
* Show the form for creating a new resource. | * Show the form for creating a new resource. | ||||
Show All 22 Lines | public function confirm($id) | ||||
} | } | ||||
if (!$domain->confirm()) { | if (!$domain->confirm()) { | ||||
return response()->json(['status' => 'error']); | return response()->json(['status' => 'error']); | ||||
} | } | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
'statusInfo' => self::statusInfo($domain), | |||||
'message' => __('app.domain-verify-success'), | 'message' => __('app.domain-verify-success'), | ||||
]); | ]); | ||||
} | } | ||||
/** | /** | ||||
* Remove the specified resource from storage. | * Remove the specified resource from storage. | ||||
* | * | ||||
* @param int $id | * @param int $id | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public function show($id) | ||||
$response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | $response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | ||||
$response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | $response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | ||||
$response['hash_code'] = $domain->hash(Domain::HASH_CODE); | $response['hash_code'] = $domain->hash(Domain::HASH_CODE); | ||||
// Add DNS/MX configuration for the domain | // Add DNS/MX configuration for the domain | ||||
$response['dns'] = self::getDNSConfig($domain); | $response['dns'] = self::getDNSConfig($domain); | ||||
$response['config'] = self::getMXConfig($domain->namespace); | $response['config'] = self::getMXConfig($domain->namespace); | ||||
$response['confirmed'] = $domain->isConfirmed(); | // Status info | ||||
$response['statusInfo'] = self::statusInfo($domain); | |||||
$response = array_merge($response, self::domainStatuses($domain)); | |||||
return response()->json($response); | return response()->json($response); | ||||
} | } | ||||
/** | /** | ||||
* Update the specified resource in storage. | * Update the specified resource in storage. | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request | * @param \Illuminate\Http\Request $request | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | protected static function getDNSConfig(Domain $domain): array | ||||
";", | ";", | ||||
"@ IN A <some-ip>", | "@ IN A <some-ip>", | ||||
"www IN A <some-ip>", | "www IN A <some-ip>", | ||||
";", | ";", | ||||
"{$hash_cname}.{$domain->namespace}. IN CNAME {$hash}.{$domain->namespace}.", | "{$hash_cname}.{$domain->namespace}. IN CNAME {$hash}.{$domain->namespace}.", | ||||
"@ 3600 TXT \"{$hash_txt}\"", | "@ 3600 TXT \"{$hash_txt}\"", | ||||
]; | ]; | ||||
} | } | ||||
/** | |||||
* Prepare domain statuses for the UI | |||||
* | |||||
* @param \App\Domain $domain Domain object | |||||
* | |||||
* @return array Statuses array | |||||
*/ | |||||
protected static function domainStatuses(Domain $domain): array | |||||
{ | |||||
return [ | |||||
'isLdapReady' => $domain->isLdapReady(), | |||||
'isConfirmed' => $domain->isConfirmed(), | |||||
'isVerified' => $domain->isVerified(), | |||||
'isSuspended' => $domain->isSuspended(), | |||||
'isActive' => $domain->isActive(), | |||||
'isDeleted' => $domain->isDeleted() || $domain->trashed(), | |||||
]; | |||||
} | |||||
/** | |||||
* Domain status (extended) information. | |||||
* | |||||
* @param \App\Domain $domain Domain object | |||||
* | |||||
* @return array Status information | |||||
*/ | |||||
public static function statusInfo(Domain $domain): array | |||||
{ | |||||
$process = []; | |||||
// If that is not a public domain, add domain specific steps | |||||
$steps = [ | |||||
'domain-new' => true, | |||||
'domain-ldap-ready' => $domain->isLdapReady(), | |||||
'domain-verified' => $domain->isVerified(), | |||||
'domain-confirmed' => $domain->isConfirmed(), | |||||
]; | |||||
$count = count($steps); | |||||
// Create a process check list | |||||
foreach ($steps as $step_name => $state) { | |||||
$step = [ | |||||
'label' => $step_name, | |||||
'title' => \trans("app.process-{$step_name}"), | |||||
'state' => $state, | |||||
]; | |||||
if ($step_name == 'domain-confirmed' && !$state) { | |||||
$step['link'] = "/domain/{$domain->id}"; | |||||
} | |||||
$process[] = $step; | |||||
if ($state) { | |||||
$count--; | |||||
} | |||||
} | |||||
return [ | |||||
'process' => $process, | |||||
'isReady' => $count === 0, | |||||
]; | |||||
} | |||||
} | } |