75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Http\Facade\SignRSA;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* ReinstallLog
|
|
*
|
|
* Audit row for every VM rebuild. Each row records:
|
|
* - which customer initiated it (custome_id — column kept for legacy compat)
|
|
* - which service / VM was rebuilt
|
|
* - which OS was chosen
|
|
* - the new credential applied to the rebuilt VM (encrypted + plaintext)
|
|
* - status lifecycle: pending → in_progress → completed | failed
|
|
*/
|
|
class ReinstallLog extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'reinstall_logs';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'started_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
'password_supplied_by_customer' => 'boolean',
|
|
];
|
|
|
|
public const PRODUCT_TYPE_VPS = 4;
|
|
|
|
public const STATUS_PENDING = 'pending';
|
|
public const STATUS_IN_PROGRESS = 'in_progress';
|
|
public const STATUS_COMPLETED = 'completed';
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class, 'custome_id');
|
|
}
|
|
|
|
public function service()
|
|
{
|
|
return $this->belongsTo(Service::class, 'service_id');
|
|
}
|
|
|
|
public function vm()
|
|
{
|
|
return $this->belongsTo(ModuleVmware::class, 'product_id');
|
|
}
|
|
|
|
public function os()
|
|
{
|
|
return $this->belongsTo(Os::class, 'os_id');
|
|
}
|
|
|
|
/** Decrypt the password column on demand (null if not yet set). */
|
|
public function decryptedPassword(): ?string
|
|
{
|
|
if (!$this->password) {
|
|
return $this->plain_password ?: null;
|
|
}
|
|
try {
|
|
return SignRSA::DecryptFunc($this->password);
|
|
} catch (\Throwable $e) {
|
|
return $this->plain_password ?: null;
|
|
}
|
|
}
|
|
}
|