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
|
<?php if (!defined('MCDATAPATH')) exit;
if (!class_exists('BVPrependProtect')) :
require_once dirname( __FILE__ ) . '/../base.php'; require_once dirname( __FILE__ ) . '/../fw/fw.php'; require_once dirname( __FILE__ ) . '/../fw/request.php'; require_once dirname( __FILE__ ) . '/../fw/config.php'; require_once dirname( __FILE__ ) . '/info.php'; require_once dirname( __FILE__ ) . '/ipstore.php'; require_once dirname( __FILE__ ) . '/logger.php';
class BVPrependProtect { public $mcConfFile; public $mcIPsFile; public $mcRulesFile;
function __construct() { $this->mcConfFile = MCDATAPATH . MCCONFKEY . '-' . 'mc.conf'; $this->mcIPsFile = MCDATAPATH . MCCONFKEY . '-' . 'mc_ips.conf'; $this->mcRulesFile = MCDATAPATH . MCCONFKEY . '-' . 'mc_rules.json'; }
public function parseFile($fname) { $result = array();
if (file_exists($fname)) { $content = file_get_contents($fname); if (($content !== false) && is_string($content)) { $result = json_decode($content, true); } }
return $result; }
public function run() { $mcConf = $this->parseFile($this->mcConfFile); $mcIPsConf = $this->parseFile($this->mcIPsFile); $mcRuleSet = $this->parseFile($this->mcRulesFile);
if (!array_key_exists('time', $mcConf) || !isset($mcConf['time']) || !($mcConf['time'] > time() - (48*3600))) { return false; }
if (empty($mcConf) || empty($mcIPsConf)) { return false; }
$brand = array_key_exists('brandname', $mcConf) ? $mcConf['brandname'] : "Protect"; $bvinfo = new BVPrependInfo($brand); $bvipstore = new BVPrependIPStore($mcIPsConf);
$ipHeader = array_key_exists('ipheader', $mcConf) ? $mcConf['ipheader'] : false; $ip = BVProtectBase::getIP($ipHeader);
$fwlogger = new BVPrependLogger();
$fwConfHash = array_key_exists('fw', $mcConf) ? $mcConf['fw'] : array(); $fw = new BVFW($fwlogger, $fwConfHash, $ip, $bvinfo, $bvipstore, $mcRuleSet);
if ($fw->isActive()) {
if ($fw->canSetIPCookie()) { $fw->setIPCookie(); }
register_shutdown_function(array($fw, 'log'));
$fw->execute(); define('MCFWLOADED', true); }
return true; }
} endif;
|