# wt-security/2.3.24/wt-security.php

WebTotem Security, version 2.3.24. 208 lines.

- Page: https://pluginprobe.com/plugins/wt-security/2.3.24/code/wt-security.php
- Raw: https://pluginprobe.com/plugins/wt-security/2.3.24/raw/wt-security.php
- Modified: 2021-03-01T06:04:42+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.3.24/code/wt-security.php#L10-L20`.

```php
<?php defined('ABSPATH') or die("Protected By WT!");

/*
Plugin Name: WT Security
Description: WT is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way.
Author: WT Security
Version: 2.3.24
*/

define("WTSEC_PAGE_TITLE", 'Dashboard');
define("WTSEC_MENU_TITLE", 'WT Security');
define("WTSEC_PLUGIN_PATH", plugin_dir_path(__FILE__));
define("WTSEC_PLUGIN_NAME", 'wt-security');
define("WTSEC_PLUGIN_PREFIX", 'wtsec_');
define("WTSEC_PAGE_PREFIX", WTSEC_PLUGIN_NAME . '-');
define("WTSEC_FILE_URL", "https://api.wtotem.com/agent");
define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/');
if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) {
    define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
    define("WTOTEMSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
} else {
    define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
    define("WTOTEMSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
}
define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__));
define("WTSEC_PLUGIN_BASENAME", plugin_basename( __FILE__));
define("WTSEC_SITE_URL", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url()));

define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.3");

$curLang = substr(get_bloginfo('language'), 0,2);
$language = (in_array($curLang,['ru','en','pl'])) ? $curLang : 'en' ;
define("WTSEC_LANGUAGE", $language);


add_action( 'deactivated_plugin', 'wtsec_DeactivatedPlugin', 1 );

//  Clear database, delete am(agents) after plugin deactivate
function wtsec_DeactivatedPlugin($plugin){

    if($plugin == WTSEC_PLUGIN_BASENAME) {

        define("WTSEC_DEACTIVATED", true);
        require_once WTSEC_PLUGIN_PATH . 'library/App.php';
        $app = new WTSEC_LIBRARY_App;
        if(wtsec_DeleteAm()){
            $app::clearDB();
        }

    }
}

add_action( 'upgrader_process_complete', 'wtsec_generate_file', 10, 2 );

//  Create file generate.php after plugin update
function wtsec_generate_file( $upgrader_object, $options ) {

    if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
        foreach( $options['plugins'] as $plugin ) {
            if( $plugin == WTSEC_PLUGIN_BASENAME ) {
                require_once WTSEC_PLUGIN_PATH . 'library/App.php';
                $fileName = WTSEC_LIBRARY_App::getOption('am_installed_file');

                wtsec_addCheckFile($fileName);
            }
        }
    }
}

add_action('admin_init', 'wtsec_admin_init');
add_action('wp_loaded', 'wtsec_init');

add_filter( 'authenticate', 'wtsec_login_check', 30, 3 );

function wtsec_init()
{
    require_once WTSEC_PLUGIN_PATH . 'library/App.php';
    require_once WTSEC_PLUGIN_PATH . 'library/Request.php';

    // WAF include (Если не админка и статус waf = "start", "uninstalled")
    // && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])
    if (!is_admin()) {
        if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) {
            $path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf;
            if (is_file($path_to_waf) && is_readable($path_to_waf)) {
                include_once $path_to_waf;
            }
        }
    }

    if (is_admin()) {
        require_once WTSEC_PLUGIN_PATH . 'library/WT.php';
        require_once WTSEC_PLUGIN_PATH . 'library/Localization.php';
        require_once WTSEC_PLUGIN_PATH . 'library/Idn.php';
        require_once WTSEC_PLUGIN_PATH . 'library/Session.php';
        require_once WTSEC_PLUGIN_PATH . 'routes.php';
        require_once WTSEC_PLUGIN_PATH . 'services.php';
        require_once WTSEC_PLUGIN_PATH . 'helpers.php';

        function wtsec_request()
        {
            return new WTSEC_LIBRARY_Request();
        }
        function wtsec_app()
        {
            return new WTSEC_LIBRARY_App();
        }
        function wtsec_filesystem_init($form_url, $method, $context, $fields = null)
        {
            global $wp_filesystem;
            if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) {
                return false;
            }
            if (!WP_Filesystem($creds)) {
                request_filesystem_credentials($form_url, $method, true, $context);
                return false;
            }
            return true;
        }
        function wtsec_locale($lmsg, $args = [])
        {
            return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args);
        }
        function wtsec_getImagePath($image)
        {
            return plugins_url('/htdocs/img/' . $image, __FILE__);
        }
        function wtsec_SIS($arr, $key, $form = null)
        {
            $key = explode(".", $key);
            foreach ($key as $_key) {
                if (!isset($arr[$_key])) {
                    $arr = "";
                    break;
                }
                $arr = $arr[$_key];
            }
            return !empty($form) ? str_replace("$" . $key, $arr, $form) : $arr;
        }
    }
}

function wtsec_admin_init()
{
    $rand = '?rand='.rand();
    if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) {
        wp_enqueue_script('subscriber',         plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true);
        wp_enqueue_script('d3-v4',              plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true);
        wp_enqueue_script('jsdelivr',           plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true);
        wp_enqueue_script('chart',              plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true);
        wp_enqueue_script('circle-progress',    plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true);
        wp_enqueue_script('range-plugin',       plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true);
        wp_enqueue_script('flatpickr',          plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true);
        wp_enqueue_script('filter-calendar',    plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true);
        wp_enqueue_script('line-progress',      plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true);
        wp_enqueue_script('main',               plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true);
        wp_enqueue_script('ajax',               plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'jquery' ),false, true );
        wp_enqueue_script('subscriber');
        wp_enqueue_script('print');
        wp_enqueue_script('d3-v4');
        wp_enqueue_script('jsdelivr');
        wp_enqueue_script('chart');
        wp_enqueue_script('circle-progress');
        wp_enqueue_script('line-progress');
        wp_enqueue_script('range-plugin');
        wp_enqueue_script('flatpickr');
        wp_enqueue_script('filter-calendar');
        wp_enqueue_script('main');
        wp_enqueue_script('ajax');

        wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
        wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
        wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__));
        wp_enqueue_style('flatpickr-css');
        wp_enqueue_style('font');
        wp_enqueue_style('print-css');
        wp_enqueue_style('main');

        $page = wtsec_request()->page;
        if ($page === wtsec_getRoute("login")) {
            if (WTSEC_LIBRARY_App::authorized()) {
                wp_safe_redirect(wtsec_getUrl('dashboard'));
            }
        } elseif ($page === wtsec_getRoute("logout")) {
            WTSEC_LIBRARY_App::logout();
            if (!WTSEC_LIBRARY_App::authorized()) {
                wp_safe_redirect(wtsec_getUrl('login'));
            }
        } elseif ($page === wtsec_getRoute("activate")) {
            if (WTSEC_LIBRARY_App::authorized()) {
                wp_safe_redirect(wtsec_getUrl('sites'));
            }
        } else {
            if (!WTSEC_LIBRARY_App::authorized()) {
                wp_safe_redirect(wtsec_getUrl('login'));
            }
        }
    }
}

function wtsec_login_check($user, $username, $password) {
    require_once WTSEC_PLUGIN_PATH . 'library/App.php';
    $app = new WTSEC_LIBRARY_App;
    if($app::getOption('authorized')){
        return $app->wtsec_login_check($user, $username, $password);
    }
    return $user;
}
```
