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

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

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

			$params = array(
				'texts'  => array(
					'title'                        => esc_html__( 'Data Security', 'happyfenceng-total-enterprise-security' ),
					'delete_tables_message'        => esc_html__( 'Delete all plugin data when uninstalled', 'happyfenceng-total-enterprise-security' ),
					'data_security_notice_title'   => esc_html__( 'Data Security Notice:', 'happyfenceng-total-enterprise-security' ),
					'notice_line_1'                => esc_html__(
						'All data stored in the database by HappyFenceNG — including configuration settings, multifactor credentials, quarantine files, and internal metadata — is encrypted using your site’s AUTH_KEY and SECURE_AUTH_SALT as defined in wp-config.php.',
						'happyfenceng-total-enterprise-security'
					),
					'notice_line_2'                => esc_html__(
						'This mechanism ensures that, even if another plugin, script, or attacker gains direct or indirect access to the database (e.g. via plugin vulnerabilities, SQL injection, or stolen backups), the internal security logic remains encrypted, unreadable, and protected against unauthorized tampering.',
						'happyfenceng-total-enterprise-security'
					),
					'important_title'              => esc_html__( 'Important:', 'happyfenceng-total-enterprise-security' ),
					'important_notice'             => esc_html__(
						'This encryption model does not prevent a site administrator — or any user with access to the wp-config.php file — from decrypting the data. However, it does raise the bar significantly against external threats.',
						'happyfenceng-total-enterprise-security'
					),
					'custom_encryption_key_title'  => esc_html__( 'Custom Encryption Keys:', 'happyfenceng-total-enterprise-security' ),
					'custom_encryption_key_notice' => esc_html__(
						'You may define your own encryption key and salt instead of using WordPress’s AUTH_KEY and SECURE_AUTH_SALT. To do this, add the following constants to your wp-config.php:',
						'happyfenceng-total-enterprise-security'
					),
					'code_notice'                  => esc_html__(
						'Leave the HAPPYFENCENG_KEY_PROVIDER constant undefined or set it to default to use these values.',
						'happyfenceng-total-enterprise-security'
					),
					'change_enc_key_warning'       => esc_html__(
						'Warning: Changing the encryption key after configuring the plugin will make all previously stored data unreadable. All plugin settings, MFA credentials, quarantine files, and other encrypted data will need to be reconfigured from scratch.',
						'happyfenceng-total-enterprise-security'
					),
					'change_enc_key_warning_2'     => esc_html__(
						'For this reason, it is strongly recommended to set a custom key only immediately after installation and before making any configuration changes.',
						'happyfenceng-total-enterprise-security'
					),
					'change_enc_key_warning_3'     => esc_html__(
						'Once these values are set and you start configuring the plugin, they will be used for all data encryption in the database.',
						'happyfenceng-total-enterprise-security'
					),

					'change_enc_key_warning_4'     => esc_html__(
						'HappyFenceNG does not provide any automatic migration mechanism for encrypted data in case of key change.',
						'happyfenceng-total-enterprise-security'
					),

					'migration_notice_title'       => esc_html__( 'WordPress Migration Notice:', 'happyfenceng-total-enterprise-security' ),
					'migration_notice_warning'     => esc_html__(
						'If you migrate your site to a new host, or reinstall WordPress, be sure to preserve the original AUTH_KEY and SECURE_AUTH_SALT (or the custom constants, if used). If these values change, any previously stored encrypted data will become unreadable. HappyFenceNG will then automatically reset its internal configuration to default values on first boot — including deactivating security modules as a precaution.',
						'happyfenceng-total-enterprise-security'
					),

					'feature_requires'             => esc_html__( 'THIS FEATURE REQUIRES AGENCY OR ENTERPRISE', 'happyfenceng-total-enterprise-security' ),
					'enable_filesystem_scan'       => esc_html__( 'Enable Filesystem Scan', '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(
					'delete_tables_on_uninstall' => HappyFenceNGCleaner::checkMe( HappyFenceNGWhoAmI::get_instance()->PCORE->delete_tables_on_uninstall, HappyFenceNGPlaceholder::BOOL_PROP_DEFAULT ),

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

				),
			);

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

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