PluginProbe
The WP Remote WordPress Plugin / trunk
The WP Remote WordPress Plugin vtrunk
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
← All changes | account.php +24 -32 5.09trunk 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
@@ -159,38 +177,12 @@
159 177 }
160 178
161 179 public function info() {
162 180 return array(
163 - "public" => substr($this->public, 0, 6),
164 - "sigmatch" => substr($this->sig_match, 0, 6)
181 + "public" => substr($this->public, 0, 6)
165 182 );
166 183 }
167 184
168 - public static function getSigMatch($request, $secret) {
169 - $method = $request->method;
170 - $time = $request->time;
171 - $version = $request->version;
172 - if ($request->is_sha1) {
173 - $sig_match = sha1($method.$secret.$time.$version);
174 - } else {
175 - $sig_match = md5($method.$secret.$time.$version);
176 - }
177 - return $sig_match;
178 - }
179 -
180 - public function authenticate($request) {
181 - $time = $request->time;
182 - if ($time < intval($this->settings->getOption('bvLastRecvTime')) - 300) {
183 - return false;
184 - }
185 - $this->sig_match = self::getSigMatch($request, $this->secret);
186 - if ($this->sig_match !== $request->sig) {
187 - return false;
188 - }
189 - $this->settings->updateOption('bvLastRecvTime', $time);
190 - return 1;
191 - }
192 -
193 185 public function updateInfo($info) {
194 186 $accounts = self::allAccounts($this->settings);
195 187 $account_type = $info["account_type"];
196 188 $pubkey = $info['pubkey'];
@@ -252,5 +244,5 @@
252 244 $accounts = self::allAccounts($settings);
253 245 return array_key_exists($pubkey, $accounts);
254 246 }
255 247 }
256 -endif;
248 +endif;