0) { domains_login_process($username); } break; default: $auth_local_required = true; break; } cacti_log("DEBUG: User '" . $username . "' attempt login locally? " . ($auth_local_required ? 'Yes':'No'), false, 'AUTH', POLLER_VERBOSITY_DEBUG); if ($auth_local_required) { secpass_login_process($username); if (!api_plugin_hook_function('login_process', false)) { /* Builtin Auth */ if ((!$user_auth)) { $stored_pass = db_fetch_cell_prepared('SELECT password FROM user_auth WHERE username = ? AND realm = 0', array($username)); if ($stored_pass != '') { $p = get_nfilter_request_var('login_password'); $valid = compat_password_verify($p, $stored_pass); cacti_log("DEBUG: User '" . $username . "' password is " . ($valid?'':'in') . "valid", false, 'AUTH', POLLER_VERBOSITY_DEBUG); if ($valid) { $user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE username = ? AND realm = 0', array($username)); if (compat_password_needs_rehash($stored_pass, PASSWORD_DEFAULT)) { $p = compat_password_hash($p, PASSWORD_DEFAULT); db_check_password_length(); db_execute_prepared('UPDATE user_auth SET password = ? WHERE username = ?', array($p, $username)); } } } } } } /* end of switch */ /* Create user from template if requested */ if (!cacti_sizeof($user) && $copy_user && get_template_account() != '0' && $username != '') { cacti_log("NOTE: User '" . $username . "' does not exist, copying template user", false, 'AUTH'); $user_template = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array(get_template_account())); /* check that template user exists */ if (!empty($user_template)) { /* get user CN*/ $cn_full_name = read_config_option('cn_full_name'); $cn_email = read_config_option('cn_email'); if ($cn_full_name != '' || $cn_email != '') { $ldap_cn_search_response = cacti_ldap_search_cn($username, array($cn_full_name,$cn_email)); if (isset($ldap_cn_search_response['cn'])) { $data_override = array(); if (array_key_exists($cn_full_name, $ldap_cn_search_response['cn'])) { $data_override['full_name'] = $ldap_cn_search_response['cn'][$cn_full_name]; } else { $data_override['full_name'] = ''; } if (array_key_exists($cn_email, $ldap_cn_search_response['cn'])) { $data_override['email_address'] = $ldap_cn_search_response['cn'][$cn_email]; } else { $data_override['email_address'] = ''; } user_copy($user_template['username'], $username, 0, $realm, false, $data_override); } else { $ldap_response = (isset($ldap_cn_search_response[0]) ? $ldap_cn_search_response[0] : '(no response given)'); $ldap_code = (isset($ldap_cn_search_response['error_num']) ? $ldap_cn_search_response['error_num'] : '(no code given)'); cacti_log('LOGIN: Email Address and Full Name fields not found, reason: ' . $ldap_response . 'code: ' . $ldap_code, false, 'AUTH'); user_copy($user_template['username'], $username, 0, $realm); } } else { user_copy($user_template['username'], $username, 0, $realm); } /* requery newly created user */ $user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE username = ? AND realm = ?', array($username, $realm)); } else { /* error */ display_custom_error_message(__('Template user id %s does not exist.', read_config_option('user_template'))); cacti_log("LOGIN: Template user id '" . read_config_option('user_template') . "' does not exist.", false, 'AUTH'); header('Location: index.php?header=false'); exit; } } /* Guest account checking - Not for builtin */ $guest_user = false; if ((!cacti_sizeof($user)) && ($user_auth) && (get_guest_account() != '0')) { /* Locate guest user record */ $user = db_fetch_row_prepared('SELECT id, username, enabled FROM user_auth WHERE id = ?', array(get_guest_account())); if ($user) { cacti_log("LOGIN: Authenticated user '" . $username . "' using guest account '" . $user['username'] . "'", false, 'AUTH'); $guest_user = true; } else { /* error */ display_custom_error_message(__('Guest user id %s does not exist.', read_config_option('guest_user'))); cacti_log("LOGIN: Unable to locate guest user '" . read_config_option('guest_user') . "'", false, 'AUTH'); header('Location: index.php?header=false'); exit; } } /* Process the user */ if (cacti_sizeof($user)) { cacti_log("LOGIN: User '" . $user['username'] . "' Authenticated", false, 'AUTH'); $client_addr = get_client_addr(''); db_execute_prepared('INSERT IGNORE INTO user_log (username, user_id, result, ip, time) VALUES (?, ?, 1, ?, NOW())', array($username, $user['id'], $client_addr)); /* is user enabled */ $user_enabled = $user['enabled']; if ($user_enabled != 'on') { /* Display error */ display_custom_error_message(__('Access Denied, user account disabled.')); header('Location: index.php?header=false'); exit; } /* remember this user */ if (isset_request_var('remember_me') && read_config_option('auth_cache_enabled') == 'on') { set_auth_cookie($user); } /* set the php session */ $_SESSION['sess_user_id'] = $user['id']; /* handle 'force change password' */ if (($user['must_change_password'] == 'on') && (read_config_option('auth_method') == 1) && ($user['password_change'] == 'on')) { $_SESSION['sess_change_password'] = true; } if (db_table_exists('user_auth_group')) { $group_options = db_fetch_cell_prepared('SELECT MAX(login_opts) FROM user_auth_group AS uag INNER JOIN user_auth_group_members AS uagm ON uag.id=uagm.group_id WHERE user_id=?', array($_SESSION['sess_user_id'])); if ($group_options > 0) { $user['login_opts'] = $group_options; } } $newtheme = false; if (user_setting_exists('selected_theme', $_SESSION['sess_user_id']) && read_config_option('selected_theme') != read_user_setting('selected_theme')) { unset($_SESSION['selected_theme']); $newtheme = true; } /* ok, at the point the user has been sucessfully authenticated; so we must decide what to do next */ switch ($user['login_opts']) { case '1': /* referer */ /* because we use plugins, we can't redirect back to graph_view.php if they don't * have console access */ if (isset($_SERVER['REDIRECT_URL'])) { $referer = sanitize_uri($_SERVER['REDIRECT_URL']); if (isset($_SERVER['REDIRECT_QUERY_STRING'])) { $referer .= '?' . $_SERVER['REDIRECT_QUERY_STRING'] . ($newtheme ? '&newtheme=1':''); } } elseif (isset($_SERVER['HTTP_REFERER'])) { $referer = sanitize_uri($_SERVER['HTTP_REFERER']); if (basename($referer) == 'logout.php') { $referer = $config['url_path'] . 'index.php' . ($newtheme ? '?newtheme=1':''); } } elseif (isset($_SERVER['REQUEST_URI'])) { $referer = sanitize_uri($_SERVER['REQUEST_URI']); if (basename($referer) == 'logout.php') { $referer = $config['url_path'] . 'index.php' . ($newtheme ? '?newtheme=1':''); } } else { $referer = $config['url_path'] . 'index.php' . ($newtheme ? '?newtheme=1':''); } if (substr_count($referer, 'plugins')) { header('Location: ' . $referer); } elseif (!is_realm_allowed(8)) { header('Location: graph_view.php' . ($newtheme ? '?newtheme=1':'')); } else { $param_char = '?'; if (substr_count($referer, '?')) { $param_char = '&'; } header('Location: ' . $referer . ($newtheme ? $param_char . 'newtheme=1':'')); } break; case '2': /* default console page */ header('Location: ' . $config['url_path'] . 'index.php' . ($newtheme ? '?newtheme=1':'')); break; case '3': /* default graph page */ header('Location: ' . $config['url_path'] . 'graph_view.php' . ($newtheme ? '?newtheme=1':'')); break; default: api_plugin_hook_function('login_options_navigate', $user['login_opts']); } exit; } else { if ((!$guest_user) && ($user_auth)) { /* No guest account defined */ display_custom_error_message(__('Access Denied, please contact you Cacti Administrator.')); cacti_log('LOGIN: Access Denied, No guest enabled or template user to copy', false, 'AUTH'); header('Location: index.php'); exit; } else { /* BAD username/password builtin and LDAP */ db_execute_prepared('INSERT IGNORE INTO user_log (username, user_id, result, ip, time) VALUES (?, 0, 0, ?, NOW())', array($username, get_client_addr(''))); } } } /* auth_display_custom_error_message - displays a custom error message to the browser that looks like the pre-defined error messages @arg $message - the actual text of the error message to display */ function auth_display_custom_error_message($message) { global $config; /* kill the session */ setcookie(session_name(), '', time() - 3600, $config['url_path']); /* print error */ print ''; print "\n"; print "
\n"; html_common_header(__('Cacti')); print "\n"; print "\n