wsal = $wsal; if ( $wsal->settings()->CurrentUserCan( 'edit' ) ) { add_action( 'admin_init', array( $this, 'setup_page' ), 10 ); add_action( 'admin_menu', array( $this, 'admin_menus' ), 10 ); add_action( 'network_admin_menu', array( $this, 'admin_menus' ), 10 ); add_action( 'wp_ajax_setup_check_security_token', array( $this, 'setup_check_security_token' ) ); } } /** * Ajax handler to verify setting token. */ public function setup_check_security_token() { if ( ! $this->wsal->settings()->CurrentUserCan( 'edit' ) ) { echo wp_json_encode( array( 'success' => false, 'message' => esc_html__( 'Access Denied.', 'wp-security-audit-log' ), ) ); die(); } $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : false; $token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : false; if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'wsal-verify-wizard-page' ) ) { echo wp_json_encode( array( 'success' => false, 'message' => esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' ), ) ); die(); } if ( empty( $token ) ) { echo wp_json_encode( array( 'success' => false, 'message' => esc_html__( 'Invalid input.', 'wp-security-audit-log' ), ) ); die(); } echo wp_json_encode( array( 'success' => true, 'token' => $token, 'tokenType' => esc_html( $this->get_token_type( $token ) ), ) ); die(); } /** * Add setup admin page. */ public function admin_menus() { // this is an empty title because we do not want it to display. add_dashboard_page( '', '', 'manage_options', 'wsal-setup', '' ); // hide it via CSS as well so screen readers pass over it. add_action( 'admin_head', function() { ?> $info ) { $plugin_info = pathinfo( $plugin ); $plugin_filenames[] = $plugin_info['filename']; } // Grab list of plugins we have addons for. $predefined_plugins = WSAL_PluginInstallAndActivate::get_installable_plugins(); $predefined_plugins = array_column( $predefined_plugins, 'addon_for' ); // Loop through plugins and create an array of slugs, we will compare these agains the plugins we have addons for. $we_have_addon = array_intersect( $plugin_filenames, $predefined_plugins ); // Check if we have a match, if so, lets fire up out nifty slide. if ( ! empty( $we_have_addon ) ) { add_filter( 'wsal_wizard_default_steps', array( $this, 'wsal_add_wizard_step' ) ); } /** * Wizard Steps. */ $wizard_steps = array( 'welcome' => array( 'name' => __( 'Welcome', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_welcome' ), ), 'log_details' => array( 'name' => __( 'Log Details', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_log_details' ), 'save' => array( $this, 'wsal_step_log_details_save' ), ), 'login' => array( 'name' => __( 'Log In', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_login' ), 'save' => array( $this, 'wsal_step_login_save' ), ), 'register' => array( 'name' => __( 'User Registrations', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_register' ), 'save' => array( $this, 'wsal_step_register_save' ), ), 'log_retention' => array( 'name' => __( 'Log Retention', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_log_retention' ), 'save' => array( $this, 'wsal_step_log_retention_save' ), ), 'finish' => array( 'name' => __( 'Finish', 'wp-security-audit-log' ), 'content' => array( $this, 'wsal_step_finish' ), 'save' => array( $this, 'wsal_step_finish_save' ), ), ); /** * Filter: `Wizard Default Steps` * * WSAL filter to filter wizard steps before they are displayed. * * @param array $wizard_steps – Wizard Steps. */ $this->wizard_steps = apply_filters( 'wsal_wizard_default_steps', $wizard_steps ); // Set current step. $current_step = filter_input( INPUT_GET, 'current-step', FILTER_SANITIZE_STRING ); $this->current_step = ! empty( $current_step ) ? $current_step : current( array_keys( $this->wizard_steps ) ); // check if current step is a valid one. if ( ! array_key_exists( $this->current_step, $this->wizard_steps ) ) { $this->current_step = 'invalid-step'; } /** * Enqueue Styles. */ $wizard_css = WSAL_ViewManager::get_asset_path('/css/dist/', 'wsal-wizard', 'css'); wp_enqueue_style( 'wsal-wizard-css', $this->wsal->GetBaseUrl() . $wizard_css, array( 'dashicons', 'install', 'forms' ), filemtime( $this->wsal->GetBaseDir() . $wizard_css ) ); /** * Enqueue Scripts. */ $wizard_js = WSAL_ViewManager::get_asset_path( '/js/dist/', 'wsal-wizard', 'js'); wp_register_script( 'wsal-wizard-js', $this->wsal->GetBaseUrl() .$wizard_js, array( 'jquery' ), filemtime( $this->wsal->GetBaseDir() .$wizard_js ), false ); $common_js = '/js/common.js'; wp_register_script( 'wsal-common', $this->wsal->GetBaseUrl() . $common_js, array( 'jquery' ), filemtime( $this->wsal->GetBaseDir() . $common_js ), true ); // Data array. $data_array = array( 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'nonce' => ( ( ! $this->wsal->settings()->CurrentUserCan( 'edit' ) ) && ! 'invalid-step' === $this->current_step ) ? wp_create_nonce( 'wsal-verify-wizard-page' ) : '', 'usersError' => esc_html__( 'Specified value in not a user.', 'wp-security-audit-log' ), 'rolesError' => esc_html__( 'Specified value in not a role.', 'wp-security-audit-log' ), 'ipError' => esc_html__( 'Specified value in not an IP address.', 'wp-security-audit-log' ), ); wp_localize_script( 'wsal-wizard-js', 'wsalData', $data_array ); $installer_script_data = array( 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'installing' => __( 'Installing, please wait', 'wp-security-audit-log' ), 'already_installed' => __( 'Already installed', 'wp-security-audit-log' ), 'installed' => __( 'Extension installed', 'wp-security-audit-log' ), 'activated' => __( 'Extension activated', 'wp-security-audit-log' ), 'failed' => __( 'Install failed', 'wp-security-audit-log' ), ); wp_localize_script( 'wsal-common', 'wsalCommonData', $installer_script_data ); /** * Save Wizard Settings. */ $save_step = filter_input( INPUT_POST, 'save_step', FILTER_SANITIZE_STRING ); if ( ! empty( $save_step ) && ! empty( $this->wizard_steps[ $this->current_step ]['save'] ) ) { call_user_func( $this->wizard_steps[ $this->current_step ]['save'] ); } $this->setup_page_header(); $this->setup_page_steps(); $this->setup_page_content(); $this->setup_page_footer(); exit; } /** * Setup Page Header. */ private function setup_page_header() { ?> > <?php esc_html_e( 'WP Activity Log › Setup Wizard', 'wp-security-audit-log' ); ?>

