| 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 WPCOMInfo($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(WPCOMAccount::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; |
| 129 |
|