- add rotating admin refresh tokens and password gates\n- expand ticket galleries, exports, and client resources\n- improve IP allocation auditing and dashboard data\n- enforce encrypted client access tokens on public routes
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class IpPoolLog extends Model
|
|
{
|
|
public const ALLOCATED = 'allocated';
|
|
public const REVOKED = 'revoked';
|
|
public const VM_ASSIGNED = 'vm_assigned';
|
|
public const VM_RELEASED = 'vm_released';
|
|
|
|
public const UPDATED_AT = null;
|
|
|
|
protected $casts = ['effective_date' => 'date:Y-m-d'];
|
|
|
|
protected $fillable = [
|
|
'ip_pool_id', 'ip_address', 'action', 'effective_date', 'status_from', 'status_to',
|
|
'customer_id', 'customer_name', 'service_name', 'service_id', 'vm_name', 'email_to', 'email_cc', 'email_bcc', 'user_id', 'note',
|
|
];
|
|
|
|
public static function record(IpPool $pool, string $action, string $statusFrom, array $attributes = []): self
|
|
{
|
|
return self::create([
|
|
'ip_pool_id' => $pool->id,
|
|
'ip_address' => $pool->ip_address,
|
|
'action' => $action,
|
|
'status_from' => $statusFrom,
|
|
'status_to' => $pool->status,
|
|
'user_id' => auth('admin')->id(),
|
|
...$attributes,
|
|
]);
|
|
}
|
|
|
|
public static function recordVm(?int $poolId, string $action, string $statusFrom, ModuleVmware $vm, ?string $note = null): void
|
|
{
|
|
$pool = $poolId ? IpPool::find($poolId) : null;
|
|
if (!$pool) {
|
|
return;
|
|
}
|
|
|
|
$service = Service::where('id', $vm->service_id)->orWhere('vm_id', $vm->id)->first(['id', 'server_name']);
|
|
|
|
self::record($pool, $action, $statusFrom, [
|
|
'vm_name' => $vm->name,
|
|
'service_id' => $service?->id,
|
|
'service_name' => $service?->server_name,
|
|
'customer_id' => $vm->customer_id,
|
|
'customer_name' => Customer::whereKey($vm->customer_id)->value('fullname'),
|
|
'note' => $note,
|
|
]);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|