PluginProbe
The WP Remote WordPress Plugin / 6.02
The WP Remote WordPress Plugin v6.02
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / protect / protect.php

protect.php in The WP Remote WordPress Plugin 6.02, at protect/protect.php

125 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit;
3
4 if (!class_exists('WPRProtect_V602')) :
5 require_once dirname( __FILE__ ) . '/logger.php';
6 require_once dirname( __FILE__ ) . '/ipstore.php';
7 require_once dirname( __FILE__ ) . '/request.php';
8 require_once dirname( __FILE__ ) . '/wp_user.php';
9 require_once dirname( __FILE__ ) . '/lib.php';
10 require_once dirname( __FILE__ ) . '/fw.php';
11 require_once dirname( __FILE__ ) . '/lp.php';
12 require_once dirname( __FILE__ ) . '/../helper.php';
13
14 class WPRProtect_V602 {
15 public static $settings;
16 public static $db;
17 public static $info;
18
19 const MODE_PREPEND = 0;
20 const MODE_WP = 1;
21
22 const CONF_VERSION = '2';
23
24 public static function init($mode) {
25 if (defined('WP_CLI') && WP_CLI) {
26 return false;
27 }
28
29 if ($mode == WPRProtect_V602::MODE_PREPEND) {
30 $config_file = MCDATAPATH . MCCONFKEY . '-' . 'mc.conf';
31 $config = WPRProtectUtils_V602::parseFile($config_file);
32
33 if (empty($config['time']) || !($config['time'] > time() - (48*3600)) ||
34 !isset($config['mc_conf_version']) ||
35 (WPRProtect_V602::CONF_VERSION !== $config['mc_conf_version'])) {
36 return false;
37
38 }
39
40 $brand_name = array_key_exists('brandname', $config) ? $config['brandname'] : 'Protect';
41 $request_ip_header = array_key_exists('ipheader', $config) ? $config['ipheader'] : null;
42 $req_config = array_key_exists('reqconfig', $config) ? $config['reqconfig'] : array();
43 $request = new WPRProtectRequest_V602($request_ip_header, $req_config);
44 $fw_config = array_key_exists('fw', $config) ? $config['fw'] : array();
45
46 WPRProtectFW_V602::getInstance($mode, $request, $fw_config, $brand_name)->init();
47 } else {
48 $plug_config = self::$settings->getOption(self::$info->services_option_name);
49 $config = array_key_exists('protect', $plug_config) ? $plug_config['protect'] : array();
50 if (!is_array($config) || !array_key_exists('mc_conf_version', $config) ||
51 (WPRProtect_V602::CONF_VERSION !== $config['mc_conf_version'])) {
52
53 return false;
54 }
55
56 $brand_name = self::$info->getBrandName();
57 $request_ip_header = array_key_exists('ipheader', $config) ? $config['ipheader'] : null;
58 $req_config = array_key_exists('reqconfig', $config) ? $config['reqconfig'] : array();
59 $request = new WPRProtectRequest_V602($request_ip_header, $req_config);
60 $fw_config = array_key_exists('fw', $config) ? $config['fw'] : array();
61 $lp_config = array_key_exists('lp', $config) ? $config['lp'] : array();
62
63 WPRProtectFW_V602::getInstance($mode, $request, $fw_config, $brand_name)->init();
64 WPRProtectLP_V602::getInstance($request, $lp_config, $brand_name)->init();
65 }
66 }
67
68 public static function uninstall() {
69 self::$settings->deleteOption('bvptconf');
70 self::$settings->deleteOption('bvptplug');
71 WPRProtectIpstore_V602::uninstall();
72 WPRProtectFW_V602::uninstall();
73 WPRProtectLP_V602::uninstall();
74
75 WPRProtect_V602::removeWPPrepend();
76 WPRProtect_V602::removePHPPrepend();
77 WPRProtect_V602::removeMCData();
78
79 return true;
80 }
81
82 private static function removeWPPrepend() {
83 $wp_conf_paths = array(
84 rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/wp-config.php",
85 rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/../wp-config.php"
86 );
87
88 if (file_exists($wp_conf_paths[0])) {
89 $fname = $wp_conf_paths[0];
90 } elseif (file_exists($wp_conf_paths[1])) {
91 $fname = $wp_conf_paths[1];
92 } else {
93 return;
94 }
95
96 $pattern = "@include '" . rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/malcare-waf.php" . "';";
97
98 WPRProtectUtils_V602::fileRemovePattern($fname, $pattern);
99 }
100
101 private static function removePHPPrepend() {
102 WPRProtect_V602::removeHtaccessPrepend();
103 WPRProtect_V602::removeUseriniPrepend();
104 }
105
106 private static function removeHtaccessPrepend() {
107 $pattern = "/# MalCare WAF(.|\n)*# END MalCare WAF/i";
108
109 WPRProtectUtils_V602::fileRemovePattern(rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/.htaccess", $pattern, true);
110 }
111
112 private static function removeUseriniPrepend() {
113 $pattern = "/; MalCare WAF(.|\n)*; END MalCare WAF/i";
114
115 WPRProtectUtils_V602::fileRemovePattern(rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/.user.ini", $pattern, true);
116 }
117
118 private static function removeMCData() {
119 $content_dir = defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : rtrim(ABSPATH, DIRECTORY_SEPARATOR) . "/wp-content";
120 $mc_data_dir = $content_dir . "/mc_data";
121
122 WPRProtectUtils_V602::rrmdir($mc_data_dir);
123 }
124 }
125 endif;