summaryrefslogtreecommitdiff
path: root/admin/admin_login_inc.php
blob: 7e7306f1981bed42f124aeea73bc87ef7d80c415 (plain)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php

use Bitweaver\BitBase;
use Bitweaver\Users\BaseAuth;
use Bitweaver\Users\BitHybridAuthManager;
// $Header$
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.

require_once USERS_PKG_CLASS_PATH.'BaseAuth.php';

$loginSettings = [
	'users_allow_register' => [
		'label' => "Users can register",
		'type' => "checkbox",
		'note' => "Registration is attempted for the lowest level supporting the creation of new users.",
	],
	'send_welcome_email' => [
		'label' => "Send registration welcome email",
		'type' => "checkbox",
		'note' => "Upon successful registration, this will send the user an email with login information, including their password.",
	],
	'after_reg_url' => [
		'label' => "After registration url",
		'type' => "text",
		'note' => "Set a url users will be directed to after registration. Default is your site's home page.",
	],
	'users_login_homepage' => [
		'label' => "After login url",
		'type' => "text",
		'note' => "Set a custom url where users will be directed after logging in. It should not include a leading slash or subdirectory. Default is users/my.php",
	],
	'users_eponymous_groups' => [
		'label' => "Create a group for each user",
		'type' => "checkbox",
		'note' => "This will create a group for each user with the same name as the user. This might be useful if you want to assign different permission settings to every user.",
	],
	'users_forgot_pass' => [
		'label' => "Remind passwords by email",
		'type' => "checkbox",
		'note' => "This will display a 'forgot password' link on the login page and allow users to have their password sent to their registered email address.",
	],
	'users_remember_me' => [
		'label' => "Remember me feature",
		'type' => "checkbox",
		'note' => "Registered users will stay logged even if they close their browser.",
	],
	'cookie_domain' => [
		'label' => "Remember me domain",
		'type' => "text",
		'note' => "Remember to use a '.' wildcard prefix if you want domain wide cookies.<br />e.g.: <strong>.mysite.com</strong> for a domain called <strong>www.mysite.com</strong>",
	],
	'cookie_path' => [
		'label' => "Remember me path",
		'type' => "text",
		'note' => "The path '/foo' would match '/foobar' and '/foo/bar.html'",
	],
];
$gBitSmarty->assign( 'loginSettings', $loginSettings );

