lasthourcloud/app/Actions/Proxy/CheckConfiguration.php

29 lines
854 B
PHP
Raw Normal View History

2023-07-28 14:42:28 +00:00
<?php
namespace App\Actions\Proxy;
2023-09-18 10:18:45 +00:00
use Lorisleiva\Actions\Concerns\AsAction;
2023-07-28 14:42:28 +00:00
use App\Models\Server;
use Illuminate\Support\Str;
2023-09-18 10:18:45 +00:00
class CheckConfiguration
2023-07-28 14:42:28 +00:00
{
2023-09-18 10:18:45 +00:00
use AsAction;
public function handle(Server $server, bool $reset = false)
2023-07-28 14:42:28 +00:00
{
$proxy_path = get_proxy_path();
$proxy_configuration = instant_remote_process([
2023-09-23 09:53:30 +00:00
"mkdir -p $proxy_path",
2023-07-28 14:42:28 +00:00
"cat $proxy_path/docker-compose.yml",
], $server, false);
2023-09-18 11:14:05 +00:00
if ($reset || !$proxy_configuration || is_null($proxy_configuration)) {
2023-07-28 14:42:28 +00:00
$proxy_configuration = Str::of(generate_default_proxy_configuration($server))->trim()->value;
}
2023-09-18 11:14:05 +00:00
if (!$proxy_configuration || is_null($proxy_configuration)) {
throw new \Exception("Could not generate proxy configuration");
}
2023-07-28 14:42:28 +00:00
return $proxy_configuration;
}
}