PluginProbe
The WP Remote WordPress Plugin / 4.79
The WP Remote WordPress Plugin v4.79
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 / prepend / protect.php

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

80 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('MCDATAPATH')) exit;
3
4 if (!class_exists('BVPrependProtect')) :
5
6 require_once dirname( __FILE__ ) . '/../base.php';
7 require_once dirname( __FILE__ ) . '/../fw/fw.php';
8 require_once dirname( __FILE__ ) . '/../fw/request.php';
9 require_once dirname( __FILE__ ) . '/../fw/config.php';
10 require_once dirname( __FILE__ ) . '/info.php';
11 require_once dirname( __FILE__ ) . '/ipstore.php';
12 require_once dirname( __FILE__ ) . '/logger.php';
13
14 class BVPrependProtect {
15 public $mcConfFile;
16 public $mcIPsFile;
17 public $mcRulesFile;
18
19 function __construct() {
20 $this->mcConfFile = MCDATAPATH . MCCONFKEY . '-' . 'mc.conf';
21 $this->mcIPsFile = MCDATAPATH . MCCONFKEY . '-' . 'mc_ips.conf';
22 $this->mcRulesFile = MCDATAPATH . MCCONFKEY . '-' . 'mc_rules.json';
23 }
24
25 public function parseFile($fname) {
26 $result = array();
27
28 if (file_exists($fname)) {
29 $content = file_get_contents($fname);
30 if (($content !== false) && is_string($content)) {
31 $result = json_decode($content, true);
32
33 if (!is_array($result)) {
34 $result = array();
35 }
36 }
37 }
38
39 return $result;
40 }
41
42 public function run() {
43 $mcConf = $this->parseFile($this->mcConfFile);
44 $mcIPsConf = $this->parseFile($this->mcIPsFile);
45 $mcRuleSet = $this->parseFile($this->mcRulesFile);
46
47 if (!array_key_exists('time', $mcConf) || !isset($mcConf['time']) || !($mcConf['time'] > time() - (48*3600))) {
48 return false;
49 }
50
51 $brand = array_key_exists('brandname', $mcConf) ? $mcConf['brandname'] : "Protect";
52 $bvinfo = new BVPrependInfo($brand);
53 $bvipstore = new BVPrependIPStore($mcIPsConf);
54
55 $ipHeader = array_key_exists('ipheader', $mcConf) ? $mcConf['ipheader'] : false;
56 $ip = BVProtectBase::getIP($ipHeader);
57
58 $fwlogger = new BVPrependLogger();
59
60 $fwConfHash = array_key_exists('fw', $mcConf) ? $mcConf['fw'] : array();
61 $fw = BVFW::getInstance($fwlogger, $fwConfHash, $ip, $bvinfo, $bvipstore, $mcRuleSet);
62
63 if ($fw->isActive()) {
64
65 if ($fw->canSetIPCookie()) {
66 $fw->setIPCookie();
67 }
68
69 register_shutdown_function(array($fw, 'log'));
70
71 $fw->execute();
72 $fw->executeRules();
73 define('MCWAFLOADED', true);
74 }
75
76 return true;
77 }
78
79 }
80 endif;