Files
portal-api/app/Jobs/VirtualMachine/Create/ConfigDatabase.php
T
pbao9 5043bea79a feat: Add IP address and DNS fields to module_vmware table
- Introduced `ip` and `dns` columns to the `module_vmware` table to store assigned IP addresses and DNS configurations.
- Implemented `ChangePasswordViaSshJob` for secure password changes via SSH.
- Created `ChangePasswordJob` for handling password changes during VM provisioning.
- Developed `ChangePasswordViaVsphereJob` to reset VM guest OS passwords using PowerShell scripts executed on the vSphere host.
- Added `SendVmCredentialsEmailJob` to send final VM credentials to customers.
- Implemented `WaitVmReadyJob` to poll vSphere API until VMware Tools are running and guest IP is available.
- Created `VmProvisionService` for managing VM provisioning tasks, including password generation and updates.
- Developed `VsphereHostSshService` for executing PowerShell scripts on the vSphere host via SSH.
- Added `IpPoolSeeder` to populate IP pools for VM service initialization.
2026-04-16 23:21:27 +07:00

85 lines
3.0 KiB
PHP

<?php
namespace App\Jobs\VirtualMachine\Create;
use App\Events\Create_VirtualMachine_Success;
use App\Http\Facade\SignRSA;
use App\Http\Facade\HelperFacade as Helper;
use App\Http\Services\Telegram;
use App\Jobs\Mail\SendInformationVirtualMachine;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ConfigDatabase implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $data;
protected $info;
protected $telegram;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data,$info)
{
$this->data = $data;
$this->info = $info;
$this->telegram = new Telegram();
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->data->update([
'name' => $this->data->ipaddress->ip . '_' . $this->data->cannotustomer->firstname,
'port' => $this->info['port'],
'user' => $this->info['user'],
'password' => SignRSA::EncryptFunc($this->info['password']),
'status' => 1
]);
$this->data->ipAddress->update([
'vm_name' => $this->data->IpAddress->ip . '_' . $this->data->Customer->firstname,
'status' => 1
]);
$setting = Setting::where('key', 'setting')->first();
$data = [
'company_name' => json_decode($setting->value)->company,
'company_logo' => json_decode($setting->value)->logo,
'client_name' => $this->data->Customer->firstname . " " . $this->data->Customer->lastname,
'product_name' => $this->data->GetInvoiceItem()->GetItemProduct()->name,
'product_billing' => Helper::billing_cycle($this->data->GetInvoiceItem()->billing),
'product_price' => number_format($this->data->GetInvoiceItem()->amount, 0, ',', '.'),
'service_host' => $this->data->IpAddress->ip,
'service_username' => $this->info['user'],
'service_port' => $this->info['port'],
'service_password' => $this->info['password'],
'os_name' => $this->data->Os->OsGroup->name . " " . $this->data->Os->version,
'service_due_exp' => Carbon::parse($this->data->next_due_date)->format('d/m/Y')
];
// Note: Email is now sent by ConfigCLICommand after password is changed
// $mail = new SendInformationVirtualMachine($data, $this->data->Customer);
// dispatch($mail)->delay(now()->addSeconds(5));
Event(new Create_VirtualMachine_Success("Máy chủ của bạn đã được khởi tạo thành công!",
$this->data->customer->id));
$this->telegram->SendInformation($this->data, $this->info['user'], $this->info['password'], $this->info['port']);
}
}