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

229 lines 6.7 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 static $api_public_key = 'bvApiPublic';
10 public static $accounts_list = 'bvAccountsList';
11
12 public function __construct($settings, $public, $secret) {
13 $this->settings = $settings;
14 $this->public = $public;
15 $this->secret = $secret;
16 }
17
18 public static function find($settings, $public) {
19 $accounts = self::allAccounts($settings);
20 if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) {
21 $secret = $accounts[$public]['secret'];
22 }
23 if (empty($secret) || (strlen($secret) < 32)) {
24 return null;
25 }
26 return new self($settings, $public, $secret);
27 }
28
29 public static function update($settings, $allAccounts) {
30 $settings->updateOption(self::$accounts_list, $allAccounts);
31 }
32
33 public static function randString($length) {
34 $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
35
36 $str = "";
37 $size = strlen($chars);
38 for( $i = 0; $i < $length; $i++ ) {
39 $str .= $chars[rand(0, $size - 1)];
40 }
41 return $str;
42 }
43
44 public static function sanitizeKey($key) {
45 return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
46 }
47
48 public static function apiPublicAccount($settings) {
49 $pubkey = $settings->getOption(self::$api_public_key);
50 return self::find($settings, $pubkey);
51 }
52
53 public static function updateApiPublicKey($settings, $pubkey) {
54 $settings->updateOption(self::$api_public_key, $pubkey);
55 }
56
57 public static function getApiPublicKey($settings) {
58 return $settings->getOption(self::$api_public_key);
59 }
60
61 public static function getPlugName($settings) {
62 $bvinfo = new WPRInfo($settings);
63 return $bvinfo->plugname;
64 }
65
66 public static function allAccounts($settings) {
67 $accounts = $settings->getOption(self::$accounts_list);
68 if (!is_array($accounts)) {
69 $accounts = array();
70 }
71 return $accounts;
72 }
73
74 public static function accountsByPlugname($settings) {
75 $accounts = self::allAccounts($settings);
76 $accountsByPlugname = array();
77 $plugname = self::getPlugName($settings);
78 foreach ($accounts as $pubkey => $value) {
79 if (array_key_exists($plugname, $value) && $value[$plugname] == 1) {
80 $accountsByPlugname[$pubkey] = $value;
81 }
82 }
83 return $accountsByPlugname;
84 }
85
86 public static function accountsByType($settings, $account_type) {
87 $accounts = self::allAccounts($settings);
88 $accounts_by_type = array();
89 foreach ($accounts as $pubkey => $value) {
90 if (array_key_exists('account_type', $value) && $value['account_type'] === $account_type) {
91 $accounts_by_type[$pubkey] = $value;
92 }
93 }
94 return $accounts_by_type;
95 }
96
97 public static function accountsByGid($settings, $account_gid) {
98 $accounts = self::allAccounts($settings);
99 $accounts_by_gid = array();
100 foreach ($accounts as $pubkey => $value) {
101 if (array_key_exists('account_gid', $value) && $value['account_gid'] === $account_gid) {
102 $accounts_by_gid[$pubkey] = $value;
103 }
104 }
105 return $accounts_by_gid;
106 }
107
108 public static function accountsByPattern($settings, $search_key, $search_pattern) {
109 $accounts = self::allAccounts($settings);
110 $accounts_by_pattern = array();
111 foreach ($accounts as $pubkey => $value) {
112 if (array_key_exists($search_key, $value) &&
113 WPRHelper::safePregMatch($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 );
164 }
165
166 public function updateInfo($info) {
167 $accounts = self::allAccounts($this->settings);
168 $account_type = $info["account_type"];
169 $pubkey = $info['pubkey'];
170 if (!array_key_exists($pubkey, $accounts)) {
171 $accounts[$pubkey] = array();
172 }
173 if (array_key_exists('secret', $info)) {
174 $accounts[$pubkey]['secret'] = $info['secret'];
175 }
176 $accounts[$pubkey]['account_gid'] = $info['account_gid'];
177 $accounts[$pubkey]['lastbackuptime'] = time();
178 if (isset($info["speed_plugname"])) {
179 $speed_plugname = $info["speed_plugname"];
180 $accounts[$pubkey][$speed_plugname] = true;
181 }
182 if (isset($info["plugname"])) {
183 $plugname = $info["plugname"];
184 $accounts[$pubkey][$plugname] = true;
185 }
186 $accounts[$pubkey]['account_type'] = $account_type;
187 $accounts[$pubkey]['url'] = $info['url'];
188 $accounts[$pubkey]['email'] = $info['email'];
189 self::update($this->settings, $accounts);
190 }
191
192 public static function remove($settings, $pubkey) {
193 $accounts = self::allAccounts($settings);
194 if (array_key_exists($pubkey, $accounts)) {
195 unset($accounts[$pubkey]);
196 self::update($settings, $accounts);
197 return true;
198 }
199 return false;
200 }
201
202 public static function removeByAccountType($settings, $account_type) {
203 $accounts = WPRAccount::accountsByType($settings, $account_type);
204 if (sizeof($accounts) >= 1) {
205 foreach ($accounts as $pubkey => $value) {
206 WPRAccount::remove($settings, $pubkey);
207 }
208 return true;
209 }
210 return false;
211 }
212
213 public static function removeByAccountGid($settings, $account_gid) {
214 $accounts = WPRAccount::accountsByGid($settings, $account_gid);
215 if (sizeof($accounts) >= 1) {
216 foreach ($accounts as $pubkey => $value) {
217 WPRAccount::remove($settings, $pubkey);
218 }
219 return true;
220 }
221 return false;
222 }
223
224 public static function exists($settings, $pubkey) {
225 $accounts = self::allAccounts($settings);
226 return array_key_exists($pubkey, $accounts);
227 }
228 }
229 endif;