PluginProbe
The WP Remote WordPress Plugin / 5.09
The WP Remote WordPress Plugin v5.09
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 5.09, at account.php

256 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) &&
114 WPRHelper::safePregMatch($search_pattern, $value[$search_key]) == 1) {
115 $accounts_by_pattern[$pubkey] = $value;
116 }
117 }
118 return $accounts_by_pattern;
119 }
120
121 public static function isConfigured($settings) {
122 $accounts = self::accountsByPlugname($settings);
123 return (sizeof($accounts) >= 1);
124 }
125
126 public static function setup($settings) {
127 $bvinfo = new WPRInfo($settings);
128 $settings->updateOption($bvinfo->plug_redirect, 'yes');
129 $settings->updateOption('bvActivateTime', time());
130 }
131
132 public function authenticatedUrl($method) {
133 $bvinfo = new WPRInfo($this->settings);
134 $qstr = http_build_query($this->newAuthParams($bvinfo->version));
135 return $bvinfo->appUrl().$method."?".$qstr;
136 }
137
138 public function newAuthParams($version) {
139 $bvinfo = new WPRInfo($this->settings);
140 $args = array();
141 $time = time();
142 $sig = sha1($this->public.$this->secret.$time.$version);
143 $args['sig'] = $sig;
144 $args['bvTime'] = $time;
145 $args['bvPublic'] = $this->public;
146 $args['bvVersion'] = $version;
147 $args['sha1'] = '1';
148 $args['plugname'] = $bvinfo->plugname;
149 return $args;
150 }
151
152 public static function addAccount($settings, $public, $secret) {
153 $accounts = self::allAccounts($settings);
154 if (!isset($public, $accounts)) {
155 $accounts[$public] = array();
156 }
157 $accounts[$public]['secret'] = $secret;
158 self::update($settings, $accounts);
159 }
160
161 public function info() {
162 return array(
163 "public" => substr($this->public, 0, 6),
164 "sigmatch" => substr($this->sig_match, 0, 6)
165 );
166 }
167
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 public function updateInfo($info) {
194 $accounts = self::allAccounts($this->settings);
195 $account_type = $info["account_type"];
196 $pubkey = $info['pubkey'];
197 if (!array_key_exists($pubkey, $accounts)) {
198 $accounts[$pubkey] = array();
199 }
200 if (array_key_exists('secret', $info)) {
201 $accounts[$pubkey]['secret'] = $info['secret'];
202 }
203 $accounts[$pubkey]['account_gid'] = $info['account_gid'];
204 $accounts[$pubkey]['lastbackuptime'] = time();
205 if (isset($info["speed_plugname"])) {
206 $speed_plugname = $info["speed_plugname"];
207 $accounts[$pubkey][$speed_plugname] = true;
208 }
209 if (isset($info["plugname"])) {
210 $plugname = $info["plugname"];
211 $accounts[$pubkey][$plugname] = true;
212 }
213 $accounts[$pubkey]['account_type'] = $account_type;
214 $accounts[$pubkey]['url'] = $info['url'];
215 $accounts[$pubkey]['email'] = $info['email'];
216 self::update($this->settings, $accounts);
217 }
218
219 public static function remove($settings, $pubkey) {
220 $accounts = self::allAccounts($settings);
221 if (array_key_exists($pubkey, $accounts)) {
222 unset($accounts[$pubkey]);
223 self::update($settings, $accounts);
224 return true;
225 }
226 return false;
227 }
228
229 public static function removeByAccountType($settings, $account_type) {
230 $accounts = WPRAccount::accountsByType($settings, $account_type);
231 if (sizeof($accounts) >= 1) {
232 foreach ($accounts as $pubkey => $value) {
233 WPRAccount::remove($settings, $pubkey);
234 }
235 return true;
236 }
237 return false;
238 }
239
240 public static function removeByAccountGid($settings, $account_gid) {
241 $accounts = WPRAccount::accountsByGid($settings, $account_gid);
242 if (sizeof($accounts) >= 1) {
243 foreach ($accounts as $pubkey => $value) {
244 WPRAccount::remove($settings, $pubkey);
245 }
246 return true;
247 }
248 return false;
249 }
250
251 public static function exists($settings, $pubkey) {
252 $accounts = self::allAccounts($settings);
253 return array_key_exists($pubkey, $accounts);
254 }
255 }
256 endif;