$registerSettings = [
	'users_validate_user'                 => [
		'label' => "Validate users by email",
		'type'  => "checkbox",
		'note'  => "Send an email to the user, to validate registration.",
	],
	'users_validate_email'                => [
		'label' => "Validate email address",
		'type'  => "checkbox",
		'link'  => "kernel/admin/index.php?page=server/General Settings",
		'note'  => "This feature should be used only when you need the maximum security and should be used with discretion. If a visitor's email server is not responding, they will not be placed into the group specified below for verified emails. If a users email is determined to be invalid (meaning, the server does respond, but negatively) they will not be able to register. You also must have a valid sender email to use this feature.",
	],
	'users_case_sensitive_login'          => [
		'label' => 'Case-Sensitive Login',
		'type'  => "checkbox",
		'note'  => 'This determines whether user login names are case-sensitive.',
	],
	'reg_real_name'                       => [
		'label' => "Real Name",
		'type'  => "checkbox",
		'note'  => "Allow users to supply their real name.",
	],
	'reg_country'                         => [
		'label' => "Country",
		'type'  => "checkbox",
		'note'  => "Allow users to pick country of residency.",
	],
	'reg_language'                        => [
		'label' => "Language",
		'type'  => "checkbox",
		'note'  => "Allow users to select their preferred language.",
	],
	'reg_homepage'                        => [
		'label' => "Homepage URL",
		'type'  => "checkbox",
		'note'  => "Allow users to enter the url to their own homepage.",
	],
	'reg_portrait'                        => [
		'label' => "Profile Picture",
		'type'  => "checkbox",
		'note'  => "Allow users to upload a profile picture.",
	],
	'users_pass_due'                      => [
		'label' => "Password invalid after days",
		'type'  => "text",
		'note'  => "",
	],
	'users_pass_chr_num'                  => [
		'label' => "Force to use characters <strong>and</strong> numbers in passwords",
		'type'  => "checkbox",
		'note'  => "",
	],
	'users_min_pass_length'               => [
		'label' => "Minimum password length",
		'type'  => "text",
		'note'  => "",
	],
	'user_password_generator'             => [
		'label' => "Password generator",
		'type'  => "checkbox",
		'note'  => "Display password generator on registration page that creates secure passwords.",
	],
	'users_register_require_passcode'     => [
		'label' => "Request passcode to register",
		'type'  => "checkbox",
		'note'  => "",
	],
	'users_register_passcode'             => [
		'label' => "Passcode",
		'type'  => "text",
		'note'  => "Enter the Passcode that is required for users to register with your site.",
	],
	'users_random_number_reg'             => [
		'label' => "Use basic captcha to prevent automatic/robot registration",
		'type'  => "checkbox",
		'note'  => "This will generate an image with a word that the user has to confirm during the registration step.",
	],
	'users_register_recaptcha'            => [
		'label' => "Use advanced reCAPTCHA to prevent automatic/robot registration",
		'type'  => "checkbox",
		'note'  => "To use reCAPTCHA you must get your API keys from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a> and enter them below.",
	],
	'users_register_recaptcha_site_key'   => [
		'label' => "reCAPTCHA Site Key",
		'type'  => "text",
		'note'  => "This will be given to you after registering your site with Google",
	],
	'users_register_recaptcha_secret_key' => [
		'label' => "reCAPTCHA Secret Key",
		'type'  => "text",
		'note'  => "This will be given to you after registering your site with Google",
	],
	'users_register_smcaptcha'            => [
		'label' => "Use Solve Media CAPTCHA to prevent automatic/robot registration",
		'type'  => "checkbox",
		'note'  => "To use Solve Media CAPTCHA you must get your API keys from <a href='https://www.solvemedia.com'>https://www.solvemedia.com</a> and enter them below.",
	],
	'users_register_smcaptcha_c_key'      => [
		'label' => "Solve Media Challenge Key (C-key)",
		'type'  => "text",
		'note'  => "This will be given to you after registering your site with Solve Media",
	],
	'users_register_smcaptcha_v_key'      => [
		'label' => "Solve Media Verification Key (V-key)",
		'type'  => "text",
		'note'  => "This will be given to you after registering your site with Solve Media",
	],
	'users_register_smcaptcha_h_key'      => [
		'label' => "Solve Media Authentication Hash Key (H-key)",
		'type'  => "text",
		'note'  => "This will be given to you after registering your site with Solve Media",
	],
];
$gBitSmarty->assign( 'registerSettings', $registerSettings );

$httpSettings = [
	'site_https_login'          => [
		'label' => "Allow secure (https) login",
		'type'  => "checkbox",
		'note'  => "",
	],
	'site_https_login_required' => [
		'label' => "Require secure (https) login",
		'type'  => "checkbox",
		'note'  => "",
	],
	'site_http_domain'          => [
		'label' => "HTTP server name",
		'type'  => "text",
		'note'  => "",
	],
	'site_http_port'            => [
		'label' => "HTTP port",
		'type'  => "text",
		'note'  => "",
	],
	'site_http_prefix'          => [
		'label' => "HTTP URL prefix",
		'type'  => "text",
		'note'  => "",
	],
	'site_https_domain'         => [
		'label' => "HTTPS server name",
		'type'  => "text",
		'note'  => "",
	],
	'site_https_port'           => [
		'label' => "HTTPS port",
		'type'  => "text",
		'note'  => "",
	],
	'site_https_prefix'         => [
		'label' => "HTTPS URL prefix",
		'type'  => "text",
		'note'  => "",
	],
];
$gBitSmarty->assign( 'httpSettings', $httpSettings );

$listHash = [ 'sort_mode' => 'role_name_asc' ];
$gBitSmarty->assign( 'roleList', $gBitUser->getAllRoles( $listHash ));

if( !function_exists("gd_info" ) ) {
	$gBitSmarty->assign( 'warning', 'PHP GD library is required for this feature (not found on your system)' );
}

BitHybridAuthManager::loadSingleton();
global $gBitHybridAuthManager;

