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-12 18:51:07 +00:00
|
|
|
$output = instantRemoteProcess([
|
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);
|
|
|
|
$server->extra_attributes->last_saved_proxy_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
|
|
|
$server->save();
|
2023-05-16 10:50:00 +00:00
|
|
|
if (is_null($output) || $reset) {
|
2023-05-15 11:45:37 +00:00
|
|
|
instantRemoteProcess([
|
|
|
|
"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
|
|
|
}
|
|
|
|
}
|