GeoNetAgent, LDAPWeb, server-audit, server-connection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.4 KiB

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
class DatabaseConnection extends Model
{
protected $fillable = [
'name',
'driver',
'host',
'port',
'database',
'username',
'password_encrypted',
'is_active',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'port' => 'integer',
];
}
public function connectionKey(): string
{
return 'dbconn_' . $this->id;
}
public function getPassword(): string
{
try {
return Crypt::decryptString($this->password_encrypted);
} catch (\Throwable) {
return '';
}
}
public function setPassword(string $password): void
{
$this->password_encrypted = Crypt::encryptString($password);
}
public function driverLabel(): string
{
return match ($this->driver) {
'sqlsrv' => 'SQL Server',
'pgsql' => 'PostgreSQL',
'mysql' => 'MySQL',
'mariadb' => 'MariaDB',
default => strtoupper($this->driver),
};
}
public function defaultPort(): int
{
return match ($this->driver) {
'sqlsrv' => 1433,
'pgsql' => 5432,
'mysql', 'mariadb' => 3306,
default => $this->port,
};
}
}