C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\malcare-security\protect\wp\protect.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
if (!defined('ABSPATH')) exit;
if (!
class_exists('BVProtect')) :

require_once 
dirname__FILE__ ) . '/../base.php';
require_once 
dirname__FILE__ ) . '/logger.php';
require_once 
dirname__FILE__ ) . '/ipstore.php';
require_once 
dirname__FILE__ ) . '/../fw/fw.php';
require_once 
dirname__FILE__ ) . '/../fw/config.php';
require_once 
dirname__FILE__ ) . '/../fw/request.php';
require_once 
dirname__FILE__ ) . '/lp/lp.php';
require_once 
dirname__FILE__ ) . '/lp/config.php';

class 
BVProtect {
    public 
$db;
    public 
$settings;
    
    function 
__construct($db$settings) {
        
$this->settings $settings;
        
$this->db $db;
    }

    public function 
init() {
        
add_action('clear_pt_config', array($this'uninstall'));
    }

    public function 
run() {
        
$bvipstore = new BVIPStore($this->db);
        
$bvipstore->init();
        
$bvinfo = new MCInfo($this->settings);
        
        
$config $this->settings->getOption('bvptconf');
        if (!
$config) {
            
$config = array();
        }

        
$ipHeader array_key_exists('ipheader'$config) ? $config['ipheader'] : false;
        
$ip BVProtectBase::getIP($ipHeader);
        
        
$fwLogger = new BVLogger($this->dbBVFWConfig::$requests_table);

        
$fwConfHash array_key_exists('fw'$config) ? $config['fw'] : array();
        
$fw = new BVFW($fwLogger$fwConfHash$ip$bvinfo$bvipstore);

        if (
$fw->isActive()) {

            if (
$fw->canSetAdminCookie()) {
                
add_action('init', array($fw'setBypassCookie'));
            }

            if (!
defined('MCFWLOADED') && $fw->canSetIPCookie()) {
                
$fw->setIPCookie();
            }

            if (!
defined('MCFWLOADED')) {
                
register_shutdown_function(array($fw'log'));

                
$fw->execute();
            }
        }

        
$lpConfHash array_key_exists('lp'$config) ? $config['lp'] : array();
        
$lp = new BVWPLP($this->db$this->settings$ip$bvipstore$lpConfHash);
        if (
$lp->isActive()) {
            
$lp->init();
        }
    }

    public function 
uninstall() {
        
$this->settings->deleteOption('bvptconf');
        
$this->db->dropBVTable(BVFWConfig::$requests_table);
        
$this->db->dropBVTable(BVWPLPConfig::$requests_table);
        
$this->settings->deleteOption('bvptplug');
        
$this->remove_wp_prepend();
        
$this->remove_php_prepend();
        
$this->remove_mcdata();
        return 
true;
    }

    private function 
remove_wp_prepend() {
        
$wp_conf_paths = array(ABSPATH "wp-config.php"ABSPATH "../wp-config.php");
        if (
file_exists($wp_conf_paths[0])) {
            
$fname $wp_conf_paths[0];
        } elseif (
file_exists($wp_conf_paths[1])) {
            
$fname $wp_conf_paths[1];
        } else {
            return;
        }

        
$content file_get_contents($fname);
        if (
$content) {
            
$pattern "@include '" ABSPATH "malcare-waf.php" "';";
            
$modified_content str_replace($pattern""$content);
            if (
$content !== $modified_content) {
                
file_put_contents($fname$modified_content);
            }
        }
    }

    private function 
remove_php_prepend() {
        
$this->remove_htaccess_prepend();
        
$this->remove_userini_prepend();
    }

    private function 
remove_prepend($fname$pattern) {
        if (!
file_exists($fname)) return;

        
$content file_get_contents($fname);
        if (
$content) {
            
$modified_content preg_replace($pattern""$content);
            if (
$content !== $modified_content) {
                
file_put_contents($fname$modified_content);
            }
        }
    }

    private function 
remove_htaccess_prepend() {
        
$pattern "/# MalCare WAF(.|\n)*# END MalCare WAF/i";
        
$this->remove_prepend(ABSPATH ".htaccess"$pattern);
    }

    private function 
remove_userini_prepend() {
        
$pattern "/; MalCare WAF(.|\n)*; END MalCare WAF/i";
        
$this->remove_prepend(ABSPATH ".user.ini"$pattern);
    }

    private function 
remove_mcdata() {
        
$this->rrmdir($this->get_contdir() . "mc_data");
    }

    private function 
rrmdir($dir) {
        if (
is_dir($dir)) {
            
$objects scandir($dir);
            foreach (
$objects as $object) {
                if (
$object != "." && $object != "..") {
                    if (
is_dir($dir "/" $object) && !is_link($dir "/" $object)) {
                        
rrmdir($dir "/" $object);
                    } else {
                        
unlink($dir "/" $object);
                    }
                }
            }
            
rmdir($dir);
        }
    }

    public function 
get_contdir() {
        return 
defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR "/" ABSPATH "wp-content/";
    }
}
endif;
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586