pantheon migrate plugin
Showing
29 changed files
with
4536 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('BVDBCallback')) : | ||
| 5 | require_once dirname( __FILE__ ) . '/../streams.php'; | ||
| 6 | |||
| 7 | class BVDBCallback extends BVCallbackBase { | ||
| 8 | public $db; | ||
| 9 | public $stream; | ||
| 10 | public $account; | ||
| 11 | public $siteinfo; | ||
| 12 | |||
| 13 | public static $bvTables = array("fw_requests", "lp_requests", "ip_store"); | ||
| 14 | |||
| 15 | const DB_WING_VERSION = 1.3; | ||
| 16 | |||
| 17 | public function __construct($callback_handler) { | ||
| 18 | $this->db = $callback_handler->db; | ||
| 19 | $this->account = $callback_handler->account; | ||
| 20 | $this->siteinfo = $callback_handler->siteinfo; | ||
| 21 | } | ||
| 22 | |||
| 23 | public function getLastID($pkeys, $end_row) { | ||
| 24 | $last_ids = array(); | ||
| 25 | foreach($pkeys as $pk) { | ||
| 26 | $last_ids[$pk] = $end_row[$pk]; | ||
| 27 | } | ||
| 28 | return $last_ids; | ||
| 29 | } | ||
| 30 | |||
| 31 | public function getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, $include_rows = false) { | ||
| 32 | $tinfo = array(); | ||
| 33 | |||
| 34 | $rows_count = $this->db->rowsCount($table); | ||
| 35 | $result = array('count' => $rows_count); | ||
| 36 | if ($limit == 0) { | ||
| 37 | $limit = $rows_count; | ||
| 38 | } | ||
| 39 | $srows = 1; | ||
| 40 | while (($limit > 0) && ($srows > 0)) { | ||
| 41 | if ($bsize > $limit) | ||
| 42 | $bsize = $limit; | ||
| 43 | $rows = $this->db->getTableContent($table, '*', $filter, $bsize, $offset); | ||
| 44 | $srows = sizeof($rows); | ||
| 45 | $data = array(); | ||
| 46 | $data["table_name"] = $tname; | ||
| 47 | $data["offset"] = $offset; | ||
| 48 | $data["size"] = $srows; | ||
| 49 | $serialized_rows = serialize($rows); | ||
| 50 | $data['md5'] = md5($serialized_rows); | ||
| 51 | $data['length'] = strlen($serialized_rows); | ||
| 52 | array_push($tinfo, $data); | ||
| 53 | if (!empty($pkeys) && $srows > 0) { | ||
| 54 | $end_row = end($rows); | ||
| 55 | $last_ids = $this->getLastID($pkeys, $end_row); | ||
| 56 | $data['last_ids'] = $last_ids; | ||
| 57 | $result['last_ids'] = $last_ids; | ||
| 58 | } | ||
| 59 | if ($include_rows) { | ||
| 60 | $data["rows"] = $rows; | ||
| 61 | $str = serialize($data); | ||
| 62 | $this->stream->writeStream($str); | ||
| 63 | } | ||
| 64 | $offset += $srows; | ||
| 65 | $limit -= $srows; | ||
| 66 | } | ||
| 67 | $result['size'] = $offset; | ||
| 68 | $result['tinfo'] = $tinfo; | ||
| 69 | return $result; | ||
| 70 | } | ||
| 71 | |||
| 72 | public function streamQueryResult($identifier, $query, $pkeys) { | ||
| 73 | $data = array(); | ||
| 74 | $data["identifier"] = $identifier; | ||
| 75 | $data["query"] = $query; | ||
| 76 | |||
| 77 | $data["query_start_time"] = time(); | ||
| 78 | $rows = $this->db->getResult($query); | ||
| 79 | $srows = sizeof($rows); | ||
| 80 | $data["size"] = $srows; | ||
| 81 | $data["query_end_time"] = time(); | ||
| 82 | if (!empty($pkeys) && $srows > 0) { | ||
| 83 | $end_row = end($rows); | ||
| 84 | $last_ids = $this->getLastID($pkeys, $end_row); | ||
| 85 | $data['last_ids'] = $last_ids; | ||
| 86 | } | ||
| 87 | $result = array_merge($data); | ||
| 88 | $data["rows"] = $rows; | ||
| 89 | $serialized_rows = serialize($data); | ||
| 90 | $this->stream->writeStream($serialized_rows); | ||
| 91 | $result['length'] = strlen($serialized_rows); | ||
| 92 | return $result; | ||
| 93 | } | ||
| 94 | |||
| 95 | function getRandomData($totalSize, $bsize) { | ||
| 96 | if ($bsize == 0) { | ||
| 97 | $bsize = $totalSize; | ||
| 98 | } | ||
| 99 | |||
| 100 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
| 101 | $charactersLength = strlen($characters); | ||
| 102 | |||
| 103 | while ($totalSize > 0) { | ||
| 104 | if ($bsize > $totalSize) { | ||
| 105 | $bsize = $totalSize; | ||
| 106 | } | ||
| 107 | |||
| 108 | $randomString = ''; | ||
| 109 | for ($i = 0; $i < $bsize; $i++) { | ||
| 110 | $randomString .= $characters[rand(0, $charactersLength - 1)]; | ||
| 111 | } | ||
| 112 | |||
| 113 | $this->stream->writeStream($randomString); | ||
| 114 | $totalSize -= $bsize; | ||
| 115 | } | ||
| 116 | return array("status" => "true"); | ||
| 117 | } | ||
| 118 | |||
| 119 | public function getCreateTableQueries($tables) { | ||
| 120 | $resp = array(); | ||
| 121 | foreach($tables as $table) { | ||
| 122 | $tname = $table; | ||
| 123 | $resp[$tname] = array("create" => $this->db->showTableCreate($table)); | ||
| 124 | } | ||
| 125 | return $resp; | ||
| 126 | } | ||
| 127 | |||
| 128 | public function checkTables($tables, $type) { | ||
| 129 | $resp = array(); | ||
| 130 | foreach($tables as $table) { | ||
| 131 | $tname = $table; | ||
| 132 | $resp[$tname] = array("status" => $this->db->checkTable($table, $type)); | ||
| 133 | } | ||
| 134 | return $resp; | ||
| 135 | } | ||
| 136 | |||
| 137 | public function describeTables($tables) { | ||
| 138 | $resp = array(); | ||
| 139 | foreach($tables as $table) { | ||
| 140 | $tname = $table; | ||
| 141 | $resp[$tname] = array("description" => $this->db->describeTable($table)); | ||
| 142 | $resp[$tname]["primary_keys_index"] = $this->db->showTableIndex($table); | ||
| 143 | } | ||
| 144 | return $resp; | ||
| 145 | } | ||
| 146 | |||
| 147 | public function checkTablesExist($tables) { | ||
| 148 | $resp = array(); | ||
| 149 | foreach($tables as $table) { | ||
| 150 | $tname = $table; | ||
| 151 | $resp[$tname] = array("tblexists" => $this->db->isTablePresent($table)); | ||
| 152 | } | ||
| 153 | return $resp; | ||
| 154 | } | ||
| 155 | |||
| 156 | public function getTablesRowCount($tables) { | ||
| 157 | $resp = array(); | ||
| 158 | foreach($tables as $table) { | ||
| 159 | $tname = $table; | ||
| 160 | $resp[$tname] = array("count" => $this->db->rowsCount($table)); | ||
| 161 | } | ||
| 162 | return $resp; | ||
| 163 | } | ||
| 164 | |||
| 165 | public function getTablesKeys($tables) { | ||
| 166 | $resp = array(); | ||
| 167 | foreach($tables as $table) { | ||
| 168 | $tname = $table; | ||
| 169 | $resp[$tname] = array("keys" => $this->db->tableKeys($table)); | ||
| 170 | } | ||
| 171 | return $resp; | ||
| 172 | } | ||
| 173 | |||
| 174 | public function multiGetResult($queries) { | ||
| 175 | $resp = array(); | ||
| 176 | foreach($queries as $query) { | ||
| 177 | array_push($resp, $this->db->getResult($query)); | ||
| 178 | } | ||
| 179 | return $resp; | ||
| 180 | } | ||
| 181 | |||
| 182 | public function process($request) { | ||
| 183 | $db = $this->db; | ||
| 184 | $params = $request->params; | ||
| 185 | $stream_init_info = BVStream::startStream($this->account, $request); | ||
| 186 | |||
| 187 | if (array_key_exists('stream', $stream_init_info)) { | ||
| 188 | $this->stream = $stream_init_info['stream']; | ||
| 189 | switch ($request->method) { | ||
| 190 | case "gettbls": | ||
| 191 | $resp = array("tables" => $db->showTables()); | ||
| 192 | break; | ||
| 193 | case "tblstatus": | ||
| 194 | $resp = array("statuses" => $db->showTableStatus()); | ||
| 195 | break; | ||
| 196 | case "tablekeys": | ||
| 197 | $table = $params['table']; | ||
| 198 | $resp = array("table_keys" => $db->tableKeys($table)); | ||
| 199 | break; | ||
| 200 | case "describetable": | ||
| 201 | $table = $params['table']; | ||
| 202 | $resp = array("table_description" => $db->describeTable($table)); | ||
| 203 | $resp["primary_keys_index"] = $db->showTableIndex($table); | ||
| 204 | break; | ||
| 205 | case "checktable": | ||
| 206 | $table = $params['table']; | ||
| 207 | $type = $params['type']; | ||
| 208 | $resp = array("status" => $db->checkTable($table, $type)); | ||
| 209 | break; | ||
| 210 | case "repairtable": | ||
| 211 | $table = $params['table']; | ||
| 212 | $resp = array("status" => $db->repairTable($table)); | ||
| 213 | break; | ||
| 214 | case "gettcrt": | ||
| 215 | $table = $params['table']; | ||
| 216 | $resp = array("create" => $db->showTableCreate($table)); | ||
| 217 | break; | ||
| 218 | case "tblskys": | ||
| 219 | $tables = $params['tables']; | ||
| 220 | $resp = $this->getTablesKeys($tables); | ||
| 221 | break; | ||
| 222 | case "getmlticrt": | ||
| 223 | $tables = $params['tables']; | ||
| 224 | $resp = $this->getCreateTableQueries($tables); | ||
| 225 | break; | ||
| 226 | case "desctbls": | ||
| 227 | $tables = $params['tables']; | ||
| 228 | $resp = $this->describeTables($tables); | ||
| 229 | break; | ||
| 230 | case "mltirwscount": | ||
| 231 | $tables = $params['tables']; | ||
| 232 | $resp = $this->getTablesRowCount($tables); | ||
| 233 | break; | ||
| 234 | case "chktabls": | ||
| 235 | $tables = $params['tables']; | ||
| 236 | $type = $params['type']; | ||
| 237 | $resp = $this->checkTables($tables, $type); | ||
| 238 | break; | ||
| 239 | case "chktablsxist": | ||
| 240 | $tables = $params['tables']; | ||
| 241 | $resp = $this->checkTablesExist($tables); | ||
| 242 | break; | ||
| 243 | case "getrowscount": | ||
| 244 | $table = $params['table']; | ||
| 245 | $resp = array("count" => $db->rowsCount($table)); | ||
| 246 | break; | ||
| 247 | case "gettablecontent": | ||
| 248 | $result = array(); | ||
| 249 | $table = $params['table']; | ||
| 250 | $fields = $params['fields']; | ||
| 251 | $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | ||
| 252 | $limit = intval($params['limit']); | ||
| 253 | $offset = intval($params['offset']); | ||
| 254 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); | ||
| 255 | $result['timestamp'] = time(); | ||
| 256 | $result['tablename'] = $table; | ||
| 257 | $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset); | ||
| 258 | $srows = sizeof($rows); | ||
| 259 | if (!empty($pkeys) && $srows > 0) { | ||
| 260 | $end_row = end($rows); | ||
| 261 | $result['last_ids'] = $this->getLastID($pkeys, $end_row); | ||
| 262 | } | ||
| 263 | $result["rows"] = $rows; | ||
| 264 | $resp = $result; | ||
| 265 | break; | ||
| 266 | case "multitablecontent": | ||
| 267 | $tableParams = $params['table_params']; | ||
| 268 | $resp = array(); | ||
| 269 | foreach($tableParams as $tableParam) { | ||
| 270 | $result = array(); | ||
| 271 | $identifier = $tableParam['identifier']; | ||
| 272 | $table = $tableParam['table']; | ||
| 273 | $tname = $tableParam['tname']; | ||
| 274 | $fields = $tableParam['fields']; | ||
| 275 | $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : ""; | ||
| 276 | $limit = $tableParam['limit']; | ||
| 277 | $offset = $tableParam['offset']; | ||
| 278 | $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array(); | ||
| 279 | $result['timestamp'] = time(); | ||
| 280 | $result['table_name'] = $tname; | ||
| 281 | $rows = $db->getTableContent($table, $fields, $filter, $limit, $offset); | ||
| 282 | $srows = sizeof($rows); | ||
| 283 | if (!empty($pkeys) && $srows > 0) { | ||
| 284 | $end_row = end($rows); | ||
| 285 | $result['last_ids'] = $this->getLastID($pkeys, $end_row); | ||
| 286 | } | ||
| 287 | $result["rows"] = $rows; | ||
| 288 | $result["size"] = $srows; | ||
| 289 | $resp[$identifier] = $result; | ||
| 290 | } | ||
| 291 | break; | ||
| 292 | case "tableinfo": | ||
| 293 | $table = $params['table']; | ||
| 294 | $offset = intval($params['offset']); | ||
| 295 | $limit = intval($params['limit']); | ||
| 296 | $bsize = intval($params['bsize']); | ||
| 297 | $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | ||
| 298 | $tname = $params['tname']; | ||
| 299 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); | ||
| 300 | $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, false); | ||
| 301 | break; | ||
| 302 | case "getmulttables": | ||
| 303 | $result = array(); | ||
| 304 | $tableParams = $params['table_params']; | ||
| 305 | $resp = array(); | ||
| 306 | foreach($tableParams as $tableParam) { | ||
| 307 | $table = $tableParam['table']; | ||
| 308 | $tname = $tableParam['tname']; | ||
| 309 | $filter = (array_key_exists('filter', $tableParam)) ? $tableParam['filter'] : ""; | ||
| 310 | $limit = intval($tableParam['limit']); | ||
| 311 | $offset = intval($tableParam['offset']); | ||
| 312 | $bsize = intval($tableParam['bsize']); | ||
| 313 | $pkeys = (array_key_exists('pkeys', $tableParam)) ? $tableParam['pkeys'] : array(); | ||
| 314 | $resp[$tname] = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true); | ||
| 315 | } | ||
| 316 | break; | ||
| 317 | case "uploadrows": | ||
| 318 | $table = $params['table']; | ||
| 319 | $offset = intval($params['offset']); | ||
| 320 | $limit = intval($params['limit']); | ||
| 321 | $bsize = intval($params['bsize']); | ||
| 322 | $filter = (array_key_exists('filter', $params)) ? $params['filter'] : ""; | ||
| 323 | $tname = $params['tname']; | ||
| 324 | $pkeys = (array_key_exists('pkeys', $params)) ? $params['pkeys'] : array(); | ||
| 325 | $resp = $this->getTableData($table, $tname, $offset, $limit, $bsize, $filter, $pkeys, true); | ||
| 326 | break; | ||
| 327 | case "tblexists": | ||
| 328 | $resp = array("tblexists" => $db->isTablePresent($params['table'])); | ||
| 329 | break; | ||
| 330 | case "crttbl": | ||
| 331 | $usedbdelta = array_key_exists('usedbdelta', $params); | ||
| 332 | $resp = array("crttbl" => $db->createTable($params['query'], $params['table'], $usedbdelta)); | ||
| 333 | break; | ||
| 334 | case "drptbl": | ||
| 335 | $resp = array("drptbl" => $db->dropBVTable($params['table'])); | ||
| 336 | break; | ||
| 337 | case "trttbl": | ||
| 338 | $resp = array("trttbl" => $db->truncateBVTable($params['table'])); | ||
| 339 | break; | ||
| 340 | case "altrtbl": | ||
| 341 | $resp = array("altrtbl" => $db->alterBVTable($params['query'], $params['query'])); | ||
| 342 | break; | ||
| 343 | case "mltigtrslt": | ||
| 344 | $resp = array("mltigtrslt" => $this->multiGetResult($params['queries'])); | ||
| 345 | break; | ||
| 346 | case "mltiqrsstrm": | ||
| 347 | $queries = $params['queries']; | ||
| 348 | $result = array(); | ||
| 349 | foreach ($queries as $qparams) { | ||
| 350 | $identifier = $qparams['identifier']; | ||
| 351 | $query = $qparams['query']; | ||
| 352 | $pkeys = (array_key_exists('pkeys', $qparams)) ? $qparams['pkeys'] : array(); | ||
| 353 | array_push($result, $this->streamQueryResult($identifier, $query, $pkeys)); | ||
| 354 | } | ||
| 355 | $resp = array('mltqrsstrm' => $result); | ||
| 356 | break; | ||
| 357 | case "getrndmdata": | ||
| 358 | $resp = array("getrndmdata" => $this->getRandomData($params['size'], $params['batch_size'])); | ||
| 359 | break; | ||
| 360 | case "tbls": | ||
| 361 | $resp = array(); | ||
| 362 | |||
| 363 | if (array_key_exists('truncate', $params)) | ||
| 364 | $resp['truncate'] = $db->truncateTables($params['truncate']); | ||
| 365 | |||
| 366 | if (array_key_exists('drop', $params)) | ||
| 367 | $resp['drop'] = $db->dropTables($params['drop']); | ||
| 368 | |||
| 369 | if (array_key_exists('create', $params)) | ||
| 370 | $resp['create'] = $db->createTables($params['create']); | ||
| 371 | |||
| 372 | if (array_key_exists('alter', $params)) | ||
| 373 | $resp['alter'] = $db->alterTables($params['alter']); | ||
| 374 | |||
| 375 | break; | ||
| 376 | default: | ||
| 377 | $resp = false; | ||
| 378 | } | ||
| 379 | $end_stream_info = $this->stream->endStream(); | ||
| 380 | if (!empty($end_stream_info) && is_array($resp)) { | ||
| 381 | $resp = array_merge($resp, $end_stream_info); | ||
| 382 | } | ||
| 383 | } else { | ||
| 384 | $resp = $stream_init_info; | ||
| 385 | } | ||
| 386 | return $resp; | ||
| 387 | } | ||
| 388 | } | ||
| 389 | 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('BVFSCallback')) : | ||
| 5 | require_once dirname( __FILE__ ) . '/../streams.php'; | ||
| 6 | |||
| 7 | class BVFSCallback extends BVCallbackBase { | ||
| 8 | public $stream; | ||
| 9 | public $account; | ||
| 10 | |||
| 11 | public static $cwAllowedFiles = array(".htaccess", ".user.ini", "malcare-waf.php"); | ||
| 12 | const FS_WING_VERSION = 1.2; | ||
| 13 | |||
| 14 | public function __construct($callback_handler) { | ||
| 15 | $this->account = $callback_handler->account; | ||
| 16 | } | ||
| 17 | |||
| 18 | function fileStat($relfile, $md5 = false) { | ||
| 19 | $absfile = ABSPATH.$relfile; | ||
| 20 | $fdata = array(); | ||
| 21 | $fdata["filename"] = $relfile; | ||
| 22 | $stats = @stat($absfile); | ||
| 23 | if ($stats) { | ||
| 24 | foreach (preg_grep('#size|uid|gid|mode|mtime#i', array_keys($stats)) as $key ) { | ||
| 25 | $fdata[$key] = $stats[$key]; | ||
| 26 | } | ||
| 27 | if (is_link($absfile)) { | ||
| 28 | $fdata["link"] = @readlink($absfile); | ||
| 29 | } | ||
| 30 | if ($md5 === true && !is_dir($absfile)) { | ||
| 31 | $fdata["md5"] = $this->calculateMd5($absfile, array(), 0, 0, 0); | ||
| 32 | } | ||
| 33 | } else { | ||
| 34 | $fdata["failed"] = true; | ||
| 35 | } | ||
| 36 | return $fdata; | ||
| 37 | } | ||
| 38 | |||
| 39 | function scanFilesUsingGlob($initdir = "./", $offset = 0, $limit = 0, $bsize = 512, $recurse = true, $regex = '{.??,}*') { | ||
| 40 | $i = 0; | ||
| 41 | $dirs = array(); | ||
| 42 | $dirs[] = $initdir; | ||
| 43 | $bfc = 0; | ||
| 44 | $bfa = array(); | ||
| 45 | $current = 0; | ||
| 46 | $abspath = realpath(ABSPATH).'/'; | ||
| 47 | $abslen = strlen($abspath); | ||
| 48 | # XNOTE: $recurse cannot be used directly here | ||
| 49 | while ($i < count($dirs)) { | ||
| 50 | $dir = $dirs[$i]; | ||
| 51 | |||
| 52 | foreach (glob($abspath.$dir.$regex, GLOB_NOSORT | GLOB_BRACE) as $absfile) { | ||
| 53 | $relfile = substr($absfile, $abslen); | ||
| 54 | if (is_dir($absfile) && !is_link($absfile)) { | ||
| 55 | $dirs[] = $relfile."/"; | ||
| 56 | } | ||
| 57 | $current++; | ||
| 58 | if ($offset >= $current) | ||
| 59 | continue; | ||
| 60 | if (($limit != 0) && (($current - $offset) > $limit)) { | ||
| 61 | $i = count($dirs); | ||
| 62 | break; | ||
| 63 | } | ||
| 64 | $bfa[] = $this->fileStat($relfile); | ||
| 65 | $bfc++; | ||
| 66 | if ($bfc == $bsize) { | ||
| 67 | $str = serialize($bfa); | ||
| 68 | $this->stream->writeStream($str); | ||
| 69 | $bfc = 0; | ||
| 70 | $bfa = array(); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | $regex = '{.??,}*'; | ||
| 74 | $i++; | ||
| 75 | if ($recurse == false) | ||
| 76 | break; | ||
| 77 | } | ||
| 78 | if ($bfc != 0) { | ||
| 79 | $str = serialize($bfa); | ||
| 80 | $this->stream->writeStream($str); | ||
| 81 | } | ||
| 82 | return array("status" => "done"); | ||
| 83 | } | ||
| 84 | |||
| 85 | function scanFiles($initdir = "./", $offset = 0, $limit = 0, $bsize = 512, $recurse = true, $md5 = false) { | ||
| 86 | $i = 0; | ||
| 87 | $links = array(); | ||
| 88 | $dirs = array(); | ||
| 89 | $dirs[] = $initdir; | ||
| 90 | $bfc = 0; | ||
| 91 | $bfa = array(); | ||
| 92 | $current = 0; | ||
| 93 | while ($i < count($dirs)) { | ||
| 94 | $dir = $dirs[$i]; | ||
| 95 | $d = @opendir(ABSPATH.$dir); | ||
| 96 | if ($d) { | ||
| 97 | while (($file = readdir($d)) !== false) { | ||
| 98 | if ($file == '.' || $file == '..') { continue; } | ||
| 99 | $relfile = $dir.$file; | ||
| 100 | $absfile = ABSPATH.$relfile; | ||
| 101 | if (is_link($absfile)) { | ||
| 102 | $links[] = $relfile; | ||
| 103 | } | ||
| 104 | if (is_dir($absfile) && !is_link($absfile)) { | ||
| 105 | $dirs[] = $relfile."/"; | ||
| 106 | } | ||
| 107 | $current++; | ||
| 108 | if ($offset >= $current) | ||
| 109 | continue; | ||
| 110 | if (($limit != 0) && (($current - $offset) > $limit)) { | ||
| 111 | $i = count($dirs); | ||
| 112 | break; | ||
| 113 | } | ||
| 114 | $bfa[] = $this->fileStat($relfile, $md5); | ||
| 115 | $bfc++; | ||
| 116 | if ($bfc == $bsize) { | ||
| 117 | $str = serialize($bfa); | ||
| 118 | $this->stream->writeStream($str); | ||
| 119 | $bfc = 0; | ||
| 120 | $bfa = array(); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | closedir($d); | ||
| 124 | } | ||
| 125 | $i++; | ||
| 126 | if ($recurse == false) | ||
| 127 | break; | ||
| 128 | } | ||
| 129 | if ($bfc != 0) { | ||
| 130 | $str = serialize($bfa); | ||
| 131 | $this->stream->writeStream($str); | ||
| 132 | } | ||
| 133 | |||
| 134 | return $links; | ||
| 135 | } | ||
| 136 | |||
| 137 | function calculateMd5($absfile, $fdata, $offset, $limit, $bsize) { | ||
| 138 | if ($offset == 0 && $limit == 0) { | ||
| 139 | $md5 = md5_file($absfile); | ||
| 140 | } else { | ||
| 141 | if ($limit == 0) | ||
| 142 | $limit = $fdata["size"]; | ||
| 143 | if ($offset + $limit < $fdata["size"]) | ||
| 144 | $limit = $fdata["size"] - $offset; | ||
| 145 | $handle = fopen($absfile, "rb"); | ||
| 146 | $ctx = hash_init('md5'); | ||
| 147 | fseek($handle, $offset, SEEK_SET); | ||
| 148 | $dlen = 1; | ||
| 149 | while (($limit > 0) && ($dlen > 0)) { | ||
| 150 | if ($bsize > $limit) | ||
| 151 | $bsize = $limit; | ||
| 152 | $d = fread($handle, $bsize); | ||
| 153 | $dlen = strlen($d); | ||
| 154 | hash_update($ctx, $d); | ||
| 155 | $limit -= $dlen; | ||
| 156 | } | ||
| 157 | fclose($handle); | ||
| 158 | $md5 = hash_final($ctx); | ||
| 159 | } | ||
| 160 | return $md5; | ||
| 161 | } | ||
| 162 | |||
| 163 | function getFilesContent($files, $withContent = true) { | ||
| 164 | $result = array(); | ||
| 165 | foreach ($files as $file) { | ||
| 166 | $fdata = $this->fileStat($file); | ||
| 167 | $absfile = ABSPATH.$file; | ||
| 168 | |||
| 169 | if (is_dir($absfile) && !is_link($absfile)) { | ||
| 170 | $fdata['is_dir'] = true; | ||
| 171 | } else { | ||
| 172 | if (!is_readable($absfile)) { | ||
| 173 | $fdata['error'] = 'file not readable'; | ||
| 174 | } else { | ||
| 175 | if ($withContent === true) { | ||
| 176 | if ($content = file_get_contents($absfile)) { | ||
| 177 | $fdata['content'] = $content; | ||
| 178 | } else { | ||
| 179 | $fdata['error'] = 'unable to read file'; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | $result[$file] = $fdata; | ||
| 186 | } | ||
| 187 | |||
| 188 | return $result; | ||
| 189 | } | ||
| 190 | |||
| 191 | function getFilesStats($files, $offset = 0, $limit = 0, $bsize = 102400, $md5 = false) { | ||
| 192 | $result = array(); | ||
| 193 | foreach ($files as $file) { | ||
| 194 | $fdata = $this->fileStat($file); | ||
| 195 | $absfile = ABSPATH.$file; | ||
| 196 | if (!is_readable($absfile)) { | ||
| 197 | $result["missingfiles"][] = $file; | ||
| 198 | continue; | ||
| 199 | } | ||
| 200 | if ($md5 === true && !is_dir($absfile)) { | ||
| 201 | $fdata["md5"] = $this->calculateMd5($absfile, $fdata, $offset, $limit, $bsize); | ||
| 202 | } | ||
| 203 | $result["stats"][] = $fdata; | ||
| 204 | } | ||
| 205 | return $result; | ||
| 206 | } | ||
| 207 | |||
| 208 | function uploadFiles($files, $offset = 0, $limit = 0, $bsize = 102400) { | ||
| 209 | $result = array(); | ||
| 210 | foreach ($files as $file) { | ||
| 211 | if (!is_readable(ABSPATH.$file)) { | ||
| 212 | $result["missingfiles"][] = $file; | ||
| 213 | continue; | ||
| 214 | } | ||
| 215 | $handle = fopen(ABSPATH.$file, "rb"); | ||
| 216 | if (($handle != null) && is_resource($handle)) { | ||
| 217 | $fdata = $this->fileStat($file); | ||
| 218 | $_limit = $limit; | ||
| 219 | $_bsize = $bsize; | ||
| 220 | if ($_limit == 0) | ||
| 221 | $_limit = $fdata["size"]; | ||
| 222 | if ($offset + $_limit > $fdata["size"]) | ||
| 223 | $_limit = $fdata["size"] - $offset; | ||
| 224 | $fdata["limit"] = $_limit; | ||
| 225 | $sfdata = serialize($fdata); | ||
| 226 | $this->stream->writeStream($sfdata); | ||
| 227 | fseek($handle, $offset, SEEK_SET); | ||
| 228 | $dlen = 1; | ||
| 229 | while (($_limit > 0) && ($dlen > 0)) { | ||
| 230 | if ($_bsize > $_limit) | ||
| 231 | $_bsize = $_limit; | ||
| 232 | $d = fread($handle, $_bsize); | ||
| 233 | $dlen = strlen($d); | ||
| 234 | $this->stream->writeStream($d); | ||
| 235 | $_limit -= $dlen; | ||
| 236 | } | ||
| 237 | fclose($handle); | ||
| 238 | } else { | ||
| 239 | $result["unreadablefiles"][] = $file; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | $result["status"] = "done"; | ||
| 243 | return $result; | ||
| 244 | } | ||
| 245 | |||
| 246 | function process($request) { | ||
| 247 | $params = $request->params; | ||
| 248 | $stream_init_info = BVStream::startStream($this->account, $request); | ||
| 249 | |||
| 250 | if (array_key_exists('stream', $stream_init_info)) { | ||
| 251 | $this->stream = $stream_init_info['stream']; | ||
| 252 | switch ($request->method) { | ||
| 253 | case "scanfilesglob": | ||
| 254 | $initdir = $params['initdir']; | ||
| 255 | $offset = intval($params['offset']); | ||
| 256 | $limit = intval($params['limit']); | ||
| 257 | $bsize = intval($params['bsize']); | ||
| 258 | $regex = $params['regex']; | ||
| 259 | $recurse = true; | ||
| 260 | if (array_key_exists('recurse', $params) && $params["recurse"] == "false") { | ||
| 261 | $recurse = false; | ||
| 262 | } | ||
| 263 | $resp = $this->scanFilesUsingGlob($initdir, $offset, $limit, $bsize, $recurse, $regex); | ||
| 264 | break; | ||
| 265 | case "scanfiles": | ||
| 266 | $links = array(); | ||
| 267 | $dir_options = array(); | ||
| 268 | if (array_key_exists('dir_options', $params)) { | ||
| 269 | $dir_options = $params['dir_options']; | ||
| 270 | } | ||
| 271 | $bsize = intval($params['bsize']); | ||
| 272 | foreach($dir_options as $option) { | ||
| 273 | $dir = $option['dir']; | ||
| 274 | $offset = intval($option['offset']); | ||
| 275 | $limit = intval($option['limit']); | ||
| 276 | $recurse = true; | ||
| 277 | if (array_key_exists('recurse', $option) && $option["recurse"] == "false") { | ||
| 278 | $recurse = false; | ||
| 279 | } | ||
| 280 | $md5 = true; | ||
| 281 | if (array_key_exists('md5', $option) && $option["md5"] == "false") { | ||
| 282 | $md5 = false; | ||
| 283 | } | ||
| 284 | |||
| 285 | $_links = $this->scanFiles($dir, $offset, $limit, $bsize, $recurse, $md5); | ||
| 286 | $links = array_merge($links, $_links); | ||
| 287 | } | ||
| 288 | $resp = array("status" => "done", "links" => $links); | ||
| 289 | break; | ||
| 290 | case "getfilesstats": | ||
| 291 | $files = $params['files']; | ||
| 292 | $offset = intval($params['offset']); | ||
| 293 | $limit = intval($params['limit']); | ||
| 294 | $bsize = intval($params['bsize']); | ||
| 295 | $md5 = false; | ||
| 296 | if (array_key_exists('md5', $params)) { | ||
| 297 | $md5 = true; | ||
| 298 | } | ||
| 299 | $resp = $this->getFilesStats($files, $offset, $limit, $bsize, $md5); | ||
| 300 | break; | ||
| 301 | case "sendmanyfiles": | ||
| 302 | $files = $params['files']; | ||
| 303 | $offset = intval($params['offset']); | ||
| 304 | $limit = intval($params['limit']); | ||
| 305 | $bsize = intval($params['bsize']); | ||
| 306 | $resp = $this->uploadFiles($files, $offset, $limit, $bsize); | ||
| 307 | break; | ||
| 308 | case "filelist": | ||
| 309 | $dir_options = array(); | ||
| 310 | if (array_key_exists('dir_options', $params)) { | ||
| 311 | $dir_options = $params['dir_options']; | ||
| 312 | } | ||
| 313 | if (array_key_exists('chdir', $params)) { | ||
| 314 | chdir(ABSPATH); | ||
| 315 | } | ||
| 316 | $resp = array(); | ||
| 317 | foreach($dir_options as $options) { | ||
| 318 | $glob_option = 0; | ||
| 319 | if (array_key_exists('onlydir', $options)) { | ||
| 320 | $glob_option = GLOB_ONLYDIR; | ||
| 321 | } | ||
| 322 | |||
| 323 | $regexes = array("*", ".*"); | ||
| 324 | if (array_key_exists('regex', $options)) { | ||
| 325 | $regexes = array($options['regex']); | ||
| 326 | } | ||
| 327 | |||
| 328 | $md5 = false; | ||
| 329 | if (array_key_exists('md5', $options)) { | ||
| 330 | $md5 = $options['md5']; | ||
| 331 | } | ||
| 332 | |||
| 333 | $directoryList = array(); | ||
| 334 | |||
| 335 | foreach($regexes as $regex) { | ||
| 336 | $directoryList = array_merge($directoryList, glob($options['dir'].$regex, $glob_option)); | ||
| 337 | } | ||
| 338 | $resp[$options['dir']] = $this->getFilesStats($directoryList, 0, 0, 0, $md5); | ||
| 339 | } | ||
| 340 | break; | ||
| 341 | case "dirsexists": | ||
| 342 | $resp = array(); | ||
| 343 | $dirs = $params['dirs']; | ||
| 344 | |||
| 345 | foreach ($dirs as $dir) { | ||
| 346 | $path = ABSPATH.$dir; | ||
| 347 | if (file_exists($path) && is_dir($path) && !is_link($path)) { | ||
| 348 | $resp[$dir] = true; | ||
| 349 | } else { | ||
| 350 | $resp[$dir] = false; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | $resp["status"] = "Done"; | ||
| 355 | break; | ||
| 356 | case "gtfilescntent": | ||
| 357 | $files = $params['files']; | ||
| 358 | $withContent = array_key_exists('withcontent', $params) ? $params['withcontent'] : true; | ||
| 359 | $resp = array("files_content" => $this->getFilesContent($files, $withContent)); | ||
| 360 | break; | ||
| 361 | case "gtfls": | ||
| 362 | $resp = array(); | ||
| 363 | |||
| 364 | if (array_key_exists('get_files_content', $params)) { | ||
| 365 | $args = $params['get_files_content']; | ||
| 366 | $with_content = array_key_exists('withcontent', $args) ? $args['withcontent'] : true; | ||
| 367 | $resp['get_files_content'] = $this->getFilesContent($args['files'], $with_content); | ||
| 368 | } | ||
| 369 | |||
| 370 | if (array_key_exists('get_files_stats', $params)) { | ||
| 371 | $args = $params['get_files_stats']; | ||
| 372 | $md5 = array_key_exists('md5', $args) ? $args['md5'] : false; | ||
| 373 | $stats = $this->getFilesStats( | ||
| 374 | $args['files'], $args['offset'], $args['limit'], $args['bsize'], $md5 | ||
| 375 | ); | ||
| 376 | |||
| 377 | $result = array(); | ||
| 378 | |||
| 379 | if (array_key_exists('stats', $stats)) { | ||
| 380 | $result['stats'] = array(); | ||
| 381 | foreach ($stats['stats'] as $stat) { | ||
| 382 | $result['stats'][$stat['filename']] = $stat; | ||
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | if (array_key_exists('missingfiles', $stats)) { | ||
| 387 | $result['missingfiles'] = $stats['missingfiles']; | ||
| 388 | } | ||
| 389 | |||
| 390 | $resp['get_files_stats'] = $result; | ||
| 391 | } | ||
| 392 | |||
| 393 | break; | ||
| 394 | default: | ||
| 395 | $resp = false; | ||
| 396 | } | ||
| 397 | $end_stream_info = $this->stream->endStream(); | ||
| 398 | if (!empty($end_stream_info) && is_array($resp)) { | ||
| 399 | $resp = array_merge($resp, $end_stream_info); | ||
| 400 | } | ||
| 401 | } else { | ||
| 402 | $resp = $stream_init_info; | ||
| 403 | } | ||
| 404 | return $resp; | ||
| 405 | } | ||
| 406 | } | ||
| 407 | 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('BVInfoCallback')) : | ||
| 5 | |||
| 6 | class BVInfoCallback extends BVCallbackBase { | ||
| 7 | public $db; | ||
| 8 | public $settings; | ||
| 9 | public $siteinfo; | ||
| 10 | public $bvinfo; | ||
| 11 | public $bvapi; | ||
| 12 | |||
| 13 | const INFO_WING_VERSION = 1.8; | ||
| 14 | |||
| 15 | public function __construct($callback_handler) { | ||
| 16 | $this->db = $callback_handler->db; | ||
| 17 | $this->siteinfo = $callback_handler->siteinfo; | ||
| 18 | $this->settings = $callback_handler->settings; | ||
| 19 | $this->bvinfo = new PTNInfo($this->settings); | ||
| 20 | $this->bvapi = new PTNWPAPI($this->settings); | ||
| 21 | } | ||
| 22 | |||
| 23 | public function getPosts($post_type, $count = 5) { | ||
| 24 | $output = array(); | ||
| 25 | $args = array('numberposts' => $count, 'post_type' => $post_type); | ||
| 26 | $posts = get_posts($args); | ||
| 27 | $keys = array('post_title', 'guid', 'ID', 'post_date'); | ||
| 28 | $result = array(); | ||
| 29 | foreach ($posts as $post) { | ||
| 30 | $pdata = array(); | ||
| 31 | $post_array = get_object_vars($post); | ||
| 32 | foreach ($keys as $key) { | ||
| 33 | $pdata[$key] = $post_array[$key]; | ||
| 34 | } | ||
| 35 | $result["posts"][] = $pdata; | ||
| 36 | } | ||
| 37 | return $result; | ||
| 38 | } | ||
| 39 | |||
| 40 | public function getStats() { | ||
| 41 | return array( | ||
| 42 | "posts" => get_object_vars(wp_count_posts()), | ||
| 43 | "pages" => get_object_vars(wp_count_posts("page")), | ||
| 44 | "comments" => get_object_vars(wp_count_comments()) | ||
| 45 | ); | ||
| 46 | } | ||
| 47 | |||
| 48 | public function getLatestWooCommerceDB() { | ||
| 49 | $version = false; | ||
| 50 | |||
| 51 | if (defined('WC_ABSPATH') && file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) { | ||
| 52 | include_once WC_ABSPATH . 'includes/class-wc-install.php'; | ||
| 53 | } | ||
| 54 | |||
| 55 | if (class_exists('WC_Install')) { | ||
| 56 | $update_versions = array_keys(WC_Install::get_db_update_callbacks()); | ||
| 57 | usort($update_versions, 'version_compare'); | ||
| 58 | if (!empty($update_versions)) { | ||
| 59 | $version = end($update_versions); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | return $version; | ||
| 64 | } | ||
| 65 | |||
| 66 | public function addDBInfoToPlugin($pdata, $plugin_file) { | ||
| 67 | switch ($plugin_file) { | ||
| 68 | case "woocommerce/woocommerce.php": | ||
| 69 | $pdata['current_db_version'] = $this->settings->getOption('woocommerce_db_version'); | ||
| 70 | $pdata['latest_db_version'] = $this->getLatestWooCommerceDB(); | ||
| 71 | break; | ||
| 72 | } | ||
| 73 | |||
| 74 | return $pdata; | ||
| 75 | } | ||
| 76 | |||
| 77 | public function getPlugins() { | ||
| 78 | if (!function_exists('get_plugins')) { | ||
| 79 | require_once (ABSPATH."wp-admin/includes/plugin.php"); | ||
| 80 | } | ||
| 81 | $plugins = get_plugins(); | ||
| 82 | $result = array(); | ||
| 83 | foreach ($plugins as $plugin_file => $plugin_data) { | ||
| 84 | $pdata = array( | ||
| 85 | 'file' => $plugin_file, | ||
| 86 | 'title' => $plugin_data['Title'], | ||
| 87 | 'version' => $plugin_data['Version'], | ||
| 88 | 'active' => is_plugin_active($plugin_file), | ||
| 89 | 'network' => $plugin_data['Network'] | ||
| 90 | ); | ||
| 91 | $pdata = $this->addDBInfoToPlugin($pdata, $plugin_file); | ||
| 92 | $result["plugins"][] = $pdata; | ||
| 93 | } | ||
| 94 | return $result; | ||
| 95 | } | ||
| 96 | |||
| 97 | public function themeToArray($theme) { | ||
| 98 | if (is_object($theme)) { | ||
| 99 | $pdata = array( | ||
| 100 | 'name' => $theme->Name, | ||
| 101 | 'title' => $theme->Title, | ||
| 102 | 'stylesheet' => $theme->get_stylesheet(), | ||
| 103 | 'template' => $theme->Template, | ||
| 104 | 'version' => $theme->Version | ||
| 105 | ); | ||
| 106 | } else { | ||
| 107 | $pdata = array( | ||
| 108 | 'name' => $theme["Name"], | ||
| 109 | 'title' => $theme["Title"], | ||
| 110 | 'stylesheet' => $theme["Stylesheet"], | ||
| 111 | 'template' => $theme["Template"], | ||
| 112 | 'version' => $theme["Version"] | ||
| 113 | ); | ||
| 114 | } | ||
| 115 | return $pdata; | ||
| 116 | } | ||
| 117 | |||
| 118 | public function getThemes() { | ||
| 119 | $result = array(); | ||
| 120 | $themes = function_exists('wp_get_themes') ? wp_get_themes() : get_themes(); | ||
| 121 | foreach($themes as $theme) { | ||
| 122 | $pdata = $this->themeToArray($theme); | ||
| 123 | $result["themes"][] = $pdata; | ||
| 124 | } | ||
| 125 | $theme = function_exists('wp_get_theme') ? wp_get_theme() : get_current_theme(); | ||
| 126 | $pdata = $this->themeToArray($theme); | ||
| 127 | $result["currenttheme"] = $pdata; | ||
| 128 | return $result; | ||
| 129 | } | ||
| 130 | |||
| 131 | public function getSystemInfo() { | ||
| 132 | $sys_info = array( | ||
| 133 | 'host' => $_SERVER['HTTP_HOST'], | ||
| 134 | 'phpversion' => phpversion(), | ||
| 135 | 'AF_INET6' => defined('AF_INET6') | ||
| 136 | ); | ||
| 137 | if (array_key_exists('SERVER_ADDR', $_SERVER)) { | ||
| 138 | $sys_info['serverip'] = $_SERVER['SERVER_ADDR']; | ||
| 139 | } | ||
| 140 | if (function_exists('get_current_user')) { | ||
| 141 | $sys_info['user'] = get_current_user(); | ||
| 142 | } | ||
| 143 | if (function_exists('getmygid')) { | ||
| 144 | $sys_info['gid'] = getmygid(); | ||
| 145 | } | ||
| 146 | if (function_exists('getmyuid')) { | ||
| 147 | $sys_info['uid'] = getmyuid(); | ||
| 148 | } | ||
| 149 | if (function_exists('posix_getuid')) { | ||
| 150 | $sys_info['webuid'] = posix_getuid(); | ||
| 151 | $sys_info['webgid'] = posix_getgid(); | ||
| 152 | } | ||
| 153 | return $sys_info; | ||
| 154 | } | ||
| 155 | |||
| 156 | public function getWpInfo() { | ||
| 157 | global $wp_version, $wp_db_version, $wp_local_package; | ||
| 158 | $siteinfo = $this->siteinfo; | ||
| 159 | $db = $this->db; | ||
| 160 | $upload_dir = wp_upload_dir(); | ||
| 161 | |||
| 162 | $wp_info = array( | ||
| 163 | 'dbprefix' => $db->dbprefix(), | ||
| 164 | 'wpmu' => $siteinfo->isMultisite(), | ||
| 165 | 'mainsite' => $siteinfo->isMainSite(), | ||
| 166 | 'main_site_id' => $siteinfo->getMainSiteId(), | ||
| 167 | 'name' => get_bloginfo('name'), | ||
| 168 | 'siteurl' => $siteinfo->siteurl(), | ||
| 169 | 'homeurl' => $siteinfo->homeurl(), | ||
| 170 | 'charset' => get_bloginfo('charset'), | ||
| 171 | 'wpversion' => $wp_version, | ||
| 172 | 'dbversion' => $wp_db_version, | ||
| 173 | 'mysql_version' => $db->getMysqlVersion(), | ||
| 174 | 'abspath' => ABSPATH, | ||
| 175 | 'bvpluginpath' => defined('PTNBASEPATH') ? PTNBASEPATH : null, | ||
| 176 | 'uploadpath' => $upload_dir['basedir'], | ||
| 177 | 'uploaddir' => wp_upload_dir(), | ||
| 178 | 'contentdir' => defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : null, | ||
| 179 | 'contenturl' => defined('WP_CONTENT_URL') ? WP_CONTENT_URL : null, | ||
| 180 | 'plugindir' => defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : null, | ||
| 181 | 'dbcharset' => defined('DB_CHARSET') ? DB_CHARSET : null, | ||
| 182 | 'disallow_file_edit' => defined('DISALLOW_FILE_EDIT'), | ||
| 183 | 'disallow_file_mods' => defined('DISALLOW_FILE_MODS'), | ||
| 184 | 'custom_users' => defined('CUSTOM_USER_TABLE') ? CUSTOM_USER_TABLE : null, | ||
| 185 | 'custom_usermeta' => defined('CUSTOM_USERMETA_TABLE') ? CUSTOM_USERMETA_TABLE : null, | ||
| 186 | 'locale' => get_locale(), | ||
| 187 | 'wp_local_string' => $wp_local_package, | ||
| 188 | 'charset_collate' => $db->getCharsetCollate() | ||
| 189 | ); | ||
| 190 | return $wp_info; | ||
| 191 | } | ||
| 192 | |||
| 193 | public function getUsers($full, $args = array()) { | ||
| 194 | $results = array(); | ||
| 195 | $users = get_users($args); | ||
| 196 | if ('true' == $full) { | ||
| 197 | $results = $this->objectToArray($users); | ||
| 198 | } else { | ||
| 199 | foreach( (array) $users as $user) { | ||
| 200 | $result = array(); | ||
| 201 | $result['user_email'] = $user->user_email; | ||
| 202 | $result['ID'] = $user->ID; | ||
| 203 | $result['roles'] = $user->roles; | ||
| 204 | $result['user_login'] = $user->user_login; | ||
| 205 | $result['display_name'] = $user->display_name; | ||
| 206 | $result['user_registered'] = $user->user_registered; | ||
| 207 | $result['user_status'] = $user->user_status; | ||
| 208 | $result['user_url'] = $user->url; | ||
| 209 | |||
| 210 | $results[] = $result; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | return $results; | ||
| 214 | } | ||
| 215 | |||
| 216 | public function availableFunctions(&$info) { | ||
| 217 | if (extension_loaded('openssl')) { | ||
| 218 | $info['openssl'] = "1"; | ||
| 219 | } | ||
| 220 | if (function_exists('is_ssl') && is_ssl()) { | ||
| 221 | $info['https'] = "1"; | ||
| 222 | } | ||
| 223 | if (function_exists('openssl_public_encrypt')) { | ||
| 224 | $info['openssl_public_encrypt'] = "1"; | ||
| 225 | } | ||
| 226 | if (function_exists('openssl_public_decrypt')) { | ||
| 227 | $info['openssl_public_decrypt'] = "1"; | ||
| 228 | } | ||
| 229 | $info['sha1'] = "1"; | ||
| 230 | $info['apissl'] = "1"; | ||
| 231 | if (function_exists('base64_encode')) { | ||
| 232 | $info['b64encode'] = true; | ||
| 233 | } | ||
| 234 | if (function_exists('base64_decode')) { | ||
| 235 | $info['b64decode'] = true; | ||
| 236 | } | ||
| 237 | return $info; | ||
| 238 | } | ||
| 239 | |||
| 240 | public function servicesInfo(&$data) { | ||
| 241 | $settings = $this->settings; | ||
| 242 | $data['protect'] = $settings->getOption('bvptconf'); | ||
| 243 | $data['brand'] = $settings->getOption($this->bvinfo->brand_option); | ||
| 244 | $data['badgeinfo'] = $settings->getOption($this->bvinfo->badgeinfo); | ||
| 245 | $data[$this->bvinfo->services_option_name] = $this->bvinfo->config; | ||
| 246 | } | ||
| 247 | |||
| 248 | public function dbconf(&$info) { | ||
| 249 | $db = $this->db; | ||
| 250 | if (defined('DB_CHARSET')) | ||
| 251 | $info['dbcharset'] = DB_CHARSET; | ||
| 252 | $info['dbprefix'] = $db->dbprefix(); | ||
| 253 | $info['charset_collate'] = $db->getCharsetCollate(); | ||
| 254 | return $info; | ||
| 255 | } | ||
| 256 | |||
| 257 | public function cookieInfo() { | ||
| 258 | $info = array(); | ||
| 259 | if (defined('COOKIEPATH')) | ||
| 260 | $info['cookiepath'] = COOKIEPATH; | ||
| 261 | if (defined('COOKIE_DOMAIN')) | ||
| 262 | $info['cookiedomain'] = COOKIE_DOMAIN; | ||
| 263 | return $info; | ||
| 264 | } | ||
| 265 | |||
| 266 | public function activate() { | ||
| 267 | $info = array(); | ||
| 268 | $this->siteinfo->basic($info); | ||
| 269 | $this->servicesInfo($info); | ||
| 270 | $this->dbconf($info); | ||
| 271 | $this->availableFunctions($info); | ||
| 272 | return $info; | ||
| 273 | } | ||
| 274 | |||
| 275 | public function getHostInfo() { | ||
| 276 | $host_info = $_SERVER; | ||
| 277 | $host_info['PHP_SERVER_NAME'] = php_uname('\n'); | ||
| 278 | if (array_key_exists('IS_PRESSABLE', get_defined_constants())) { | ||
| 279 | $host_info['IS_PRESSABLE'] = true; | ||
| 280 | } | ||
| 281 | |||
| 282 | if (array_key_exists('GRIDPANE', get_defined_constants())) { | ||
| 283 | $host_info['IS_GRIDPANE'] = true; | ||
| 284 | } | ||
| 285 | |||
| 286 | if (defined('WPE_APIKEY')) { | ||
| 287 | $host_info['WPE_APIKEY'] = WPE_APIKEY; | ||
| 288 | } | ||
| 289 | |||
| 290 | return $host_info; | ||
| 291 | } | ||
| 292 | |||
| 293 | public function serverConfig() { | ||
| 294 | return array( | ||
| 295 | 'software' => $_SERVER['SERVER_SOFTWARE'], | ||
| 296 | 'sapi' => (function_exists('php_sapi_name')) ? php_sapi_name() : false, | ||
| 297 | 'has_apache_get_modules' => function_exists('apache_get_modules'), | ||
| 298 | 'posix_getuid' => (function_exists('posix_getuid')) ? posix_getuid() : null, | ||
| 299 | 'uid' => (function_exists('getmyuid')) ? getmyuid() : null, | ||
| 300 | 'user_ini' => ini_get('user_ini.filename'), | ||
| 301 | 'php_major_version' => PHP_MAJOR_VERSION | ||
| 302 | ); | ||
| 303 | } | ||
| 304 | |||
| 305 | function refreshUpdatesInfo() { | ||
| 306 | global $wp_current_filter; | ||
| 307 | $wp_current_filter[] = 'load-update-core.php'; | ||
| 308 | |||
| 309 | if (function_exists('wp_clean_update_cache')) { | ||
| 310 | wp_clean_update_cache(); | ||
| 311 | } else { | ||
| 312 | $this->settings->deleteTransient('update_plugins'); | ||
| 313 | $this->settings->deleteTransient('update_themes'); | ||
| 314 | $this->settings->deleteTransient('update_core'); | ||
| 315 | } | ||
| 316 | |||
| 317 | wp_update_plugins(); | ||
| 318 | wp_update_themes(); | ||
| 319 | |||
| 320 | array_pop($wp_current_filter); | ||
| 321 | |||
| 322 | wp_update_plugins(); | ||
| 323 | wp_update_themes(); | ||
| 324 | |||
| 325 | wp_version_check(); | ||
| 326 | wp_version_check(array(), true); | ||
| 327 | |||
| 328 | return true; | ||
| 329 | } | ||
| 330 | |||
| 331 | function getUsersHandler($args = array()) { | ||
| 332 | $db = $this->db; | ||
| 333 | $table = "{$db->dbprefix()}users"; | ||
| 334 | $count = $db->rowsCount($table); | ||
| 335 | $result = array("count" => $count); | ||
| 336 | |||
| 337 | $max_users = array_key_exists('max_users', $args) ? $args['max_users'] : 500; | ||
| 338 | $roles = array_key_exists('roles', $args) ? $args['roles'] : array(); | ||
| 339 | |||
| 340 | $users = array(); | ||
| 341 | if (($count > $max_users) && !empty($roles)) { | ||
| 342 | foreach ($roles as $role) { | ||
| 343 | if ($max_users <= 0) | ||
| 344 | break; | ||
| 345 | $args['number'] = $max_users; | ||
| 346 | $args['role'] = $role; | ||
| 347 | $fetched = $this->getUsers($args['full'], $args); | ||
| 348 | $max_users -= sizeof($fetched); | ||
| 349 | $users = array_merge($users, $fetched); | ||
| 350 | } | ||
| 351 | } else { | ||
| 352 | $args['number'] = $max_users; | ||
| 353 | $users = $this->getUsers($args['full'], $args); | ||
| 354 | } | ||
| 355 | $result['users_info'] = $users; | ||
| 356 | |||
| 357 | return $result; | ||
| 358 | } | ||
| 359 | |||
| 360 | function getTransient($name, $asarray = true) { | ||
| 361 | $transient = $this->settings->getTransient($name); | ||
| 362 | if ($transient && $asarray) | ||
| 363 | $transient = $this->objectToArray($transient); | ||
| 364 | return array("transient" => $transient); | ||
| 365 | } | ||
| 366 | |||
| 367 | function getPluginsHandler($args = array()) { | ||
| 368 | $result = array_merge($this->getPlugins(), $this->getTransient('update_plugins')); | ||
| 369 | |||
| 370 | if (array_key_exists('clear_filters', $args)) { | ||
| 371 | $filters = $args['clear_filters']; | ||
| 372 | foreach ($filters as $filter) | ||
| 373 | remove_all_filters($filter); | ||
| 374 | $transient_without_filters = $this->getTransient('update_plugins'); | ||
| 375 | $result['transient_without_filters'] = $transient_without_filters['transient']; | ||
| 376 | } | ||
| 377 | |||
| 378 | return $result; | ||
| 379 | } | ||
| 380 | |||
| 381 | function getThemesHandler($args = array()) { | ||
| 382 | $result = array_merge($this->getThemes(), $this->getTransient('update_themes')); | ||
| 383 | |||
| 384 | if (array_key_exists('clear_filters', $args)) { | ||
| 385 | $filters = $args['clear_filters']; | ||
| 386 | foreach ($filters as $filter) | ||
| 387 | remove_all_filters($filter); | ||
| 388 | $transient_without_filters = $this->getTransient('update_themes'); | ||
| 389 | $result['transient_without_filters'] = $transient_without_filters['transient']; | ||
| 390 | } | ||
| 391 | |||
| 392 | return $result; | ||
| 393 | } | ||
| 394 | |||
| 395 | function getCoreHandler() { | ||
| 396 | global $wp_db_version; | ||
| 397 | |||
| 398 | $result = $this->getTransient('update_core'); | ||
| 399 | $result['current_db_version'] = $this->settings->getOption('db_version'); | ||
| 400 | $result['latest_db_version'] = $wp_db_version; | ||
| 401 | |||
| 402 | return $result; | ||
| 403 | } | ||
| 404 | |||
| 405 | function getSiteInfo($args) { | ||
| 406 | $result = array(); | ||
| 407 | |||
| 408 | if (array_key_exists('pre_refresh_get_options', $args)) { | ||
| 409 | $result['pre_refresh_get_options'] = $this->settings->getOptions( | ||
| 410 | $args['pre_refresh_get_options'] | ||
| 411 | ); | ||
| 412 | } | ||
| 413 | |||
| 414 | if (array_key_exists('refresh', $args)) | ||
| 415 | $result['refreshed'] = $this->refreshUpdatesInfo(); | ||
| 416 | |||
| 417 | if (array_key_exists('users', $args)) | ||
| 418 | $result['users'] = $this->getUsersHandler($args['users']); | ||
| 419 | |||
| 420 | if (array_key_exists('plugins', $args)) | ||
| 421 | $result['plugins'] = $this->getPluginsHandler($args['plugins']); | ||
| 422 | |||
| 423 | if (array_key_exists('themes', $args)) | ||
| 424 | $result['themes'] = $this->getThemesHandler($args['themes']); | ||
| 425 | |||
| 426 | if (array_key_exists('core', $args)) | ||
| 427 | $result['core'] = $this->getCoreHandler(); | ||
| 428 | |||
| 429 | if (array_key_exists('sys', $args)) | ||
| 430 | $result['sys'] = $this->getSystemInfo(); | ||
| 431 | |||
| 432 | if (array_key_exists('get_options', $args)) | ||
| 433 | $result['get_options'] = $this->settings->getOptions($args['get_options']); | ||
| 434 | |||
| 435 | return $result; | ||
| 436 | } | ||
| 437 | |||
| 438 | function pingBV() { | ||
| 439 | $info = array(); | ||
| 440 | $this->siteinfo->basic($info); | ||
| 441 | $this->bvapi->pingbv('/bvapi/pingbv', $info); | ||
| 442 | return true; | ||
| 443 | } | ||
| 444 | |||
| 445 | function getPostActivateInfo($args) { | ||
| 446 | $result = array(); | ||
| 447 | |||
| 448 | if (array_key_exists('pingbv', $args)) | ||
| 449 | $result['pingbv'] = array('status' => $this->pingBV()); | ||
| 450 | |||
| 451 | if (array_key_exists('activate_info', $args)) | ||
| 452 | $result['activate_info'] = $this->activate(); | ||
| 453 | |||
| 454 | if (array_key_exists('cookie_info', $args)) | ||
| 455 | $result['cookie_info'] = $this->cookieInfo(); | ||
| 456 | |||
| 457 | if (array_key_exists('get_host', $args)) | ||
| 458 | $result['get_host'] = $this->getHostInfo(); | ||
| 459 | |||
| 460 | if (array_key_exists('get_wp', $args)) | ||
| 461 | $result['get_wp'] = $this->getWpInfo(); | ||
| 462 | |||
| 463 | if (array_key_exists('get_options', $args)) | ||
| 464 | $result['get_options'] = $this->settings->getOptions($args['get_options']); | ||
| 465 | |||
| 466 | if (array_key_exists('get_tables', $args)) | ||
| 467 | $result['get_tables'] = $this->db->showTables(); | ||
| 468 | |||
| 469 | $result['status'] = true; | ||
| 470 | |||
| 471 | return $result; | ||
| 472 | } | ||
| 473 | |||
| 474 | function getPluginServicesInfo($args) { | ||
| 475 | $result = array(); | ||
| 476 | |||
| 477 | if (array_key_exists('get_options', $args)) | ||
| 478 | $result['get_options'] = $this->settings->getOptions($args['get_options']); | ||
| 479 | |||
| 480 | if (array_key_exists('pingbv', $args)) | ||
| 481 | $result['pingbv'] = array('status' => $this->pingBV()); | ||
| 482 | |||
| 483 | if (array_key_exists('server_config', $args)) | ||
| 484 | $result['server_config'] = $this->serverConfig(); | ||
| 485 | |||
| 486 | return $result; | ||
| 487 | } | ||
| 488 | |||
| 489 | public function process($request) { | ||
| 490 | $db = $this->db; | ||
| 491 | $params = $request->params; | ||
| 492 | switch ($request->method) { | ||
| 493 | case "activateinfo": | ||
| 494 | $resp = array('actinfo' => $this->activate()); | ||
| 495 | break; | ||
| 496 | case "ckeyinfo": | ||
| 497 | $resp = array('cookieinfo' => $this->cookieInfo()); | ||
| 498 | break; | ||
| 499 | case "gtpsts": | ||
| 500 | $count = 5; | ||
| 501 | if (array_key_exists('count', $params)) | ||
| 502 | $count = $params['count']; | ||
| 503 | $resp = $this->getPosts($params['post_type'], $count); | ||
| 504 | break; | ||
| 505 | case "gtsts": | ||
| 506 | $resp = $this->getStats(); | ||
| 507 | break; | ||
| 508 | case "gtdbvariables": | ||
| 509 | $variable = (array_key_exists('variable', $params)) ? $variable : ""; | ||
| 510 | $resp = $this->db->showDbVariables($variable); | ||
| 511 | break; | ||
| 512 | case "gtplgs": | ||
| 513 | $resp = $this->getPlugins(); | ||
| 514 | break; | ||
| 515 | case "gtthms": | ||
| 516 | $resp = $this->getThemes(); | ||
| 517 | break; | ||
| 518 | case "gtsym": | ||
| 519 | $resp = array('sys' => $this->getSystemInfo()); | ||
| 520 | break; | ||
| 521 | case "gtwp": | ||
| 522 | $resp = array('wp' => $this->getWpInfo()); | ||
| 523 | break; | ||
| 524 | case "gtallhdrs": | ||
| 525 | $data = (function_exists('getallheaders')) ? getallheaders() : false; | ||
| 526 | $resp = array("allhdrs" => $data); | ||
| 527 | break; | ||
| 528 | case "gtsvr": | ||
| 529 | $resp = array("svr" => $_SERVER); | ||
| 530 | break; | ||
| 531 | case "getoption": | ||
| 532 | $resp = array("option" => $this->settings->getOption($params['name'])); | ||
| 533 | break; | ||
| 534 | case "gtusrs": | ||
| 535 | $full = false; | ||
| 536 | if (array_key_exists('full', $params)) | ||
| 537 | $full = true; | ||
| 538 | $resp = array('users' => $this->getUsers($full, $params['args'])); | ||
| 539 | break; | ||
| 540 | case "gttrnsnt": | ||
| 541 | $resp = $this->getTransient($params['name'], array_key_exists('asarray', $params)); | ||
| 542 | break; | ||
| 543 | case "gthost": | ||
| 544 | $resp = array('host_info' => $this->getHostInfo()); | ||
| 545 | break; | ||
| 546 | case "gtplinfo": | ||
| 547 | $args = array( | ||
| 548 | 'slug' => wp_unslash($params['slug']) | ||
| 549 | ); | ||
| 550 | $action = $params['action']; | ||
| 551 | $args = (object) $args; | ||
| 552 | $args = apply_filters('plugins_api_args', $args, $action); | ||
| 553 | $data = apply_filters('plugins_api', false, $action, $args); | ||
| 554 | $resp = array("plugins_info" => $data); | ||
| 555 | break; | ||
| 556 | case "gtpostactinfo": | ||
| 557 | $resp = $this->getPostActivateInfo($params); | ||
| 558 | break; | ||
| 559 | case "gtsteinfo": | ||
| 560 | $resp = $this->getSiteInfo($params); | ||
| 561 | break; | ||
| 562 | case "psinfo": | ||
| 563 | $resp = $this->getPluginServicesInfo($params); | ||
| 564 | break; | ||
| 565 | default: | ||
| 566 | $resp = false; | ||
| 567 | } | ||
| 568 | return $resp; | ||
| 569 | } | ||
| 570 | } | ||
| 571 | 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 |
834 Bytes
6.63 KB
| 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 | WordPress - Web publishing software | ||
| 2 | |||
| 3 | Copyright 2015 by the contributors | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 2 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program; if not, write to the Free Software | ||
| 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | |||
| 19 | This program incorporates work covered by the following copyright and | ||
| 20 | permission notices: | ||
| 21 | |||
| 22 | b2 is (c) 2001, 2002 Michel Valdrighi - m@tidakada.com - | ||
| 23 | http://tidakada.com | ||
| 24 | |||
| 25 | Wherever third party code has been used, credit has been given in the code's | ||
| 26 | comments. | ||
| 27 | |||
| 28 | b2 is released under the GPL | ||
| 29 | |||
| 30 | and | ||
| 31 | |||
| 32 | WordPress - Web publishing software | ||
| 33 | |||
| 34 | Copyright 2003-2010 by the contributors | ||
| 35 | |||
| 36 | WordPress is released under the GPL | ||
| 37 | |||
| 38 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 39 | |||
| 40 | GNU GENERAL PUBLIC LICENSE | ||
| 41 | Version 2, June 1991 | ||
| 42 | |||
| 43 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., | ||
| 44 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 45 | Everyone is permitted to copy and distribute verbatim copies | ||
| 46 | of this license document, but changing it is not allowed. | ||
| 47 | |||
| 48 | Preamble | ||
| 49 | |||
| 50 | The licenses for most software are designed to take away your | ||
| 51 | freedom to share and change it. By contrast, the GNU General Public | ||
| 52 | License is intended to guarantee your freedom to share and change free | ||
| 53 | software--to make sure the software is free for all its users. This | ||
| 54 | General Public License applies to most of the Free Software | ||
| 55 | Foundation's software and to any other program whose authors commit to | ||
| 56 | using it. (Some other Free Software Foundation software is covered by | ||
| 57 | the GNU Lesser General Public License instead.) You can apply it to | ||
| 58 | your programs, too. | ||
| 59 | |||
| 60 | When we speak of free software, we are referring to freedom, not | ||
| 61 | price. Our General Public Licenses are designed to make sure that you | ||
| 62 | have the freedom to distribute copies of free software (and charge for | ||
| 63 | this service if you wish), that you receive source code or can get it | ||
| 64 | if you want it, that you can change the software or use pieces of it | ||
| 65 | in new free programs; and that you know you can do these things. | ||
| 66 | |||
| 67 | To protect your rights, we need to make restrictions that forbid | ||
| 68 | anyone to deny you these rights or to ask you to surrender the rights. | ||
| 69 | These restrictions translate to certain responsibilities for you if you | ||
| 70 | distribute copies of the software, or if you modify it. | ||
| 71 | |||
| 72 | For example, if you distribute copies of such a program, whether | ||
| 73 | gratis or for a fee, you must give the recipients all the rights that | ||
| 74 | you have. You must make sure that they, too, receive or can get the | ||
| 75 | source code. And you must show them these terms so they know their | ||
| 76 | rights. | ||
| 77 | |||
| 78 | We protect your rights with two steps: (1) copyright the software, and | ||
| 79 | (2) offer you this license which gives you legal permission to copy, | ||
| 80 | distribute and/or modify the software. | ||
| 81 | |||
| 82 | Also, for each author's protection and ours, we want to make certain | ||
| 83 | that everyone understands that there is no warranty for this free | ||
| 84 | software. If the software is modified by someone else and passed on, we | ||
| 85 | want its recipients to know that what they have is not the original, so | ||
| 86 | that any problems introduced by others will not reflect on the original | ||
| 87 | authors' reputations. | ||
| 88 | |||
| 89 | Finally, any free program is threatened constantly by software | ||
| 90 | patents. We wish to avoid the danger that redistributors of a free | ||
| 91 | program will individually obtain patent licenses, in effect making the | ||
| 92 | program proprietary. To prevent this, we have made it clear that any | ||
| 93 | patent must be licensed for everyone's free use or not licensed at all. | ||
| 94 | |||
| 95 | The precise terms and conditions for copying, distribution and | ||
| 96 | modification follow. | ||
| 97 | |||
| 98 | GNU GENERAL PUBLIC LICENSE | ||
| 99 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
| 100 | |||
| 101 | 0. This License applies to any program or other work which contains | ||
| 102 | a notice placed by the copyright holder saying it may be distributed | ||
| 103 | under the terms of this General Public License. The "Program", below, | ||
| 104 | refers to any such program or work, and a "work based on the Program" | ||
| 105 | means either the Program or any derivative work under copyright law: | ||
| 106 | that is to say, a work containing the Program or a portion of it, | ||
| 107 | either verbatim or with modifications and/or translated into another | ||
| 108 | language. (Hereinafter, translation is included without limitation in | ||
| 109 | the term "modification".) Each licensee is addressed as "you". | ||
| 110 | |||
| 111 | Activities other than copying, distribution and modification are not | ||
| 112 | covered by this License; they are outside its scope. The act of | ||
| 113 | running the Program is not restricted, and the output from the Program | ||
| 114 | is covered only if its contents constitute a work based on the | ||
| 115 | Program (independent of having been made by running the Program). | ||
| 116 | Whether that is true depends on what the Program does. | ||
| 117 | |||
| 118 | 1. You may copy and distribute verbatim copies of the Program's | ||
| 119 | source code as you receive it, in any medium, provided that you | ||
| 120 | conspicuously and appropriately publish on each copy an appropriate | ||
| 121 | copyright notice and disclaimer of warranty; keep intact all the | ||
| 122 | notices that refer to this License and to the absence of any warranty; | ||
| 123 | and give any other recipients of the Program a copy of this License | ||
| 124 | along with the Program. | ||
| 125 | |||
| 126 | You may charge a fee for the physical act of transferring a copy, and | ||
| 127 | you may at your option offer warranty protection in exchange for a fee. | ||
| 128 | |||
| 129 | 2. You may modify your copy or copies of the Program or any portion | ||
| 130 | of it, thus forming a work based on the Program, and copy and | ||
| 131 | distribute such modifications or work under the terms of Section 1 | ||
| 132 | above, provided that you also meet all of these conditions: | ||
| 133 | |||
| 134 | a) You must cause the modified files to carry prominent notices | ||
| 135 | stating that you changed the files and the date of any change. | ||
| 136 | |||
| 137 | b) You must cause any work that you distribute or publish, that in | ||
| 138 | whole or in part contains or is derived from the Program or any | ||
| 139 | part thereof, to be licensed as a whole at no charge to all third | ||
| 140 | parties under the terms of this License. | ||
| 141 | |||
| 142 | c) If the modified program normally reads commands interactively | ||
| 143 | when run, you must cause it, when started running for such | ||
| 144 | interactive use in the most ordinary way, to print or display an | ||
| 145 | announcement including an appropriate copyright notice and a | ||
| 146 | notice that there is no warranty (or else, saying that you provide | ||
| 147 | a warranty) and that users may redistribute the program under | ||
| 148 | these conditions, and telling the user how to view a copy of this | ||
| 149 | License. (Exception: if the Program itself is interactive but | ||
| 150 | does not normally print such an announcement, your work based on | ||
| 151 | the Program is not required to print an announcement.) | ||
| 152 | |||
| 153 | These requirements apply to the modified work as a whole. If | ||
| 154 | identifiable sections of that work are not derived from the Program, | ||
| 155 | and can be reasonably considered independent and separate works in | ||
| 156 | themselves, then this License, and its terms, do not apply to those | ||
| 157 | sections when you distribute them as separate works. But when you | ||
| 158 | distribute the same sections as part of a whole which is a work based | ||
| 159 | on the Program, the distribution of the whole must be on the terms of | ||
| 160 | this License, whose permissions for other licensees extend to the | ||
| 161 | entire whole, and thus to each and every part regardless of who wrote it. | ||
| 162 | |||
| 163 | Thus, it is not the intent of this section to claim rights or contest | ||
| 164 | your rights to work written entirely by you; rather, the intent is to | ||
| 165 | exercise the right to control the distribution of derivative or | ||
| 166 | collective works based on the Program. | ||
| 167 | |||
| 168 | In addition, mere aggregation of another work not based on the Program | ||
| 169 | with the Program (or with a work based on the Program) on a volume of | ||
| 170 | a storage or distribution medium does not bring the other work under | ||
| 171 | the scope of this License. | ||
| 172 | |||
| 173 | 3. You may copy and distribute the Program (or a work based on it, | ||
| 174 | under Section 2) in object code or executable form under the terms of | ||
| 175 | Sections 1 and 2 above provided that you also do one of the following: | ||
| 176 | |||
| 177 | a) Accompany it with the complete corresponding machine-readable | ||
| 178 | source code, which must be distributed under the terms of Sections | ||
| 179 | 1 and 2 above on a medium customarily used for software interchange; or, | ||
| 180 | |||
| 181 | b) Accompany it with a written offer, valid for at least three | ||
| 182 | years, to give any third party, for a charge no more than your | ||
| 183 | cost of physically performing source distribution, a complete | ||
| 184 | machine-readable copy of the corresponding source code, to be | ||
| 185 | distributed under the terms of Sections 1 and 2 above on a medium | ||
| 186 | customarily used for software interchange; or, | ||
| 187 | |||
| 188 | c) Accompany it with the information you received as to the offer | ||
| 189 | to distribute corresponding source code. (This alternative is | ||
| 190 | allowed only for noncommercial distribution and only if you | ||
| 191 | received the program in object code or executable form with such | ||
| 192 | an offer, in accord with Subsection b above.) | ||
| 193 | |||
| 194 | The source code for a work means the preferred form of the work for | ||
| 195 | making modifications to it. For an executable work, complete source | ||
| 196 | code means all the source code for all modules it contains, plus any | ||
| 197 | associated interface definition files, plus the scripts used to | ||
| 198 | control compilation and installation of the executable. However, as a | ||
| 199 | special exception, the source code distributed need not include | ||
| 200 | anything that is normally distributed (in either source or binary | ||
| 201 | form) with the major components (compiler, kernel, and so on) of the | ||
| 202 | operating system on which the executable runs, unless that component | ||
| 203 | itself accompanies the executable. | ||
| 204 | |||
| 205 | If distribution of executable or object code is made by offering | ||
| 206 | access to copy from a designated place, then offering equivalent | ||
| 207 | access to copy the source code from the same place counts as | ||
| 208 | distribution of the source code, even though third parties are not | ||
| 209 | compelled to copy the source along with the object code. | ||
| 210 | |||
| 211 | 4. You may not copy, modify, sublicense, or distribute the Program | ||
| 212 | except as expressly provided under this License. Any attempt | ||
| 213 | otherwise to copy, modify, sublicense or distribute the Program is | ||
| 214 | void, and will automatically terminate your rights under this License. | ||
| 215 | However, parties who have received copies, or rights, from you under | ||
| 216 | this License will not have their licenses terminated so long as such | ||
| 217 | parties remain in full compliance. | ||
| 218 | |||
| 219 | 5. You are not required to accept this License, since you have not | ||
| 220 | signed it. However, nothing else grants you permission to modify or | ||
| 221 | distribute the Program or its derivative works. These actions are | ||
| 222 | prohibited by law if you do not accept this License. Therefore, by | ||
| 223 | modifying or distributing the Program (or any work based on the | ||
| 224 | Program), you indicate your acceptance of this License to do so, and | ||
| 225 | all its terms and conditions for copying, distributing or modifying | ||
| 226 | the Program or works based on it. | ||
| 227 | |||
| 228 | 6. Each time you redistribute the Program (or any work based on the | ||
| 229 | Program), the recipient automatically receives a license from the | ||
| 230 | original licensor to copy, distribute or modify the Program subject to | ||
| 231 | these terms and conditions. You may not impose any further | ||
| 232 | restrictions on the recipients' exercise of the rights granted herein. | ||
| 233 | You are not responsible for enforcing compliance by third parties to | ||
| 234 | this License. | ||
| 235 | |||
| 236 | 7. If, as a consequence of a court judgment or allegation of patent | ||
| 237 | infringement or for any other reason (not limited to patent issues), | ||
| 238 | conditions are imposed on you (whether by court order, agreement or | ||
| 239 | otherwise) that contradict the conditions of this License, they do not | ||
| 240 | excuse you from the conditions of this License. If you cannot | ||
| 241 | distribute so as to satisfy simultaneously your obligations under this | ||
| 242 | License and any other pertinent obligations, then as a consequence you | ||
| 243 | may not distribute the Program at all. For example, if a patent | ||
| 244 | license would not permit royalty-free redistribution of the Program by | ||
| 245 | all those who receive copies directly or indirectly through you, then | ||
| 246 | the only way you could satisfy both it and this License would be to | ||
| 247 | refrain entirely from distribution of the Program. | ||
| 248 | |||
| 249 | If any portion of this section is held invalid or unenforceable under | ||
| 250 | any particular circumstance, the balance of the section is intended to | ||
| 251 | apply and the section as a whole is intended to apply in other | ||
| 252 | circumstances. | ||
| 253 | |||
| 254 | It is not the purpose of this section to induce you to infringe any | ||
| 255 | patents or other property right claims or to contest validity of any | ||
| 256 | such claims; this section has the sole purpose of protecting the | ||
| 257 | integrity of the free software distribution system, which is | ||
| 258 | implemented by public license practices. Many people have made | ||
| 259 | generous contributions to the wide range of software distributed | ||
| 260 | through that system in reliance on consistent application of that | ||
| 261 | system; it is up to the author/donor to decide if he or she is willing | ||
| 262 | to distribute software through any other system and a licensee cannot | ||
| 263 | impose that choice. | ||
| 264 | |||
| 265 | This section is intended to make thoroughly clear what is believed to | ||
| 266 | be a consequence of the rest of this License. | ||
| 267 | |||
| 268 | 8. If the distribution and/or use of the Program is restricted in | ||
| 269 | certain countries either by patents or by copyrighted interfaces, the | ||
| 270 | original copyright holder who places the Program under this License | ||
| 271 | may add an explicit geographical distribution limitation excluding | ||
| 272 | those countries, so that distribution is permitted only in or among | ||
| 273 | countries not thus excluded. In such case, this License incorporates | ||
| 274 | the limitation as if written in the body of this License. | ||
| 275 | |||
| 276 | 9. The Free Software Foundation may publish revised and/or new versions | ||
| 277 | of the General Public License from time to time. Such new versions will | ||
| 278 | be similar in spirit to the present version, but may differ in detail to | ||
| 279 | address new problems or concerns. | ||
| 280 | |||
| 281 | Each version is given a distinguishing version number. If the Program | ||
| 282 | specifies a version number of this License which applies to it and "any | ||
| 283 | later version", you have the option of following the terms and conditions | ||
| 284 | either of that version or of any later version published by the Free | ||
| 285 | Software Foundation. If the Program does not specify a version number of | ||
| 286 | this License, you may choose any version ever published by the Free Software | ||
| 287 | Foundation. | ||
| 288 | |||
| 289 | 10. If you wish to incorporate parts of the Program into other free | ||
| 290 | programs whose distribution conditions are different, write to the author | ||
| 291 | to ask for permission. For software which is copyrighted by the Free | ||
| 292 | Software Foundation, write to the Free Software Foundation; we sometimes | ||
| 293 | make exceptions for this. Our decision will be guided by the two goals | ||
| 294 | of preserving the free status of all derivatives of our free software and | ||
| 295 | of promoting the sharing and reuse of software generally. | ||
| 296 | |||
| 297 | NO WARRANTY | ||
| 298 | |||
| 299 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||
| 300 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | ||
| 301 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||
| 302 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | ||
| 303 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
| 304 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | ||
| 305 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | ||
| 306 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | ||
| 307 | REPAIR OR CORRECTION. | ||
| 308 | |||
| 309 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
| 310 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||
| 311 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | ||
| 312 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | ||
| 313 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | ||
| 314 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | ||
| 315 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | ||
| 316 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | ||
| 317 | POSSIBILITY OF SUCH DAMAGES. | ||
| 318 | |||
| 319 | END OF TERMS AND CONDITIONS | ||
| 320 | |||
| 321 | How to Apply These Terms to Your New Programs | ||
| 322 | |||
| 323 | If you develop a new program, and you want it to be of the greatest | ||
| 324 | possible use to the public, the best way to achieve this is to make it | ||
| 325 | free software which everyone can redistribute and change under these terms. | ||
| 326 | |||
| 327 | To do so, attach the following notices to the program. It is safest | ||
| 328 | to attach them to the start of each source file to most effectively | ||
| 329 | convey the exclusion of warranty; and each file should have at least | ||
| 330 | the "copyright" line and a pointer to where the full notice is found. | ||
| 331 | |||
| 332 | <one line to give the program's name and a brief idea of what it does.> | ||
| 333 | Copyright (C) <year> <name of author> | ||
| 334 | |||
| 335 | This program is free software; you can redistribute it and/or modify | ||
| 336 | it under the terms of the GNU General Public License as published by | ||
| 337 | the Free Software Foundation; either version 2 of the License, or | ||
| 338 | (at your option) any later version. | ||
| 339 | |||
| 340 | This program is distributed in the hope that it will be useful, | ||
| 341 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 342 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 343 | GNU General Public License for more details. | ||
| 344 | |||
| 345 | You should have received a copy of the GNU General Public License along | ||
| 346 | with this program; if not, write to the Free Software Foundation, Inc., | ||
| 347 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 348 | |||
| 349 | Also add information on how to contact you by electronic and paper mail. | ||
| 350 | |||
| 351 | If the program is interactive, make it output a short notice like this | ||
| 352 | when it starts in an interactive mode: | ||
| 353 | |||
| 354 | Gnomovision version 69, Copyright (C) year name of author | ||
| 355 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
| 356 | This is free software, and you are welcome to redistribute it | ||
| 357 | under certain conditions; type `show c' for details. | ||
| 358 | |||
| 359 | The hypothetical commands `show w' and `show c' should show the appropriate | ||
| 360 | parts of the General Public License. Of course, the commands you use may | ||
| 361 | be called something other than `show w' and `show c'; they could even be | ||
| 362 | mouse-clicks or menu items--whatever suits your program. | ||
| 363 | |||
| 364 | You should also get your employer (if you work as a programmer) or your | ||
| 365 | school, if any, to sign a "copyright disclaimer" for the program, if | ||
| 366 | necessary. Here is a sample; alter the names: | ||
| 367 | |||
| 368 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | ||
| 369 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | ||
| 370 | |||
| 371 | <signature of Ty Coon>, 1 April 1989 | ||
| 372 | Ty Coon, President of Vice | ||
| 373 | |||
| 374 | This General Public License does not permit incorporating your program into | ||
| 375 | proprietary programs. If your program is a subroutine library, you may | ||
| 376 | consider it more useful to permit linking proprietary applications with the | ||
| 377 | library. If this is what you want to do, use the GNU Lesser General | ||
| 378 | Public License instead of this License. | ||
| 379 | |||
| 380 | WRITTEN OFFER | ||
| 381 | |||
| 382 | The source code for any program binaries or compressed scripts that are | ||
| 383 | included with WordPress can be freely obtained at the following URL: | ||
| 384 | |||
| 385 | https://wordpress.org/download/source/ |
| 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 | <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 |
-
Please register or sign in to post a comment