aea5fa23 by Jeremy Groot

pantheon migrate plugin

1 parent 061534ff
Showing 29 changed files with 2784 additions and 0 deletions
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNAccount')) :
5 class PTNAccount {
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 PTNInfo($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 PTNHelper::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 PTNInfo($settings);
127 $settings->updateOption($bvinfo->plug_redirect, 'yes');
128 $settings->updateOption('bvActivateTime', time());
129 }
130
131 public function authenticatedUrl($method) {
132 $bvinfo = new PTNInfo($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 PTNInfo($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 = PTNAccount::accountsByType($settings, $account_type);
204 if (sizeof($accounts) >= 1) {
205 foreach ($accounts as $pubkey => $value) {
206 PTNAccount::remove($settings, $pubkey);
207 }
208 return true;
209 }
210 return false;
211 }
212
213 public static function removeByAccountGid($settings, $account_gid) {
214 $accounts = PTNAccount::accountsByGid($settings, $account_gid);
215 if (sizeof($accounts) >= 1) {
216 foreach ($accounts as $pubkey => $value) {
217 PTNAccount::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;
...\ No newline at end of file ...\ No newline at end of file
1 <div class="logo-container" style="padding: 50px 0px 10px 20px">
2 <a href="http://blogvault.net/" style="padding-right: 20px;"><img src="<?php echo esc_url(plugins_url($this->getPluginLogo(), __FILE__)); ?>" /></a>
3 </div>
4
5 <div id="wrapper toplevel_page_ptn-automated-migration">
6 <form id="ptn_migrate_form" dummy=">" action="<?php echo esc_url($this->bvinfo->appUrl()); ?>/home/migrate" onsubmit="document.getElementById('migratesubmit').disabled = true;" style="padding:0 2% 2em 1%;" method="post" name="signup">
7 <h1>Migrate Site to Pantheon</h1>
8 <p><font size="3">This plugin makes it very easy to migrate your site to Pantheon</font></p>
9 <input type="hidden" name="bvsrc" value="wpplugin" />
10 <input type="hidden" name="migrate" value="pantheon" />
11 <input type="hidden" name="type" value="sftp" />
12 <?php echo $this->siteInfoTags(); ?>
13 <p>No Pantheon site yet? Start by <a href="https://dashboard.pantheon.io/sites/migrate">migrating an existing site</a> on your Pantheon dashboard.</p>
14 <div class="row-fluid">
15 <div class="span5" style="border-right: 1px solid #EEE; padding-top:1%;">
16 <label class="control-label" for="input02">Pantheon Site Name</label>
17 <div class="control-group">
18 <div class="controls">
19 <input type="text" class="input-large" name="newurl">
20 </div>
21 </div>
22 <label class="control-label" for="input01">Machine Token</label>
23 <div class="control-group">
24 <div class="controls">
25 <input type="text" class="input-large" name="machine_token">
26 </div>
27 </div>
28 <?php if (array_key_exists('auth_required_source', $_REQUEST)) { ?>
29 <div id="source-auth">
30 <label class="control-label" for="input02" style="color:red">User <small>(for this site)</small></label>
31 <div class="control-group">
32 <div class="controls">
33 <input type="text" class="input-large" name="httpauth_src_user">
34 </div>
35 </div>
36 <label class="control-label" for="input02" style="color:red">Password <small>(for this site)</small></label>
37 <div class="control-group">
38 <div class="controls">
39 <input type="password" class="input-large" name="httpauth_src_password">
40 </div>
41 </div>
42 </div>
43 <?php } ?>
44 <?php if (array_key_exists('auth_required_dest', $_REQUEST)) { ?>
45 <label class="control-label" for="input02" style="color:red">Username <small>(for Pantheon Install)</small></label>
46 <div class="control-group">
47 <div class="controls">
48 <input type="text" class="input-large" name="httpauth_dest_user">
49 </div>
50 </div>
51 <label class="control-label" for="input02" style="color:red">Password <small>(for Pantheon Install)</small></label>
52 <div class="control-group">
53 <div class="controls">
54 <input type="password" class="input-large" name="httpauth_dest_password">
55 </div>
56 </div>
57 <?php } ?>
58 <div class="control-group">
59 <div class="controls">
60 <br><input type="checkbox" name="consent" onchange="document.getElementById('migratesubmit').disabled = !this.checked;" value="1"/>I agree to Blogvault <a href="https://blogvault.net/tos" target="_blank" rel="noopener noreferrer">Terms of Service</a> and <a href="https://blogvault.net/privacy" target="_blank" rel="noopener noreferrer">Privacy Policy</a>
61 </div>
62 </div>
63 </div>
64
65 </div>
66 </div>
67 <input type='submit' disabled id='migratesubmit' value='Migrate'>
68 </form>
69 </div> <!-- wrapper ends here -->
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVCallbackBase')) :
5
6 class BVCallbackBase {
7
8 public static $wing_infos = array("BRAND_WING_VERSION" => '1.0',
9 "DB_WING_VERSION" => '1.3',
10 "ACCOUNT_WING_VERSION" => '1.2',
11 "MISC_WING_VERSION" => '1.2',
12 "FS_WING_VERSION" => '1.2',
13 "INFO_WING_VERSION" => '1.8',
14 );
15
16 public function objectToArray($obj) {
17 return json_decode(json_encode($obj), true);
18 }
19
20 public function base64Encode($data, $chunk_size) {
21 if ($chunk_size) {
22 $out = "";
23 $len = strlen($data);
24 for ($i = 0; $i < $len; $i += $chunk_size) {
25 $out .= base64_encode(substr($data, $i, $chunk_size));
26 }
27 } else {
28 $out = base64_encode($data);
29 }
30 return $out;
31 }
32 }
33 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVCallbackHandler')) :
5
6 class BVCallbackHandler {
7 public $db;
8 public $settings;
9 public $siteinfo;
10 public $request;
11 public $account;
12 public $response;
13 public $bvinfo;
14
15 public function __construct($db, $settings, $siteinfo, $request, $account, $response) {
16 $this->db = $db;
17 $this->settings = $settings;
18 $this->siteinfo = $siteinfo;
19 $this->request = $request;
20 $this->account = $account;
21 $this->response = $response;
22 $this->bvinfo = new PTNInfo($this->settings);
23 }
24
25 public function bvAdmExecuteWithoutUser() {
26 $this->execute(array("bvadmwithoutuser" => true));
27 }
28
29 public function bvAdmExecuteWithUser() {
30 $this->execute(array("bvadmwithuser" => true));
31 }
32
33 public function execute($resp = array()) {
34 $params = $this->request->params;
35 if (array_key_exists('disable_global_cache', $params)) {
36 $GLOBALS['_wp_using_ext_object_cache'] = false;
37 }
38
39 $this->routeRequest();
40 $resp = array(
41 "request_info" => $this->request->info(),
42 "site_info" => $this->siteinfo->info(),
43 "account_info" => $this->account->info(),
44 "bvinfo" => $this->bvinfo->info(),
45 "api_pubkey" => substr(PTNAccount::getApiPublicKey($this->settings), 0, 8)
46 );
47 $this->response->terminate($resp);
48 }
49
50 public function routeRequest() {
51 switch ($this->request->wing) {
52 case 'manage':
53 require_once dirname( __FILE__ ) . '/wings/manage.php';
54 $module = new BVManageCallback($this);
55 break;
56 case 'fs':
57 require_once dirname( __FILE__ ) . '/wings/fs.php';
58 $module = new BVFSCallback($this);
59 break;
60 case 'db':
61 require_once dirname( __FILE__ ) . '/wings/db.php';
62 $module = new BVDBCallback($this);
63 break;
64 case 'info':
65 require_once dirname( __FILE__ ) . '/wings/info.php';
66 $module = new BVInfoCallback($this);
67 break;
68 case 'dynsync':
69 require_once dirname( __FILE__ ) . '/wings/dynsync.php';
70 $module = new BVDynSyncCallback($this);
71 break;
72 case 'ipstr':
73 require_once dirname( __FILE__ ) . '/wings/ipstore.php';
74 $module = new BVIPStoreCallback($this);
75 break;
76 case 'wtch':
77 require_once dirname( __FILE__ ) . '/wings/watch.php';
78 $module = new BVWatchCallback($this);
79 break;
80 case 'brand':
81 require_once dirname( __FILE__ ) . '/wings/brand.php';
82 $module = new BVBrandCallback($this);
83 break;
84 case 'pt':
85 require_once dirname( __FILE__ ) . '/wings/protect.php';
86 $module = new BVProtectCallback($this);
87 break;
88 case 'act':
89 require_once dirname( __FILE__ ) . '/wings/account.php';
90 $module = new BVAccountCallback($this);
91 break;
92 case 'fswrt':
93 require_once dirname( __FILE__ ) . '/wings/fs_write.php';
94 $module = new BVFSWriteCallback();
95 break;
96 case 'actlg':
97 require_once dirname( __FILE__ ) . '/wings/actlog.php';
98 $module = new BVActLogCallback($this);
99 break;
100 case 'speed':
101 require_once dirname( __FILE__ ) . '/wings/speed.php';
102 $module = new BVSpeedCallback($this);
103 break;
104 case 'scrty':
105 require_once dirname( __FILE__ ) . '/wings/security.php';
106 $module = new BVSecurityCallback($this);
107 break;
108 default:
109 require_once dirname( __FILE__ ) . '/wings/misc.php';
110 $module = new BVMiscCallback($this);
111 break;
112 }
113 $resp = $module->process($this->request);
114 if ($resp === false) {
115 $resp = array(
116 "statusmsg" => "Bad Command",
117 "status" => false);
118 }
119 $resp = array(
120 $this->request->wing => array(
121 $this->request->method => $resp
122 )
123 );
124 $this->response->addStatus("callbackresponse", $resp);
125 return 1;
126 }
127 }
128 endif;
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVCallbackRequest')) :
5 class BVCallbackRequest {
6 public $params;
7 public $method;
8 public $wing;
9 public $is_afterload;
10 public $is_admin_ajax;
11 public $is_debug;
12 public $account;
13 public $settings;
14 public $sig;
15 public $sighshalgo;
16 public $time;
17 public $version;
18 public $is_sha1;
19 public $bvb64stream;
20 public $bvb64cksize;
21 public $checksum;
22 public $error = array();
23 public $pubkey_name;
24 public $bvprmsmac;
25 public $bvboundry;
26
27 public function __construct($account, $in_params, $settings) {
28 $this->params = array();
29 $this->account = $account;
30 $this->settings = $settings;
31 $this->wing = $in_params['wing'];
32 $this->method = $in_params['bvMethod'];
33 $this->is_afterload = array_key_exists('afterload', $in_params);
34 $this->is_admin_ajax = array_key_exists('adajx', $in_params);
35 $this->is_debug = array_key_exists('bvdbg', $in_params);
36 $this->sig = $in_params['sig'];
37 $this->sighshalgo = !empty($in_params['sighshalgo']) ? $in_params['sighshalgo'] : null;
38 $this->time = intval($in_params['bvTime']);
39 $this->version = $in_params['bvVersion'];
40 $this->is_sha1 = array_key_exists('sha1', $in_params);
41 $this->bvb64stream = isset($in_params['bvb64stream']);
42 $this->bvb64cksize = array_key_exists('bvb64cksize', $in_params) ? intval($in_params['bvb64cksize']) : false;
43 $this->checksum = array_key_exists('checksum', $in_params) ? $in_params['checksum'] : false;
44 $this->pubkey_name = !empty($in_params['pubkeyname']) ?
45 PTNAccount::sanitizeKey($in_params['pubkeyname']) : 'm_public';
46 $this->bvprmsmac = !empty($in_params['bvprmsmac']) ? PTNAccount::sanitizeKey($in_params['bvprmsmac']) : "";
47 $this->bvboundry = !empty($in_params['bvboundry']) ? $in_params['bvboundry'] : "";
48 }
49
50 public function isAPICall() {
51 return array_key_exists('apicall', $this->params);
52 }
53
54 public function curlRequest($url, $body) {
55 $ch = curl_init($url);
56 curl_setopt($ch, CURLOPT_POST, 1);
57 curl_setopt($ch, CURLOPT_TIMEOUT, 15);
58 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
59 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
60 return curl_exec($ch);
61 }
62
63 public function fileGetContentRequest($url, $body) {
64 $options = array(
65 'http' => array(
66 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
67 'method' => 'POST',
68 'content' => http_build_query($body)
69 )
70 );
71
72 $context = stream_context_create($options);
73 return file_get_contents($url, false, $context);
74 }
75
76 public function http_request($url, $body) {
77 if (in_array('curl', get_loaded_extensions())) {
78 return $this->curlRequest($url, $body);
79 } else {
80 return $this->fileGetContentRequest($url, $body);
81 }
82 }
83
84 public function get_params_via_api($params_key, $apiurl) {
85 $res = $this->http_request($apiurl, array('bvkey' => $params_key));
86
87 if ($res === FALSE) {
88 return false;
89 }
90
91 return $res;
92 }
93
94 public function info() {
95 $info = array(
96 "requestedsig" => $this->sig,
97 "requestedtime" => $this->time,
98 "requestedversion" => $this->version,
99 "error" => $this->error
100 );
101 if ($this->is_debug) {
102 $info["inreq"] = $this->params;
103 }
104 if ($this->is_admin_ajax) {
105 $info["adajx"] = true;
106 }
107 if ($this->is_afterload) {
108 $info["afterload"] = true;
109 }
110 return $info;
111 }
112
113 public function processParams($in_params) {
114 $params = array();
115
116 if (array_key_exists('obend', $in_params) && function_exists('ob_end_clean'))
117 @ob_end_clean();
118
119 if (array_key_exists('op_reset', $in_params) && function_exists('output_reset_rewrite_vars'))
120 @output_reset_rewrite_vars();
121
122 if (array_key_exists('concat', $in_params)) {
123 foreach ($in_params['concat'] as $key) {
124 $concated = '';
125 $count = intval($in_params[$key]);
126 for ($i = 1; $i <= $count; $i++) {
127 $concated .= $in_params[$key."_bv_".$i];
128 }
129 $in_params[$key] = $concated;
130 }
131 }
132
133 if (isset($in_params['bvpdataviaapi']) && isset($in_params['bvapiurl'])) {
134 $pdata = $this->get_params_via_api($in_params['bvpdataviaapi'], $in_params['bvapiurl']);
135 if ($pdata !== false) {
136 $in_params["bvprms"] = $pdata;
137 }
138 }
139
140 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
141 if (!empty($in_params['bvprmshshalgo']) && $in_params['bvprmshshalgo'] === 'sha256') {
142 $calculated_mac = hash_hmac('SHA256', $in_params['bvprms'], $this->account->secret);
143 } else {
144 $calculated_mac = hash_hmac('SHA1', $in_params['bvprms'], $this->account->secret);
145 }
146
147 if ($this->compare_mac($this->bvprmsmac, $calculated_mac) === true) {
148
149 if (array_key_exists('b64', $in_params)) {
150 foreach ($in_params['b64'] as $key) {
151 if (is_array($in_params[$key])) {
152 $in_params[$key] = array_map('base64_decode', $in_params[$key]);
153 } else {
154 $in_params[$key] = base64_decode($in_params[$key]);
155 }
156 }
157 }
158
159 if (array_key_exists('unser', $in_params)) {
160 foreach ($in_params['unser'] as $key) {
161 $in_params[$key] = json_decode($in_params[$key], TRUE);
162 }
163 }
164
165 if (array_key_exists('sersafe', $in_params)) {
166 $key = $in_params['sersafe'];
167 $in_params[$key] = BVCallbackRequest::serialization_safe_decode($in_params[$key]);
168 }
169
170 if (array_key_exists('bvprms', $in_params) && isset($in_params['bvprms'])) {
171 $params = $in_params['bvprms'];
172 }
173
174 if (array_key_exists('clacts', $in_params)) {
175 foreach ($in_params['clacts'] as $action) {
176 remove_all_actions($action);
177 }
178 }
179
180 if (array_key_exists('clallacts', $in_params)) {
181 global $wp_filter;
182 foreach ( $wp_filter as $filter => $val ){
183 remove_all_actions($filter);
184 }
185 }
186
187 if (array_key_exists('memset', $in_params)) {
188 $val = intval($in_params['memset']);
189 @ini_set('memory_limit', $val.'M');
190 }
191
192 return $params;
193 }
194 }
195 return false;
196 }
197
198 private function compare_mac($l_hash, $r_hash) {
199 if (!is_string($l_hash) || !is_string($r_hash)) {
200 return false;
201 }
202
203 if (strlen($l_hash) !== strlen($r_hash)) {
204 return false;
205 }
206
207 if (function_exists('hash_equals')) {
208 return hash_equals($l_hash, $r_hash);
209 } else {
210 return $l_hash === $r_hash;
211 }
212 }
213
214 public static function serialization_safe_decode($data) {
215 if (is_array($data)) {
216 $data = array_map(array('BVCallbackRequest', 'serialization_safe_decode'), $data);
217 } elseif (is_string($data)) {
218 $data = base64_decode($data);
219 }
220
221 return $data;
222 }
223
224 public function authenticate() {
225 if (!$this->account) {
226 $this->error["message"] = "ACCOUNT_NOT_FOUND";
227 return false;
228 }
229
230 $bv_last_recv_time = $this->settings->getOption('bvLastRecvTime');
231 if ($this->time < intval($bv_last_recv_time) - 300) {
232 return false;
233 }
234
235 $data = $this->method.$this->account->secret.$this->time.$this->version.$this->bvprmsmac;
236 if (!$this->verify($data, base64_decode($this->sig), $this->sighshalgo)) {
237 return false;
238 }
239 $this->settings->updateOption('bvLastRecvTime', $this->time);
240
241 return 1;
242 }
243
244 public function verify($data, $sig, $sighshalgo) {
245 if (!function_exists('openssl_verify') || !function_exists('openssl_pkey_get_public')) {
246 $this->error["message"] = "OPENSSL_FUNCS_NOT_FOUND";
247 return false;
248 }
249
250 $key_file = dirname( __FILE__ ) . '/../public_keys/' . $this->pubkey_name . '.pub';
251 if (!file_exists($key_file)) {
252 $this->error["message"] = "PUBLIC_KEY_NOT_FOUND";
253 return false;
254 }
255 $public_key_str = file_get_contents($key_file);
256 $public_key = openssl_pkey_get_public($public_key_str);
257 if (!$public_key) {
258 $this->error["message"] = "UNABLE_TO_LOAD_PUBLIC_KEY";
259 return false;
260 }
261
262 if ($sighshalgo === 'sha256') {
263 $verify = openssl_verify($data, $sig, $public_key, OPENSSL_ALGO_SHA256);
264 } else {
265 $verify = openssl_verify($data, $sig, $public_key);
266 }
267 if ($verify === 1) {
268 return true;
269 } elseif ($verify === 0) {
270 $this->error["message"] = "INCORRECT_SIGNATURE";
271 $this->error["pubkey_sig"] = substr(hash('md5', $public_key_str), 0, 8);
272 } else {
273 $this->error["message"] = "OPENSSL_VERIFY_FAILED";
274 }
275 return false;
276 }
277
278 public function corruptedParamsResp() {
279 $bvinfo = new PTNInfo($this->settings);
280
281 return array(
282 "account_info" => $this->account->info(),
283 "request_info" => $this->info(),
284 "bvinfo" => $bvinfo->info(),
285 "statusmsg" => "BVPRMS_CORRUPTED"
286 );
287 }
288
289 public function authFailedResp() {
290 $api_public_key = PTNAccount::getApiPublicKey($this->settings);
291 $default_secret = PTNRecover::getDefaultSecret($this->settings);
292 $bvinfo = new PTNInfo($this->settings);
293 $resp = array(
294 "request_info" => $this->info(),
295 "bvinfo" => $bvinfo->info(),
296 "statusmsg" => "FAILED_AUTH",
297 "api_pubkey" => substr($api_public_key, 0, 8),
298 "def_sigmatch" => substr(hash('sha1', $this->method.$default_secret.$this->time.$this->version), 0, 8)
299 );
300
301 if ($this->account) {
302 $resp["account_info"] = $this->account->info();
303 $resp["sigmatch"] = substr(hash('sha1', $this->method.$this->account->secret.$this->time.$this->version), 0, 6);
304 } else {
305 $resp["account_info"] = array("error" => "ACCOUNT_NOT_FOUND");
306 }
307
308 return $resp;
309 }
310 }
311 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVCallbackResponse')) :
5
6 class BVCallbackResponse extends BVCallbackBase {
7 public $status;
8 public $bvb64cksize;
9
10 public function __construct($bvb64cksize) {
11 $this->status = array("blogvault" => "response");
12 $this->bvb64cksize = $bvb64cksize;
13 }
14
15 public function addStatus($key, $value) {
16 $this->status[$key] = $value;
17 }
18
19 public function addArrayToStatus($key, $value) {
20 if (!isset($this->status[$key])) {
21 $this->status[$key] = array();
22 }
23 $this->status[$key][] = $value;
24 }
25
26 public function terminate($resp = array()) {
27 $resp = array_merge($this->status, $resp);
28 $resp["signature"] = "Blogvault API";
29 $response = "bvbvbvbvbv".serialize($resp)."bvbvbvbvbv";
30 $response = "bvb64bvb64".$this->base64Encode($response, $this->bvb64cksize)."bvb64bvb64";
31 die($response);
32
33 exit;
34 }
35 }
36 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVRespStream')) :
5
6 class BVStream extends BVCallbackBase {
7 public $bvb64stream;
8 public $bvb64cksize;
9 public $checksum;
10
11 function __construct($request) {
12 $this->bvb64stream = $request->bvb64stream;
13 $this->bvb64cksize = $request->bvb64cksize;
14 $this->checksum = $request->checksum;
15 }
16
17 public function writeChunk($chunk) {
18 }
19
20 public static function startStream($account, $request) {
21 $result = array();
22 $params = $request->params;
23 $stream = new BVRespStream($request);
24 if ($request->isAPICall()) {
25 $stream = new BVHttpStream($request);
26 if (!$stream->connect()) {
27 $apicallstatus = array(
28 "httperror" => "Cannot Open Connection to Host",
29 "streamerrno" => $stream->errno,
30 "streamerrstr" => $stream->errstr
31 );
32 return array("apicallstatus" => $apicallstatus);
33 }
34 if (array_key_exists('acbmthd', $params)) {
35 $qstr = http_build_query(array('bvapicheck' => $params['bvapicheck']));
36 $url = '/bvapi/'.$params['acbmthd']."?".$qstr;
37 if (array_key_exists('acbqry', $params)) {
38 $url .= "&".$params['acbqry'];
39 }
40 $stream->multipartChunkedPost($url);
41 } else {
42 return array("apicallstatus" => array("httperror" => "ApiCall method not present"));
43 }
44 }
45 return array('stream' => $stream);
46 }
47
48 public function writeStream($chunk) {
49 if (strlen($chunk) > 0) {
50 $bvb64_prefix = "";
51 if ($this->bvb64stream) {
52 $chunk_size = $this->bvb64cksize;
53 $chunk = $this->base64Encode($chunk, $chunk_size);
54 $bvb64_prefix .= "BVB64" . ":";
55 }
56
57 $hash_prefix = "";
58 if ($this->checksum == 'crc32') {
59 $hash_prefix .= "CRC32" . ":" . crc32($chunk) . ":";
60 } else if ($this->checksum == 'md5') {
61 $hash_prefix .= "MD5" . ":" . md5($chunk) . ":";
62 }
63
64 $chunk = $hash_prefix . $bvb64_prefix . strlen($chunk) . ":" . $chunk;
65
66 $this->writeChunk($chunk);
67 }
68 }
69 }
70
71 class BVRespStream extends BVStream {
72 public $bvboundry;
73
74 function __construct($request) {
75 parent::__construct($request);
76 $this->bvboundry = $request->bvboundry;
77 }
78
79 public function writeChunk($chunk) {
80 echo $this->bvboundry . "ckckckckck" . $chunk . $this->bvboundry . "ckckckckck";
81 }
82 public function endStream() {
83 echo $this->bvboundry . "rerererere";
84
85 return array();
86 }
87 }
88
89 class BVHttpStream extends BVStream {
90 var $user_agent = 'BVHttpStream';
91 var $host;
92 var $port;
93 var $timeout = 20;
94 var $conn;
95 var $errno;
96 var $errstr;
97 var $boundary;
98 var $apissl;
99
100 function __construct($request) {
101 parent::__construct($request);
102 $this->host = $request->params['apihost'];
103 $this->port = intval($request->params['apiport']);
104 $this->apissl = array_key_exists('apissl', $request->params);
105 }
106
107 public function connect() {
108 if ($this->apissl && function_exists('stream_socket_client')) {
109 $this->conn = stream_socket_client("ssl://".$this->host.":".$this->port, $errno, $errstr, $this->timeout);
110 } else {
111 $this->conn = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
112 }
113 if (!$this->conn) {
114 $this->errno = $errno;
115 $this->errstr = $errstr;
116 return false;
117 }
118 socket_set_timeout($this->conn, $this->timeout);
119 return true;
120 }
121
122 public function write($data) {
123 fwrite($this->conn, $data);
124 }
125
126 public function sendChunk($data) {
127 $this->write(sprintf("%x\r\n", strlen($data)));
128 $this->write($data);
129 $this->write("\r\n");
130 }
131
132 public function sendRequest($method, $url, $headers = array(), $body = null) {
133 $def_hdrs = array("Connection" => "keep-alive",
134 "Host" => $this->host);
135 $headers = array_merge($def_hdrs, $headers);
136 $request = strtoupper($method)." ".$url." HTTP/1.1\r\n";
137 if (null != $body) {
138 $headers["Content-length"] = strlen($body);
139 }
140 foreach($headers as $key=>$val) {
141 $request .= $key.":".$val."\r\n";
142 }
143 $request .= "\r\n";
144 if (null != $body) {
145 $request .= $body;
146 }
147 $this->write($request);
148 return $request;
149 }
150
151 public function post($url, $headers = array(), $body = "") {
152 if(is_array($body)) {
153 $b = "";
154 foreach($body as $key=>$val) {
155 $b .= $key."=".urlencode($val)."&";
156 }
157 $body = substr($b, 0, strlen($b) - 1);
158 }
159 $this->sendRequest("POST", $url, $headers, $body);
160 }
161
162 public function streamedPost($url, $headers = array()) {
163 $headers['Transfer-Encoding'] = "chunked";
164 $this->sendRequest("POST", $url, $headers);
165 }
166
167 public function multipartChunkedPost($url) {
168 $mph = array(
169 "Content-Disposition" => "form-data; name=bvinfile; filename=data",
170 "Content-Type" => "application/octet-stream"
171 );
172 $rnd = rand(100000, 999999);
173 $this->boundary = "----".$rnd;
174 $prologue = "--".$this->boundary."\r\n";
175 foreach($mph as $key=>$val) {
176 $prologue .= $key.":".$val."\r\n";
177 }
178 $prologue .= "\r\n";
179 $headers = array('Content-Type' => "multipart/form-data; boundary=".$this->boundary);
180 $this->streamedPost($url, $headers);
181 $this->sendChunk($prologue);
182 }
183
184 public function writeChunk($data) {
185 $this->sendChunk($data);
186 }
187
188 public function closeChunk() {
189 $this->sendChunk("");
190 }
191
192 public function endStream() {
193 $epilogue = "\r\n\r\n--".$this->boundary."--\r\n";
194 $this->sendChunk($epilogue);
195 $this->closeChunk();
196
197 $result = array();
198 $resp = $this->getResponse();
199 if (array_key_exists('httperror', $resp)) {
200 $result["httperror"] = $resp['httperror'];
201 } else {
202 $result["respstatus"] = $resp['status'];
203 $result["respstatus_string"] = $resp['status_string'];
204 }
205 return array("apicallstatus" => $result);
206 }
207
208 public function getResponse() {
209 $response = array();
210 $response['headers'] = array();
211 $state = 1;
212 $conlen = 0;
213 stream_set_timeout($this->conn, 300);
214 while (!feof($this->conn)) {
215 $line = fgets($this->conn, 4096);
216 if (1 == $state) {
217 if (!PTNHelper::safePregMatch('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
218 $response['httperror'] = "Status code line invalid: ".htmlentities($line);
219 return $response;
220 }
221 $response['http_version'] = $m[1];
222 $response['status'] = $m[2];
223 $response['status_string'] = $m[3];
224 $state = 2;
225 } else if (2 == $state) {
226 # End of headers
227 if (2 == strlen($line)) {
228 if ($conlen > 0)
229 $response['body'] = fread($this->conn, $conlen);
230 return $response;
231 }
232 if (!PTNHelper::safePregMatch('/([^:]+):\\s*(.*)/', $line, $m)) {
233 // Skip to the next header
234 continue;
235 }
236 $key = strtolower(trim($m[1]));
237 $val = trim($m[2]);
238 $response['headers'][$key] = $val;
239 if ($key == "content-length") {
240 $conlen = intval($val);
241 }
242 }
243 }
244 return $response;
245 }
246 }
247 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVAccountCallback')) :
5 class BVAccountCallback extends BVCallbackBase {
6 public $account;
7 public $settings;
8
9 const ACCOUNT_WING_VERSION = 1.2;
10
11 public function __construct($callback_handler) {
12 $this->account = $callback_handler->account;
13 $this->settings = $callback_handler->settings;
14 }
15
16 function updateInfo($args) {
17 $result = array();
18
19 if (array_key_exists('update_info', $args)) {
20 $this->account->updateInfo($args['update_info']);
21 $result['update_info'] = array(
22 "status" => PTNAccount::exists($this->settings, $args['update_info']['pubkey'])
23 );
24 }
25
26 if (array_key_exists('update_api_key', $args)) {
27 PTNAccount::updateApiPublicKey($this->settings, $args['update_api_key']['pubkey']);
28 $result['update_api_key'] = array(
29 "status" => $this->settings->getOption(PTNAccount::$api_public_key)
30 );
31 }
32
33 if (array_key_exists('update_options', $args))
34 $result['update_options'] = $this->settings->updateOptions($args['update_options']);
35
36 if (array_key_exists('delete_options', $args))
37 $result['delete_options'] = $this->settings->deleteOptions($args['delete_options']);
38
39 $result['status'] = true;
40
41 return $result;
42 }
43
44 function process($request) {
45 $params = $request->params;
46 $account = $this->account;
47 $settings = $this->settings;
48 switch ($request->method) {
49 case "addacc":
50 PTNAccount::addAccount($this->settings, $params['public'], $params['secret']);
51 $resp = array("status" => PTNAccount::exists($this->settings, $params['public']));
52 break;
53 case "rmacc":
54 $resp = array("status" => PTNAccount::remove($this->settings, $params['public']));
55 break;
56 case "updt":
57 $account->updateInfo($params);
58 $resp = array("status" => PTNAccount::exists($this->settings, $params['pubkey']));
59 break;
60 case "updtapikey":
61 PTNAccount::updateApiPublicKey($this->settings, $params['pubkey']);
62 $resp = array("status" => $this->settings->getOption(PTNAccount::$api_public_key));
63 break;
64 case "rmbvscrt":
65 $resp = array("status" => $settings->deleteOption('bvSecretKey'));
66 break;
67 case "rmbvkeys":
68 $resp = array("status" => $settings->deleteOption('bvKeys'));
69 break;
70 case "rmdefpub":
71 $resp = array("status" => $settings->deleteOption('bvDefaultPublic'));
72 break;
73 case "rmoldbvacc":
74 $resp = array("status" => $settings->deleteOption('bvAccounts'));
75 break;
76 case "fetch":
77 $accounts = PTNAccount::allAccounts($this->settings);
78 if (!isset($params['full'])) {
79 foreach ($accounts as &$account) {
80 if (isset($account['secret'])) {
81 unset($account['secret']);
82 }
83 }
84 }
85 $resp = array("status" => $accounts);
86 break;
87 case "updtinfo":
88 $resp = $this->updateInfo($params);
89 break;
90 default:
91 $resp = false;
92 }
93 return $resp;
94 }
95 }
96 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVBrandCallback')) :
5
6 class BVBrandCallback extends BVCallbackBase {
7 public $settings;
8
9 const BRAND_WING_VERSION = 1.0;
10
11 public function __construct($callback_handler) {
12 $this->settings = $callback_handler->settings;
13 }
14
15 public function process($request) {
16 $bvinfo = new PTNInfo($this->settings);
17 $option_name = $bvinfo->brand_option;
18 $params = $request->params;
19 switch($request->method) {
20 case 'setbrand':
21 $brandinfo = array();
22 if (array_key_exists('hide', $params)) {
23 $brandinfo['hide'] = $params['hide'];
24 } else {
25 $brandinfo['name'] = $params['name'];
26 $brandinfo['title'] = $params['title'];
27 $brandinfo['description'] = $params['description'];
28 $brandinfo['pluginuri'] = $params['pluginuri'];
29 $brandinfo['author'] = $params['author'];
30 $brandinfo['authorname'] = $params['authorname'];
31 $brandinfo['authoruri'] = $params['authoruri'];
32 $brandinfo['menuname'] = $params['menuname'];
33 $brandinfo['logo'] = $params['logo'];
34 $brandinfo['webpage'] = $params['webpage'];
35 $brandinfo['appurl'] = $params['appurl'];
36 if (array_key_exists('hide_plugin_details', $params)) {
37 $brandinfo['hide_plugin_details'] = $params['hide_plugin_details'];
38 }
39 if (array_key_exists('hide_from_menu', $params)) {
40 $brandinfo['hide_from_menu'] = $params['hide_from_menu'];
41 }
42 }
43 $this->settings->updateOption($option_name, $brandinfo);
44 $resp = array("setbrand" => $this->settings->getOption($option_name));
45 break;
46 case 'rmbrand':
47 $this->settings->deleteOption($option_name);
48 $resp = array("rmbrand" => !$this->settings->getOption($option_name));
49 break;
50 default:
51 $resp = false;
52 }
53 return $resp;
54 }
55 }
56 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVMiscCallback')) :
5
6 class BVMiscCallback extends BVCallbackBase {
7 public $settings;
8 public $bvinfo;
9 public $siteinfo;
10 public $account;
11 public $bvapi;
12 public $db;
13
14 const MISC_WING_VERSION = 1.2;
15
16 public function __construct($callback_handler) {
17 $this->settings = $callback_handler->settings;
18 $this->siteinfo = $callback_handler->siteinfo;
19 $this->account = $callback_handler->account;
20 $this->db = $callback_handler->db;
21 $this->bvinfo = new PTNInfo($callback_handler->settings);
22 $this->bvapi = new PTNWPAPI($callback_handler->settings);
23 }
24
25 public function refreshPluginUpdates() {
26 global $wp_current_filter;
27 $wp_current_filter[] = 'load-update-core.php';
28
29 wp_update_plugins();
30
31 array_pop($wp_current_filter);
32
33 wp_update_plugins();
34
35 return array("wpupdateplugins" => true);
36 }
37
38 public function refreshThemeUpdates() {
39 global $wp_current_filter;
40 $wp_current_filter[] = 'load-update-core.php';
41
42 wp_update_themes();
43
44 array_pop($wp_current_filter);
45
46 wp_update_themes();
47
48 return array("wpupdatethemes" => true);
49 }
50
51 public function getWingInfo() {
52 return array('wing_info' => self::$wing_infos);
53 }
54
55 public function post_types_data($post_params) {
56 $result = array();
57 $get_post_types_args = $post_params['get_post_types_args'];
58 $post_types = get_post_types($get_post_types_args);
59 $post_types = array_merge($post_types, $post_params['include_post_types']);
60 $post_types = array_diff( $post_types, $post_params['exclude_post_types']);
61 $result['post_types'] = $post_types;
62 $post_types = esc_sql($post_types);
63 $post_types = "'" . implode("','", $post_types) . "'";
64 $post_table = $post_params['table'];
65 $post_select_columns = implode(", ", $post_params['select_column']);
66 $post_query = "SELECT MAX(ID) as $post_select_columns FROM ( SELECT
67 $post_select_columns FROM $post_table WHERE post_type IN ( $post_types )
68 AND post_status='publish' ORDER BY post_date DESC ) AS posts GROUP BY post_type";
69 $posts = $this->db->getResult($post_query);
70 foreach ( $posts as $key => $post ) {
71 $posts[$key]['url'] = get_permalink($post['ID']);
72 }
73 $result['posts'] = $posts;
74 return $result;
75 }
76
77 public function taxonomy_data($taxonomy_params) {
78 $result = array();
79 $get_taxonomies_args = $taxonomy_params['get_taxonomies_args'];
80 $taxonomies = get_taxonomies($get_taxonomies_args);
81 $taxonomies = array_diff($taxonomies, $taxonomy_params['exclude_taxonomies']);
82 $result['taxonomies'] = $taxonomies;
83 $taxonomies = esc_sql( $taxonomies );
84 $taxonomies = "'" . implode( "','", $taxonomies ) . "'";
85 $taxonomy_table = $taxonomy_params['table'];
86 $taxonomy_select_columns = implode(", ", $taxonomy_params['select_column']);
87 $taxonomy_query = "SELECT MAX( term_id ) AS $taxonomy_select_columns FROM (
88 SELECT $taxonomy_select_columns FROM $taxonomy_table WHERE taxonomy IN (
89 $taxonomies ) AND count > 0) AS taxonomies GROUP BY taxonomy";
90
91 $taxonomies = $this->db->getResult($taxonomy_query);
92 foreach($taxonomies as $key => $taxonomy) {
93 $taxonomies[$key]['url'] = get_term_link((int)$taxonomy['term_id'], $taxonomy['taxonomy']);
94 }
95 $result['taxonomy_data'] = $taxonomies;
96 return $result;
97 }
98
99 public function process($request) {
100 $bvinfo = $this->bvinfo;
101 $settings = $this->settings;
102 $params = $request->params;
103 switch ($request->method) {
104 case "dummyping":
105 $resp = array();
106 $resp = array_merge($resp, $this->siteinfo->info());
107 $resp = array_merge($resp, $this->account->info());
108 $resp = array_merge($resp, $this->bvinfo->info());
109 $resp = array_merge($resp, $this->getWingInfo());
110 break;
111 case "pngbv":
112 $info = array();
113 $this->siteinfo->basic($info);
114 $this->bvapi->pingbv('/bvapi/pingbv', $info);
115 $resp = array("status" => true);
116 break;
117 case "enablebadge":
118 $option = $bvinfo->badgeinfo;
119 $badgeinfo = array();
120 $badgeinfo['badgeurl'] = $params['badgeurl'];
121 $badgeinfo['badgeimg'] = $params['badgeimg'];
122 $badgeinfo['badgealt'] = $params['badgealt'];
123 $settings->updateOption($option, $badgeinfo);
124 $resp = array("status" => $settings->getOption($option));
125 break;
126 case "disablebadge":
127 $option = $bvinfo->badgeinfo;
128 $settings->deleteOption($option);
129 $resp = array("status" => !$settings->getOption($option));
130 break;
131 case "getoption":
132 $resp = array('getoption' => $settings->getOption($params['opkey']));
133 break;
134 case "setdynplug":
135 $settings->updateOption('bvdynplug', $params['dynplug']);
136 $resp = array("setdynplug" => $settings->getOption('bvdynplug'));
137 break;
138 case "unsetdynplug":
139 $settings->deleteOption('bvdynplug');
140 $resp = array("unsetdynplug" => $settings->getOption('bvdynplug'));
141 break;
142 case "wpupplgs":
143 $resp = $this->refreshPluginUpdates();
144 break;
145 case "wpupthms":
146 $resp = $this->refreshThemeUpdates();
147 break;
148 case "wpupcre":
149 $resp = array("wpupdatecore" => wp_version_check());
150 break;
151 case "phpinfo":
152 phpinfo();
153 die();
154 break;
155 case "wpnonce":
156 $resp = array("wpnonce" => wp_create_nonce($params["wpnonce_action"]));
157 break;
158 case "dlttrsnt":
159 $resp = array("dlttrsnt" => $settings->deleteTransient($params['key']));
160 break;
161 case "optns":
162 $resp = array();
163
164 if (array_key_exists("get_options", $params))
165 $resp["get_options"] = $settings->getOptions($params["get_options"]);
166
167 if (array_key_exists("update_options", $params))
168 $resp["update_options"] = $settings->updateOptions($params["update_options"]);
169
170 if (array_key_exists("delete_options", $params))
171 $resp["delete_options"] = $settings->deleteOptions($params["delete_options"]);
172
173 break;
174 case "setbvss":
175 $resp = array("status" => $settings->updateOption('bv_site_settings', $params['bv_site_settings']));
176 break;
177 case "stsrvcs":
178 $resp = array();
179 $deleted_configs = array();
180 $updated_configs = array();
181 if (array_key_exists("configs_to_delete", $params)) {
182 foreach($params["configs_to_delete"] as $config_name) {
183 $deleted_configs[$config_name] = $settings->deleteOption($config_name);
184 }
185 }
186 if (array_key_exists("configs_to_update", $params)) {
187 foreach($params["configs_to_update"] as $config_name => $config_value) {
188 $settings->updateOption($config_name, $config_value);
189 $updated_configs[$config_name] = $settings->getOption($config_name);
190 }
191 }
192 $resp["updated_configs"] = $updated_configs;
193 $resp["deleted_configs"] = $deleted_configs;
194 break;
195 case "critical_css_data":
196 $resp = array();
197 if (array_key_exists('fetch_post_data', $params) && $params['fetch_post_data'] == true) {
198 $post_params = $params['post_params'];
199 $post_result = $this->post_types_data($post_params);
200 $resp['post_cp_results'] = $post_result['posts'];
201 $resp['post_types'] = $post_result['post_types'];
202 }
203 if (array_key_exists('fetch_taxonomy_data', $params) && $params['fetch_taxonomy_data'] == true) {
204 $taxonomy_params = $params['taxonomy_params'];
205 $taxonomy_result = $this->taxonomy_data($taxonomy_params);
206 $resp['taxonomy_cp_results'] = $taxonomy_result['taxonomy_data'];
207 $resp['taxonomies'] = $taxonomy_result['taxonomies'];
208 }
209 break;
210
211 case "get_post_ids":
212 if (array_key_exists('urls', $params)) {
213 $resp = array();
214 foreach ( $params['urls'] as $url ) {
215 $resp[$url] = url_to_postid($url);
216 }
217 }
218 break;
219
220 case "permalink":
221 if (array_key_exists('post_ids', $params)) {
222 $resp = array();
223 foreach ( $params['post_ids'] as $id ) {
224 $resp[$id]['url'] = get_permalink($id);
225 }
226 }
227 break;
228 default:
229 $resp = false;
230 }
231 return $resp;
232 }
233 }
234 endif;
...\ No newline at end of file ...\ No newline at end of file
1
2 .toplevel_page_ptn-automated-migration label{
3 float: left;
4 width: 220px;
5 font-weight: bold;
6 }
7
8 .toplevel_page_ptn-automated-migration input, .toplevel_page_ptn-automated-migration textarea{
9 width: 180px;
10 margin-bottom: 20px;
11 }
12
13 .toplevel_page_ptn-automated-migration textarea{
14 width: 250px;
15 height: 150px;
16 }
17
18 .boxes{
19 width: 1em;
20 }
21
22 #submitbutton{
23 margin-left: 300px;
24 margin-top: 5px;
25 width: 100px;
26 }
27
28 br{
29 clear: left;
30 }
31
32 #wrapper {
33 width:100%;
34 clear:both;
35 overflow: hidden;
36 position: relative;
37 width: 100%;
38 }
39
40 .logo-left {
41 max-width: 50%;
42 float: left;
43 }
44 .logo-right {
45 max-width: 50%;
46 float: right;
47 }
1 <?php
2
3 if (!class_exists('PTNHelper')) :
4 class PTNHelper {
5 public static function safePregMatch($pattern, $subject, &$matches = null, $flags = 0, $offset = 0) {
6 if (!is_string($pattern) || !is_string($subject)) {
7 return false;
8 }
9 return preg_match($pattern, $subject, $matches, $flags, $offset);
10 }
11 }
12 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNInfo')) :
5 class PTNInfo {
6 public $settings;
7 public $config;
8 public $plugname = 'pantheon';
9 public $brandname = 'Pantheon Migrate';
10 public $badgeinfo = 'ptnbadge';
11 public $ip_header_option = 'ptnipheader';
12 public $brand_option = 'ptnbrand';
13 public $version = '5.25';
14 public $webpage = 'https://pantheon.io';
15 public $appurl = 'https://migrate.blogvault.net';
16 public $slug = 'bv-pantheon-migration/pantheon.php';
17 public $plug_redirect = 'ptnredirect';
18 public $logo = '../img/logo.png';
19 public $brand_icon = '/img/icon.png';
20 public $services_option_name = 'BVSERVICESOPTIONNAME';
21 public $author = 'Pantheon';
22 public $title = 'Pantheon Migration';
23
24 const DB_VERSION = '4';
25
26 public function __construct($settings) {
27 $this->settings = $settings;
28 $this->config = $this->settings->getOption($this->services_option_name);
29 }
30
31 public function getCurrentDBVersion() {
32 $bvconfig = $this->config;
33 if ($bvconfig && array_key_exists('db_version', $bvconfig)) {
34 return $bvconfig['db_version'];
35 }
36 return false;
37 }
38
39 public function hasValidDBVersion() {
40 return PTNInfo::DB_VERSION === $this->getCurrentDBVersion();
41 }
42
43 public static function getRequestID() {
44 if (!defined("BV_REQUEST_ID")) {
45 define("BV_REQUEST_ID", uniqid(mt_rand()));
46 }
47 return BV_REQUEST_ID;
48 }
49
50 public function canSetCWBranding() {
51 if (PTNWPSiteInfo::isCWServer()) {
52
53 $bot_protect_accounts = PTNAccount::accountsByType($this->settings, 'botprotect');
54 if (sizeof($bot_protect_accounts) >= 1)
55 return true;
56
57 $bot_protect_accounts = PTNAccount::accountsByPattern($this->settings, 'email', '/@cw_user\.com$/');
58 if (sizeof($bot_protect_accounts) >= 1)
59 return true;
60 }
61
62 return false;
63 }
64
65 public function getBrandInfo() {
66 return $this->settings->getOption($this->brand_option);
67 }
68
69 public function getBrandName() {
70 $brand = $this->getBrandInfo();
71 if (is_array($brand) && array_key_exists('menuname', $brand)) {
72 return $brand['menuname'];
73 }
74
75 return $this->brandname;
76 }
77
78 public function getBrandIcon() {
79 $brand = $this->getBrandInfo();
80 if (is_array($brand) && array_key_exists('brand_icon', $brand)) {
81 return $brand['brand_icon'];
82 }
83 return $this->brand_icon;
84 }
85
86 public function getWatchTime() {
87 $time = $this->settings->getOption('bvwatchtime');
88 return ($time ? $time : 0);
89 }
90
91 public function appUrl() {
92 if (defined('BV_APP_URL')) {
93 return BV_APP_URL;
94 } else {
95 $brand = $this->getBrandInfo();
96 if (is_array($brand) && array_key_exists('appurl', $brand)) {
97 return $brand['appurl'];
98 }
99 return $this->appurl;
100 }
101 }
102
103 public function isActivePlugin() {
104 $expiry_time = time() - (3 * 24 * 3600);
105 return ($this->getWatchTime() > $expiry_time);
106 }
107
108 public function isValidEnvironment(){
109 $bvsiteinfo = new PTNWPSiteInfo();
110 $bvconfig = $this->config;
111
112 if (is_multisite()) {
113 return true;
114 } elseif ($bvconfig && array_key_exists("siteurl_scheme", $bvconfig)) {
115 $siteurl = $bvsiteinfo->siteurl('', $bvconfig["siteurl_scheme"]);
116 if (array_key_exists("abspath", $bvconfig) &&
117 array_key_exists("siteurl", $bvconfig) && !empty($siteurl)) {
118 return ($bvconfig["abspath"] == ABSPATH && $bvconfig["siteurl"] == $siteurl);
119 }
120 }
121 return true;
122 }
123
124 public function isProtectModuleEnabled() {
125 return $this->isServiceActive("protect") && $this->isValidEnvironment();
126 }
127
128 public function isDynSyncModuleEnabled() {
129 if ($this->isServiceActive("dynsync")) {
130 $dynconfig = $this->config['dynsync'];
131 if (array_key_exists('dynplug', $dynconfig) && ($dynconfig['dynplug'] === $this->plugname)) {
132 return true;
133 }
134 }
135 return false;
136 }
137
138 public function isServiceActive($service) {
139 $bvconfig = $this->config;
140 if ($bvconfig && array_key_exists('services', $bvconfig)) {
141 return in_array($service, $bvconfig['services']) && $this->isActivePlugin();
142 }
143 return false;
144 }
145
146 public function isActivateRedirectSet() {
147 return ($this->settings->getOption($this->plug_redirect) === 'yes') ? true : false;
148 }
149
150 public function isMalcare() {
151 return $this->getBrandName() === 'MalCare';
152 }
153
154 public function isBlogvault() {
155 return $this->getBrandName() === 'BlogVault';
156 }
157
158 public function info() {
159 return array(
160 "bvversion" => $this->version,
161 "sha1" => "true",
162 "plugname" => $this->plugname
163 );
164 }
165 }
166 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 /*
3 Plugin Name: Pantheon Migration
4 Plugin URI: https://pantheon.io
5 Description: The easiest way to migrate your site to Pantheon
6 Author: Pantheon
7 Author URI: https://pantheon.io
8 Version: 5.25
9 Network: True
10 */
11
12 /* Copyright 2017 Pantheon Migrate (email : support@blogvault.net)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /* Global response array */
29
30 if (!defined('ABSPATH')) exit;
31 ##OLDWPR##
32
33 require_once dirname( __FILE__ ) . '/wp_settings.php';
34 require_once dirname( __FILE__ ) . '/wp_site_info.php';
35 require_once dirname( __FILE__ ) . '/wp_db.php';
36 require_once dirname( __FILE__ ) . '/wp_api.php';
37 require_once dirname( __FILE__ ) . '/wp_actions.php';
38 require_once dirname( __FILE__ ) . '/info.php';
39 require_once dirname( __FILE__ ) . '/account.php';
40 require_once dirname( __FILE__ ) . '/helper.php';
41 ##WPCACHEMODULE##
42
43
44 $bvsettings = new PTNWPSettings();
45 $bvsiteinfo = new PTNWPSiteInfo();
46 $bvdb = new PTNWPDb();
47
48
49 $bvapi = new PTNWPAPI($bvsettings);
50 $bvinfo = new PTNInfo($bvsettings);
51 $wp_action = new PTNWPAction($bvsettings, $bvsiteinfo, $bvapi);
52
53 register_uninstall_hook(__FILE__, array('PTNWPAction', 'uninstall'));
54 register_activation_hook(__FILE__, array($wp_action, 'activate'));
55 register_deactivation_hook(__FILE__, array($wp_action, 'deactivate'));
56
57 add_action('wp_footer', array($wp_action, 'footerHandler'), 100);
58 add_action('clear_bv_services_config', array($wp_action, 'clear_bv_services_config'));
59 ##SOADDUNINSTALLACTION##
60
61 ##DISABLE_OTHER_OPTIMIZATION_PLUGINS##
62
63 ##WPCLIMODULE##
64 if (is_admin()) {
65 require_once dirname( __FILE__ ) . '/wp_admin.php';
66 $wpadmin = new PTNWPAdmin($bvsettings, $bvsiteinfo);
67 add_action('admin_init', array($wpadmin, 'initHandler'));
68 add_filter('all_plugins', array($wpadmin, 'initBranding'));
69 add_filter('plugin_row_meta', array($wpadmin, 'hidePluginDetails'), 10, 2);
70 ##HEALTH_INFO_HOOK##
71 if ($bvsiteinfo->isMultisite()) {
72 add_action('network_admin_menu', array($wpadmin, 'menu'));
73 } else {
74 add_action('admin_menu', array($wpadmin, 'menu'));
75 }
76 add_filter('plugin_action_links', array($wpadmin, 'settingsLink'), 10, 2);
77 add_action('admin_head', array($wpadmin, 'removeAdminNotices'), 3);
78 ##ACTIVATEWARNING##
79 add_action('admin_enqueue_scripts', array($wpadmin, 'ptnsecAdminMenu'));
80 ##ALPURGECACHEFUNCTION##
81 ##ALADMINMENU##
82 }
83
84 if ((array_key_exists('bvreqmerge', $_POST)) || (array_key_exists('bvreqmerge', $_GET))) {
85 $_REQUEST = array_merge($_GET, $_POST);
86 }
87
88 if ($bvinfo->hasValidDBVersion()) {
89 ##ACTLOGMODULE##
90 }
91
92 if ((array_key_exists('bvplugname', $_REQUEST)) && ($_REQUEST['bvplugname'] == "pantheon")) {
93 require_once dirname( __FILE__ ) . '/callback/base.php';
94 require_once dirname( __FILE__ ) . '/callback/response.php';
95 require_once dirname( __FILE__ ) . '/callback/request.php';
96 require_once dirname( __FILE__ ) . '/recover.php';
97
98 $pubkey = PTNAccount::sanitizeKey($_REQUEST['pubkey']);
99
100 if (array_key_exists('rcvracc', $_REQUEST)) {
101 $account = PTNRecover::find($bvsettings, $pubkey);
102 } else {
103 $account = PTNAccount::find($bvsettings, $pubkey);
104 }
105
106 $request = new BVCallbackRequest($account, $_REQUEST, $bvsettings);
107 $response = new BVCallbackResponse($request->bvb64cksize);
108
109 if ($request->authenticate() === 1) {
110 ##BVBASEPATH##
111
112 require_once dirname( __FILE__ ) . '/callback/handler.php';
113
114 $params = $request->processParams($_REQUEST);
115 if ($params === false) {
116 $response->terminate($request->corruptedParamsResp());
117 }
118 $request->params = $params;
119 $callback_handler = new BVCallbackHandler($bvdb, $bvsettings, $bvsiteinfo, $request, $account, $response);
120 if ($request->is_afterload) {
121 add_action('wp_loaded', array($callback_handler, 'execute'));
122 } else if ($request->is_admin_ajax) {
123 add_action('wp_ajax_bvadm', array($callback_handler, 'bvAdmExecuteWithUser'));
124 add_action('wp_ajax_nopriv_bvadm', array($callback_handler, 'bvAdmExecuteWithoutUser'));
125 } else {
126 $callback_handler->execute();
127 }
128 } else {
129 $response->terminate($request->authFailedResp());
130 }
131 } else {
132 if ($bvinfo->hasValidDBVersion()) {
133 ##PROTECTMODULE##
134 ##DYNSYNCMODULE##
135 }
136 ##WPAUTOUPDATEBLOCKMODULE##
137 ##HIDEPLUGINUPDATEMODULE##
138 }
...\ No newline at end of file ...\ No newline at end of file
1 -----BEGIN PUBLIC KEY-----
2 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzBFU9onxE3A+NpctmsLi
3 ZvPgj9QV2aBKDKEsRDJw7O0vyI2bpU/aScYJVOkuqlAkyrbZglJA0H+mSf+alvWp
4 pDFO4pyal04uxwwzji9xZ7kCSiA1wrzZFxG4SwZXpwr4qc+XtrnkSakxkyi2V4RX
5 ey42pOvSbSASBs6zcPq28R6LSBDhLNHho2T2qXBf7vKeuE4DR1nNcBlsLnge0x/Q
6 YBey+64b/8cJGyxcceAMV3F5jKI2XkkbyXtE8v+N2K5HjStyMwS3dUa4aoHl8ph4
7 buoEXCu6WFyUF2oMqKmkVAaE8qZQA8Q9Qni7rNHRRjVss5Z+tFOxbDBBSfsYjmvE
8 lQIDAQAB
9 -----END PUBLIC KEY-----
1 === Pantheon Migrations ===
2 Contributors: akshatc, blogvault, getpantheon
3 Tags: pantheon, migration
4 Requires at least: 4.0
5 Tested up to: 6.4
6 Requires PHP: 5.4.0
7 Stable tag: 5.25
8 License: GPLv2 or later
9 License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11 The easiest way to migrate your site to Pantheon
12
13 == Description ==
14
15 Pantheon is a website management platform that is the best place to run your WordPress site — hands down. And migrating your WordPress site doesn’t get any easier than with Pantheon Migrations.
16
17 With this plugin forget the headaches of manually migrating your site. All you need to activate the plugin is administrative access to your WordPress site. Just copy and paste your SFTP credentials from your new Pantheon site to the Pantheon Migrations tab in your WordPress Dashboard and click “migrate”. You can get back to work on other projects, and our migrations team will email you when everything is complete.
18
19 For full instructions please see our [docs page](https://pantheon.io/docs/migrate-wordpress/) on Pantheon Migrations.
20
21 Shout out to [BlogVault.net](https://blogvault.net/) for the development and hand in creating this plugin. By using this plugin you are agreeing to their [Terms of Service](https://blogvault.net/tos)
22
23
24 == Installation ==
25
26 = There are two methods =
27
28 1. Upload `bv-pantheon-migration` to the `/wp-content/plugins/` directory
29 2. Activate the plugin through the 'Plugins' menu in WordPress
30
31 Once the plugin is activated, click on Pantheon Migration in the left side navigation
32
33 Enter the required information:
34
35 `Destination URL:` (this will be your pantheon address you are migrating to, example: http://dev-sitename.pantheon.io)
36 `Machine Token:` (Machine tokens are used to uniquely identify your machine and securely authenticate via Terminus)
37
38 Click the `Migrate` button and you will be redirected to the migration landing page. The plugin will automatically verify your Machine Token and let you know if there are any issues.
39
40 After the migration is complete there will be a button you can click to see the results of your migration and automatically redirected to your Pantheon site URL.
41
42 == Frequently Asked Questions ==
43
44 = 1) I do not have a Pantheon account, can I still use this plugin? =
45
46 No, but signing up for a Pantheon account is free and so is migrating your site with Pantheon Migrations. [Sign up here!](https://pantheon.io/register)
47
48 = 2) What information will the plugin ask for? =
49
50 You will have to provide the plugin your destination url and Machine Token from your Pantheon account. Please read the [Installation section](https://wordpress.org/plugins/bv-pantheon-migration/installation/) for more information on where to find this.
51
52 = 3) Why do you need my email? =
53
54 We require an email address to send you updates on the migration process, notify you of any errors that occur during the migration.
55
56 = 4) Is Multisite supported with this plugin =
57
58 Not yet, Pantheon is currently working on testing the support of Multisite on our platform but it's still too soon. We will update this section when it's available.
59
60 = 5) How long does it take to migrate a website? =
61
62 This can range anywhere from 30 minutes to several hours depending on the size of the website. On average, migrations to Pantheon take about 1 hour.
63
64 = 6) Can I migrate a site from WordPress.com? =
65
66 Currently you can only migrate a self hosted WordPress installation, the plugin does not support migrating from WordPress.com.
67
68 = 7) What happens if I run into an error after the migration is complete? =
69
70 We are always wanting to assist and help out in any way that we can. If you encounter any type of issue please use the support section of our plugin. [Click here](https://wordpress.org/support/plugin/bv-pantheon-migration/) to file an issue. `This section is monitored daily.`
71
72 = 8) Do I need to leave the window open while the migration is processing? =
73
74 No, that's the beauty of this plugin. It runs on a SAAS based technology and a secure web address that runs everything in the background. Once you start the migration you can close the window at any time and come back to it later while it's still running, no need to wait for hours. You will also receive an email once the migration has completed.
75
76 == Screenshots ==
77
78 1. Accessing your SFTP credentials within Pantheon
79 2. Adding information to the Pantheon Migrations plugin
80
81 == Changelog ==
82 = 5.25 =
83 * Bug fix get_admin_url
84
85 = 5.24 =
86 * SHA256 Support
87 * Stream Improvements
88
89 = 5.22 =
90 * Code Improvements
91 * Reduced Memory Footprint
92
93 = 5.16 =
94 * Bug Fixes
95
96 = 5.15 =
97 * Upgraded Authentication
98
99 = 5.05 =
100 * Code Improvements for PHP 8.2 compatibility
101 * Site Health BugFix
102
103 = 4.97 =
104 * Code Improvements
105 * Sync Improvements
106 * Code Cleanup
107 * Bug Fixes
108
109 = 4.78 =
110 * Better handling for plugin, theme infos
111 * Sync Improvements
112
113 = 4.69 =
114 * Improved network call efficiency for site info callbacks.
115
116 = 4.68 =
117 * Removing use of constants for arrays for PHP 5.4 support.
118 * Post type fetch improvement.
119
120 = 4.65 =
121 * Robust handling of requests params.
122 * Callback wing versioning.
123
124 = 4.62 =
125 * MultiTable Sync in single callback functionality added.
126 * Improved host info
127 * Fixed services data fetch bug
128 * Fixed account listing bug in wp-admin
129
130 = 4.58 =
131 * Better Handling of error message from Server on signup
132
133 = 4.35 =
134 * Improved scanfiles and filelist api
135
136 = 4.31 =
137 * Fetching Mysql Version
138 * Robust data fetch APIs
139 * Core plugin changes
140 * Sanitizing incoming params
141
142 = 3.4 =
143 * Plugin branding fixes
144
145 = 3.2 =
146 * Updating account authentication struture
147
148 = 3.1 =
149 * Adding params validation
150 * Adding support for custom user tables
151
152 = 2.1 =
153 * Restructuring classes
154
155 = 1.88 =
156 * Callback improvements
157
158 = 1.86 =
159 * Updating tested upto 5.1
160
161 = 1.84 =
162 * Disable form on submit
163
164 = 1.82 =
165 * Updating tested upto 5.0
166
167 = 1.77 =
168 * Adding function_exists for getmyuid and get_current_user functions
169
170 = 1.76 =
171 * Removing create_funtion for PHP 7.2 compatibility
172
173 = 1.72 =
174 * Adding Misc Callback
175
176 = 1.71 =
177 * Adding logout functionality in the plugin
178
179 = 1.69 =
180 * Adding support for chunked base64 encoding
181
182 = 1.68 =
183 * Updating upload rows
184
185 = 1.66 =
186 * Updating TOS and privacy policies
187
188 = 1.64 =
189 * Bug fixes for lp and fw
190
191 = 1.62 =
192 * SSL support in plugin for API calls
193 * Adding support for plugin branding
194
195 = 1.44 =
196 * Removed bv_manage_site
197 * Updated asym_key
198
199 = 1.41 =
200 * Better integrity checking
201 * Woo Commerce Dynamic sync support
202
203 = 1.40 =
204 * Manage sites straight from BlogVault dashboard
205
206 = 1.31 =
207 * Changing dynamic backups to be pull-based
208
209 = 1.30 =
210 * Using dbsig based authenticatation
211
212 = 1.22 =
213 * Adding support for GLOB based directory listings
214 * Adding support for Machine Tokens instead of SFTP details
215
216 = 1.21 =
217 * Adding support for PHP 5 style constructors
218
219 = 1.20 =
220 * Adding DB Signature and Server Signature to uniquely identify a site
221 * Adding the stats api to the WordPress Backup plugin.
222 * Sending tablename/rcount as part of the callback
223
224 = 1.17 =
225 * Add support for repair table so that the backup plugin itself can be used to repair tables without needing PHPMyAdmin access
226 * Making the plugin to be available network wide.
227 * Adding support for 401 Auth checks on the source or destination
228
229 = 1.16 =
230 * Improving the Base64 Decode functionality so that it is extensible for any parameter in the future and backups can be completed for any site
231 * Separating out callbacks gettablecreate and getrowscount to make the backups more modular
232 * The plugin will now automatically ping the server once a day. This will ensure that we know if we are not doing the backup of a site where the plugin is activated.
233 * Use SHA1 for authentication instead of MD5
234
235 = 1.15 =
236 * First release of Pantheon Plugin
1 <?php
2 if (!defined('ABSPATH')) exit;
3 if (!class_exists('PTNRecover')) :
4 class PTNRecover {
5 public static $default_secret_key = 'bvSecretKey';
6
7 public static function defaultSecret($settings) {
8 $secret = self::getDefaultSecret($settings);
9 if (empty($secret)) {
10 $secret = PTNAccount::randString(32);
11 self::updateDefaultSecret($settings, $secret);
12 }
13 return $secret;
14 }
15
16 public static function deleteDefaultSecret($settings) {
17 $settings->deleteOption(self::$default_secret_key);
18 }
19
20 public static function getDefaultSecret($settings) {
21 return $settings->getOption(self::$default_secret_key);
22 }
23
24 public static function updateDefaultSecret($settings, $secret) {
25 $settings->updateOption(self::$default_secret_key, $secret);
26 }
27
28 public static function validate($pubkey) {
29 if ($pubkey && strlen($pubkey) >= 32) {
30 return true;
31 } else {
32 return false;
33 }
34 }
35
36 public static function find($settings, $pubkey) {
37 if (!self::validate($pubkey)) {
38 return null;
39 }
40 $secret = self::getDefaultSecret($settings);
41 if (!empty($secret) && (strlen($secret) >= 32)) {
42 $account = new PTNAccount($settings, $pubkey, $secret);
43 }
44 return $account;
45 }
46 }
47 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPAction')) :
5 class PTNWPAction {
6 public $settings;
7 public $siteinfo;
8 public $bvinfo;
9 public $bvapi;
10
11 public function __construct($settings, $siteinfo, $bvapi) {
12 $this->settings = $settings;
13 $this->siteinfo = $siteinfo;
14 $this->bvapi = $bvapi;
15 $this->bvinfo = new PTNInfo($settings);
16 }
17
18 public function activate() {
19 if (!isset($_REQUEST['blogvaultkey'])) {
20 ##BVKEYSLOCATE##
21 }
22 if (PTNAccount::isConfigured($this->settings)) {
23 /* This informs the server about the activation */
24 $info = array();
25 $this->siteinfo->basic($info);
26 $this->bvapi->pingbv('/bvapi/activate', $info);
27 } else {
28 PTNAccount::setup($this->settings);
29 }
30 }
31
32 public function deactivate() {
33 $info = array();
34 $this->siteinfo->basic($info);
35 ##DISABLECACHE##
36 $this->bvapi->pingbv('/bvapi/deactivate', $info);
37 }
38
39 public static function uninstall() {
40 ##CLEARPTCONFIG##
41 ##CLEARIPSTORE##
42 ##CLEARDYNSYNCCONFIG##
43 ##CLEARCACHECONFIG##
44 do_action('clear_bv_services_config');
45 }
46
47 public function clear_bv_services_config() {
48 $this->settings->deleteOption($this->bvinfo->services_option_name);
49 }
50
51 ##SOUNINSTALLFUNCTION##
52
53 public function footerHandler() {
54 $bvfooter = $this->settings->getOption($this->bvinfo->badgeinfo);
55 if ($bvfooter) {
56 echo '<div style="max-width:150px;min-height:70px;margin:0 auto;text-align:center;position:relative;">
57 <a href='.esc_url($bvfooter['badgeurl']).' target="_blank" ><img src="'.esc_url(plugins_url($bvfooter['badgeimg'], __FILE__)).'" alt="'.esc_attr($bvfooter['badgealt']).'" /></a></div>';
58 }
59 }
60 }
61 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPAdmin')) :
5 class PTNWPAdmin {
6 public $settings;
7 public $siteinfo;
8 public $bvinfo;
9 public $bvapi;
10
11 function __construct($settings, $siteinfo, $bvapi = null) {
12 $this->settings = $settings;
13 $this->siteinfo = $siteinfo;
14 $this->bvapi = $bvapi;
15 $this->bvinfo = new PTNInfo($this->settings);
16 }
17
18 public function mainUrl($_params = '') {
19 if (function_exists('network_admin_url')) {
20 return network_admin_url('admin.php?page='.$this->bvinfo->plugname.$_params);
21 } else {
22 return admin_url('admin.php?page='.$this->bvinfo->plugname.$_params);
23 }
24 }
25
26 function removeAdminNotices() {
27 if (array_key_exists('page', $_REQUEST) && $_REQUEST['page'] == $this->bvinfo->plugname) {
28 remove_all_actions('admin_notices');
29 remove_all_actions('all_admin_notices');
30 }
31 }
32
33 public function initHandler() {
34 if (!current_user_can('activate_plugins'))
35 return;
36
37 if ($this->bvinfo->isActivateRedirectSet()) {
38 $this->settings->updateOption($this->bvinfo->plug_redirect, 'no');
39 wp_redirect($this->mainUrl());
40 }
41 }
42
43 public function menu() {
44 $brand = $this->bvinfo->getBrandInfo();
45 if (!is_array($brand) || (!array_key_exists('hide', $brand) && !array_key_exists('hide_from_menu', $brand))) {
46 $bname = $this->bvinfo->getBrandName();
47 $icon = $this->bvinfo->getBrandIcon();
48 add_menu_page($bname, $bname, 'manage_options', $this->bvinfo->plugname,
49 array($this, 'adminPage'), plugins_url($icon, __FILE__ ));
50 }
51 }
52
53 public function hidePluginDetails($plugin_metas, $slug) {
54 $brand = $this->bvinfo->getBrandInfo();
55 $bvslug = $this->bvinfo->slug;
56
57 if ($slug === $bvslug && is_array($brand) && array_key_exists('hide_plugin_details', $brand)) {
58 foreach ($plugin_metas as $pluginKey => $pluginValue) {
59 if (strpos($pluginValue, sprintf('>%s<', translate('View details')))) {
60 unset($plugin_metas[$pluginKey]);
61 break;
62 }
63 }
64 }
65 return $plugin_metas;
66 }
67
68 public function settingsLink($links, $file) {
69 if ( $file == plugin_basename( dirname(__FILE__).'/pantheon.php' ) ) {
70 $links[] = '<a href="'.$this->mainUrl().'">'.__( 'Settings' ).'</a>';
71 }
72 return $links;
73 }
74
75 public function ptnsecAdminMenu($hook) {
76 if ($hook === 'toplevel_page_pantheon') {
77 wp_enqueue_style( 'ptnsurface', plugins_url( 'css/style.css', __FILE__));
78 wp_enqueue_style('ptnsurface');
79 }
80 }
81
82 public function getPluginLogo() {
83 $brand = $this->bvinfo->getBrandInfo();
84 if ($brand && array_key_exists('logo', $brand)) {
85 return $brand['logo'];
86 }
87 return $this->bvinfo->logo;
88 }
89
90 public function getWebPage() {
91 $brand = $this->bvinfo->getBrandInfo();
92 if ($brand && array_key_exists('webpage', $brand)) {
93 return $brand['webpage'];
94 }
95 return $this->bvinfo->webpage;
96 }
97
98 public function siteInfoTags() {
99 require_once dirname( __FILE__ ) . '/recover.php';
100 $secret = PTNRecover::defaultSecret($this->settings);
101 $public = PTNAccount::getApiPublicKey($this->settings);
102 $tags = "<input type='hidden' name='url' value='".esc_attr($this->siteinfo->wpurl())."'/>\n".
103 "<input type='hidden' name='homeurl' value='".esc_attr($this->siteinfo->homeurl())."'/>\n".
104 "<input type='hidden' name='siteurl' value='".esc_attr($this->siteinfo->siteurl())."'/>\n".
105 "<input type='hidden' name='dbsig' value='".esc_attr($this->siteinfo->dbsig(false))."'/>\n".
106 "<input type='hidden' name='plug' value='".esc_attr($this->bvinfo->plugname)."'/>\n".
107 "<input type='hidden' name='adminurl' value='".esc_attr($this->mainUrl())."'/>\n".
108 "<input type='hidden' name='bvversion' value='".esc_attr($this->bvinfo->version)."'/>\n".
109 "<input type='hidden' name='serverip' value='".esc_attr($_SERVER["SERVER_ADDR"])."'/>\n".
110 "<input type='hidden' name='abspath' value='".esc_attr(ABSPATH)."'/>\n".
111 "<input type='hidden' name='secret' value='".esc_attr($secret)."'/>\n".
112 "<input type='hidden' name='public' value='".esc_attr($public)."'/>\n";
113 return $tags;
114 }
115
116 public function activateWarning() {
117 global $hook_suffix;
118 if (!PTNAccount::isConfigured($this->settings) && $hook_suffix == 'index.php' ) {
119 ?>
120 <div id="message" class="updated" style="padding: 8px; font-size: 16px; background-color: #dff0d8">
121 <a class="button-primary" href="<?php echo esc_url($this->mainUrl()); ?>">Activate Pantheon</a>
122 &nbsp;&nbsp;&nbsp;<b>Almost Done:</b> Activate your Pantheon account to migrate your site.
123 </div>
124 <?php
125 }
126 }
127
128 public function adminPage() {
129 require_once dirname( __FILE__ ) . '/admin/main_page.php';
130 }
131
132 public function initBranding($plugins) {
133 $slug = $this->bvinfo->slug;
134
135 if (!is_array($plugins) || !isset($slug, $plugins)) {
136 return $plugins;
137 }
138
139 $brand = $this->bvinfo->getBrandInfo();
140 if (is_array($brand)) {
141 if (array_key_exists('hide', $brand)) {
142 unset($plugins[$slug]);
143 } else {
144 if (array_key_exists('name', $brand)) {
145 $plugins[$slug]['Name'] = $brand['name'];
146 }
147 if (array_key_exists('title', $brand)) {
148 $plugins[$slug]['Title'] = $brand['title'];
149 }
150 if (array_key_exists('description', $brand)) {
151 $plugins[$slug]['Description'] = $brand['description'];
152 }
153 if (array_key_exists('authoruri', $brand)) {
154 $plugins[$slug]['AuthorURI'] = $brand['authoruri'];
155 }
156 if (array_key_exists('author', $brand)) {
157 $plugins[$slug]['Author'] = $brand['author'];
158 }
159 if (array_key_exists('authorname', $brand)) {
160 $plugins[$slug]['AuthorName'] = $brand['authorname'];
161 }
162 if (array_key_exists('pluginuri', $brand)) {
163 $plugins[$slug]['PluginURI'] = $brand['pluginuri'];
164 }
165 }
166 }
167 return $plugins;
168 }
169 }
170 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPAPI')) :
5 class PTNWPAPI {
6 public $settings;
7
8 public function __construct($settings) {
9 $this->settings = $settings;
10 }
11
12 public function pingbv($method, $body, $public = false) {
13 if ($public) {
14 return $this->do_request($method, $body, $public);
15 } else {
16 $api_public_key = $this->settings->getOption('bvApiPublic');
17 if (!empty($api_public_key) && (strlen($api_public_key) >= 32)) {
18 return $this->do_request($method, $body, $api_public_key);
19 }
20 }
21 }
22
23 public function do_request($method, $body, $pubkey) {
24 $account = PTNAccount::find($this->settings, $pubkey);
25 if (isset($account)) {
26 $url = $account->authenticatedUrl($method);
27 return $this->http_request($url, $body);
28 }
29 }
30
31 public function http_request($url, $body, $headers = array()) {
32 $_body = array(
33 'method' => 'POST',
34 'timeout' => 15,
35 'body' => $body
36 );
37 if (!empty($headers)) {
38 $_body['headers'] = $headers;
39 }
40 return wp_remote_post($url, $_body);
41 }
42 }
43 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPDb')) :
5
6 class PTNWPDb {
7 public function dbprefix() {
8 global $wpdb;
9 $prefix = $wpdb->base_prefix ? $wpdb->base_prefix : $wpdb->prefix;
10 return $prefix;
11 }
12
13 public function prepare($query, $args) {
14 global $wpdb;
15 return $wpdb->prepare($query, $args);
16 }
17
18 public function getSiteId() {
19 global $wpdb;
20 return $wpdb->siteid;
21 }
22
23 public function getResult($query, $obj = ARRAY_A) {
24 global $wpdb;
25 return $wpdb->get_results($query, $obj);
26 }
27
28 public function query($query) {
29 global $wpdb;
30 return $wpdb->query($query);
31 }
32
33 public function getVar($query, $col = 0, $row = 0) {
34 global $wpdb;
35 return $wpdb->get_var($query, $col, $row);
36 }
37
38 public function getCol($query, $col = 0) {
39 global $wpdb;
40 return $wpdb->get_col($query, $col);
41 }
42
43 public function tableName($table) {
44 return $table[0];
45 }
46
47 public function showTables() {
48 $tables = $this->getResult("SHOW TABLES", ARRAY_N);
49 return array_map(array($this, 'tableName'), $tables);
50 }
51
52
53 public function showTableStatus() {
54 return $this->getResult("SHOW TABLE STATUS");
55 }
56
57 public function tableKeys($table) {
58 return $this->getResult("SHOW KEYS FROM $table;");
59 }
60
61 public function showDbVariables($variable) {
62 $variables = $this->getResult("Show variables like '%$variable%' ;");
63 $result = array();
64 foreach ($variables as $variable) {
65 $result[$variable["Variable_name"]] = $variable["Value"];
66 }
67 return $result;
68 }
69
70 public function describeTable($table) {
71 return $this->getResult("DESCRIBE $table;");
72 }
73
74 public function showTableIndex($table) {
75 return $this->getResult("SHOW INDEX FROM $table");
76 }
77
78 public function checkTable($table, $type) {
79 return $this->getResult("CHECK TABLE $table $type;");
80 }
81
82 public function repairTable($table) {
83 return $this->getResult("REPAIR TABLE $table;");
84 }
85
86 public function showTableCreate($table) {
87 return $this->getVar("SHOW CREATE TABLE $table;", 1);
88 }
89
90 public function rowsCount($table) {
91 $count = $this->getVar("SELECT COUNT(*) FROM $table;");
92 return intval($count);
93 }
94
95 public function createTable($query, $name, $usedbdelta = false) {
96 $table = $this->getBVTable($name);
97 if (!$this->isTablePresent($table)) {
98 if ($usedbdelta) {
99 if (!function_exists('dbDelta'))
100 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
101 dbDelta($query);
102 } else {
103 $this->query($query);
104 }
105 }
106 return $this->isTablePresent($table);
107 }
108
109 public function createTables($tables, $usedbdelta = false) {
110 $result = array();
111 foreach ($tables as $table => $query) {
112 $result[$table] = $this->createTable($query, $table, $usedbdelta);
113 }
114 return $result;
115 }
116
117 public function alterBVTable($query, $name) {
118 $resp = false;
119 $table = $this->getBVTable($name);
120 if ($this->isTablePresent($table)) {
121 $resp = $this->query($query);
122 }
123 return $resp;
124 }
125
126 public function alterTables($tables) {
127 $result = array();
128 foreach ($tables as $table => $query) {
129 $result[$table] = $this->alterBVTable($query, $table);
130 }
131 return $result;
132 }
133
134 public function getTableContent($table, $fields = '*', $filter = '', $limit = 0, $offset = 0) {
135 $query = "SELECT $fields from $table $filter";
136 if ($limit > 0)
137 $query .= " LIMIT $limit";
138 if ($offset > 0)
139 $query .= " OFFSET $offset";
140 $rows = $this->getResult($query);
141 return $rows;
142 }
143
144 public function isTablePresent($table) {
145 return ($this->getVar("SHOW TABLES LIKE '$table'") === $table);
146 }
147
148 public function getCharsetCollate() {
149 global $wpdb;
150 return $wpdb->get_charset_collate();
151 }
152
153 public function getWPTable($name) {
154 return ($this->dbprefix() . $name);
155 }
156
157 public function getBVTable($name) {
158 return ($this->getWPTable("bv_" . $name));
159 }
160
161 public function truncateBVTable($name) {
162 $table = $this->getBVTable($name);
163 if ($this->isTablePresent($table)) {
164 return $this->query("TRUNCATE TABLE $table;");
165 } else {
166 return false;
167 }
168 }
169
170 public function deleteBVTableContent($name, $filter = "") {
171 $table = $this->getBVTable($name);
172 if ($this->isTablePresent($table)) {
173 return $this->query("DELETE FROM $table $filter;");
174 } else {
175 return false;
176 }
177 }
178
179 public function dropBVTable($name) {
180 $table = $this->getBVTable($name);
181 if ($this->isTablePresent($table)) {
182 $this->query("DROP TABLE IF EXISTS $table;");
183 }
184 return !$this->isTablePresent($table);
185 }
186
187 public function dropTables($tables) {
188 $result = array();
189 foreach ($tables as $table) {
190 $result[$table] = $this->dropBVTable($table);
191 }
192 return $result;
193 }
194
195 public function truncateTables($tables) {
196 $result = array();
197 foreach ($tables as $table) {
198 $result[$table] = $this->truncateBVTable($table);
199 }
200 return $result;
201 }
202
203 public function deleteRowsFromtable($name, $count = 1) {
204 $table = $this->getBVTable($name);
205 if ($this->isTablePresent($table)) {
206 return $this->getResult("DELETE FROM $table LIMIT $count;");
207 } else {
208 return false;
209 }
210 }
211
212 public function replaceIntoBVTable($name, $value) {
213 global $wpdb;
214 $table = $this->getBVTable($name);
215 return $wpdb->replace($table, $value);
216 }
217
218 public function tinfo($name) {
219 $result = array();
220 $table = $this->getBVTable($name);
221
222 $result['name'] = $table;
223
224 if ($this->isTablePresent($table)) {
225 $result['exists'] = true;
226 $result['createquery'] = $this->showTableCreate($table);
227 }
228
229 return $result;
230 }
231
232 public function getMysqlVersion() {
233 return $this->showDbVariables('version')['version'];
234 }
235 }
236 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPSettings')) :
5 class PTNWPSettings {
6 public function getOption($key) {
7 $res = false;
8 if (function_exists('get_site_option')) {
9 $res = get_site_option($key, false);
10 }
11 if ($res === false) {
12 $res = get_option($key, false);
13 }
14 return $res;
15 }
16
17 public function deleteOption($key) {
18 if (function_exists('delete_site_option')) {
19 return delete_site_option($key);
20 } else {
21 return delete_option($key);
22 }
23 }
24
25 public function updateOption($key, $value) {
26 if (function_exists('update_site_option')) {
27 return update_site_option($key, $value);
28 } else {
29 return update_option($key, $value);
30 }
31 }
32
33 public function getOptions($options = array()) {
34 $result = array();
35
36 foreach ($options as $option)
37 $result[$option] = $this->getOption($option);
38
39 return $result;
40 }
41
42 public function updateOptions($args) {
43 $result = array();
44
45 foreach ($args as $option => $value) {
46 $this->updateOption($option, $value);
47 $result[$option] = $this->getOption($option);
48 }
49
50 return $result;
51 }
52
53 public function deleteOptions($options) {
54 $result = array();
55
56 foreach ($options as $option) {
57 $this->deleteOption($option);
58 $result[$option] = !$this->getOption($option);
59 }
60
61 return $result;
62 }
63
64 public function setTransient($name, $value, $time) {
65 if (function_exists('set_site_transient')) {
66 return set_site_transient($name, $value, $time);
67 }
68 return false;
69 }
70
71 public function deleteTransient($name) {
72 if (function_exists('delete_site_transient')) {
73 return delete_site_transient($name);
74 }
75 return false;
76 }
77
78 public function getTransient($name) {
79 if (function_exists('get_site_transient')) {
80 return get_site_transient($name);
81 }
82 return false;
83 }
84 }
85 endif;
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('PTNWPSiteInfo')) :
5
6 class PTNWPSiteInfo {
7 public function wpurl() {
8 if (function_exists('network_site_url'))
9 return network_site_url();
10 else
11 return get_bloginfo('wpurl');
12 }
13
14 public function siteurl($path = '', $scheme = null) {
15 if (function_exists('site_url')) {
16 return site_url($path, $scheme);
17 } else {
18 return get_bloginfo('wpurl');
19 }
20 }
21
22 public function homeurl() {
23 if (function_exists('home_url')) {
24 return home_url();
25 } else {
26 return get_bloginfo('url');
27 }
28 }
29
30 public function isMultisite() {
31 if (function_exists('is_multisite') && is_multisite())
32 return true;
33 return false;
34 }
35
36 public function isMainSite() {
37 if (!function_exists('is_main_site' ) || !$this->isMultisite())
38 return true;
39 return is_main_site();
40 }
41
42 public function getMainSiteId() {
43 if (!function_exists('get_main_site_id'))
44 return 0;
45 return get_main_site_id();
46 }
47
48 public function info() {
49 $info = array();
50 $this->basic($info);
51 $info['dbsig'] = $this->dbsig(false);
52 $info["serversig"] = $this->serversig(false);
53 return $info;
54 }
55
56 public function basic(&$info) {
57 $info['wpurl'] = $this->wpurl();
58 $info['siteurl'] = $this->siteurl();
59 $info['homeurl'] = $this->homeurl();
60 if (array_key_exists('SERVER_ADDR', $_SERVER)) {
61 $info['serverip'] = $_SERVER['SERVER_ADDR'];
62 }
63 $info['abspath'] = ABSPATH;
64 }
65
66 public function serversig($full = false) {
67 $sig_param = ABSPATH;
68 if (array_key_exists('SERVER_ADDR', $_SERVER)) {
69 $sig_param = $_SERVER['SERVER_ADDR'].ABSPATH;
70 }
71 $sig = sha1($sig_param);
72 if ($full)
73 return $sig;
74 else
75 return substr($sig, 0, 6);
76 }
77
78 public function dbsig($full = false) {
79 if (defined('DB_USER') && defined('DB_NAME') &&
80 defined('DB_PASSWORD') && defined('DB_HOST')) {
81 $sig = sha1(DB_USER.DB_NAME.DB_PASSWORD.DB_HOST);
82 } else {
83 $sig = "bvnone".PTNAccount::randString(34);
84 }
85 if ($full)
86 return $sig;
87 else
88 return substr($sig, 0, 6);
89 }
90
91 public static function isCWServer() {
92 return isset($_SERVER['cw_allowed_ip']);
93 }
94 }
95 endif;
...\ No newline at end of file ...\ No newline at end of file