WP Activity Log

current_step; // Array of step keys. $keys = array_keys( $this->wizard_steps ); if ( end( $keys ) === $current_step ) { // If last step is active then return WP Admin URL. return admin_url(); } // Search for step index in step keys. $step_index = array_search( $current_step, $keys, true ); if ( false === $step_index ) { // If index is not found then return empty string. return ''; } // Return next step. return add_query_arg( 'current-step', $keys[ $step_index + 1 ] ); } /** * Gets a link to the first wizard step. * * @method get_welcome_step * @since 4.0.2 * @return string */ private function get_welcome_step() { return remove_query_arg( 'current-step' ); } /** * Setup Page Content. */ private function setup_page_content() { ?>
wizard_steps[ $this->current_step ]['content'] ) && ! empty( $this->wizard_steps[ $this->current_step ]['content'] && is_callable( $this->wizard_steps[ $this->current_step ]['content'] ) ) ) { call_user_func( $this->wizard_steps[ $this->current_step ]['content'] ); } else { $this->render_invalid_step(); } ?>

get_welcome_step() ) . '">', '' ); ?>

wsal->GetGlobalBooleanSetting( 'setup-modal-dismissed', false ) ) { $this->wsal->SetGlobalBooleanSetting( 'setup-modal-dismissed', true ); } ?>