if( !empty( $_POST ) ) {
	// Save all HybridAuth Single Sign On configuration
	if( !empty( $_REQUEST['hybridauth'] ) ) {
		$allAuthProviders = $gBitHybridAuthManager->getAllProviders();
		// make sure all (un)checkboxes stick
		foreach( $allAuthProviders as $providerKey=>$providerConfig ) {
			$enabledConfig = $gBitHybridAuthManager->getEnabledConfigKey( $providerConfig['provider'] );
			$gBitSystem->storeConfig( $enabledConfig, BitBase::getParameter( $_REQUEST['hybridauth'], $enabledConfig, null ) );
		}
		foreach( $_REQUEST['hybridauth'] as $prefName=>$prefValue ) {
			if( $prefName == 'users_ha_facebook_scope' ) {
				$prefName = preg_replace('/\s+/', '', $prefName );
			}
			$gBitSystem->storeConfig( $prefName, !empty( $prefValue ) ? $prefValue : null );
		}
		$gBitHybridAuthManager->clearFromCache();
	}

	// Save all preferences
	foreach( [ 'loginprefs'=>'loginSettings', 'registerprefs'=>'registerSettings', 'httpprefs'=>'httpSettings' ] as $prefGroup=>$prefHash ) {
		$settings = $$prefHash;
		foreach( array_keys( $settings ) as $feature ) {
			if( $settings[$feature]['type'] == 'text' ) {
				simple_set_value( $feature, USERS_PKG_NAME );
			} else {
				simple_set_toggle( $feature, USERS_PKG_NAME );
			}
		}
	}

	if( !preg_match( "#^/#", $_REQUEST['cookie_path'] ) ) {
		$_REQUEST['cookie_path'] = '/'.$_REQUEST['cookie_path'];
	} elseif( $_REQUEST['cookie_path'] == BIT_ROOT_URL ) {
		$_REQUEST['cookie_path'] = '';
	}

	if( $_REQUEST['cookie_domain'] == $_SERVER["SERVER_NAME"] ) {
		$_REQUEST['cookie_domain'] = '';
	}

	simple_set_value( 'users_remember_time', USERS_PKG_NAME );
	simple_set_value( 'users_auth_method', USERS_PKG_NAME );
	simple_set_value( 'users_validate_email_group', USERS_PKG_NAME );

	if( isset( $_REQUEST['registration_role_choice'] ) ) {
		$listHash = [];
		$roleList = $gBitUser->getAllRoles( $listHash );

		$in = [];
		$out = [];
		foreach( $roleList as $ro ) {
			if( $ro['role_id'] == ANONYMOUS_TEAM_ID ) {
				continue;
			}

			// work out if something has been selected or deselected
			if( $ro['is_public'] == 'y' && !in_array( $ro['role_id'], $_REQUEST['registration_role_choice'] )) {
				$out[] = $ro['role_id'];
			} elseif( $ro['is_public'] != 'y' && in_array( $ro['role_id'], $_REQUEST['registration_role_choice'] )) {
				$in[] = $ro['role_id'];
			}
		}
		if( count( $in ) ) {
			$gBitUser->storeRegistrationChoice( $in, 'y' );
		}
		if( count( $out ) ) {
			$gBitUser->storeRegistrationChoice( $out, null );
		}
	}
	$gBitSystem->clearFromCache();
}

$gBitSmarty->assign( 'hybridProviders', $gBitHybridAuthManager->getAllProviders() );

$listHash = [];

// This needs to be made more generic so that it picks up all plugins
// Could not see where the 'auth_ldap' was defined in the $options['avail'] array
$options = BaseAuth::getConfig();
if( !empty( $_REQUEST["auth_ldap"] ) ) {
	$option_ldap = $options['avail']['ldap']['options'];
	foreach( array_keys( $option_ldap ) as $feature ) {
		if( $option_ldap[$feature]['type'] == 'text' ) {
			simple_set_value( $feature, USERS_PKG_NAME );
		} else {
			simple_set_toggle( $feature, USERS_PKG_NAME );
		}
	}
}

$gBitSmarty->assign( 'authSettings', BaseAuth::getConfig() );