<?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 HappyFenceNGVRCLISEC extends HappyFenceNGAVRoute {

	/**PHPCS -> code compliance: we put useful comments where needed.. */
	public function doRoute() {
		try {

			$nonce_save_settings = wp_create_nonce( 'happyfenceng_CLISEC_save_settings' );
			$burn                = HappyFenceNGFailFast::setup();

			$params = array(
				'texts'  => array(
					'title'                 => esc_html__( 'WP-Command line interface security', 'happyfenceng-total-enterprise-security' ),

					'note_line_1'           => esc_html__( 'Some HappyFence features can lock you out of WordPress permanently—unless you disable the plugin itself.', 'happyfenceng-total-enterprise-security' ),
					'note_line_2'           => esc_html__( 'HappyFenceNG provides some secure WP-CLI commands that you can use to recover your wordpress without disabling the firewall.', 'happyfenceng-total-enterprise-security' ),
					'note_line_3'           => esc_html__( 'If you do not have WP-CLI please install it and restart the plugin, otherwise the commands below will not be available.', 'happyfenceng-total-enterprise-security' ),

					'note_line_4'           => esc_html__( 'Please take note of the following commands:', 'happyfenceng-total-enterprise-security' ),

					'note_line_5'           => esc_html__( 'Disable CloudFlare Guard:', 'happyfenceng-total-enterprise-security' ),

					'note_line_6'           => esc_html__( 'Disable IP Blacklist Guard:', 'happyfenceng-total-enterprise-security' ),

					'note_line_7'           => esc_html__( 'Show current login slug:', 'happyfenceng-total-enterprise-security' ),

					'note_line_8'           => esc_html__( 'Show dashboard to check modules:', 'happyfenceng-total-enterprise-security' ),

					'note_line_9'           => esc_html__( 'Show registered filters (all):', 'happyfenceng-total-enterprise-security' ),

					'note_line_10'          => esc_html__( 'Show registered filters (happyfenceng):', 'happyfenceng-total-enterprise-security' ),

					'warning_title'         => esc_html__( 'WARNING!!', 'happyfenceng-total-enterprise-security' ),
					'warning_line_1'        => esc_html__( 'To avoid improper use of HappyFenceNG WP-CLI Commandline you have to enter the self generated password.', 'happyfenceng-total-enterprise-security' ),
					'warning_line_2'        => esc_html__( 'This password was generated at the first plugin activation and is saved fully encrypted in the HappyFence Config tables.', 'happyfenceng-total-enterprise-security' ),
					'warning_line_3'        => esc_html__( 'There is NO EASY WAY to recover it from the database as the Config table is FULLY encrypted (names and values ) so, please write it down.', 'happyfenceng-total-enterprise-security' ),
					'warning_line_4'        => esc_html__( 'Before migrating check the Data Security menu for important information about encryption.', 'happyfenceng-total-enterprise-security' ),

					'clipass_title'         => esc_html__( 'CLI Password', 'happyfenceng-total-enterprise-security' ),
					'clipass_current'       => esc_html__( 'Current password:', 'happyfenceng-total-enterprise-security' ),
					'clipass_compromised'   => esc_html__( 'If you think your password is compromised click the re-generate button below', 'happyfenceng-total-enterprise-security' ),

					'feature_requires'      => esc_html__( 'THIS FEATURE IS FREE', 'happyfenceng-total-enterprise-security' ),
					'save_settings'         => esc_html__( 'New CLI Password', 'happyfenceng-total-enterprise-security' ),
					'settings_saved'        => esc_html__( 'Done', 'happyfenceng-total-enterprise-security' ),
					'error_saving_settings' => esc_html__( 'Error generating new password', 'happyfenceng-total-enterprise-security' ),

				),
				'links'  => array(
					'happyfenceng_logo_url' => esc_url( HAPPYFENCENG_PLUGIN_URL . 'assets/images/happyfenceng-small.png' ),

				),
				'values' => array(
					'wpcli_secpass'   => esc_html( HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->wpcli_secpass, 'WARNING DB ERROR NO PASSWORD DEFINED!' ) ),

					'checkbox_on'     => HappyFenceNGPlaceholder::CHECKBOX_ON,
					'checkbox_off'    => HappyFenceNGPlaceholder::CHECKBOX_OFF,
					'nonce'           => $nonce_save_settings,
					'burnNonce'       => $burn,
					'feature_enabled' => true,
				),
			);

			ob_start();
			HappyFenceNGVControl::renderView( $params, 'clisec' );
			// phpcs:ignore WordPress.Security.EscapeOutput
			echo ob_get_clean();

		} catch ( Throwable $e ) {
			HappyFenceNGLOGCORE::logcore(
				'HappyFenceNGVRCLISEC - cannot render UI ' . $e->getMessage(),
				HappyFenceNGSyslogFacility::UI,
				HappyFenceNGSyslogSeverity::ERROR
			);
			ob_end_clean();
			HappyFenceNGCleaner::cleaner_oops();
		}
	}
}
