| 1 |
<?php defined('ABSPATH') or die("Protected By WT!"); |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: WebTotem Security |
| 5 |
Description: WebTotem is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way. |
| 6 |
Author: WebTotem |
| 7 |
Version: 2.3.44 |
| 8 |
Text Domain: wtotem |
| 9 |
Domain Path: /languages |
| 10 |
*/ |
| 11 |
|
| 12 |
__( 'WebTotem Security', 'wtotem' ); |
| 13 |
__( 'WebTotem is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way.', 'wtotem' ); |
| 14 |
|
| 15 |
define("WTSEC_PAGE_TITLE", 'Dashboard'); |
| 16 |
define("WTSEC_MENU_TITLE", 'WT Security'); |
| 17 |
define("WTSEC_PLUGIN_PATH", plugin_dir_path(__FILE__)); |
| 18 |
define("WTSEC_PLUGIN_NAME", 'wt-security'); |
| 19 |
define("WTSEC_PLUGIN_PREFIX", 'wtsec_'); |
| 20 |
define("WTSEC_PAGE_PREFIX", WTSEC_PLUGIN_NAME . '-'); |
| 21 |
define("WTSEC_FILE_URL", "https://api.wtotem.com/agent"); |
| 22 |
define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/'); |
| 23 |
|
| 24 |
if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) { |
| 25 |
define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR); |
| 26 |
} else { |
| 27 |
define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/'); |
| 28 |
} |
| 29 |
|
| 30 |
define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__)); |
| 31 |
define("WTSEC_PLUGIN_BASENAME", plugin_basename( __FILE__)); |
| 32 |
define("WTSEC_SITE_URL", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url())); |
| 33 |
|
| 34 |
define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.3"); |
| 35 |
|
| 36 |
$curLang = substr(get_bloginfo('language'), 0,2); |
| 37 |
$language = (in_array($curLang,['ru','en','pl'])) ? $curLang : 'en' ; |
| 38 |
define("WTSEC_LANGUAGE", $language); |
| 39 |
|
| 40 |
add_action( 'plugins_loaded', function(){ |
| 41 |
load_plugin_textdomain( 'wtotem', false, dirname( plugin_basename(__FILE__) ) . '/languages' ); |
| 42 |
}); |
| 43 |
|
| 44 |
add_action('wp_loaded', 'wtsec_init'); |
| 45 |
add_action('admin_init', 'wtsec_admin_init'); |
| 46 |
add_action( 'upgrader_process_complete', 'wtsec_generate_file', 10, 2 ); |
| 47 |
register_deactivation_hook( __FILE__, 'wtsec_DeactivatedPlugin' ); |
| 48 |
|
| 49 |
function wtsec_init() |
| 50 |
{ |
| 51 |
require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 52 |
require_once WTSEC_PLUGIN_PATH . 'library/Request.php'; |
| 53 |
|
| 54 |
# Check if user has permission to edit posts and pages |
| 55 |
if( ! current_user_can( 'publish_posts' ) ){ |
| 56 |
if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) { |
| 57 |
$path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf; |
| 58 |
if (is_file($path_to_waf) && is_readable($path_to_waf)) { |
| 59 |
include_once $path_to_waf; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
if (is_admin()) { |
| 65 |
require_once WTSEC_PLUGIN_PATH . 'library/WT.php'; |
| 66 |
require_once WTSEC_PLUGIN_PATH . 'library/Idn.php'; |
| 67 |
require_once WTSEC_PLUGIN_PATH . 'library/Session.php'; |
| 68 |
require_once WTSEC_PLUGIN_PATH . 'routes.php'; |
| 69 |
require_once WTSEC_PLUGIN_PATH . 'services.php'; |
| 70 |
require_once WTSEC_PLUGIN_PATH . 'helpers.php'; |
| 71 |
|
| 72 |
function wtsec_request() |
| 73 |
{ |
| 74 |
return new WTSEC_LIBRARY_Request(); |
| 75 |
} |
| 76 |
|
| 77 |
function wtsec_app() |
| 78 |
{ |
| 79 |
return new WTSEC_LIBRARY_App(); |
| 80 |
} |
| 81 |
|
| 82 |
function wtsec_filesystem_init($form_url, $method, $context, $fields = null) |
| 83 |
{ |
| 84 |
global $wp_filesystem; |
| 85 |
if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) { |
| 86 |
return false; |
| 87 |
} |
| 88 |
if (!WP_Filesystem($creds)) { |
| 89 |
request_filesystem_credentials($form_url, $method, true, $context); |
| 90 |
return false; |
| 91 |
} |
| 92 |
return true; |
| 93 |
} |
| 94 |
|
| 95 |
function wtsec_getImagePath($image) |
| 96 |
{ |
| 97 |
return plugins_url('/htdocs/img/' . $image, __FILE__); |
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
function wtsec_admin_init() |
| 104 |
{ |
| 105 |
if(!function_exists('wtsec_request')){ |
| 106 |
function wtsec_request(){ |
| 107 |
require_once WTSEC_PLUGIN_PATH . 'library/Request.php'; |
| 108 |
return new WTSEC_LIBRARY_Request(); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
$rand = '?rand='.rand(); |
| 113 |
if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) { |
| 114 |
if(WTSEC_LIBRARY_App::authorized()){ |
| 115 |
wp_enqueue_script('subscriber', plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true); |
| 116 |
wp_enqueue_script('amplitude', plugins_url('/htdocs/js/wtsec_amplitude.js', __FILE__ ), array(),false, true ); |
| 117 |
wp_enqueue_script('d3-v4', plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true); |
| 118 |
wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true); |
| 119 |
wp_enqueue_script('chart', plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true); |
| 120 |
wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true); |
| 121 |
wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true); |
| 122 |
wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true); |
| 123 |
wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true); |
| 124 |
wp_enqueue_script('line-progress', plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true); |
| 125 |
wp_enqueue_script('main', plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true); |
| 126 |
wp_enqueue_script('ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'wp-i18n','jquery' ),false, true ); |
| 127 |
wp_enqueue_script('subscriber'); |
| 128 |
wp_enqueue_script('amplitude'); |
| 129 |
wp_enqueue_script('d3-v4'); |
| 130 |
wp_enqueue_script('jsdelivr'); |
| 131 |
wp_enqueue_script('chart'); |
| 132 |
wp_enqueue_script('circle-progress'); |
| 133 |
wp_enqueue_script('range-plugin'); |
| 134 |
wp_enqueue_script('flatpickr'); |
| 135 |
wp_enqueue_script('filter-calendar'); |
| 136 |
wp_enqueue_script('line-progress'); |
| 137 |
wp_enqueue_script('main'); |
| 138 |
wp_enqueue_script('ajax'); |
| 139 |
|
| 140 |
//wp_register_script( 'ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), [ 'wp-i18n', 'jquery' ], false, true ); |
| 141 |
wp_set_script_translations( 'ajax', 'wtotem' ); |
| 142 |
} |
| 143 |
|
| 144 |
wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css'); |
| 145 |
wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap'); |
| 146 |
wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__)); |
| 147 |
wp_enqueue_style('flatpickr-css'); |
| 148 |
wp_enqueue_style('font'); |
| 149 |
wp_enqueue_style('main'); |
| 150 |
|
| 151 |
$page = wtsec_request()->page; |
| 152 |
if ($page === wtsec_getRoute("login")) { |
| 153 |
if (WTSEC_LIBRARY_App::authorized()) { |
| 154 |
wp_safe_redirect(wtsec_getUrl('dashboard')); |
| 155 |
} |
| 156 |
} elseif ($page === wtsec_getRoute("logout")) { |
| 157 |
WTSEC_LIBRARY_App::setSiteOption('am_installed', false); |
| 158 |
WTSEC_LIBRARY_App::logout(); |
| 159 |
wp_safe_redirect(wtsec_getUrl('login')); |
| 160 |
} else { |
| 161 |
if (!WTSEC_LIBRARY_App::authorized()) { |
| 162 |
wp_safe_redirect(wtsec_getUrl('login')); |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
// Create file generate.php after plugin update |
| 169 |
function wtsec_generate_file( $upgrader_object, $options ) { |
| 170 |
|
| 171 |
if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) { |
| 172 |
foreach( $options['plugins'] as $plugin ) { |
| 173 |
if( $plugin == WTSEC_PLUGIN_BASENAME ) { |
| 174 |
require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 175 |
$fileName = WTSEC_LIBRARY_App::getOption('am_installed_file'); |
| 176 |
|
| 177 |
wtsec_addCheckFile($fileName); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
|