# wt-security/2.4.9/lib/Interface.php

WebTotem Security, version 2.4.9. 219 lines.

- Page: https://pluginprobe.com/plugins/wt-security/2.4.9/code/lib/Interface.php
- Raw: https://pluginprobe.com/plugins/wt-security/2.4.9/raw/lib/Interface.php
- Modified: 2022-06-13T09:10:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wt-security/2.4.9/code/lib/Interface.php#L10-L20`.

```php
<?php

if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
	if (!headers_sent()) {
		header('HTTP/1.1 403 Forbidden');
	}
	die("Protected By WebTotem!");
}

/**
 * Plugin initializer.
 *
 */
class WebTotemInterface extends WebTotem {

	/**
	 * Execute pre-checks before every page.
	 *
	 * @return void
	 */
	public static function startupChecks() {
		$_page = WebTotemRequest::get('page');
		if(strpos($_page, 'wtotem') === 0){

			if(!WebTotemOption::isActivated()){
				// Checking the old version of options.
				WebTotemOption::checkOldOptions();
			}

			WebTotemOption::multisiteCheck();

			if(!WebTotemOption::isActivated() and $_page !== 'wtotem_activation') {
				// If the plugin is not activated by the API key, then redirect to the activation page.
				wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_activation') );
				exit;
			}
			elseif (WebTotemOption::isActivated() and ($_page === 'wtotem_activation' or $_page === 'wtotem')){
				// If the plugin is activated by the API key, then redirect to the main page.
				if(self::isMultiSite() and is_super_admin()){
					// Main page is all sites page.
					wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_all_sites') );
				} else {
					// Main page is dashboard page.
					wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_dashboard') );
				}
				exit;
			}
			elseif(WebTotemOption::isActivated()) {
				// Checking whether agents are installed, if they are not installed, then install.
				self::checkAgents();
			}
		}

		$sapi = @php_sapi_name();
		if( ! current_user_can( 'publish_posts' ) and $sapi != "cli" ) {
			if ($waf = WebTotemOption::getOption(("waf_installed_file"))) {
				$include_waf_file = ABSPATH . '/_include_' . $waf;

				if (is_file($include_waf_file) && is_readable($include_waf_file)) {
					include_once $include_waf_file;
				}
			}
		}
	}

	/**
	 * Checking whether agents are installed, if they are not installed, then install.
	 */
	private static function checkAgents(){

		$api_key = WebTotemOption::getOption('api_key');

		// Check if the plugin version has changed.
		WebTotemAgentManager::checkVersion();

		if(!$api_key){
			$api_key = WebTotemOption::getOption('api_key');
		}

		$host = WebTotemAPI::siteInfo();

		if ($api_key && array_key_exists('id', $host)) {

			// Install Agent Manager if it was not previously installed.
			$am_installed = WebTotemAgentManager::checkInstalledService('am');
			if (!$am_installed['option_status'] || !$am_installed['file_status']) {

				$am_was_installed = WebTotemAgentManager::amInstall();

				if (!$am_was_installed) {
					WebTotemOption::setOptions(['am_installed' => FALSE]);
				}
			}

		}
	}

	/**
	 * When adding a new site, add it to the WebTotem platform.
	 */
	public static function addNewSite($new_site){
			$domain = untrailingslashit($new_site->domain . $new_site->path);
			WebTotemOption::setNotification( 'info', __('A new website has been added: ', 'wtotem') . $domain);
			WebTotemAPI::addMultiSiteNewSites([$domain]);
	}

	/**
	 * Verify the nonce of the previous page after a form submission.
	 *
	 * @return bool True if the nonce is valid, false otherwise.
	 */
	public static function checkNonce() {
		if (!empty($_POST)) {
			$name = 'wtotem_page_nonce';
			$value = WebTotemRequest::post($name);

			if (!$value || !wp_verify_nonce($value, $name)) {
				WebTotemOption::setNotification('error', __('The WordPress CSRF check failed. The submitted form is missing an important unique code. Go back and try again.', 'wtotem'));
				return false;
			}
		}

		return true;
	}

	/**
	 * A safe way to add JavaScript and css files to a WordPress-managed page
	 *
	 * @return void
	 */
	public static function enqueueScripts() {
		$_page = WebTotemRequest::get('page');
		if(strpos($_page, 'wtotem') === 0){
			// Adding CSS files.
			wp_register_style(
				'wtotem_flatpickr',
				WEBTOTEM_URL . '/includes/css/flatpickr.min.css',
				array(),
				WebTotem::fileVersion('includes/css/flatpickr.min.css')
			);
			wp_enqueue_style('wtotem_flatpickr');

			wp_register_style(
				'wtotem_main_css',
				WEBTOTEM_URL . '/includes/css/main.css',
				array(),
				WebTotem::fileVersion('includes/css/main.css')
			);
			wp_enqueue_style('wtotem_main_css');

			// Adding JS files.
			wp_register_script(
				'wtotem_amplitude',
				WEBTOTEM_URL . '/includes/js/amplitude.js',
				array( 'jquery' ),
				WebTotem::fileVersion('includes/js/amplitude.js'),
				false
			);
			wp_enqueue_script('wtotem_amplitude');

			wp_register_script(
				'wtotem_d3',
				WEBTOTEM_URL . '/includes/js/d3.v4.js',
				array( 'jquery' ),
				WebTotem::fileVersion('includes/js/d3.v4.js'),
				true
			);
			wp_enqueue_script('wtotem_d3');

			wp_register_script(
				'wtotem_chart',
				WEBTOTEM_URL . '/includes/js/chart.js',
				array( 'jquery', 'wtotem_d3', 'wtotem_jsdelivr'),
				WebTotem::fileVersion('includes/js/chart.js'),
				true
			);
			wp_enqueue_script('wtotem_chart');

			wp_register_script(
				'wtotem_flatpickr_js',
				WEBTOTEM_URL . '/includes/js/flatpickr.js',
				array( 'jquery', 'wp-i18n' ),
				WebTotem::fileVersion('includes/js/flatpickr.js'),
				true
			);
			wp_enqueue_script('wtotem_flatpickr_js');
			wp_set_script_translations( 'wtotem_flatpickr_js', 'wtotem' );

			wp_register_script(
				'wtotem_jsdelivr',
				WEBTOTEM_URL . '/includes/js/jsdelivr_chart.js',
				array( 'jquery' ),
				WebTotem::fileVersion('includes/js/jsdelivr_chart.js'),
				true
			);
			wp_enqueue_script('wtotem_jsdelivr');

			wp_register_script(
				'wtotem_progress_bar',
				WEBTOTEM_URL . '/includes/js/progress_bar.js',
				array(),
				WebTotem::fileVersion('includes/js/progress_bar.js'),
				true
			);
			wp_enqueue_script('wtotem_progress_bar');

			wp_register_script(
				'wtotem_main',
				WEBTOTEM_URL . '/includes/js/main.js',
				array( 'jquery' ),
				WebTotem::fileVersion('includes/js/main.js'),
				true
			);
			wp_enqueue_script('wtotem_main');
		}
	}

}

```
