Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require 'vendor/autoload.php';
require_once('accounts/account_creator.php');
require_once('accounts/base_ecloud_account_creator.php');
require_once('accounts/ldap/user.php');
require_once('language.php');
require_once('helpers.php');
use LdapRecord\Connection;
use LdapRecord\Container;
class LDAPAccountCreator extends BaseEcloudAccountCreator
{
private Connection $conn;
private int $quotaInBytes = 1073741824;
public function __construct(string $ecloudUrl)
{
parent::__construct($ecloudUrl);
$quota = getenv('CLOUD_QUOTA_IN_BYTES');
if (!$quota) {
$this->quota = $this->quotaInBytes;
} else {
$this->quota = intval($quota);
}
$this->usernameIsEmail = false;
$this->connectToLDAPServer();
}
protected function createAccount(string $email, string $username, string $password, string $pw2, string $name, int $quota, string $authmail, ?string $referrerCode = null)
{
$baseDn = getenv('LDAP_USERS_BASE_DN');
$userDn = "username=$username," . $baseDn;
$userClusterID = getenv('CLUSTER_ID');
$answer = new \stdClass();
try {
$user =[
'mailAddress' => $email,
'username' => $username,
'usernameWithoutDomain' => $username,
'userPassword' => $password,
'displayName' => $name,
'quota' => $quota,
'mailAlternate' => $authmail,
'recoveryMailAddress' => $authmail,
'active'=> 'TRUE',
'mailActive' => 'TRUE',
'userClusterID' => $userClusterID,
'objectClass' => User::$objectClasses
];
$userEntry = new User($user);
$userEntry->setDn($userDn);
$userEntry->save();
} catch (Exception $e) {
error_log('Error creating user ' . $e->getMessage());
$answer->success= false;
$answer->type = 'error_creating_account';
return $answer;
}
$answer = $this->postCreationActions($email, $username, $authmail, $quota, 'v2');
return $answer;
}
private function getLDAPConfig() : array
{
$ldapHosts = getenv('LDAP_HOSTS');
$ldapHosts = explode(",", $ldapHosts);
$ldapPort = getenv('LDAP_PORT');
$ldapAdminDn = getenv('LDAP_ADMIN_DN');
$ldapAdminPassword = getenv('LDAP_ADMIN_PASSWORD');
$baseDn = getenv('LDAP_USERS_BASE_DN');
return [
'hosts' => $ldapHosts,
'port' => $ldapPort,
'base_dn' => $baseDn,
'username' => $ldapAdminDn,
'password' => $ldapAdminPassword
];
}
private function connectToLDAPServer() : void
{
$config = $this->getLDAPConfig();
$this->conn = new Connection(
$config
);
Container::addConnection($this->conn);
}
}