PluginProbe
The WP Remote WordPress Plugin / 6.76
The WP Remote WordPress Plugin v6.76
6.76 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 All 54 releases
← All changes | account.php +26 -33 4.976.76 View file →
@@ -5,12 +5,12 @@
5 5 class WPRAccount {
6 6 public $settings;
7 7 public $public;
8 8 public $secret;
9 - public $sig_match;
10 9 public static $api_public_key = 'bvApiPublic';
11 10 public static $accounts_list = 'bvAccountsList';
12 -
11 + private static $default_credential = array();
12 +
13 13 public function __construct($settings, $public, $secret) {
14 14 $this->settings = $settings;
15 15 $this->public = $public;
16 16 $this->secret = $secret;
@@ -16,14 +16,24 @@
16 16 $this->secret = $secret;
17 17 }
18 18
19 19 public static function find($settings, $public) {
20 + if (!is_string($public)) {
21 + return null;
22 + }
23 +
20 24 $accounts = self::allAccounts($settings);
21 25 if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) {
22 26 $secret = $accounts[$public]['secret'];
23 27 }
24 28 if (empty($secret) || (strlen($secret) < 32)) {
25 - return null;
29 + if (!empty(self::$default_credential) && array_key_exists($public, self::$default_credential)
30 + && strlen($public) >= 32) {
31 + $secret = self::$default_credential[$public];
32 + self::addAccount($settings, $public, $secret);
33 + } else {
34 + return null;
35 + }
26 36 }
27 37 return new self($settings, $public, $secret);
28 38 }
29 39
@@ -36,14 +46,18 @@
36 46
37 47 $str = "";
38 48 $size = strlen($chars);
39 49 for( $i = 0; $i < $length; $i++ ) {
40 - $str .= $chars[rand(0, $size - 1)];
50 + $str .= $chars[random_int(0, $size - 1)];
41 51 }
42 52 return $str;
43 53 }
44 54
45 55 public static function sanitizeKey($key) {
56 + if (!is_string($key)) {
57 + return '';
58 + }
59 +
46 60 return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
47 61 }
48 62
49 63 public static function apiPublicAccount($settings) {
@@ -54,8 +68,12 @@
54 68 public static function updateApiPublicKey($settings, $pubkey) {
55 69 $settings->updateOption(self::$api_public_key, $pubkey);
56 70 }
57 71
72 + public static function getDefaultPublicKey() {
73 + return WPRHelper::arrayKeyFirst(self::$default_credential);
74 + }
75 +
58 76 public static function getApiPublicKey($settings) {
59 77 return $settings->getOption(self::$api_public_key);
60 78 }
61 79
@@ -109,9 +127,10 @@
109 127 public static function accountsByPattern($settings, $search_key, $search_pattern) {
110 128 $accounts = self::allAccounts($settings);
111 129 $accounts_by_pattern = array();
112 130 foreach ($accounts as $pubkey => $value) {
113 - if (array_key_exists($search_key, $value) && preg_match($search_pattern, $value[$search_key]) == 1) {
131 + if (array_key_exists($search_key, $value) &&
132 + WPRHelper::safePregMatch($search_pattern, $value[$search_key]) == 1) {
114 133 $accounts_by_pattern[$pubkey] = $value;
115 134 }
116 135 }
117 136 return $accounts_by_pattern;
@@ -158,38 +177,12 @@
158 177 }
159 178
160 179 public function info() {
161 180 return array(
162 - "public" => substr($this->public, 0, 6),
163 - "sigmatch" => substr($this->sig_match, 0, 6)
181 + "public" => substr($this->public, 0, 6)
164 182 );
165 183 }
166 184
167 - public static function getSigMatch($request, $secret) {
168 - $method = $request->method;
169 - $time = $request->time;
170 - $version = $request->version;
171 - if ($request->is_sha1) {
172 - $sig_match = sha1($method.$secret.$time.$version);
173 - } else {
174 - $sig_match = md5($method.$secret.$time.$version);
175 - }
176 - return $sig_match;
177 - }
178 -
179 - public function authenticate($request) {
180 - $time = $request->time;
181 - if ($time < intval($this->settings->getOption('bvLastRecvTime')) - 300) {
182 - return false;
183 - }
184 - $this->sig_match = self::getSigMatch($request, $this->secret);
185 - if ($this->sig_match !== $request->sig) {
186 - return false;
187 - }
188 - $this->settings->updateOption('bvLastRecvTime', $time);
189 - return 1;
190 - }
191 -
192 185 public function updateInfo($info) {
193 186 $accounts = self::allAccounts($this->settings);
194 187 $account_type = $info["account_type"];
195 188 $pubkey = $info['pubkey'];
@@ -251,5 +244,5 @@
251 244 $accounts = self::allAccounts($settings);
252 245 return array_key_exists($pubkey, $accounts);
253 246 }
254 247 }
255 -endif;
248 +endif;