| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVProtectCallback')) : |
| 5 |
|
| 6 |
require_once dirname( __FILE__ ) . '/../../protect/wp/protect.php'; |
| 7 |
require_once dirname( __FILE__ ) . '/../../protect/fw/config.php'; |
| 8 |
require_once dirname( __FILE__ ) . '/../../protect/wp/lp/config.php'; |
| 9 |
|
| 10 |
class BVProtectCallback extends BVCallbackBase { |
| 11 |
public $db; |
| 12 |
public $settings; |
| 13 |
|
| 14 |
const PROTECT_WING_VERSION = 1.0; |
| 15 |
|
| 16 |
public function __construct($callback_handler) { |
| 17 |
$this->db = $callback_handler->db; |
| 18 |
$this->settings = $callback_handler->settings; |
| 19 |
} |
| 20 |
|
| 21 |
public function serverConfig() { |
| 22 |
return array( |
| 23 |
'software' => $_SERVER['SERVER_SOFTWARE'], |
| 24 |
'sapi' => (function_exists('php_sapi_name')) ? php_sapi_name() : false, |
| 25 |
'has_apache_get_modules' => function_exists('apache_get_modules'), |
| 26 |
'posix_getuid' => (function_exists('posix_getuid')) ? posix_getuid() : null, |
| 27 |
'uid' => (function_exists('getmyuid')) ? getmyuid() : null, |
| 28 |
'user_ini' => ini_get('user_ini.filename'), |
| 29 |
'php_major_version' => PHP_MAJOR_VERSION |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
public function unBlockLogins() { |
| 34 |
$this->settings->deleteTransient('bvlp_block_logins'); |
| 35 |
$this->settings->setTransient('bvlp_allow_logins', 'true', 1800); |
| 36 |
return $this->settings->getTransient('bvlp_allow_logins'); |
| 37 |
} |
| 38 |
|
| 39 |
public function blockLogins($time) { |
| 40 |
$this->settings->deleteTransient('bvlp_allow_logins'); |
| 41 |
$this->settings->setTransient('bvlp_block_logins', 'true', $time); |
| 42 |
return $this->settings->getTransient('bvlp_block_logins'); |
| 43 |
} |
| 44 |
|
| 45 |
public function unBlockIP($ip, $attempts, $time) { |
| 46 |
$transient_name = BVWPLP::$unblock_ip_transient.$ip; |
| 47 |
$this->settings->setTransient($transient_name, $attempts, $time); |
| 48 |
return $this->settings->getTransient($transient_name); |
| 49 |
} |
| 50 |
|
| 51 |
public function process($request) { |
| 52 |
$bvinfo = new WPRInfo($this->settings); |
| 53 |
$params = $request->params; |
| 54 |
|
| 55 |
switch ($request->method) { |
| 56 |
case "gtipprobeinfo": |
| 57 |
$resp = array(); |
| 58 |
$headers = $params['hdrs']; |
| 59 |
$hdrsinfo = array(); |
| 60 |
if ($headers && is_array($headers)) { |
| 61 |
foreach($headers as $hdr) { |
| 62 |
if (array_key_exists($hdr, $_SERVER)) { |
| 63 |
$hdrsinfo[$hdr] = $_SERVER[$hdr]; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
$resp["hdrsinfo"] = $hdrsinfo; |
| 68 |
break; |
| 69 |
case "gtrulcnf": |
| 70 |
$resp = array('conf' => $this->settings->getOption('bvruleset')); |
| 71 |
break; |
| 72 |
case "clrrulcnf": |
| 73 |
$this->settings->deleteOption('bvruleset'); |
| 74 |
$resp = array("clearconfig" => true); |
| 75 |
break; |
| 76 |
case "dorulcnf": |
| 77 |
$this->settings->updateOption('bvruleset', $params['conf']); |
| 78 |
$resp = array('conf' => $this->settings->getOption('bvruleset')); |
| 79 |
break; |
| 80 |
case "gtraddr": |
| 81 |
$raddr = array_key_exists('REMOTE_ADDR', $_SERVER) ? $_SERVER['REMOTE_ADDR'] : false; |
| 82 |
$resp = array("raddr" => $raddr); |
| 83 |
break; |
| 84 |
case "svrcnf": |
| 85 |
$resp = array("serverconfig" => $this->serverConfig()); |
| 86 |
break; |
| 87 |
case "unblklogins": |
| 88 |
$resp = array("unblocklogins" => $this->unBlockLogins()); |
| 89 |
break; |
| 90 |
case "blklogins": |
| 91 |
$time = array_key_exists('time', $params) ? $params['time'] : 1800; |
| 92 |
$resp = array("blocklogins" => $this->blockLogins($time)); |
| 93 |
break; |
| 94 |
case "unblkip": |
| 95 |
$resp = array("unblockip" => $this->unBlockIP($params['ip'], $params['attempts'], $params['time'])); |
| 96 |
break; |
| 97 |
case "rmwatchtime": |
| 98 |
$this->settings->deleteOption('bvwatchtime'); |
| 99 |
$resp = array("rmwatchtime" => !$bvinfo->getWatchTime()); |
| 100 |
break; |
| 101 |
default: |
| 102 |
$resp = false; |
| 103 |
} |
| 104 |
|
| 105 |
return $resp; |
| 106 |
} |
| 107 |
} |
| 108 |
endif; |