2023-09-18 10:18:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Proxy;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class SaveConfiguration
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
2023-09-21 09:03:52 +00:00
|
|
|
public function handle(Server $server, ?string $proxy_settings = null)
|
2023-09-18 10:18:45 +00:00
|
|
|
{
|
2023-09-21 09:03:52 +00:00
|
|
|
if (is_null($proxy_settings)) {
|
|
|
|
$proxy_settings = CheckConfiguration::run($server, true);
|
|
|
|
}
|
2024-03-11 14:08:05 +00:00
|
|
|
$proxy_path = $server->proxyPath();
|
2023-09-18 10:18:45 +00:00
|
|
|
$docker_compose_yml_base64 = base64_encode($proxy_settings);
|
|
|
|
|
2024-06-25 08:37:10 +00:00
|
|
|
$server->proxy->last_saved_settings = str($docker_compose_yml_base64)->pipe('md5')->value;
|
2023-09-18 10:18:45 +00:00
|
|
|
$server->save();
|
|
|
|
|
|
|
|
return instant_remote_process([
|
|
|
|
"mkdir -p $proxy_path",
|
2024-04-17 08:49:34 +00:00
|
|
|
"echo '$docker_compose_yml_base64' | base64 -d | tee $proxy_path/docker-compose.yml > /dev/null",
|
2023-09-18 10:18:45 +00:00
|
|
|
], $server);
|
|
|
|
}
|
|
|
|
}
|