lasthourcloud/routes/web.php

201 lines
11 KiB
PHP
Raw Normal View History

2023-03-17 14:33:48 +00:00
<?php
2023-04-19 10:42:15 +00:00
use App\Http\Controllers\ApplicationController;
2023-06-07 13:08:35 +00:00
use App\Http\Controllers\Controller;
use App\Http\Controllers\DatabaseController;
2023-06-07 13:08:35 +00:00
use App\Http\Controllers\MagicController;
use App\Http\Controllers\ProjectController;
2023-08-14 13:22:29 +00:00
use App\Http\Controllers\ServerController;
use App\Models\GithubApp;
use App\Models\GitlabApp;
2023-04-25 07:38:05 +00:00
use App\Models\InstanceSettings;
2023-05-03 10:38:57 +00:00
use App\Models\PrivateKey;
use App\Models\Server;
2023-05-02 10:47:52 +00:00
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
2023-05-08 11:36:49 +00:00
use Illuminate\Http\Request;
2023-06-12 14:39:48 +00:00
use Illuminate\Support\Facades\Password;
2023-03-17 14:33:48 +00:00
use Illuminate\Support\Facades\Route;
2023-05-08 19:56:44 +00:00
use Illuminate\Support\Str;
2023-06-12 14:39:48 +00:00
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
use Laravel\Fortify\Fortify;
2023-03-17 14:33:48 +00:00
2023-06-12 14:39:48 +00:00
Route::post('/forgot-password', function (Request $request) {
2023-06-16 12:27:34 +00:00
if (is_transactional_emails_active()) {
2023-06-12 14:39:48 +00:00
set_transanctional_email_settings();
$request->validate([Fortify::email() => 'required|email']);
$status = Password::broker(config('fortify.passwords'))->sendResetLink(
$request->only(Fortify::email())
);
2023-06-16 12:27:34 +00:00
if ($status == Password::RESET_LINK_SENT) {
return app(SuccessfulPasswordResetLinkRequestResponse::class, ['status' => $status]);
}
if ($status == Password::RESET_THROTTLED) {
return response('Already requested a password reset in the past minutes.', 400);
}
return app(FailedPasswordResetLinkRequestResponse::class, ['status' => $status]);
2023-06-12 13:47:42 +00:00
}
2023-06-12 14:39:48 +00:00
return response()->json(['message' => 'Transactional emails are not active'], 400);
2023-06-12 13:47:42 +00:00
})->name('password.forgot');
2023-08-15 12:11:38 +00:00
Route::get('/waitlist', [Controller::class, 'waitlist'])->name('auth.waitlist');
2023-06-06 09:35:50 +00:00
Route::prefix('magic')->middleware(['auth'])->group(function () {
2023-06-07 13:08:35 +00:00
Route::get('/servers', [MagicController::class, 'servers']);
Route::get('/destinations', [MagicController::class, 'destinations']);
Route::get('/projects', [MagicController::class, 'projects']);
Route::get('/environments', [MagicController::class, 'environments']);
2023-06-15 07:15:41 +00:00
Route::get('/project/new', [MagicController::class, 'newProject']);
Route::get('/environment/new', [MagicController::class, 'newEnvironment']);
2023-06-05 22:18:48 +00:00
});
2023-06-07 13:08:35 +00:00
Route::middleware(['auth'])->group(function () {
2023-06-07 13:08:35 +00:00
Route::get('/projects', [ProjectController::class, 'all'])->name('projects');
2023-06-22 07:33:26 +00:00
Route::get('/project/{project_uuid}/edit', [ProjectController::class, 'edit'])->name('project.edit');
2023-06-07 13:08:35 +00:00
Route::get('/project/{project_uuid}', [ProjectController::class, 'show'])->name('project.show');
Route::get('/project/{project_uuid}/{environment_name}/new', [ProjectController::class, 'new'])->name('project.resources.new');
Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources');
2023-08-09 14:47:24 +00:00
// Applications
2023-06-07 13:08:35 +00:00
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ApplicationController::class, 'configuration'])->name('project.application.configuration');
2023-06-22 13:25:57 +00:00
Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment', [ApplicationController::class, 'deployments'])->name('project.application.deployments');
2023-06-07 13:08:35 +00:00
Route::get(
'/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}',
[ApplicationController::class, 'deployment']
)->name('project.application.deployment');
2023-08-09 14:47:24 +00:00
// Databases
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [DatabaseController::class, 'configuration'])->name('project.database.configuration');
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups', [DatabaseController::class, 'backups'])->name('project.database.backups.all');
2023-08-11 08:42:57 +00:00
Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups/{backup_uuid}', [DatabaseController::class, 'executions'])->name('project.database.backups.executions');
2023-06-07 13:08:35 +00:00
});
2023-04-25 07:38:05 +00:00
2023-06-07 13:08:35 +00:00
Route::middleware(['auth'])->group(function () {
2023-08-11 18:48:52 +00:00
Route::get('/servers', fn () => view('server.all', [
2023-06-15 07:15:41 +00:00
'servers' => Server::ownedByCurrentTeam()->get()
]))->name('server.all');
2023-08-14 13:22:29 +00:00
Route::get('/server/new', [ServerController::class, 'new_server'])->name('server.create');
2023-08-11 18:48:52 +00:00
Route::get('/server/{server_uuid}', fn () => view('server.show', [
2023-07-28 19:36:19 +00:00
'server' => Server::ownedByCurrentTeam(['name', 'description', 'ip', 'port', 'user', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail(),
2023-06-15 07:15:41 +00:00
]))->name('server.show');
2023-08-11 18:48:52 +00:00
Route::get('/server/{server_uuid}/proxy', fn () => view('server.proxy', [
2023-06-20 18:19:31 +00:00
'server' => Server::ownedByCurrentTeam(['name', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail(),
2023-06-15 07:15:41 +00:00
]))->name('server.proxy');
2023-08-11 18:48:52 +00:00
Route::get('/server/{server_uuid}/private-key', fn () => view('server.private-key', [
2023-06-15 12:18:49 +00:00
'server' => Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail(),
'privateKeys' => PrivateKey::ownedByCurrentTeam()->get(),
2023-06-15 12:18:49 +00:00
]))->name('server.private-key');
2023-08-11 18:48:52 +00:00
Route::get('/server/{server_uuid}/destinations', fn () => view('server.destinations', [
2023-07-28 19:36:19 +00:00
'server' => Server::ownedByCurrentTeam(['name', 'proxy'])->whereUuid(request()->server_uuid)->firstOrFail()
2023-06-15 12:18:49 +00:00
]))->name('server.destinations');
2023-06-07 13:08:35 +00:00
});
2023-04-25 07:38:05 +00:00
2023-06-07 13:08:35 +00:00
Route::middleware(['auth'])->group(function () {
Route::get('/', [Controller::class, 'dashboard'])->name('dashboard');
2023-08-22 15:44:49 +00:00
Route::get('/boarding', [Controller::class, 'boarding'])->name('boarding');
2023-08-15 12:27:45 +00:00
Route::middleware(['throttle:force-password-reset'])->group(function() {
Route::get('/force-password-reset', [Controller::class, 'force_passoword_reset'])->name('auth.force-password-reset');
});
2023-08-24 14:14:09 +00:00
Route::get('/subscription', [Controller::class, 'subscription'])->name('subscription.show');
Route::get('/subscription/success', fn () => view('subscription.success'))->name('subscription.success');
Route::get('/subscription/cancel', fn () => view('profile'))->name('subscription.cancel');
2023-06-07 20:07:26 +00:00
Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration');
2023-07-14 10:09:56 +00:00
Route::get('/settings/license', [Controller::class, 'license'])->name('settings.license');
2023-08-11 18:48:52 +00:00
Route::get('/profile', fn () => view('profile', ['request' => request()]))->name('profile');
2023-06-16 13:01:58 +00:00
Route::get('/team', [Controller::class, 'team'])->name('team.show');
2023-08-11 18:48:52 +00:00
Route::get('/team/new', fn () => view('team.create'))->name('team.create');
Route::get('/team/notifications', fn () => view('team.notifications'))->name('team.notifications');
2023-08-07 13:31:42 +00:00
Route::get('/team/storages', [Controller::class, 'storages'])->name('team.storages.all');
2023-08-11 18:48:52 +00:00
Route::get('/team/storages/new', fn () => view('team.storages.create'))->name('team.storages.new');
2023-08-07 13:31:42 +00:00
Route::get('/team/storages/{storage_uuid}', [Controller::class, 'storages_show'])->name('team.storages.show');
2023-07-13 20:03:27 +00:00
Route::get('/team/members', [Controller::class, 'members'])->name('team.members');
2023-08-11 18:48:52 +00:00
Route::get('/command-center', fn () => view('command-center', ['servers' => Server::isReachable()->get()]))->name('command-center');
2023-06-15 07:15:41 +00:00
Route::get('/invitations/{uuid}', [Controller::class, 'acceptInvitation'])->name('team.invitation.accept');
Route::get('/invitations/{uuid}/revoke', [Controller::class, 'revokeInvitation'])->name('team.invitation.revoke');
2023-04-25 07:38:05 +00:00
});
2023-05-03 10:38:57 +00:00
Route::middleware(['auth'])->group(function () {
2023-08-11 18:48:52 +00:00
Route::get('/private-keys', fn () => view('private-key.all', [
2023-06-19 10:23:30 +00:00
'privateKeys' => PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related'])->where('is_git_related', false)->get()
2023-06-15 07:58:17 +00:00
]))->name('private-key.all');
2023-08-11 18:48:52 +00:00
Route::get('/private-key/new', fn () => view('private-key.new'))->name('private-key.new');
Route::get('/private-key/{private_key_uuid}', fn () => view('private-key.show', [
2023-06-19 08:58:00 +00:00
'private_key' => PrivateKey::ownedByCurrentTeam(['name', 'description', 'private_key', 'is_git_related'])->whereUuid(request()->private_key_uuid)->firstOrFail()
2023-06-07 13:08:35 +00:00
]))->name('private-key.show');
2023-05-03 10:38:57 +00:00
});
2023-06-07 13:08:35 +00:00
2023-05-08 11:36:49 +00:00
Route::middleware(['auth'])->group(function () {
2023-08-11 18:48:52 +00:00
Route::get('/source/new', fn () => view('source.new'))->name('source.new');
2023-06-12 20:02:10 +00:00
Route::get('/sources', function () {
2023-08-22 15:44:49 +00:00
$sources = currentTeam()->sources();
2023-06-12 20:02:10 +00:00
return view('source.all', [
'sources' => $sources,
]);
})->name('source.all');
2023-05-08 11:36:49 +00:00
Route::get('/source/github/{github_app_uuid}', function (Request $request) {
2023-07-04 11:08:27 +00:00
$github_app = GithubApp::where('uuid', request()->github_app_uuid)->first()->makeVisible('client_secret')->makeVisible('webhook_secret');
2023-05-16 15:09:50 +00:00
$settings = InstanceSettings::get();
2023-06-14 07:44:40 +00:00
$name = Str::of(Str::kebab($github_app->name));
if ($settings->public_ipv4) {
$ipv4 = 'http://' . $settings->public_ipv4 . ':' . config('app.port');
}
if ($settings->public_ipv6) {
$ipv6 = 'http://' . $settings->public_ipv6 . ':' . config('app.port');
}
2023-05-08 19:56:44 +00:00
return view('source.github.show', [
'github_app' => $github_app,
2023-05-09 09:33:50 +00:00
'name' => $name,
2023-06-14 07:44:40 +00:00
'ipv4' => $ipv4 ?? null,
'ipv6' => $ipv6 ?? null,
'fqdn' => $settings->fqdn,
2023-05-08 19:56:44 +00:00
]);
2023-05-08 11:36:49 +00:00
})->name('source.github.show');
2023-06-12 20:02:10 +00:00
Route::get('/source/gitlab/{gitlab_app_uuid}', function (Request $request) {
$gitlab_app = GitlabApp::where('uuid', request()->gitlab_app_uuid)->first();
return view('source.gitlab.show', [
'gitlab_app' => $gitlab_app,
]);
})->name('source.gitlab.show');
2023-05-08 11:36:49 +00:00
});
2023-04-25 08:47:13 +00:00
2023-05-02 10:47:52 +00:00
Route::middleware(['auth'])->group(function () {
2023-06-13 08:02:58 +00:00
Route::get('/destinations', function () {
$servers = Server::all();
$destinations = collect([]);
foreach ($servers as $server) {
$destinations = $destinations->merge($server->destinations());
}
return view('destination.all', [
'destinations' => $destinations,
]);
})->name('destination.all');
2023-05-03 09:16:08 +00:00
Route::get('/destination/new', function () {
2023-07-14 11:38:24 +00:00
$servers = Server::isUsable()->get();
2023-05-12 11:10:09 +00:00
$pre_selected_server_uuid = data_get(request()->query(), 'server');
if ($pre_selected_server_uuid) {
$server = $servers->firstWhere('uuid', $pre_selected_server_uuid);
if ($server) {
$server_id = $server->id;
}
}
2023-05-03 09:16:08 +00:00
return view('destination.new', [
2023-05-04 09:14:37 +00:00
"servers" => $servers,
2023-05-12 11:10:09 +00:00
"server_id" => $server_id ?? null,
2023-05-03 09:16:08 +00:00
]);
})->name('destination.new');
2023-05-02 10:47:52 +00:00
Route::get('/destination/{destination_uuid}', function () {
$standalone_dockers = StandaloneDocker::where('uuid', request()->destination_uuid)->first();
$swarm_dockers = SwarmDocker::where('uuid', request()->destination_uuid)->first();
if (!$standalone_dockers && !$swarm_dockers) {
abort(404);
}
$destination = $standalone_dockers ? $standalone_dockers : $swarm_dockers;
return view('destination.show', [
2023-05-04 09:14:37 +00:00
'destination' => $destination->load(['server']),
2023-05-02 10:47:52 +00:00
]);
})->name('destination.show');
});