' . __('Cacti is Locked Out for Maintenance') . ''; print '

' . __('The primary Cacti administrator has locked out the Cacti user interface for maintenance for activities such as upgrades. If you feel this is in error, please contact your Cacti adminnistrator. This lockout will stay in place for approximately 30 minutes.') . '

'; bottom_footer(); exit; } } } } /** * If the special boolean $guest_account is set for a page, then the guest * account can be used. Where this may not be the case is with basic auth * where to enter the Cacti website, you must first have a valid account. * if that is the case, then use that valid accounts permissions and not * the guest account. */ if (isset($guest_account)) { $guest_user_id = get_guest_account(); // find guest user if (!empty($guest_user_id)) { if (empty($_SESSION[SESS_USER_ID])) { $_SESSION[SESS_USER_ID] = $guest_user_id; $_SESSION[SESS_USER_AGENT] = $_SERVER['HTTP_USER_AGENT']; $_SESSION[SESS_CLIENT_ADDR] = get_client_addr(); } $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', [$_SESSION[SESS_USER_ID]]); // GHSA-4rmr-wvjq-qxc2: fall through to the per-page realm check below // instead of returning, so the guest account's access to this page is // authorized rather than assumed. } } /** * If we are a guest user in a non-guest area, wipe credentials * user will be redirected back to the login page. */ if (!isset($guest_account) && isset($_SESSION[SESS_USER_ID])) { if (get_guest_account() === $_SESSION[SESS_USER_ID]) { kill_session_var(SESS_USER_ID); cacti_session_destroy(); cacti_session_start(); } } if (empty($_SESSION[SESS_USER_ID])) { if (isset($auth_json) && $auth_json == true) { print json_encode( [ 'status' => '500', 'statusText' => __('Not Logged In'), 'responseText' => __('You must be logged in to access this area of Cacti.') ] ); } elseif (isset($auth_text) && $auth_text == true) { // handle graph_image.php to respond with text. print __('FATAL: You must be logged in to access this area of Cacti.'); } else { require_once(CACTI_PATH_BASE . '/auth_login.php'); } exit; } else { if (empty($_SESSION[SESS_USER_2FA]) && db_column_exists('user_auth', 'tfa_enabled')) { if (read_config_option('secpass_2fa_enabled') == 'on') { if (is_2fa_enabled($_SESSION[SESS_USER_ID])) { header('Location: ' . CACTI_PATH_URL . 'auth_2fa.php'); exit; } else { $_SESSION[SESS_USER_2FA] = time(); } } } $realm_id = 0; if (isset($user_auth_realm_filenames[get_current_page()])) { $realm_id = $user_auth_realm_filenames[get_current_page()]; } // Are we upgrading from a version before 1.2 which has the Install/Upgrade realm 26 if ($realm_id == 26) { // See if we can find any users that are allowed to upgrade $install_sql_query = ' SELECT COUNT(*) FROM ( SELECT realm_id FROM user_auth_realm AS uar WHERE uar.realm_id = ?'; $install_sql_params = [$realm_id]; // See if the group realms exist and if so, check if permission exists there too if (db_table_exists('user_auth_group_realm') && db_table_exists('user_auth_group') && db_table_exists('user_auth_group_members')) { $install_sql_query .= ' UNION SELECT realm_id FROM user_auth_group_realm AS uagr INNER JOIN user_auth_group_members AS uagm ON uagr.group_id=uagm.group_id INNER JOIN user_auth_group AS uag ON uag.id=uagr.group_id WHERE uag.enabled="on" AND uagr.realm_id = ?'; $install_sql_params = array_merge($install_sql_params, [$realm_id]); } $install_sql_query .= ' ) AS authorized'; $has_install_user = db_fetch_cell_prepared($install_sql_query, $install_sql_params); if (!$has_install_user) { /* We did not find any existing users who can upgrade/install so add any admin * * who has access to the system settings (realm 15) by default */ db_execute('INSERT INTO `user_auth_realm` (realm_id, user_id) SELECT 26 as realm_id, ua.id FROM user_auth ua INNER JOIN user_auth_realm uar ON uar.user_id=ua.id LEFT JOIN user_auth_realm uar2 ON uar2.user_id=ua.id AND uar2.realm_id=26 WHERE uar.realm_id=15 AND uar2.user_id IS NULL'); } } if ($realm_id > 0) { $auth_sql_query = ' SELECT COUNT(*) FROM ( SELECT realm_id FROM user_auth_realm AS uar WHERE uar.user_id = ? AND uar.realm_id = ?'; $auth_sql_params = [$_SESSION[SESS_USER_ID], $realm_id]; /* Because we now expect installation to be done by authorized users, check the group_realm * * exists before using it as this may not be present if upgrading from pre-1.x */ if (db_table_exists('user_auth_group_realm') && db_table_exists('user_auth_group') && db_table_exists('user_auth_group_members')) { $auth_sql_query .= ' UNION SELECT realm_id FROM user_auth_group_realm AS uagr INNER JOIN user_auth_group_members AS uagm ON uagr.group_id = uagm.group_id INNER JOIN user_auth_group AS uag ON uag.id = uagr.group_id WHERE uag.enabled = "on" AND uagm.user_id = ? AND uagr.realm_id = ?'; $auth_sql_params = array_merge($auth_sql_params, [$_SESSION[SESS_USER_ID], $realm_id]); } $auth_sql_query .= ' ) AS authorized'; $authorized = db_fetch_cell_prepared($auth_sql_query, $auth_sql_params); } else { $authorized = false; } if ($realm_id != -1 && !$authorized) { if (api_plugin_hook_function('custom_denied', OPER_MODE_NATIVE) == OPER_MODE_RESKIN) { exit; } if (isset($_SERVER['HTTP_REFERER'])) { $goBack = "[" . __('Return') . " | " . __('Login Again') . ']'; } elseif ($auth_method != AUTH_METHOD_BASIC) { $goBack = "[" . __('Login Again') . ']'; } else { $goBack = ''; } raise_ajax_permission_denied(); $title_header = __('Permission Denied'); $title_body = '

' . __('You are not permitted to access this section of Cacti.') . '

' . __('If you feel that this is an error. Please contact your Cacti Administrator.'); if ($realm_id == 26) { $title_header = __('Installation In Progress'); $title_body = '

' . __('There is an Installation or Upgrade in progress.') . '

' . __('Only Cacti Administrators with Install/Upgrade privilege may login at this time') . '

'; } print "\n"; print "\n"; print "\n"; html_common_header($title_header); print "\n"; print "
" . $title_header . "
" . $title_body . '

' . $goBack . "
" . __('Version') . ' ' . $version . ' | ' . COPYRIGHT_YEARS_SHORT . "
\n"; include_once('global_session.php'); print " \n"; exit; } $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', [$_SESSION[SESS_USER_ID]]); // Handle saved filter-layout AJAX (save/rename/delete/publish) posted to // any filter page, now that the user is authenticated and authorized for // the current page. Returns immediately for all non-layout requests. filter_layouts_handle_request(); }