valid_log_levels, true ) ) { // if we have an unexpected log level then use default: 'geek'. $log_details = $this->valid_log_levels[0]; } // Save log details option. $this->wsal->SetGlobalSetting( 'details-level', $log_details ); if ( ! empty( $log_details ) && 'basic' === $log_details ) { $this->wsal->settings()->set_basic_mode(); } elseif ( ! empty( $log_details ) && 'geek' === $log_details ) { $this->wsal->settings()->set_geek_mode(); } wp_safe_redirect( esc_url_raw( $this->get_next_step() ) ); exit(); } /** * Step View: `Login Sensor` */ private function wsal_step_login() { ?>


get_next_step() ) ); exit(); } /** * Step View: `Register Sensor` */ private function wsal_step_register() { ?>


get_next_step() ) ); exit(); } /** * Step View: `Log Retention` */ private function wsal_step_log_retention() { ?>



upgrade to Premium and use the Database tools to store the WordPress activity log in an external database.', 'wp-security-audit-log' ); echo wp_kses( $step_help, $this->wsal->allowed_html_tags ); ?>

valid_prune_times, true ) ) { // if $pruning_limit is not valid value then use default - 6. $pruning_limit = $this->valid_prune_times[0]; } // Save log retention setting. if ( ! empty( $pruning_limit ) ) { switch ( $pruning_limit ) { case '6': case '12': // 6 or 12 months. $this->wsal->SetGlobalBooleanSetting( 'pruning-date-e', true ); $this->wsal->SetGlobalSetting( 'pruning-date', $pruning_limit . ' months' ); break; case 'none': // None. $this->wsal->SetGlobalBooleanSetting( 'pruning-date-e', false ); break; default: break; } } wp_safe_redirect( esc_url_raw( $this->get_next_step() ) ); exit(); } /** * Get Token Type. * * @param string $token - Token type. */ protected function get_token_type( $token ) { return $this->wsal->settings()->get_token_type( $token ); } /** * Step View: `Finish` */ private function wsal_step_finish() { ?>

please get in touch!', 'wp-security-audit-log' ), $this->wsal->allowed_html_tags ); ?>

wsal->SetGlobalBooleanSetting( 'setup-complete', true ); wp_safe_redirect( esc_url_raw( $this->get_next_step() ) ); exit(); } /** * 3rd Party plugins */ function wsal_add_wizard_step( $wizard_steps ) { $new_wizard_steps = array( 'test' => array( 'name' => __( 'Third Party Extensions', 'wp-security-audit-log' ), 'content' => array( $this, 'addons_step' ), 'save' => array( $this, 'addons_step_save' ), ), ); // Count number of items in the array. $number_of_steps = count( $wizard_steps ); // Subtract 1, as we want to insert our step one before the last item. $number_of_steps = $number_of_steps - 1; // Slice the steps up, so we have 2 parts we can insert our slide between. $first_part = array_slice( $wizard_steps, 0, $number_of_steps, true ); $last_part = array_slice( $wizard_steps, -1, 1, true ); // combine the two arrays. $wizard_steps = $first_part + $new_wizard_steps + $last_part; return $wizard_steps; } private function addons_step() { $our_plugins = WSAL_PluginInstallAndActivate::get_installable_plugins(); // Grab list of installed plugins. $all_plugins = get_plugins(); $plugin_filenames = array(); foreach ( $all_plugins as $plugin => $info ) { $plugin_info = pathinfo( $plugin ); $plugin_filenames[] = $plugin_info['filename']; } // Grab list of plugins we have addons for. $predefined_plugins = array_column( $our_plugins, 'addon_for' ); // Loop through plugins and create an array of slugs, we will compare these against the plugins we have addons for. $we_have_addon = array_intersect( $plugin_filenames, $predefined_plugins ); ?>

get_next_step() ) ); exit(); } }