diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index 39d1b99b3..fbdf0bba4 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -2,7 +2,6 @@ namespace App\Actions\Database; -use App\Models\Server; use App\Models\StandaloneMongodb; use Illuminate\Support\Str; use Symfony\Component\Yaml\Yaml; @@ -16,7 +15,7 @@ class StartMongodb public array $commands = []; public string $configuration_dir; - public function handle(Server $server, StandaloneMongodb $database) + public function handle(StandaloneMongodb $database) { $this->database = $database; @@ -102,7 +101,7 @@ public function handle(Server $server, StandaloneMongodb $database) $this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md"; $this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d"; $this->commands[] = "echo '####### {$database->name} started.'"; - return remote_process($this->commands, $server); + return remote_process($this->commands, $database->destination->server); } private function generate_local_persistent_volumes() @@ -160,6 +159,5 @@ private function add_custom_mongo_conf() $content = $this->database->mongo_conf; $content_base64 = base64_encode($content); $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/{$filename}"; - } } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 615f3ed4a..46e410980 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -2,7 +2,6 @@ namespace App\Actions\Database; -use App\Models\Server; use App\Models\StandalonePostgresql; use Illuminate\Support\Str; use Symfony\Component\Yaml\Yaml; @@ -17,7 +16,7 @@ class StartPostgresql public array $init_scripts = []; public string $configuration_dir; - public function handle(Server $server, StandalonePostgresql $database) + public function handle(StandalonePostgresql $database) { $this->database = $database; $container_name = $this->database->uuid; @@ -104,7 +103,7 @@ public function handle(Server $server, StandalonePostgresql $database) $this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md"; $this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d"; $this->commands[] = "echo '####### {$database->name} started.'"; - return remote_process($this->commands, $server); + return remote_process($this->commands, $database->destination->server); } private function generate_local_persistent_volumes() diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index 6ea950f5d..af6b2ad4f 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -2,7 +2,6 @@ namespace App\Actions\Database; -use App\Models\Server; use App\Models\StandaloneRedis; use Illuminate\Support\Str; use Symfony\Component\Yaml\Yaml; @@ -17,7 +16,7 @@ class StartRedis public string $configuration_dir; - public function handle(Server $server, StandaloneRedis $database) + public function handle(StandaloneRedis $database) { $this->database = $database; @@ -104,7 +103,7 @@ public function handle(Server $server, StandaloneRedis $database) $this->commands[] = "echo '{$readme}' > $this->configuration_dir/README.md"; $this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d"; $this->commands[] = "echo '####### {$database->name} started.'"; - return remote_process($this->commands, $server); + return remote_process($this->commands, $database->destination->server); } private function generate_local_persistent_volumes() diff --git a/app/Http/Livewire/Dashboard.php b/app/Http/Livewire/Dashboard.php index b46df481a..723b00f7f 100644 --- a/app/Http/Livewire/Dashboard.php +++ b/app/Http/Livewire/Dashboard.php @@ -17,10 +17,6 @@ public function mount() $this->servers = Server::ownedByCurrentTeam()->get(); $this->projects = Project::ownedByCurrentTeam()->get(); } - // public function createToken() { - // $token = auth()->user()->createToken('test'); - // ray($token); - // } // public function getIptables() // { // $servers = Server::ownedByCurrentTeam()->get(); diff --git a/app/Http/Livewire/Project/Database/Heading.php b/app/Http/Livewire/Project/Database/Heading.php index 1a199ecb7..6045e2b7f 100644 --- a/app/Http/Livewire/Project/Database/Heading.php +++ b/app/Http/Livewire/Project/Database/Heading.php @@ -47,15 +47,15 @@ public function stop() public function start() { if ($this->database->type() === 'standalone-postgresql') { - $activity = StartPostgresql::run($this->database->destination->server, $this->database); + $activity = StartPostgresql::run($this->database); $this->emit('newMonitorActivity', $activity->id); } if ($this->database->type() === 'standalone-redis') { - $activity = StartRedis::run($this->database->destination->server, $this->database); + $activity = StartRedis::run($this->database); $this->emit('newMonitorActivity', $activity->id); } if ($this->database->type() === 'standalone-mongodb') { - $activity = StartMongodb::run($this->database->destination->server, $this->database); + $activity = StartMongodb::run($this->database); $this->emit('newMonitorActivity', $activity->id); } } diff --git a/app/Http/Livewire/Security/ApiTokens.php b/app/Http/Livewire/Security/ApiTokens.php new file mode 100644 index 000000000..f00b30930 --- /dev/null +++ b/app/Http/Livewire/Security/ApiTokens.php @@ -0,0 +1,38 @@ +tokens = auth()->user()->tokens; + } + public function addNewToken() + { + try { + $this->validate([ + 'description' => 'required|min:3|max:255', + ]); + $token = auth()->user()->createToken($this->description); + $this->tokens = auth()->user()->tokens; + session()->flash('token', $token->plainTextToken); + } catch (\Exception $e) { + return handleError($e, $this); + } + } + public function revoke(int $id) + { + $token = auth()->user()->tokens()->where('id', $id)->first(); + $token->delete(); + $this->tokens = auth()->user()->tokens; + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index f78ed363f..f60994c61 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -46,9 +46,9 @@ protected function configureRateLimiting(): void { RateLimiter::for('api', function (Request $request) { if ($request->path() === 'api/health') { - return Limit::perMinute(5000)->by($request->user()?->id ?: $request->ip()); + return Limit::perMinute(1000)->by($request->user()?->id ?: $request->ip()); } - return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); + return Limit::perMinute(30)->by($request->user()?->id ?: $request->ip()); }); RateLimiter::for('5', function (Request $request) { return Limit::perMinute(5)->by($request->user()?->id ?: $request->ip()); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index dd761b449..123670dc5 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1,7 +1,12 @@ environment->project->team_id === $teamId) { + return $resource; + } + return null; + } else { + return $resource; + } +} +function queryResourcesByUuid(string $uuid) +{ + $resource = null; + $application = Application::whereUuid($uuid)->first(); + if ($application) return $application; + $service = Service::whereUuid($uuid)->first(); + if ($service) return $service; + $postgresql = StandalonePostgresql::whereUuid($uuid)->first(); + if ($postgresql) return $postgresql; + $redis = StandaloneRedis::whereUuid($uuid)->first(); + if ($redis) return $redis; + $mongodb = StandaloneMongodb::whereUuid($uuid)->first(); + if ($mongodb) return $mongodb; + return $resource; +} diff --git a/resources/views/components/security/navbar.blade.php b/resources/views/components/security/navbar.blade.php index 1d2296cc1..084ed4d82 100644 --- a/resources/views/components/security/navbar.blade.php +++ b/resources/views/components/security/navbar.blade.php @@ -10,8 +10,15 @@ diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 2e79582e1..cd4f8a458 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -100,9 +100,6 @@ @endforeach -{{--