Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ldap options to global_settings #1639

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions account_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
</td>
<td>
<?php
if( $t_ldap && ON == config_get( 'use_ldap_email' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_email' ) ) {
# With LDAP
echo string_display_line( $u_email );
} else {
Expand All @@ -220,7 +220,7 @@
</td>
</tr>
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_realname' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'realname' ) . '</td>';
echo '<td>';
Expand Down
4 changes: 2 additions & 2 deletions account_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@

# Update email (but only if LDAP isn't being used)
# Do not update email for a user verification
if( !( $t_ldap && config_get( 'use_ldap_email' ) )
if( !( $t_ldap && config_get_global( 'use_ldap_email' ) )
&& !$t_account_verification ) {
if( !is_blank( $f_email ) && $f_email != user_get_email( $t_user_id ) ) {
$t_update_email = true;
}
}

# Update real name (but only if LDAP isn't being used)
if( !( $t_ldap && config_get( 'use_ldap_realname' ) ) ) {
if( !( $t_ldap && config_get_global( 'use_ldap_realname' ) ) ) {
# strip extra spaces from real name
$t_realname = string_normalize( $f_realname );
if( $t_realname != user_get_field( $t_user_id, 'realname' ) ) {
Expand Down
5 changes: 4 additions & 1 deletion config_defaults_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4325,7 +4325,10 @@
'ldap_simulation_file_path', 'plugin_path', 'bottom_include_page', 'top_include_page',
'default_home_page', 'logout_redirect_page', 'manual_url', 'logo_url', 'wiki_engine_url',
'cdn_enabled', 'public_config_names', 'email_login_enabled', 'email_ensure_unique',
'impersonate_user_threshold', 'email_retry_in_days', 'neato_tool', 'dot_tool'
'impersonate_user_threshold', 'email_retry_in_days', 'neato_tool', 'dot_tool',
'ldap_server', 'ldap_root_dn', 'ldap_organization', 'ldap_protocol_version',
'ldap_network_timeout', 'ldap_follow_referrals', 'ldap_bind_dn', 'ldap_bind_passwd',
'ldap_uid_field', 'ldap_realname_field', 'use_ldap_realname', 'use_ldap_email'
);

/**
Expand Down
2 changes: 1 addition & 1 deletion core/email_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function email_is_valid( $p_email ) {
# If blank email is allowed or current user is admin, then accept blank emails which are useful for
# accounts that should never receive email notifications (e.g. anonymous account)
if( OFF == $t_validate_email ||
ON == config_get( 'use_ldap_email' ) ||
ON == config_get_global( 'use_ldap_email' ) ||
( is_blank( $p_email ) && ( ON == config_get( 'allow_blank_email' ) || current_user_is_administrator() ) )
) {
return true;
Expand Down
32 changes: 16 additions & 16 deletions core/ldap_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
trigger_error( ERROR_LDAP_EXTENSION_NOT_LOADED, ERROR );
}

$t_ldap_server = config_get( 'ldap_server' );
$t_ldap_server = config_get_global( 'ldap_server' );

log_event( LOG_LDAP, 'Attempting connection to LDAP server/URI \'' . $t_ldap_server . '\'.' );
$t_ds = @ldap_connect( $t_ldap_server );
Expand All @@ -75,7 +75,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {

log_event( LOG_LDAP, 'Connection accepted by LDAP server' );

$t_network_timeout = config_get( 'ldap_network_timeout' );
$t_network_timeout = config_get_global( 'ldap_network_timeout' );
if( $t_network_timeout > 0 ) {
log_event( LOG_LDAP, "Setting LDAP network timeout to " . $t_network_timeout );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_NETWORK_TIMEOUT, $t_network_timeout );
Expand All @@ -84,7 +84,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
}
}

$t_protocol_version = config_get( 'ldap_protocol_version' );
$t_protocol_version = config_get_global( 'ldap_protocol_version' );
if( $t_protocol_version > 0 ) {
log_event( LOG_LDAP, 'Setting LDAP protocol version to ' . $t_protocol_version );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_PROTOCOL_VERSION, $t_protocol_version );
Expand All @@ -94,7 +94,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
}

# Set referrals flag.
$t_follow_referrals = ON == config_get( 'ldap_follow_referrals' );
$t_follow_referrals = ON == config_get_global( 'ldap_follow_referrals' );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_REFERRALS, $t_follow_referrals );
if( !$t_result ) {
ldap_log_error( $t_ds );
Expand All @@ -103,8 +103,8 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
# If no Bind DN and Password is set, attempt to login as the configured
# Bind DN.
if( is_blank( $p_binddn ) && is_blank( $p_password ) ) {
$p_binddn = config_get( 'ldap_bind_dn', '' );
$p_password = config_get( 'ldap_bind_passwd', '' );
$p_binddn = config_get_global( 'ldap_bind_dn', '' );
$p_password = config_get_global( 'ldap_bind_passwd', '' );
}

if( !is_blank( $p_binddn ) && !is_blank( $p_password ) ) {
Expand Down Expand Up @@ -169,7 +169,7 @@ function ldap_realname_from_username( $p_username ) {
if( ldap_simulation_is_enabled() ) {
$t_realname = ldap_simulatiom_realname_from_username( $p_username );
} else {
$t_ldap_realname_field = config_get( 'ldap_realname_field' );
$t_ldap_realname_field = config_get_global( 'ldap_realname_field' );
$t_realname = (string)ldap_get_field_from_username( $p_username, $t_ldap_realname_field );
}
return $t_realname;
Expand Down Expand Up @@ -221,15 +221,15 @@ function ldap_cache_user_data( $p_username ) {
}

# Search
$t_ldap_organization = config_get( 'ldap_organization' );
$t_ldap_root_dn = config_get( 'ldap_root_dn' );
$t_ldap_uid_field = config_get( 'ldap_uid_field' );
$t_ldap_organization = config_get_global( 'ldap_organization' );
$t_ldap_root_dn = config_get_global( 'ldap_root_dn' );
$t_ldap_uid_field = config_get_global( 'ldap_uid_field' );

$t_search_filter = '(&' . $t_ldap_organization
. '(' . $t_ldap_uid_field . '=' . ldap_escape_string( $p_username ) . '))';
$t_search_attrs = array(
'mail',
config_get( 'ldap_realname_field' )
config_get_global( 'ldap_realname_field' )
);

log_event( LOG_LDAP, 'Searching for ' . $t_search_filter );
Expand Down Expand Up @@ -327,10 +327,10 @@ function ldap_authenticate_by_username( $p_username, $p_password ) {
} else {
$c_username = ldap_escape_string( $p_username );

$t_ldap_organization = config_get( 'ldap_organization' );
$t_ldap_root_dn = config_get( 'ldap_root_dn' );
$t_ldap_organization = config_get_global( 'ldap_organization' );
$t_ldap_root_dn = config_get_global( 'ldap_root_dn' );

$t_ldap_uid_field = config_get( 'ldap_uid_field', 'uid' );
$t_ldap_uid_field = config_get_global( 'ldap_uid_field', 'uid' );
$t_search_filter = '(&' . $t_ldap_organization . '(' . $t_ldap_uid_field . '=' . $c_username . '))';
$t_search_attrs = array(
$t_ldap_uid_field,
Expand Down Expand Up @@ -391,11 +391,11 @@ function ldap_authenticate_by_username( $p_username, $p_password ) {

$t_fields_to_update = array('password' => md5( $p_password ));

if( ON == config_get( 'use_ldap_realname' ) ) {
if( ON == config_get_global( 'use_ldap_realname' ) ) {
$t_fields_to_update['realname'] = ldap_realname_from_username( $p_username );
}

if( ON == config_get( 'use_ldap_email' ) ) {
if( ON == config_get_global( 'use_ldap_email' ) ) {
$t_fields_to_update['email'] = ldap_email_from_username( $p_username );
}

Expand Down
6 changes: 3 additions & 3 deletions core/user_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ function user_signup( $p_username, $p_email = null ) {
# I'll re-enable this once a plan has been properly formulated for LDAP
# account management and creation.
# $t_email = '';
# if( ON == config_get( 'use_ldap_email' ) ) {
# if( ON == config_get_global( 'use_ldap_email' ) ) {
# $t_email = ldap_email_from_username( $p_username );
# }
# if( !is_blank( $t_email ) ) {
Expand Down Expand Up @@ -921,7 +921,7 @@ function user_get_field( $p_user_id, $p_field_name ) {
*/
function user_get_email( $p_user_id ) {
$t_email = '';
if( LDAP == config_get_global( 'login_method' ) && ON == config_get( 'use_ldap_email' ) ) {
if( LDAP == config_get_global( 'login_method' ) && ON == config_get_global( 'use_ldap_email' ) ) {
$t_email = ldap_email( $p_user_id );
}
if( is_blank( $t_email ) ) {
Expand Down Expand Up @@ -954,7 +954,7 @@ function user_get_username( $p_user_id ) {
function user_get_realname( $p_user_id ) {
$t_realname = '';

if( LDAP == config_get_global( 'login_method' ) && ON == config_get( 'use_ldap_realname' ) ) {
if( LDAP == config_get_global( 'login_method' ) && ON == config_get_global( 'use_ldap_realname' ) ) {
$t_realname = ldap_realname( $p_user_id );
}

Expand Down
4 changes: 2 additions & 2 deletions manage_user_create_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<input type="text" id="user-username" name="username" class="input-sm" size="32" maxlength="<?php echo DB_FIELD_SIZE_USERNAME;?>" />
</td>
</tr><?php
if( !$t_ldap || config_get( 'use_ldap_realname' ) == OFF ) { ?>
if( !$t_ldap || config_get_global( 'use_ldap_realname' ) == OFF ) { ?>
<tr>
<td class="category">
<?php echo lang_get( 'realname' ) ?>
Expand All @@ -93,7 +93,7 @@
</td>
</tr><?php
}
if( !$t_ldap || config_get( 'use_ldap_email' ) == OFF ) { ?>
if( !$t_ldap || config_get_global( 'use_ldap_email' ) == OFF ) { ?>
<tr>
<td class="category">
<?php echo lang_get( 'email' ) ?>
Expand Down
4 changes: 2 additions & 2 deletions manage_user_edit_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

<!-- Realname -->
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_realname' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'realname_label' ) . '</td>';
echo '<td>';
Expand All @@ -144,7 +144,7 @@
</tr>
<!-- Email -->
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_email' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_email' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'email_label' ) . '</td>';
echo '<td>' . string_display_line( user_get_email( $t_user_id ) ) . '</td>';
Expand Down
4 changes: 2 additions & 2 deletions manage_user_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@

$t_ldap = ( LDAP == config_get_global( 'login_method' ) );

if( $t_ldap && config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && config_get_global( 'use_ldap_realname' ) ) {
$t_realname = ldap_realname_from_username( $f_username );
} else {
# strip extra space from real name
$t_realname = string_normalize( $f_realname );
}

if( $t_ldap && config_get( 'use_ldap_email' ) ) {
if( $t_ldap && config_get_global( 'use_ldap_email' ) ) {
$t_email = ldap_email( $f_user_id );
} else {
$t_email = trim( $f_email );
Expand Down