Sync wireguard rules uses internal jumps if they are available

This commit is contained in:
2025-04-08 20:23:16 +01:00
parent acf48a7ea6
commit 55b9485fcf
4 changed files with 10 additions and 4 deletions

View File

@@ -27,11 +27,16 @@ class SyncWireguardRules
$output = $result->getOutput();
$commands = collect();
$server->organisation->servers()->where('id', '!=', $server->id)->each(function ($organisationServer) use (&$commands, $output) {
$server->organisation->servers()->where('id', '!=', $server->id)->each(function ($organisationServer) use (&$commands, $output, $server) {
if (Str::contains($output, $organisationServer->internal_public_key)) {
$commands->push("wg set wg0 peer {$organisationServer->internal_public_key} remove");
}
$commands->push("wg set wg0 peer {$organisationServer->internal_public_key} allowed-ips {$organisationServer->internal_ip}/32");
if ($organisationServer->external_network_id === $server->external_network_id) {
$commands->push("wg set wg0 peer {$organisationServer->internal_public_key} allowed-ips {$organisationServer->internal_ip}/32");
} else {
$commands->push("wg set wg0 peer {$organisationServer->internal_public_key} allowed-ips {$organisationServer->ipv4}/32,{$organisationServer->ipv6}/128");
}
});
$result = $ssh->execute($commands->toArray());

View File

@@ -15,6 +15,7 @@ class Provider extends Model
use HasFactory;
protected $guarded = [];
protected $hidden = ['token'];
protected function casts(): array

View File

@@ -43,7 +43,7 @@ class DatabaseSeeder extends Seeder
'name' => 'keystone',
'external_id' => 'net-12345',
'provider_id' => $provider->id,
'ip_range' => fake()->ipv4() . '/24',
'ip_range' => fake()->ipv4().'/24',
]);
$servers = Server::factory(40)

View File

@@ -35,7 +35,7 @@ const props = defineProps({
</div>
</div>
<div class="grid gap-4 rounded-xl p-4 md:grid-cols-2 lg:grid-cols-3">
<Card v-for="application in applications.data" :key="`application{$applications.id}`" class="relative w-full">
<Card v-for="application in applications" :key="`application{$applications.id}`" class="relative w-full">
<CardHeader>
<CardTitle>{{ application.name }}</CardTitle>
</CardHeader>