lasthourcloud/app/Actions/Proxy/CheckProxySettingsInSync.php

34 lines
1.1 KiB
PHP
Raw Normal View History

2023-05-12 18:42:39 +00:00
<?php
namespace App\Actions\Proxy;
use App\Enums\ProxyTypes;
use App\Models\Server;
2023-05-15 11:45:37 +00:00
use Illuminate\Support\Str;
2023-05-12 18:42:39 +00:00
class CheckProxySettingsInSync
{
2023-05-15 20:06:08 +00:00
public function __invoke(Server $server, bool $reset = false)
2023-05-12 18:42:39 +00:00
{
2023-05-15 11:45:37 +00:00
$proxy_path = config('coolify.proxy_config_path');
2023-05-24 13:25:08 +00:00
$output = instant_remote_process([
2023-05-15 11:45:37 +00:00
"cat $proxy_path/docker-compose.yml",
], $server, false);
2023-05-15 20:06:08 +00:00
if (is_null($output) || $reset) {
2023-05-15 19:48:36 +00:00
$final_output = Str::of(getProxyConfiguration($server))->trim()->value;
2023-05-15 11:45:37 +00:00
} else {
2023-05-15 19:48:36 +00:00
$final_output = Str::of($output)->trim()->value;
2023-05-15 11:45:37 +00:00
}
$docker_compose_yml_base64 = base64_encode($final_output);
2023-06-20 18:19:31 +00:00
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
2023-05-15 11:45:37 +00:00
$server->save();
2023-05-16 10:50:00 +00:00
if (is_null($output) || $reset) {
2023-05-24 13:25:08 +00:00
instant_remote_process([
2023-05-15 11:45:37 +00:00
"mkdir -p $proxy_path",
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
], $server);
}
return $final_output;
2023-05-12 18:42:39 +00:00
}
}