mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-16 16:45:07 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
84 lines
2.4 KiB
PHP
84 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Identity\Ldap;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* The single row describing this installation's directory.
|
|
*
|
|
* Shaped after MailProviderSettings, including the part that matters most:
|
|
* `bind_password` carries an `'encrypted'` cast, so a database dump does
|
|
* not hand over a service-account credential. v1 stored this one in plain
|
|
* text and then echoed it into the settings form's HTML `value=`.
|
|
*
|
|
* @property bool $active
|
|
* @property string|null $host
|
|
* @property int $port
|
|
* @property LdapEncryption $encryption
|
|
* @property string|null $ca_cert_path
|
|
* @property string|null $bind_dn
|
|
* @property string|null $bind_password
|
|
* @property string|null $base_dn
|
|
* @property string|null $user_filter
|
|
* @property string $email_attribute
|
|
* @property string $name_attribute
|
|
* @property bool $auto_provision
|
|
* @property bool $auto_approve
|
|
*/
|
|
class LdapSettings extends Model
|
|
{
|
|
protected $table = 'ldap_settings';
|
|
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* Column defaults only apply on INSERT, so they never reach the unsaved
|
|
* instance `current()` hands back on a fresh install — these do.
|
|
*/
|
|
protected $attributes = [
|
|
'active' => false,
|
|
'port' => 389,
|
|
'encryption' => 'tls',
|
|
'email_attribute' => 'mail',
|
|
'name_attribute' => 'cn',
|
|
'auto_provision' => false,
|
|
'auto_approve' => false,
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'active' => 'boolean',
|
|
'port' => 'integer',
|
|
'encryption' => LdapEncryption::class,
|
|
'bind_password' => 'encrypted',
|
|
'auto_provision' => 'boolean',
|
|
'auto_approve' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public static function current(): self
|
|
{
|
|
return static::query()->firstOrNew([]);
|
|
}
|
|
|
|
/**
|
|
* Whether a login may consult the directory at all.
|
|
*
|
|
* The extension check is part of the answer rather than a separate
|
|
* question: an administrator can save settings on a server that cannot
|
|
* talk LDAP, and every login must then behave exactly as if the
|
|
* feature were switched off rather than throwing.
|
|
*/
|
|
public function usable(): bool
|
|
{
|
|
return $this->active
|
|
&& extension_loaded('ldap')
|
|
&& is_string($this->host) && $this->host !== ''
|
|
&& is_string($this->base_dn) && $this->base_dn !== '';
|
|
}
|
|
}
|