forked from 22decembre/ldap_login
-
Notifications
You must be signed in to change notification settings - Fork 15
/
class.config.php
203 lines (182 loc) · 7.16 KB
/
class.config.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
declare(strict_types=1);
class Config
{
private $log;
private $config;
private $warn_msg;
private $default_val = [
'ld_forgot_url' => 'password.php',
'ld_debug_location' => './logs/',
'ld_debug_file' => 1,
'ld_debug_clearupdate' => 1,
'ld_debug_level' => 'debug',
'ld_debug_php' => 1,
'ld_host' => 'localhost',
'ld_port' => '389',
'ld_basedn' => 'ou=domain,dc=domain,dc=tld',
'ld_user_class' => 'person',
'ld_user_attr' => 'samaccountName',
'ld_user_filter' => 'cn=*',
'ld_group_class' => 'group',
'ld_group_filter' => 'cn=*',
'ld_group_attr' => 'name',
'ld_group_desc' => 'description',
'ld_group_basedn' => 'cn=groups,ou=domain,dc=domain,dc=tld',
'ld_group_member_attr' => 'member',
'ld_user_member_attr' => 'memberOf',
'ld_user_mail_attr' => 'mail',
'ld_group_webmaster' => 'cn=piwigo_webmasters,cn=groups,ou=domain,dc=domain,dc=tld',
'ld_group_admin' => 'cn=piwigo_admins,cn=groups,ou=domain,dc=domain,dc=tld',
'ld_group_user' => 'cn=piwigo_users,cn=groups,ou=domain,dc=domain,dc=tld',
'ld_binddn' => 'cn=service_account, ou=users, ou=domain, dc=domain,dc=tld',
'ld_bindpw' => null,
'ld_anonbind' => 0,
'ld_use_ssl' => 0,
'ld_membership_user' => 0,
'ld_group_user_active' => 1,
'ld_group_admin_active' => 0,
'ld_group_webmaster_active' => 0,
'ld_sync_data' => null,
'ld_auth_type' => 'ld_auth_ldap',
'ld_azure_auth_url' => 'https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize',
'ld_azure_scopes' => 'openid profile User.Read email',
'ld_azure_token_url' => 'https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token',
'ld_azure_resource_url' => 'https://graph.microsoft.com/v1.0/me?$select=userPrincipalName,mail',
'ld_azure_logout_url' => null,
'ld_azure_user_identifier' => 'userPrincipalName',
'ld_azure_client_id' => null,
'ld_azure_client_secret' => null,
'ld_azure_jwks_url' => 'https://login.microsoftonline.com/{TENANT_ID}/discovery/keys',
'ld_azure_tenant_id' => null,
'ld_azure_redirect_uri' => 'https://your_piwigo_url/admin.php?page=plugin§ion=Ldap_Login/azure/callback.php',
'ld_azure_claim_name' => 'roles',
'ld_allow_newusers' => 1,
'ld_use_mail' => 1,
'ld_allow_profile' => 1,
'ld_advertise_admin_new_ldapuser' => 0,
'ld_send_password_by_mail_ldap' => 0,
];
public function __construct()
{
global $ld_log;
$this->log = $ld_log;
$ld_log->debug('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> initialized Config Class');
}
/**
* Retrieves value from Config.
*
* @param string $var_name
* @param bool $ignore_default
*/
public function getValue($var_name, $ignore_default = false)
{
return $this->checkConfig($var_name, $ignore_default);
}
public function setValue($var_name, $var_value)
{
return $this->config[$var_name] = $var_value;
}
/**
* Retrieves full config in Array.
*
* @param bool
*/
public function getAllValues($default = false)
{
if (! $default) {
return $this->config;
}
return $this->default_val;
}
/**
* loads default config item if no config was found.
*
* @param string $var_name
* @param bool $ignore_default
*/
private function checkConfig($var_name = null, $ignore_default = false)
{
$var_u = strtoupper($var_name);
$var_l = strtolower($var_name);
if (! (isset($this->config[$var_l]))) { // is var set in loaded config
if ($ignore_default) {
return; // return empty
}
// $this->warn_msg[$var_u]="Default loaded"; //give red warning
return $this->default_val[$var_l]; // return default value
}
return $this->config[$var_l];
}
/**
* Loads default config.
*
* @return void
*/
public function loadDefaultConfig()
{
foreach ($this->default_val as $key => $value) {
$this->config[$key] = $value;
}
$this->log->debug('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> load_default_config');
}
/**
* Loads Config from DB.
*
* @param bool $merge
*
* @return void
*/
public function loadConfig($merge = false)
{
if (! $merge) {
$this->log->debug('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> Getting data from SQL table');
$this->config = ld_sql('get'); // get x keys
}
else {
// New default config contains n keys. Old personal config x keys.
$data = ld_sql('get'); // old config (x keys)
foreach ($data as $key => $value) { // looping over x keys and replace n key with x key. New config will contain user x keys and a few new n keys
$this->config[$key] = $value; // setting value
}
}
}
/**
* Load Old Config from file.
*
* @return void
*/
public function loadOldConfig()
{
if (file_exists(LDAP_LOGIN_PATH . '/config/data.dat')) {
// first we load the base config
$conf_file = @file_get_contents(LDAP_LOGIN_PATH . '/config/data.dat');
if ($conf_file !== false) {
$this->config = unserialize($conf_file);
$this->log->info('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> Getting data from ./config/data.dat');
}
}
}
/**
* Save Config to DB.
*
* @return void
*/
public function saveConfig()
{
$this->log->info('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> Saving values in SQL table');
ld_sql('update', 'update_value', $this->config);
}
/**
* Export Config.
*
* @return void
*/
public function exportConfig()
{
$file = fopen(LDAP_LOGIN_PATH . '/config/data.dat', 'w');
fwrite($file, serialize($this->config));
fclose($file);
$this->log->info('[' . basename(__FILE__) . '/' . __FUNCTION__ . ':' . __LINE__ . ']> Saving values in config/data.dat');
}
}