Add all files

This commit is contained in:
root
2025-11-30 11:57:22 +01:00
parent 2ee51cac4f
commit 044271db3d
1476 changed files with 142544 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace Paymenter\Extensions\Servers\Proxmox\Jobs;
use App\Helpers\ExtensionHelper;
use App\Helpers\NotificationHelper;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
class ReinstallJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 5;
public int $timeout = 600; // 10 minutes
public function __construct(public Server $server) {}
public function handle(): void
{
$proxmox = new Proxmox;
// Stop and delete existing VM if it exists
try {
$proxmox->requestAndWait(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/status/stop',
'post',
['vmid' => $this->server->vm_id],
$this->server->node->name
);
$proxmox->requestAndWait(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id,
'delete',
[],
$this->server->node->name
);
} catch (Exception $e) {
if (!str_contains($e->getMessage(), 'does not exist')) {
throw $e;
}
}
// Generate a new password
$password = Str::password(16);
// Reinstall server — install() will now use the updated password
$settings = array_merge(ExtensionHelper::settingsToArray($this->server->service->product->settings), ExtensionHelper::getServiceProperties($this->server->service));
$proxmox->install($this->server, $settings, $password);
// Send notification to the user
NotificationHelper::serverCreatedNotification(
$this->server->service->user,
$this->server->service,
[
'password' => $password,
'ip' => $this->server->primaryIpv4?->ip,
'ipv6' => $this->server->primaryIpv6?->ip,
'hostname' => $this->server->hostname,
]
);
}
}