From 6c2d0a2d50f764f25ff92a7d27157e094db631e4 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 2 Jun 2024 21:59:12 -0400 Subject: [PATCH 1/2] Remove shenanigans --- app/Services/Nodes/NodeUpdateService.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/Services/Nodes/NodeUpdateService.php b/app/Services/Nodes/NodeUpdateService.php index f948686ed..708605b19 100644 --- a/app/Services/Nodes/NodeUpdateService.php +++ b/app/Services/Nodes/NodeUpdateService.php @@ -32,21 +32,10 @@ class NodeUpdateService $data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH); } - [$updated, $exception] = $this->connection->transaction(function () use ($data, $node) { - /** @var \App\Models\Node $updated */ - $updated = $node->replicate(); - $updated->forceFill($data)->save(); + [$node, $exception] = $this->connection->transaction(function () use ($data, $node) { + $node->forceFill($data)->save(); try { - // If we're changing the FQDN for the node, use the newly provided FQDN for the connection - // address. This should alleviate issues where the node gets pointed to a "valid" FQDN that - // isn't actually running the daemon software, and therefore you can't actually change it - // back. - // - // This makes more sense anyways, because only the Panel uses the FQDN for connecting, the - // node doesn't actually care about this. - $node->fqdn = $updated->fqdn; - - $this->configurationRepository->setNode($node)->update($updated); + $this->configurationRepository->setNode($node)->update($node); } catch (DaemonConnectionException $exception) { logger()->warning($exception, ['node_id' => $node->id]); @@ -56,16 +45,16 @@ class NodeUpdateService // // This avoids issues with proxies such as Cloudflare which will see daemon as offline and then // inject their own response pages, causing this logic to get fucked up. - return [$updated, true]; + return [$node, true]; } - return [$updated, false]; + return [$node, false]; }); if ($exception) { throw new ConfigurationNotPersistedException(trans('exceptions.node.daemon_off_config_updated')); } - return $updated; + return $node; } } From 7ee52affb2136b62e29a27b8baa53258c061382a Mon Sep 17 00:00:00 2001 From: notCharles Date: Fri, 7 Jun 2024 17:38:58 -0400 Subject: [PATCH 2/2] Update token rotation --- app/Services/Nodes/NodeUpdateService.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Services/Nodes/NodeUpdateService.php b/app/Services/Nodes/NodeUpdateService.php index 708605b19..8377261af 100644 --- a/app/Services/Nodes/NodeUpdateService.php +++ b/app/Services/Nodes/NodeUpdateService.php @@ -27,15 +27,22 @@ class NodeUpdateService */ public function handle(Node $node, array $data, bool $resetToken = false): Node { + $data['id'] = $node->id; + if ($resetToken) { $data['daemon_token'] = Str::random(Node::DAEMON_TOKEN_LENGTH); $data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH); } - [$node, $exception] = $this->connection->transaction(function () use ($data, $node) { - $node->forceFill($data)->save(); + [$updated, $exception] = $this->connection->transaction(function () use ($data, $node) { + /** @var \App\Models\Node $updated */ + $updated = $node->replicate(); + $updated->exists = true; + $updated->forceFill($data)->save(); try { - $this->configurationRepository->setNode($node)->update($node); + $node->fqdn = $updated->fqdn; + + $this->configurationRepository->setNode($node)->update($updated); } catch (DaemonConnectionException $exception) { logger()->warning($exception, ['node_id' => $node->id]); @@ -45,16 +52,16 @@ class NodeUpdateService // // This avoids issues with proxies such as Cloudflare which will see daemon as offline and then // inject their own response pages, causing this logic to get fucked up. - return [$node, true]; + return [$updated, true]; } - return [$node, false]; + return [$updated, false]; }); if ($exception) { throw new ConfigurationNotPersistedException(trans('exceptions.node.daemon_off_config_updated')); } - return $node; + return $updated; } }