<?php

/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRISS 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       HappyWPRIss
 * @uri         https://happywPRIss.com
 * @set all
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
/**PHPCS -> code compliance: we put useful comments where needed.. */
class HappyFenceNGVRRESH extends HappyFenceNGAVRoute {
    /**PHPCS -> code compliance: we put useful comments where needed.. */
    public function doRoute() {
        try {
            $nonce_save_settings = wp_create_nonce( 'happyfenceng_RESH_save_settings' );
            $nonce_delete = wp_create_nonce( 'happyfenceng_RESH_delete' );
            $nonce_trust = wp_create_nonce( 'happyfenceng_RESH_trust' );
            $nonce_quarantine = wp_create_nonce( 'happyfenceng_RESH_quarantine' );
            $burn = HappyFenceNGFailFast::setup();
            $quarantine_files = null;
            $params = array(
                'texts'  => array(
                    'title'                              => esc_html__( 'Remote Shell Scanner Settings', 'happyfenceng-total-enterprise-security' ),
                    'description_1'                      => esc_html__( 'The RemoteShellScanner periodically scans your WordPress files looking for malicious PHP code, such as reverse shells or hidden functions.', 'happyfenceng-total-enterprise-security' ),
                    'description_2'                      => esc_html__( 'It searches for dangerous PHP functions like eval, shell_exec, and base64_decode, and quarantines suspicious files to prevent their execution.', 'happyfenceng-total-enterprise-security' ),
                    'description_3'                      => esc_html__( 'This module runs hourly and covers wp-content and the plugin directories.', 'happyfenceng-total-enterprise-security' ),
                    'enable_shell_scanner_title'         => esc_html__( 'Enable Shell Scanner', 'happyfenceng-total-enterprise-security' ),
                    'enable_shell_scanner_description'   => esc_html__( 'Enable background scanning for remote shell activity.', 'happyfenceng-total-enterprise-security' ),
                    'enable_shell_scanner_tooltip'       => esc_html__( 'When enabling this option the plugin add a schedule in the wordpress to check files against remote shell.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_wpcontent_title'        => esc_html__( 'Enable Shell Scanner on wp-content(all)', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_wpcontent_description'  => esc_html__( 'Be careful this could affect wordpress operations.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_wpcontent_tooltip'      => esc_html__( 'This will enable the background scan of the entire WordPress wp-content, be careful anche check false positives.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_plugins_title'          => esc_html__( 'Enable Shell Scanner on plugins', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_plugins_description'    => esc_html__( 'Enable background scanning on plugins subdirectory.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_plugins_tooltip'        => esc_html__( 'When enabled scans the plugins directory, be careful and always check false positives.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_mu_plugins_title'       => esc_html__( 'Enable Shell Scanner on MU plugins', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_mu_plugins_description' => esc_html__( 'Enable background scanning on must use plugins subdirectory.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_mu_plugins_tooltip'     => esc_html__( 'Warning! Be careful before delering or quarantine files in this directory as your wordpress could brake forever.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_uploads_title'          => esc_html__( 'Enable Shell Scanner on uploads', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_uploads_description'    => esc_html__( 'Enable background scanning on uploads subdirectory.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_uploads_tooltip'        => esc_html__( 'When enabled periodically checks for harmful files in the upload directory.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_logs_title'             => esc_html__( 'Enable Shell Scanner on logs', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_logs_description'       => esc_html__( 'Enable background scanning on logs subdirectory.', 'happyfenceng-total-enterprise-security' ),
                    'enable_scan_logs_tooltip'           => esc_html__( 'When enabled scans on logs subdirectory for malicious logs injections.', 'happyfenceng-total-enterprise-security' ),
                    'custom_scan_subdirs_title'          => esc_html__( 'Specify custom subdirs', 'happyfenceng-total-enterprise-security' ),
                    'custom_scan_subdirs_description'    => esc_html__( 'Specify a comma separated list of subdirs to scan.', 'happyfenceng-total-enterprise-security' ),
                    'custom_scan_subdirs_tooltip'        => esc_html__( 'Add here other custom subdirectories you would scan.', 'happyfenceng-total-enterprise-security' ),
                    'quarantine_files_title'             => esc_html__( 'Shell Quarantine Files', 'happyfenceng-total-enterprise-security' ),
                    'filename_title'                     => esc_html__( 'Filename', 'happyfenceng-total-enterprise-security' ),
                    'when_title'                         => esc_html__( 'When', 'happyfenceng-total-enterprise-security' ),
                    'status_title'                       => esc_html__( 'Status', 'happyfenceng-total-enterprise-security' ),
                    'hash_title'                         => esc_html__( 'Hash', 'happyfenceng-total-enterprise-security' ),
                    'no_data_title'                      => esc_html__( 'No data.', 'happyfenceng-total-enterprise-security' ),
                    'quarantine_button'                  => esc_html__( 'Quarantine', 'happyfenceng-total-enterprise-security' ),
                    'trust_button'                       => esc_html__( 'Trust', 'happyfenceng-total-enterprise-security' ),
                    'delete_button'                      => esc_html__( 'Delete', 'happyfenceng-total-enterprise-security' ),
                    'feature_requires'                   => esc_html__( 'THIS FEATURE REQUIRES ENTERPRISE', 'happyfenceng-total-enterprise-security' ),
                    'save_settings'                      => esc_html__( 'Save Settings', 'happyfenceng-total-enterprise-security' ),
                    'settings_saved'                     => esc_html__( 'Settings Saved', 'happyfenceng-total-enterprise-security' ),
                    'error_saving_settings'              => esc_html__( 'Error saving settings', 'happyfenceng-total-enterprise-security' ),
                ),
                'links'  => array(
                    'happyfenceng_logo_url' => esc_url( HAPPYFENCENG_PLUGIN_URL . 'assets/images/happyfenceng-small.png' ),
                ),
                'values' => array(
                    'enable_shell_scanner'   => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_shell_scanner, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'enable_scan_wpcontent'  => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_scan_wpcontent, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'enable_scan_plugins'    => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_scan_plugins, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'enable_scan_mu_plugins' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_scan_mu_plugins, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'enable_scan_uploads'    => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_scan_uploads, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'enable_scan_logs'       => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->enable_scan_logs, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),
                    'custom_scan_subdirs'    => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->RESCAN->custom_scan_subdirs, HappyFenceNGPlaceholder::EMPTY_STRING ),
                    'quarantine_files'       => $quarantine_files,
                    'suspicious'             => HappyFenceNGErsh::SUSPICIOUS,
                    'trusted'                => HappyFenceNGErsh::TRUSTED,
                    'quarantined'            => HappyFenceNGErsh::QUARANTINED,
                    'checkbox_on'            => HappyFenceNGPlaceholder::CHECKBOX_ON,
                    'checkbox_off'           => HappyFenceNGPlaceholder::CHECKBOX_OFF,
                    'nonce'                  => $nonce_save_settings,
                    'nonce_delete'           => $nonce_delete,
                    'nonce_trust'            => $nonce_trust,
                    'nonce_quarantine'       => $nonce_quarantine,
                    'burnNonce'              => $burn,
                    'feature_enabled'        => function_exists( 'htes_fs' ) && HappyFenceNGTR::is_in( static::class, array(HappyFenceNGTR::BUNKER) ),
                ),
            );
            ob_start();
            HappyFenceNGVControl::renderView( $params, 'resh' );
            // phpcs:ignore WordPress.Security.EscapeOutput
            echo ob_get_clean();
        } catch ( Throwable $e ) {
            HappyFenceNGLOGCORE::logcore( 'HappyFenceNGVRRESH - cannot render UI ' . $e->getMessage(), HappyFenceNGSyslogFacility::UI, HappyFenceNGSyslogSeverity::ERROR );
            ob_end_clean();
            HappyFenceNGCleaner::cleaner_oops();
        }
    }

}
