2023-03-28 13:47:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2023-11-28 11:11:03 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2023-03-28 13:47:37 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-11-28 11:11:03 +00:00
|
|
|
use Spatie\Url\Url;
|
2023-03-28 13:47:37 +00:00
|
|
|
|
2025-03-24 16:55:10 +00:00
|
|
|
class InstanceSettings extends Model
|
2023-03-28 13:47:37 +00:00
|
|
|
{
|
2023-07-14 09:27:08 +00:00
|
|
|
protected $guarded = [];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-01-07 14:31:43 +00:00
|
|
|
protected $casts = [
|
|
|
|
|
'smtp_enabled' => 'boolean',
|
|
|
|
|
'smtp_from_address' => 'encrypted',
|
|
|
|
|
'smtp_from_name' => 'encrypted',
|
|
|
|
|
'smtp_recipients' => 'encrypted',
|
|
|
|
|
'smtp_host' => 'encrypted',
|
|
|
|
|
'smtp_port' => 'integer',
|
|
|
|
|
'smtp_username' => 'encrypted',
|
|
|
|
|
'smtp_password' => 'encrypted',
|
|
|
|
|
'smtp_timeout' => 'integer',
|
|
|
|
|
|
|
|
|
|
'resend_enabled' => 'boolean',
|
|
|
|
|
'resend_api_key' => 'encrypted',
|
|
|
|
|
|
|
|
|
|
'allowed_ip_ranges' => 'array',
|
|
|
|
|
'is_auto_update_enabled' => 'boolean',
|
|
|
|
|
'auto_update_frequency' => 'string',
|
|
|
|
|
'update_check_frequency' => 'string',
|
|
|
|
|
'sentinel_token' => 'encrypted',
|
2025-12-17 11:09:13 +00:00
|
|
|
'is_wire_navigate_enabled' => 'boolean',
|
2025-01-07 14:31:43 +00:00
|
|
|
];
|
|
|
|
|
|
2024-10-21 10:06:13 +00:00
|
|
|
protected static function booted(): void
|
|
|
|
|
{
|
|
|
|
|
static::updated(function ($settings) {
|
2025-10-15 20:00:21 +00:00
|
|
|
// Clear trusted hosts cache when FQDN changes
|
2025-10-15 20:20:52 +00:00
|
|
|
if ($settings->wasChanged('fqdn')) {
|
2025-10-15 20:00:21 +00:00
|
|
|
\Cache::forget('instance_settings_fqdn_host');
|
|
|
|
|
}
|
2024-10-21 10:06:13 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 11:11:03 +00:00
|
|
|
public function fqdn(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
set: function ($value) {
|
|
|
|
|
if ($value) {
|
|
|
|
|
$url = Url::fromString($value);
|
|
|
|
|
$host = $url->getHost();
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
|
return $url->getScheme().'://'.$host;
|
2023-11-28 11:11:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-08-26 13:26:08 +00:00
|
|
|
public function updateCheckFrequency(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
set: function ($value) {
|
|
|
|
|
return translate_cron_expression($value);
|
|
|
|
|
},
|
|
|
|
|
get: function ($value) {
|
|
|
|
|
return translate_cron_expression($value);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function autoUpdateFrequency(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
set: function ($value) {
|
|
|
|
|
return translate_cron_expression($value);
|
|
|
|
|
},
|
|
|
|
|
get: function ($value) {
|
|
|
|
|
return translate_cron_expression($value);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public static function get()
|
|
|
|
|
{
|
2025-01-07 14:31:43 +00:00
|
|
|
return InstanceSettings::findOrFail(0);
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-24 16:55:10 +00:00
|
|
|
// public function getRecipients($notification)
|
|
|
|
|
// {
|
|
|
|
|
// $recipients = data_get($notification, 'emails', null);
|
|
|
|
|
// if (is_null($recipients) || $recipients === '') {
|
|
|
|
|
// return [];
|
|
|
|
|
// }
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-03-24 16:55:10 +00:00
|
|
|
// return explode(',', $recipients);
|
|
|
|
|
// }
|
2024-06-22 08:41:15 +00:00
|
|
|
|
|
|
|
|
public function getTitleDisplayName(): string
|
|
|
|
|
{
|
|
|
|
|
$instanceName = $this->instance_name;
|
|
|
|
|
if (! $instanceName) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "[{$instanceName}]";
|
|
|
|
|
}
|
2024-10-21 20:40:43 +00:00
|
|
|
|
|
|
|
|
// public function helperVersion(): Attribute
|
|
|
|
|
// {
|
|
|
|
|
// return Attribute::make(
|
|
|
|
|
// get: function ($value) {
|
|
|
|
|
// if (isDev()) {
|
|
|
|
|
// return 'latest';
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return $value;
|
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
// }
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|