<?php

/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRESS is a RazorVue Trademark.
 *
 * @package     HappyFenceNG
 * @developer   Simonluca Scillitani
 * @copyright   2025 RazorVue di Scillitani Simonluca
 * @link        https://razorvue.it
 * @author      RazorVue di Scillitani Simonluca
 * @brand       HappyWPress
 * @uri         https://happywpress.com
 * @set all
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**PHPCS -> code compliance: we put useful comments where needed.. */
class HappyFenceNGCore extends HappyFenceNGService {
    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @var bool $xmlrpc_logged should be something like "maybe yes or no"?.
     */
    private bool $xmlrpc_logged = false;

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function init() {
        add_filter( 'xmlrpc_enabled', array($this, 'manage_xmlrpc'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_XMLRPCF, HappyFenceNGRgs::SR );
        add_action( 'parse_request', array($this, 'svc_hide_dangerous_files'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        /**The following headers cannot be disabled/changed for security reasons */
        add_action( 'send_headers', function () {
            // X-Frame-Options per proteggere contro il clickjacking.
            header( 'X-Frame-Options: SAMEORIGIN' );
            // No X-Redirect-By.
            header_remove( 'X-Redirect-By' );
            // No X-Powered-By.
            header_remove( 'X-Powered-By' );
            // no mime sniff.
            header( 'X-Content-Type-Options: nosniff' );
            // strict https.
            // header('Strict-Transport-Security: max-age=31536000; includeSubDomains; preload');.
            // xss protection.
            header( 'X-XSS-Protection: 1; mode=block' );
            // referrer policy.
            header( 'Referrer-Policy: no-referrer-when-downgrade' );
            // content security policy base.
            // header('Content-Security-Policy: default-src \'self\'; script-src \'self\'; style-src \'self\';');.
        }, HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        add_action( 'wp_head', array($this, 'svc_handle_meta_generator'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_META, HappyFenceNGRgs::SR );
        add_action( 'wp_footer', array($this, 'svc_handle_embed_script'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_EMBED, HappyFenceNGRgs::SR );
        add_action( 'login_init', array($this, 'svc_check_custom_login'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        add_action( 'parse_request', array($this, 'svc_check_custom_login'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_CULOG, HappyFenceNGRgs::SR );
        add_action( 'do_feed', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_1, HappyFenceNGRgs::SR );
        add_action( 'do_feed_rdf', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_2, HappyFenceNGRgs::SR );
        add_action( 'do_feed_rss', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_3, HappyFenceNGRgs::SR );
        add_action( 'do_feed_rss2', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_4, HappyFenceNGRgs::SR );
        add_action( 'do_feed_atom', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_5, HappyFenceNGRgs::SR );
        add_action( 'do_feed_rss2_comments', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_6, HappyFenceNGRgs::SR );
        add_action( 'do_feed_atom_comments', array($this, 'svc_disable_rss_feed_die'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_RSS_FEED_7, HappyFenceNGRgs::SR );
        add_filter( 'wp_is_application_passwords_available', array($this, 'svc_disable_app_passwords'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        HappyFenceNGCStore::registerFunction( HappyFenceNGRgs::RFS_APP_PWD, HappyFenceNGRgs::SR );
        add_filter( 'svc_script_loader_src', array($this, 'svc_script_loader'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
        add_filter( 'style_loader_src', array($this, 'svc_script_loader'), HappyFenceNGStStored::FILTER_PRIORITY_ACORE );
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $method_name .... another useless comment.
     */
    public static function getStatus( string $method_name ) {
        switch ( $method_name ) {
            case 'manage_xmlrpc':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->XMLRPC->block_xmlrpc, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_block_rest_for_guests':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->REST->block_rest_guests, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_remove_user_endpoints':
                return HappyFenceNGPlaceholder::STATUS_ON;
            case 'svc_redirect_author_page':
                return HappyFenceNGPlaceholder::STATUS_ON;
            case 'svc_manage_remove_rest_head_link':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->REST->remove_rest_links, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_manage_obfuscate_login_errors':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->LOGIN->login_obfuscation, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_handle_xmlrpc_methods':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PINGBACK->block_xmlrpc_pingback, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_handle_meta_generator':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->remove_meta_generator, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_handle_embed_script':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->EMBED->remove_embed_script, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_handle_wp_oembed':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->EMBED->disable_oembed_discovery, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_check_custom_login':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->enable_custom_login, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_disable_rss_feed_die':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->disable_rss_feed, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_disable_rss_feed':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->disable_rss_feed, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_disable_app_passwords':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->svc_disable_app_passwords, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_script_loader':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->remove_meta_generator, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            case 'svc_block_authors':
                return HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->block_author, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            default:
                return HappyFenceNGPlaceholder::UNKNOWN;
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_handle_meta_generator() {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->remove_meta_generator, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                remove_action( 'wp_head', 'wp_generator' );
                HappyFenceNGAlog::get_instance()->log( 'Removed meta generator tag from wp_head', HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::INFO );
            } else {
                HappyFenceNGAlog::get_instance()->log( 'Meta generator tag is active, please disable it.', HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::NOTICE );
            }
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $url ..is url what else?.
     */
    public function svc_script_loader( $url ) {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->META->remove_meta_generator, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                return remove_query_arg( 'ver', $url );
            }
            return $url;
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_handle_embed_script() {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->EMBED->remove_embed_script, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                wp_deregister_script( 'wp-embed' );
                HappyFenceNGAlog::get_instance()->log( 'Wp-embed deregistered', HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::INFO );
            } else {
                wp_enqueue_script( 'wp-embed' );
                HappyFenceNGAlog::get_instance()->log( 'Wp-embed registered, you should disable this!', HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::NOTICE );
            }
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param array $headers are headers.
     */
    public function handle_x_pingback( $headers ) {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_handle_wp_oembed() {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param array $methods ...uhm maybe is an array of method names?.
     */
    public function svc_handle_xmlrpc_methods( $methods ) {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_check_custom_login() {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            $ip = HappyFenceNGUtils::get_user_ip();
            if ( HappyFenceNGPROC::equals( $ip, HappyFenceNGPlaceholder::WP_CRON ) ) {
                return;
            }
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->enable_custom_login, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                $uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
                $ua = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
                $method = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ?? esc_html__( 'Unknown', 'happyfenceng-total-enterprise-security' ) ) );
                $referer = sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
                if ( empty( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->custom_login_slug, HappyFenceNGPlaceholder::EMPTY_STRING ) ) ) {
                    HappyFenceNGAlog::get_instance()->log( 'Custom login enabled but no slug defined, fallback on defaults!!!!', HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::WARNING );
                    return;
                } elseif ( isset( $_SERVER['REQUEST_URI'] ) ) {
                    $filtered = wp_parse_url( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) ), PHP_URL_PATH );
                    $request_path = $filtered ?? '/';
                    HappyFenceNGAlog::get_instance()->log( 'Checking required uri ' . $filtered . ' req_path=' . $request_path, HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::INFO );
                    if ( str_contains( $request_path, 'wp-login.php' ) ) {
                        if ( str_starts_with( $request_path, HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->custom_login_slug, HappyFenceNGPlaceholder::EMPTY_STRING ) ) ) {
                            HappyFenceNGAlog::get_instance()->log( sprintf(
                                'Granted access to custom slug, redirect to wp-admin | IP: %s | URI: %s | Method: %s | UA: %s | Referer: %s',
                                $ip,
                                $uri,
                                $method,
                                $ua,
                                $referer
                            ), HappyFenceNGSyslogFacility::CORE, HappyFenceNGSyslogSeverity::NOTICE );
                            $token = HappyFenceNGUtils::generateToken( $ip, $ua, time() );
                            $cookie_name = 'happyfenceng_xyz';
                            $cookie_value = md5( $token );
                            $my_domain = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ?? '' ) );
                            $host_parts = explode( ':', $my_domain, 2 );
                            $the_domain = $host_parts[0];
                            setcookie( $cookie_name, $cookie_value, array(
                                'expires'  => time() + DAY_IN_SECONDS,
                                'path'     => '/',
                                'domain'   => $the_domain,
                                'secure'   => !(defined( 'HAPPYFENCENG_DEV_MODE' ) && HAPPYFENCENG_DEV_MODE),
                                'httponly' => true,
                                'samesite' => 'Lax',
                            ) );
                            set_transient( $cookie_value, $token, DAY_IN_SECONDS );
                            //phpcs:ignore
                            wp_safe_redirect( site_url( 'wp-login.php' ) );
                            exit;
                        } else {
                            $cookie_value = sanitize_text_field( wp_unslash( $_COOKIE['happyfenceng_xyz'] ?? '' ) );
                            $stored_value = HappyFenceNGPlaceholder::INVALID;
                            $token = '';
                            if ( !empty( $cookie_value ) ) {
                                $stored_value = ( HappyFenceNGCleaner::must_be_md5( $cookie_value ) ? get_transient( $cookie_value ) : '' );
                                if ( !empty( $stored_value ) ) {
                                    $token = HappyFenceNGUtils::getToken( $stored_value );
                                } else {
                                    $stored_value = HappyFenceNGPlaceholder::INVALID;
                                }
                            }
                            $reason = '';
                            if ( empty( $cookie_value ) ) {
                                $reason = 'NO COOKIE';
                            } elseif ( HappyFenceNGPROC::equals( $stored_value, HappyFenceNGPlaceholder::INVALID ) ) {
                                $reason = 'INVALID COOKIE';
                            } elseif ( empty( $token ) ) {
                                $reason = 'EMPTY TOKEN';
                            } elseif ( HappyFenceNGPROC::not_equals( $token['IP'], $ip ) ) {
                                $reason = 'IP DOES NOT MATCH!';
                            } elseif ( HappyFenceNGPROC::not_equals( $token['UA'], $ua ) ) {
                                $reason = 'UA DOES NOT MATCH!';
                            } else {
                                HappyFenceNGAlog::get_instance()->log( sprintf(
                                    'Granted access to wp-admin with virtual slug | VSLUG: %s | IP: %s | URI: %s | Method: %s | UA: %s | Referer: %s',
                                    $token['VSLUG'],
                                    $ip,
                                    $uri,
                                    $method,
                                    $ua,
                                    $referer
                                ), HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::NOTICE );
                                return;
                            }
                            HappyFenceNGAlog::get_instance()->log( sprintf(
                                'Denied access to wp-admin | IP: %s | URI: %s | Method: %s | UA: %s | Referer: %s | Reason: %s',
                                $ip,
                                $uri,
                                $method,
                                $ua,
                                $referer,
                                $reason
                            ), HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::WARNING );
                            HappyFenceNGCleaner::cleaner_die( esc_html__( 'Sorry access to this url is denied.', 'happyfenceng-total-enterprise-security' ) );
                        }
                    } else {
                        return;
                    }
                }
                HappyFenceNGCleaner::cleaner_die( esc_html__( 'Don\'t know what you\'re trying to do .. but you can\'t, sorry.', 'happyfenceng-total-enterprise-security' ) );
            }
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
            HappyFenceNGCleaner::cleaner_oops();
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_hide_dangerous_files() {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            $ip = HappyFenceNGUtils::get_user_ip();
            if ( HappyFenceNGPROC::equals( $ip, HappyFenceNGPlaceholder::WP_CRON ) ) {
                return;
            }
            $request_uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
            $uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
            $ua = sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
            $method = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ?? esc_html__( 'Unknown', 'happyfenceng-total-enterprise-security' ) ) );
            $referer = sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ?? HappyFenceNGPlaceholder::EMPTY_STRING ) );
            $request_path = wp_parse_url( $request_uri, PHP_URL_PATH );
            $basename = strtolower( basename( $request_path ) );
            $blocked_files = array(
                'debug.log',
                'readme.txt',
                'readme.html',
                'license.txt'
            );
            $match = false;
            foreach ( $blocked_files as $file ) {
                if ( preg_match( '/' . preg_quote( $file, '/' ) . '/i', $request_uri ) ) {
                    // trovato!
                    $match = true;
                    break;
                }
            }
            if ( in_array( $basename, $blocked_files, true ) || $match ) {
                HappyFenceNGAlog::get_instance()->log( sprintf(
                    'Access to sensitive file denied | File: %s | IP: %s | URI: %s | Method: %s | UA: %s | Referer: %s - If you see the file you should modifiy your webserver configuration to deny it or remove the file itself.',
                    $basename,
                    $ip,
                    $uri,
                    $method,
                    $ua,
                    $referer
                ), HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::WARNING );
                HappyFenceNGCleaner::cleaner_die( esc_html__( 'This action is not permitted, sorry.', 'happyfenceng-total-enterprise-security' ) );
            }
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_disable_rss_feed_die() {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->disable_rss_feed, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                $ip = HappyFenceNGUtils::get_user_ip();
                HappyFenceNGAlog::get_instance()->log( 'Blocked (RSS feed is disabled) ' . $ip, HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::WARNING );
                HappyFenceNGCleaner::cleaner_die( esc_html__( 'RSS feed is disabled.', 'happyfenceng-total-enterprise-security' ) );
            }
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $available ...omg we have an unknown parameters.
     */
    public function svc_disable_app_passwords( $available ) {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            if ( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->svc_disable_app_passwords, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ) ) {
                $ip = HappyFenceNGUtils::get_user_ip();
                HappyFenceNGAlog::get_instance()->log( 'Blocked (App password is disabled) ' . $ip, HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::WARNING );
                HappyFenceNGCleaner::cleaner_die( esc_html__( 'You cannot do this.', 'happyfenceng-total-enterprise-security' ) );
            }
            return $available;
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
            return HappyFenceNGPlaceholder::EMPTY_STRING;
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $error .. it's a passthrougt.
     */
    public function svc_manage_obfuscate_login_errors( $error ) {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
        $ip = HappyFenceNGUtils::get_user_ip();
        if ( HappyFenceNGPROC::equals( $ip, HappyFenceNGPlaceholder::WP_CRON ) ) {
            return;
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_manage_remove_rest_head_link() {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $result .. we need results.
     */
    public function svc_block_rest_for_guests( $result ) {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     */
    public function svc_block_authors() {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param string $endpoints ... what else?.
     */
    public function svc_remove_user_endpoints( $endpoints ) {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
    }

    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function svc_redirect_author_page() {
        HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
        $ip = HappyFenceNGUtils::get_user_ip();
        if ( HappyFenceNGPROC::equals( $ip, HappyFenceNGPlaceholder::WP_CRON ) ) {
            return;
        }
    }

    /**PHPCS -> code compliance: we put useful comments where needed..
     *
     * @param bool $enabled ... maybe true,maybe false.
     */
    public function manage_xmlrpc( $enabled ) {
        try {
            HappyFenceNGWhoAmI::get_instance()->EXECCHAIN::push_log( __FUNCTION__ );
            $enabled = HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->XMLRPC->block_xmlrpc, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT );
            HappyFenceNGAlog::get_instance()->log( 'XML-RPC interface is =>' . (( $enabled ? 'enabled' : 'disabled' )), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::INFO );
            if ( $enabled ) {
                $ip = HappyFenceNGUtils::get_user_ip();
                HappyFenceNGAlog::get_instance()->log( 'Blocked XML-RPC ' . $ip, HappyFenceNGSyslogFacility::SECURITY, HappyFenceNGSyslogSeverity::WARNING );
                HappyFenceNGCleaner::cleaner_die( esc_html__( 'Not permitted, sorry.', 'happyfenceng-total-enterprise-security' ) );
            }
            return $enabled;
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNG.CORE - scanner error ' . $e->getMessage(), HappyFenceNGSyslogFacility::SCANNER, HappyFenceNGSyslogSeverity::ERROR );
        }
    }

}
