PluginProbe
The WP Remote WordPress Plugin / 4.97
The WP Remote WordPress Plugin v4.97
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
wpremote / account.php

account.php in The WP Remote WordPress Plugin 4.97, at account.php

255 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('WPRAccount')) :
5 class WPRAccount {
6 public $settings;
7 public $public;
8 public $secret;
9 public $sig_match;
10 public static $api_public_key = 'bvApiPublic';
11 public static $accounts_list = 'bvAccountsList';
12
13 public function __construct($settings, $public, $secret) {
14 $this->settings = $settings;
15 $this->public = $public;
16 $this->secret = $secret;
17 }
18
19 public static function find($settings, $public) {
20 $accounts = self::allAccounts($settings);
21 if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) {
22 $secret = $accounts[$public]['secret'];
23 }
24 if (empty($secret) || (strlen($secret) < 32)) {
25 return null;
26 }
27 return new self($settings, $public, $secret);
28 }
29
30 public static function update($settings, $allAccounts) {
31 $settings->updateOption(self::$accounts_list, $allAccounts);
32 }
33
34 public static function randString($length) {
35 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
36
37 $str = "";
38 $size = strlen($chars);
39 for( $i = 0; $i < $length; $i++ ) {
40 $str .= $chars[rand(0, $size - 1)];
41 }
42 return $str;
43 }
44
45 public static function sanitizeKey($key) {
46 return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
47 }
48
49 public static function apiPublicAccount($settings) {
50 $pubkey = $settings->getOption(self::$api_public_key);
51 return self::find($settings, $pubkey);
52 }
53
54 public static function updateApiPublicKey($settings, $pubkey) {
55 $settings->updateOption(self::$api_public_key, $pubkey);
56 }
57
58 public static function getApiPublicKey($settings) {
59 return $settings->getOption(self::$api_public_key);
60 }
61
62 public static function getPlugName($settings) {
63 $bvinfo = new WPRInfo($settings);
64 return $bvinfo->plugname;
65 }
66
67 public static function allAccounts($settings) {
68 $accounts = $settings->getOption(self::$accounts_list);
69 if (!is_array($accounts)) {
70 $accounts = array();
71 }
72 return $accounts;
73 }
74
75 public static function accountsByPlugname($settings) {
76 $accounts = self::allAccounts($settings);
77 $accountsByPlugname = array();
78 $plugname = self::getPlugName($settings);
79 foreach ($accounts as $pubkey => $value) {
80 if (array_key_exists($plugname, $value) && $value[$plugname] == 1) {
81 $accountsByPlugname[$pubkey] = $value;
82 }
83 }
84 return $accountsByPlugname;
85 }
86
87 public static function accountsByType($settings, $account_type) {
88 $accounts = self::allAccounts($settings);
89 $accounts_by_type = array();
90 foreach ($accounts as $pubkey => $value) {
91 if (array_key_exists('account_type', $value) && $value['account_type'] === $account_type) {
92 $accounts_by_type[$pubkey] = $value;
93 }
94 }
95 return $accounts_by_type;
96 }
97
98 public static function accountsByGid($settings, $account_gid) {
99 $accounts = self::allAccounts($settings);
100 $accounts_by_gid = array();
101 foreach ($accounts as $pubkey => $value) {
102 if (array_key_exists('account_gid', $value) && $value['account_gid'] === $account_gid) {
103 $accounts_by_gid[$pubkey] = $value;
104 }
105 }
106 return $accounts_by_gid;
107 }
108
109 public static function accountsByPattern($settings, $search_key, $search_pattern) {
110 $accounts = self::allAccounts($settings);
111 $accounts_by_pattern = array();
112 foreach ($accounts as $pubkey => $value) {
113 if (array_key_exists($search_key, $value) && preg_match($search_pattern, $value[$search_key]) == 1) {
114 $accounts_by_pattern[$pubkey] = $value;
115 }
116 }
117 return $accounts_by_pattern;
118 }
119
120 public static function isConfigured($settings) {
121 $accounts = self::accountsByPlugname($settings);
122 return (sizeof($accounts) >= 1);
123 }
124
125 public static function setup($settings) {
126 $bvinfo = new WPRInfo($settings);
127 $settings->updateOption($bvinfo->plug_redirect, 'yes');
128 $settings->updateOption('bvActivateTime', time());
129 }
130
131 public function authenticatedUrl($method) {
132 $bvinfo = new WPRInfo($this->settings);
133 $qstr = http_build_query($this->newAuthParams($bvinfo->version));
134 return $bvinfo->appUrl().$method."?".$qstr;
135 }
136
137 public function newAuthParams($version) {
138 $bvinfo = new WPRInfo($this->settings);
139 $args = array();
140 $time = time();
141 $sig = sha1($this->public.$this->secret.$time.$version);
142 $args['sig'] = $sig;
143 $args['bvTime'] = $time;
144 $args['bvPublic'] = $this->public;
145 $args['bvVersion'] = $version;
146 $args['sha1'] = '1';
147 $args['plugname'] = $bvinfo->plugname;
148 return $args;
149 }
150
151 public static function addAccount($settings, $public, $secret) {
152 $accounts = self::allAccounts($settings);
153 if (!isset($public, $accounts)) {
154 $accounts[$public] = array();
155 }
156 $accounts[$public]['secret'] = $secret;
157 self::update($settings, $accounts);
158 }
159
160 public function info() {
161 return array(
162 "public" => substr($this->public, 0, 6),
163 "sigmatch" => substr($this->sig_match, 0, 6)
164 );
165 }
166
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 public function updateInfo($info) {
193 $accounts = self::allAccounts($this->settings);
194 $account_type = $info["account_type"];
195 $pubkey = $info['pubkey'];
196 if (!array_key_exists($pubkey, $accounts)) {
197 $accounts[$pubkey] = array();
198 }
199 if (array_key_exists('secret', $info)) {
200 $accounts[$pubkey]['secret'] = $info['secret'];
201 }
202 $accounts[$pubkey]['account_gid'] = $info['account_gid'];
203 $accounts[$pubkey]['lastbackuptime'] = time();
204 if (isset($info["speed_plugname"])) {
205 $speed_plugname = $info["speed_plugname"];
206 $accounts[$pubkey][$speed_plugname] = true;
207 }
208 if (isset($info["plugname"])) {
209 $plugname = $info["plugname"];
210 $accounts[$pubkey][$plugname] = true;
211 }
212 $accounts[$pubkey]['account_type'] = $account_type;
213 $accounts[$pubkey]['url'] = $info['url'];
214 $accounts[$pubkey]['email'] = $info['email'];
215 self::update($this->settings, $accounts);
216 }
217
218 public static function remove($settings, $pubkey) {
219 $accounts = self::allAccounts($settings);
220 if (array_key_exists($pubkey, $accounts)) {
221 unset($accounts[$pubkey]);
222 self::update($settings, $accounts);
223 return true;
224 }
225 return false;
226 }
227
228 public static function removeByAccountType($settings, $account_type) {
229 $accounts = WPRAccount::accountsByType($settings, $account_type);
230 if (sizeof($accounts) >= 1) {
231 foreach ($accounts as $pubkey => $value) {
232 WPRAccount::remove($settings, $pubkey);
233 }
234 return true;
235 }
236 return false;
237 }
238
239 public static function removeByAccountGid($settings, $account_gid) {
240 $accounts = WPRAccount::accountsByGid($settings, $account_gid);
241 if (sizeof($accounts) >= 1) {
242 foreach ($accounts as $pubkey => $value) {
243 WPRAccount::remove($settings, $pubkey);
244 }
245 return true;
246 }
247 return false;
248 }
249
250 public static function exists($settings, $pubkey) {
251 $accounts = self::allAccounts($settings);
252 return array_key_exists($pubkey, $accounts);
253 }
254 }
255 endif;