lasthourcloud/app/Actions/Proxy/CheckConfiguration.php

34 lines
973 B
PHP
Raw Normal View History

2023-07-28 14:42:28 +00:00
<?php
namespace App\Actions\Proxy;
use App\Models\Server;
2024-06-10 20:43:34 +00:00
use Lorisleiva\Actions\Concerns\AsAction;
2023-07-28 14:42:28 +00:00
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;
2024-06-10 20:43:34 +00:00
2023-09-18 10:18:45 +00:00
public function handle(Server $server, bool $reset = false)
2023-07-28 14:42:28 +00:00
{
2024-03-11 14:08:05 +00:00
$proxyType = $server->proxyType();
if ($proxyType === 'NONE') {
return 'OK';
}
$proxy_path = $server->proxyPath();
2024-04-16 18:57:54 +00:00
$payload = [
"mkdir -p $proxy_path",
"cat $proxy_path/docker-compose.yml",
];
2024-04-16 13:42:38 +00:00
$proxy_configuration = instant_remote_process($payload, $server, false);
2024-06-10 20:43:34 +00:00
if ($reset || ! $proxy_configuration || is_null($proxy_configuration)) {
$proxy_configuration = str(generate_default_proxy_configuration($server))->trim()->value;
2023-07-28 14:42:28 +00:00
}
2024-06-10 20:43:34 +00:00
if (! $proxy_configuration || is_null($proxy_configuration)) {
throw new \Exception('Could not generate proxy configuration');
2023-09-18 11:14:05 +00:00
}
2024-06-10 20:43:34 +00:00
2023-07-28 14:42:28 +00:00
return $proxy_configuration;
}
}