new \WP_Error( 'itsec.firewall.db-error', __( 'Could not delete firewall rules.', 'better-wp-security' ), [ 'error' => $this->wpdb->last_error, ] ) ); } return Result::success( $this->wpdb->rows_affected ); } /** * Fetches rules from the DB. * * @param Rules_Options $options * * @return Result */ public function get_rules( Rules_Options $options ): Result { $sql = "SELECT * FROM {$this->table}"; [ $where, $prepare ] = $this->build_where_clause( $options ); $sql .= $where; $sql .= ' ORDER BY `id` DESC'; if ( $options->get_per_page() ) { $sql .= sprintf( ' LIMIT %d, %d', $options->get_per_page() * ( $options->get_page() - 1 ), $options->get_per_page() ); } if ( $prepare ) { $execute = $this->wpdb->prepare( $sql, $prepare ); } else { $execute = $sql; } $results = $this->wpdb->get_results( $execute, ARRAY_A ); if ( $this->wpdb->last_error ) { return Result::error( new \WP_Error( 'itsec.firewall.db-error', __( 'Could not fetch firewall rules.', 'better-wp-security' ), [ 'error' => $this->wpdb->last_error, ] ) ); } return Result::success( array_filter( array_map( [ $this, 'try_hydrate' ], $results ) ) ); } /** * Count rules in the DB. * * @param Rules_Options $options * * @return Result */ public function count_rules( Rules_Options $options ): Result { $sql = "SELECT count(*) as c FROM {$this->table}"; [ $where, $prepare ] = $this->build_where_clause( $options ); $sql .= $where; $count = $this->wpdb->get_var( $this->wpdb->prepare( $sql, $prepare ) ); if ( $this->wpdb->last_error ) { return Result::error( new \WP_Error( 'itsec.firewall.db-error', __( 'Could not count firewall rules.', 'better-wp-security' ), [ 'error' => $this->wpdb->last_error, ] ) ); } return Result::success( (int) $count ); } private function build_where_clause( Rules_Options $options ): array { $wheres = []; $prepare = []; if ( $providers = $options->get_providers() ) { $wheres[] = sprintf( '`provider` IN (%s)', implode( ', ', array_fill( 0, count( $providers ), '%s' ) ) ); $prepare = array_merge( $prepare, $providers ); } if ( $vulnerabilities = $options->get_vulnerabilities() ) { $wheres[] = sprintf( '`vulnerability` IN (%s)', implode( ', ', array_fill( 0, count( $vulnerabilities ), '%s' ) ) ); $prepare = array_merge( $prepare, $vulnerabilities ); } if ( $options->get_paused() === true ) { $wheres[] = '`paused_at` IS NOT NULL'; } elseif ( $options->get_paused() === false ) { $wheres[] = '`paused_at` IS NULL'; } if ( $search = $options->get_search() ) { $wheres[] = '`name` LIKE %s'; $prepare[] = '%' . $this->wpdb->esc_like( $search ) . '%'; } if ( $provider_refs = $options->get_provider_refs() ) { $wheres[] = sprintf( '(%s)', implode( ' OR ', array_map( function ( array $rule ) use ( &$prepare ) { $prepare[] = $rule['provider']; $prepare[] = $rule['ref']; return '(`provider` = %s AND `provider_ref` = %s)'; }, $provider_refs ) ) ); } if ( ! $wheres ) { return [ '', [] ]; } return [ ' WHERE ' . implode( ' AND ', $wheres ), $prepare ]; } /** * Loads the set of firewall rules to execute. * * @return array */ public function load_rules(): array { $rows = $this->wpdb->get_results( "SELECT `id`, `vulnerability`, `config` FROM {$this->table} WHERE `paused_at` IS NULL", ARRAY_A ); if ( $this->wpdb->last_error ) { return []; } return array_filter( array_map( function ( $row ) { $data = json_decode( $row['config'], true ); if ( ! is_array( $data ) ) { return null; } $id = $row['id']; if ( $row['vulnerability'] ) { $id .= '|' . $row['vulnerability']; } return array_merge( $data, [ 'id' => $id ] ); }, $rows ) ); } private function try_hydrate( array $data ): ?Rule { try { return $this->hydrate( $data ); } catch ( \Exception $e ) { return null; } } private function hydrate( array $data ): Rule { return new Rule( $data['id'], $data['provider'], $data['provider_ref'], $data['name'], $data['vulnerability'], json_decode( $data['config'], true ), new \DateTimeImmutable( $data['created_at'], new \DateTimeZone( 'UTC' ) ), $data['paused_at'] ? new \DateTimeImmutable( $data['paused_at'], new \DateTimeZone( 'UTC' ) ) : null ); } }
Fatal error: Uncaught Error: Class "iThemesSecurity\Modules\Firewall\Rules\Repository" not found in /htdocs/wp-content/plugins/better-wp-security/core/modules/firewall/container.php:37 Stack trace: #0 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php(125): ITSEC_Modules::iThemesSecurity\Modules\Firewall\{closure}(Object(iThemesSecurity\Strauss\Pimple\Container)) #1 /htdocs/wp-content/plugins/better-wp-security/core/modules/firewall/container.php(41): iThemesSecurity\Strauss\Pimple\Container->offsetGet('iThemesSecurity...') #2 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php(125): ITSEC_Modules::iThemesSecurity\Modules\Firewall\{closure}(Object(iThemesSecurity\Strauss\Pimple\Container)) #3 /htdocs/wp-content/plugins/better-wp-security/core/modules/firewall/container.php(47): iThemesSecurity\Strauss\Pimple\Container->offsetGet('iThemesSecurity...') #4 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php(125): ITSEC_Modules::iThemesSecurity\Modules\Firewall\{closure}(Object(iThemesSecurity\Strauss\Pimple\Container)) #5 /htdocs/wp-content/plugins/better-wp-security/core/modules/firewall/container.php(19): iThemesSecurity\Strauss\Pimple\Container->offsetGet('iThemesSecurity...') #6 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php(125): ITSEC_Modules::iThemesSecurity\Modules\Firewall\{closure}(Object(iThemesSecurity\Strauss\Pimple\Container)) #7 /htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Psr11/Container.php(51): iThemesSecurity\Strauss\Pimple\Container->offsetGet('iThemesSecurity...') #8 /htdocs/wp-content/plugins/better-wp-security/core/modules.php(1176): iThemesSecurity\Strauss\Pimple\Psr11\Container->get('iThemesSecurity...') #9 /htdocs/wp-content/plugins/better-wp-security/core/modules.php(779): ITSEC_Modules->run('iThemesSecurity...') #10 /htdocs/wp-content/plugins/better-wp-security/core/modules.php(867): ITSEC_Modules::load_module_file('active.php', Array) #11 /htdocs/wp-content/plugins/better-wp-security/core/core.php(182): ITSEC_Modules::run_active_modules() #12 /htdocs/wp-content/plugins/better-wp-security/core/core.php(233): ITSEC_Core->shared_init() #13 /htdocs/wp-includes/class-wp-hook.php(324): ITSEC_Core->continue_init('') #14 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #15 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #16 /htdocs/wp-settings.php(555): do_action('plugins_loaded') #17 /htdocs/wp-config.php(100): require_once('/htdocs/wp-sett...') #18 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #19 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #20 /htdocs/index.php(17): require('/htdocs/wp-blog...') #21 {main} thrown in /htdocs/wp-content/plugins/better-wp-security/core/modules/firewall/container.php on line 37