PluginProbe ʕ •ᴥ•ʔ
Wordfence Security – Firewall, Malware Scan, and Login Security / 3.2.6
Wordfence Security – Firewall, Malware Scan, and Login Security v3.2.6
8.2.2 8.2.1 8.2.0 3.7.1 3.7.2 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.9.1 4.0.1 4.0.2 4.0.3 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.1 5.1.2 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.1 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.1 5.3.10 5.3.11 5.3.12 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.3.8 5.3.9 6.0.1 6.0.10 6.0.11 6.0.12 6.0.14 6.0.15 6.0.16 6.0.17 6.0.18 6.0.19 6.0.2 6.0.20 6.0.21 6.0.22 6.0.23 6.0.24 6.0.25 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.1 6.1.10 6.1.11 6.1.12 6.1.14 6.1.15 6.1.16 6.1.17 6.1.2 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.1.9 6.2.0 6.2.1 6.2.10 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.2.8 6.2.9 6.3.0 6.3.1 6.3.10 6.3.11 6.3.12 6.3.14 6.3.15 6.3.16 6.3.17 6.3.18 6.3.19 6.3.2 6.3.20 6.3.21 6.3.22 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.3.8 6.3.9 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.14 7.1.15 7.1.16 7.1.17 7.1.18 7.1.19 7.1.2 7.1.20 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.10.0 7.10.1 7.10.2 7.10.3 7.10.4 7.10.5 7.10.6 7.10.7 7.11.0 7.11.1 7.11.2 7.11.3 7.11.4 7.11.5 7.11.6 7.11.7 7.2.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.4.0 7.4.1 7.4.10 7.4.11 7.4.12 7.4.14 7.4.2 7.4.3 trunk 7.4.4 1.1 7.4.5 1.2 7.4.6 1.3 7.4.7 1.3.1 7.4.8 1.3.2 7.4.9 1.3.3 7.5.0 1.4.2 7.5.1 1.4.3 7.5.10 1.4.4 7.5.11 1.4.5 7.5.2 1.4.6 7.5.3 1.4.7 7.5.4 1.4.8 7.5.5 1.5.1 7.5.6 1.5.2 7.5.7 1.5.3 7.5.8 1.5.4 7.5.9 1.5.5 7.6.0 1.5.6 7.6.1 2.0.1 7.6.2 2.0.2 7.7.0 2.0.3 7.7.1 2.0.5 7.8.0 2.0.6 7.8.1 2.0.7 7.8.2 2.1.0 7.9.0 2.1.1 7.9.1 2.1.2 7.9.2 2.1.3 7.9.3 2.1.4 8.0.0 2.1.5 8.0.1 3.0.2 8.0.2 3.0.3 8.0.3 3.0.4 8.0.4 3.0.5 8.0.5 3.0.6 8.1.0 3.0.7 8.1.1 3.0.8 8.1.2 3.0.9 8.1.3 3.1.0 8.1.4 3.1.1 v1.4.1 3.1.2 3.1.4 3.1.6 3.2.1 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.1 3.4.4 3.4.5 3.5.1 3.5.2 3.6.1 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9
wordfence / lib / wfAPI.php
wordfence / lib Last commit date
Diff 14 years ago .htaccess 14 years ago Diff.php 14 years ago GeoIP.dat 13 years ago IPTraf.php 13 years ago diffResult.php 14 years ago email_genericAlert.php 14 years ago email_newIssues.php 14 years ago email_unlockRequest.php 14 years ago menu_activity.php 13 years ago menu_blockedIPs.php 13 years ago menu_countryBlocking.php 13 years ago menu_options.php 13 years ago menu_scan.php 13 years ago menu_scanSchedule.php 13 years ago schedWeekEntry.php 13 years ago sysinfo.php 14 years ago unknownFiles.php 13 years ago viewFullActivityLog.php 13 years ago wf503.php 13 years ago wfAPI.php 13 years ago wfAction.php 14 years ago wfArray.php 13 years ago wfBrowscap.php 14 years ago wfBrowscapCache.php 14 years ago wfBulkCountries.php 13 years ago wfConfig.php 13 years ago wfCountryMap.php 13 years ago wfCrawl.php 13 years ago wfDB.php 13 years ago wfDict.php 14 years ago wfGeoIP.php 13 years ago wfIssues.php 13 years ago wfLockedOut.php 14 years ago wfLog.php 13 years ago wfModTracker.php 14 years ago wfRate.php 14 years ago wfScanEngine.php 13 years ago wfSchema.php 13 years ago wfUnlockMsg.php 14 years ago wfUtils.php 13 years ago wfViewResult.php 14 years ago wordfenceClass.php 13 years ago wordfenceConstants.php 13 years ago wordfenceHash.php 13 years ago wordfenceScanner.php 13 years ago wordfenceURLHoover.php 13 years ago
wfAPI.php
174 lines
1 <?php
2 require_once('wordfenceConstants.php');
3 require_once('wordfenceClass.php');
4 class wfAPI {
5 public $lastHTTPStatus = '';
6 public $lastCurlErrorNo = '';
7 private $curlDataWritten = 0;
8 private $curlContent = 0;
9 private $APIKey = '';
10 private $wordpressVersion = '';
11 private static $maintMsg = "The Wordfence scanning server could not be contacted.";
12 public function __construct($apiKey, $wordpressVersion){
13 $this->APIKey = $apiKey;
14 $this->wordpressVersion = $wordpressVersion;
15 }
16 public function call($action, $getParams = array(), $postParams = array()){
17 $json = $this->getURL($this->getAPIURL() . '/v' . WORDFENCE_API_VERSION . '/?' . $this->makeAPIQueryString() . '&' . http_build_query(
18 array_merge(
19 array('action' => $action),
20 $getParams
21 )), $postParams);
22 if(! $json){
23 throw new Exception("We received an empty data response from the Wordfence scanning servers when calling the '$action' function.");
24 }
25
26 $dat = json_decode($json, true);
27 if(! is_array($dat)){
28 throw new Exception("We received a data structure that is not the expected array when contacting the Wordfence scanning servers and calling the '$action' function.");
29 }
30 if(is_array($dat) && isset($dat['errorMsg'])){
31 throw new Exception($dat['errorMsg']);
32 }
33 return $dat;
34 }
35 public function curlWrite($h, $d){
36 $this->curlContent .= $d;
37 if($this->curlDataWritten > 10000000){ //10 megs
38 return 0;
39 } else {
40 return strlen($d);
41 }
42 }
43 protected function getURL($url, $postParams = array()){
44 if(function_exists('curl_init')){
45 $this->curlDataWritten = 0;
46 $this->curlContent = "";
47 $curl = curl_init($url);
48 curl_setopt ($curl, CURLOPT_TIMEOUT, 300);
49 curl_setopt ($curl, CURLOPT_USERAGENT, "Wordfence.com UA " . (defined('WORDFENCE_VERSION') ? WORDFENCE_VERSION : '[Unknown version]') );
50 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
51 curl_setopt ($curl, CURLOPT_HEADER, 0);
52 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false);
53 curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, false);
54 curl_setopt ($curl, CURLOPT_WRITEFUNCTION, array($this, 'curlWrite'));
55 curl_setopt($curl, CURLOPT_POST, true);
56 curl_setopt($curl, CURLOPT_POSTFIELDS, $postParams);
57
58 $curlResult = curl_exec($curl);
59 $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
60 $this->lastCurlErrorNo = curl_errno($curl);
61 if($httpStatus == 200){
62 curl_close($curl);
63 return $this->curlContent;
64 } else {
65 $cerror = curl_error($curl);
66 curl_close($curl);
67 throw new Exception("We received an error response when trying to contact the Wordfence scanning servers. The HTTP status code was [$httpStatus]" . ($cerror ? (' and the error from CURL was ' . $cerror) : ''));
68 }
69 } else {
70 $data = $this->fileGet($url, $postParams);
71 if($data === false){
72 $err = error_get_last();
73 if($err){
74 throw new Exception("We received an error response when trying to contact the Wordfence scanning servers using PHP's file_get_contents function. The error was: " . $err);
75 } else {
76 throw new Exception("We received an empty response when trying to contact the Wordfence scanning servers using PHP's file_get_contents function.");
77 }
78 }
79 return $data;
80 }
81
82 }
83 private function fileGet($url, $postParams){
84 $body = "";
85 if(is_array($postParams)){
86 $bodyArr = array();
87 foreach($postParams as $key => $val){
88 $bodyArr[] = urlencode($key) . '=' . urlencode($val);
89 }
90 $body = implode('&', $bodyArr);
91 } else {
92 $body = $postParams;
93 }
94 $opts = array('http' =>
95 array(
96 'method' => 'POST',
97 'content' => $body,
98 'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
99 'timeout' => 60
100 )
101 );
102 $context = stream_context_create($opts);
103 return @file_get_contents($url, false, $context, -1);
104 }
105 public function binCall($func, $postData){
106 $url = $this->getAPIURL() . '/v' . WORDFENCE_API_VERSION . '/?' . $this->makeAPIQueryString() . '&action=' . $func;
107 if(function_exists('curl_init')){
108 $curl = curl_init($url);
109 curl_setopt ($curl, CURLOPT_TIMEOUT, 300);
110 //curl_setopt($curl, CURLOPT_VERBOSE, true);
111 curl_setopt ($curl, CURLOPT_USERAGENT, "Wordfence");
112 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
113 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false);
114 curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, false);
115 curl_setopt($curl, CURLOPT_POST, true);
116 if($postData){
117 curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
118 } else {
119 curl_setopt($curl, CURLOPT_POSTFIELDS, array());
120 }
121 $data = curl_exec($curl);
122 $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
123 if($httpStatus != 200){
124 $cError = curl_error($curl);
125 curl_close($curl);
126 if($cError){
127 throw new Exception("We received an error response when trying to fetch binary data from the Wordfence scanning server. The HTTP status was [$httpStatus] with error: $cError");
128 } else {
129 throw new Exception("We received an error HTTP response when trying to fetch binary data from the Wordfence scanning server: [$httpStatus]");
130 }
131 }
132 } else {
133 $data = $this->fileGet($url, $postData);
134 if($data === false){
135 $err = error_get_last();
136 if($err){
137 throw new Exception("We received an error response when trying to fetch binary data from the Wordfence scanning server using file_get_contents: $err");
138 } else {
139 throw new Exception("We received an error when trying to fetch binary data from the Wordfence scanning server using file_get_contents. There was no message explaining the error.");
140 }
141 }
142 $httpStatus = '200';
143 }
144 if(preg_match('/\{.*errorMsg/', $data)){
145 $jdat = @json_decode($data, true);
146 if(is_array($jdat) && $jdat['errorMsg']){
147 throw new Exception($jdat['errorMsg']);
148 }
149 }
150 return array('code' => $httpStatus, 'data' => $data);
151 }
152 public function makeAPIQueryString(){
153 $siteurl = '';
154 if(function_exists('get_bloginfo')){
155 $siteurl = get_bloginfo('siteurl');
156 }
157 return http_build_query(array(
158 'v' => $this->wordpressVersion,
159 's' => $siteurl,
160 'k' => $this->APIKey
161 ));
162 }
163 private function getAPIURL(){
164 $ssl_supported = false;
165 if(defined('CURL_VERSION_SSL') && function_exists('curl_version')){
166 $version = curl_version();
167 $ssl_supported = ($version['features'] & CURL_VERSION_SSL);
168 }
169 return $ssl_supported ? WORDFENCE_API_URL_SEC : WORDFENCE_API_URL_NONSEC;
170 }
171 }
172
173 ?>
174