| 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 |
|
| 12 |
const INFO_WING_VERSION = 1.0; |
| 13 |
|
| 14 |
public function __construct($callback_handler) { |
| 15 |
$this->db = $callback_handler->db; |
| 16 |
$this->siteinfo = $callback_handler->siteinfo; |
| 17 |
$this->settings = $callback_handler->settings; |
| 18 |
$this->bvinfo = new WPRInfo($this->settings); |
| 19 |
} |
| 20 |
|
| 21 |
public function getPosts($post_type, $count = 5) { |
| 22 |
$output = array(); |
| 23 |
$args = array('numberposts' => $count, 'post_type' => $post_type); |
| 24 |
$posts = get_posts($args); |
| 25 |
$keys = array('post_title', 'guid', 'ID', 'post_date'); |
| 26 |
$result = array(); |
| 27 |
foreach ($posts as $post) { |
| 28 |
$pdata = array(); |
| 29 |
$post_array = get_object_vars($post); |
| 30 |
foreach ($keys as $key) { |
| 31 |
$pdata[$key] = $post_array[$key]; |
| 32 |
} |
| 33 |
$result["posts"][] = $pdata; |
| 34 |
} |
| 35 |
return $result; |
| 36 |
} |
| 37 |
|
| 38 |
public function getStats() { |
| 39 |
return array( |
| 40 |
"posts" => get_object_vars(wp_count_posts()), |
| 41 |
"pages" => get_object_vars(wp_count_posts("page")), |
| 42 |
"comments" => get_object_vars(wp_count_comments()) |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
public function getPlugins() { |
| 47 |
if (!function_exists('get_plugins')) { |
| 48 |
require_once (ABSPATH."wp-admin/includes/plugin.php"); |
| 49 |
} |
| 50 |
$plugins = get_plugins(); |
| 51 |
$result = array(); |
| 52 |
foreach ($plugins as $plugin_file => $plugin_data) { |
| 53 |
$pdata = array( |
| 54 |
'file' => $plugin_file, |
| 55 |
'title' => $plugin_data['Title'], |
| 56 |
'version' => $plugin_data['Version'], |
| 57 |
'active' => is_plugin_active($plugin_file), |
| 58 |
'network' => $plugin_data['Network'] |
| 59 |
); |
| 60 |
$result["plugins"][] = $pdata; |
| 61 |
} |
| 62 |
return $result; |
| 63 |
} |
| 64 |
|
| 65 |
public function themeToArray($theme) { |
| 66 |
if (is_object($theme)) { |
| 67 |
$pdata = array( |
| 68 |
'name' => $theme->Name, |
| 69 |
'title' => $theme->Title, |
| 70 |
'stylesheet' => $theme->get_stylesheet(), |
| 71 |
'template' => $theme->Template, |
| 72 |
'version' => $theme->Version |
| 73 |
); |
| 74 |
} else { |
| 75 |
$pdata = array( |
| 76 |
'name' => $theme["Name"], |
| 77 |
'title' => $theme["Title"], |
| 78 |
'stylesheet' => $theme["Stylesheet"], |
| 79 |
'template' => $theme["Template"], |
| 80 |
'version' => $theme["Version"] |
| 81 |
); |
| 82 |
} |
| 83 |
return $pdata; |
| 84 |
} |
| 85 |
|
| 86 |
public function getThemes() { |
| 87 |
$result = array(); |
| 88 |
$themes = function_exists('wp_get_themes') ? wp_get_themes() : get_themes(); |
| 89 |
foreach($themes as $theme) { |
| 90 |
$pdata = $this->themeToArray($theme); |
| 91 |
$result["themes"][] = $pdata; |
| 92 |
} |
| 93 |
$theme = function_exists('wp_get_theme') ? wp_get_theme() : get_current_theme(); |
| 94 |
$pdata = $this->themeToArray($theme); |
| 95 |
$result["currenttheme"] = $pdata; |
| 96 |
return $result; |
| 97 |
} |
| 98 |
|
| 99 |
public function getSystemInfo() { |
| 100 |
$sys_info = array( |
| 101 |
'host' => $_SERVER['HTTP_HOST'], |
| 102 |
'phpversion' => phpversion(), |
| 103 |
'AF_INET6' => defined('AF_INET6') |
| 104 |
); |
| 105 |
if (array_key_exists('SERVER_ADDR', $_SERVER)) { |
| 106 |
$sys_info['serverip'] = $_SERVER['SERVER_ADDR']; |
| 107 |
} |
| 108 |
if (function_exists('get_current_user')) { |
| 109 |
$sys_info['user'] = get_current_user(); |
| 110 |
} |
| 111 |
if (function_exists('getmygid')) { |
| 112 |
$sys_info['gid'] = getmygid(); |
| 113 |
} |
| 114 |
if (function_exists('getmyuid')) { |
| 115 |
$sys_info['uid'] = getmyuid(); |
| 116 |
} |
| 117 |
if (function_exists('posix_getuid')) { |
| 118 |
$sys_info['webuid'] = posix_getuid(); |
| 119 |
$sys_info['webgid'] = posix_getgid(); |
| 120 |
} |
| 121 |
return array("sys" => $sys_info); |
| 122 |
} |
| 123 |
|
| 124 |
public function getWpInfo() { |
| 125 |
global $wp_version, $wp_db_version, $wp_local_package; |
| 126 |
$siteinfo = $this->siteinfo; |
| 127 |
$db = $this->db; |
| 128 |
$upload_dir = wp_upload_dir(); |
| 129 |
|
| 130 |
$wp_info = array( |
| 131 |
'dbprefix' => $db->dbprefix(), |
| 132 |
'wpmu' => $siteinfo->isMultisite(), |
| 133 |
'mainsite' => $siteinfo->isMainSite(), |
| 134 |
'main_site_id' => $siteinfo->getMainSiteId(), |
| 135 |
'name' => get_bloginfo('name'), |
| 136 |
'siteurl' => $siteinfo->siteurl(), |
| 137 |
'homeurl' => $siteinfo->homeurl(), |
| 138 |
'charset' => get_bloginfo('charset'), |
| 139 |
'wpversion' => $wp_version, |
| 140 |
'dbversion' => $wp_db_version, |
| 141 |
'mysql_version' => $db->getMysqlVersion(), |
| 142 |
'abspath' => ABSPATH, |
| 143 |
'bvpluginpath' => defined('WPRBASEPATH') ? WPRBASEPATH : null, |
| 144 |
'uploadpath' => $upload_dir['basedir'], |
| 145 |
'uploaddir' => wp_upload_dir(), |
| 146 |
'contentdir' => defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : null, |
| 147 |
'contenturl' => defined('WP_CONTENT_URL') ? WP_CONTENT_URL : null, |
| 148 |
'plugindir' => defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : null, |
| 149 |
'dbcharset' => defined('DB_CHARSET') ? DB_CHARSET : null, |
| 150 |
'disallow_file_edit' => defined('DISALLOW_FILE_EDIT'), |
| 151 |
'disallow_file_mods' => defined('DISALLOW_FILE_MODS'), |
| 152 |
'custom_users' => defined('CUSTOM_USER_TABLE') ? CUSTOM_USER_TABLE : null, |
| 153 |
'custom_usermeta' => defined('CUSTOM_USERMETA_TABLE') ? CUSTOM_USERMETA_TABLE : null, |
| 154 |
'locale' => get_locale(), |
| 155 |
'wp_local_string' => $wp_local_package, |
| 156 |
'charset_collate' => $db->getCharsetCollate() |
| 157 |
); |
| 158 |
return array("wp" => $wp_info); |
| 159 |
} |
| 160 |
|
| 161 |
public function getUsers($full, $args = array()) { |
| 162 |
$results = array(); |
| 163 |
$users = get_users($args); |
| 164 |
if ('true' == $full) { |
| 165 |
$results = $this->objectToArray($users); |
| 166 |
} else { |
| 167 |
foreach( (array) $users as $user) { |
| 168 |
$result = array(); |
| 169 |
$result['user_email'] = $user->user_email; |
| 170 |
$result['ID'] = $user->ID; |
| 171 |
$result['roles'] = $user->roles; |
| 172 |
$result['user_login'] = $user->user_login; |
| 173 |
$result['display_name'] = $user->display_name; |
| 174 |
$result['user_registered'] = $user->user_registered; |
| 175 |
$result['user_status'] = $user->user_status; |
| 176 |
$result['user_url'] = $user->url; |
| 177 |
|
| 178 |
$results[] = $result; |
| 179 |
} |
| 180 |
} |
| 181 |
return array("users" => $results); |
| 182 |
} |
| 183 |
|
| 184 |
public function availableFunctions(&$info) { |
| 185 |
if (extension_loaded('openssl')) { |
| 186 |
$info['openssl'] = "1"; |
| 187 |
} |
| 188 |
if (function_exists('is_ssl') && is_ssl()) { |
| 189 |
$info['https'] = "1"; |
| 190 |
} |
| 191 |
if (function_exists('openssl_public_encrypt')) { |
| 192 |
$info['openssl_public_encrypt'] = "1"; |
| 193 |
} |
| 194 |
if (function_exists('openssl_public_decrypt')) { |
| 195 |
$info['openssl_public_decrypt'] = "1"; |
| 196 |
} |
| 197 |
$info['sha1'] = "1"; |
| 198 |
$info['apissl'] = "1"; |
| 199 |
if (function_exists('base64_encode')) { |
| 200 |
$info['b64encode'] = true; |
| 201 |
} |
| 202 |
if (function_exists('base64_decode')) { |
| 203 |
$info['b64decode'] = true; |
| 204 |
} |
| 205 |
return $info; |
| 206 |
} |
| 207 |
|
| 208 |
public function servicesInfo(&$data) { |
| 209 |
$settings = $this->settings; |
| 210 |
$data['protect'] = $settings->getOption('bvptconf'); |
| 211 |
$data['brand'] = $settings->getOption($this->bvinfo->brand_option); |
| 212 |
$data['badgeinfo'] = $settings->getOption($this->bvinfo->badgeinfo); |
| 213 |
$data[$this->bvinfo->services_option_name] = $this->bvinfo->config; |
| 214 |
} |
| 215 |
|
| 216 |
public function dbconf(&$info) { |
| 217 |
$db = $this->db; |
| 218 |
if (defined('DB_CHARSET')) |
| 219 |
$info['dbcharset'] = DB_CHARSET; |
| 220 |
$info['dbprefix'] = $db->dbprefix(); |
| 221 |
$info['charset_collate'] = $db->getCharsetCollate(); |
| 222 |
return $info; |
| 223 |
} |
| 224 |
|
| 225 |
public function cookieInfo() { |
| 226 |
$resp = array(); |
| 227 |
if (defined('COOKIEPATH')) |
| 228 |
$resp['cookiepath'] = COOKIEPATH; |
| 229 |
if (defined('COOKIE_DOMAIN')) |
| 230 |
$resp['cookiedomain'] = COOKIE_DOMAIN; |
| 231 |
return array('cookieinfo' => $resp); |
| 232 |
} |
| 233 |
|
| 234 |
public function activate() { |
| 235 |
$resp = array(); |
| 236 |
$this->siteinfo->basic($resp); |
| 237 |
$this->servicesInfo($resp); |
| 238 |
$this->dbconf($resp); |
| 239 |
$this->availableFunctions($resp); |
| 240 |
return array('actinfo' => $resp); |
| 241 |
} |
| 242 |
|
| 243 |
public function getHostInfo() { |
| 244 |
$host_info = $_SERVER; |
| 245 |
$host_info['PHP_SERVER_NAME'] = php_uname('\n'); |
| 246 |
if (array_key_exists('IS_PRESSABLE', get_defined_constants())) { |
| 247 |
$host_info['IS_PRESSABLE'] = true; |
| 248 |
} |
| 249 |
|
| 250 |
if (array_key_exists('GRIDPANE', get_defined_constants())) { |
| 251 |
$host_info['IS_GRIDPANE'] = true; |
| 252 |
} |
| 253 |
|
| 254 |
if (defined('WPE_APIKEY')) { |
| 255 |
$host_info['WPE_APIKEY'] = WPE_APIKEY; |
| 256 |
} |
| 257 |
|
| 258 |
return array('host_info' => $host_info); |
| 259 |
} |
| 260 |
|
| 261 |
public function process($request) { |
| 262 |
$db = $this->db; |
| 263 |
$params = $request->params; |
| 264 |
switch ($request->method) { |
| 265 |
case "activateinfo": |
| 266 |
$resp = $this->activate(); |
| 267 |
break; |
| 268 |
case "ckeyinfo": |
| 269 |
$resp = $this->cookieInfo(); |
| 270 |
break; |
| 271 |
case "gtpsts": |
| 272 |
$count = 5; |
| 273 |
if (array_key_exists('count', $params)) |
| 274 |
$count = $params['count']; |
| 275 |
$resp = $this->getPosts($params['post_type'], $count); |
| 276 |
break; |
| 277 |
case "gtsts": |
| 278 |
$resp = $this->getStats(); |
| 279 |
break; |
| 280 |
case "gtplgs": |
| 281 |
$resp = $this->getPlugins(); |
| 282 |
break; |
| 283 |
case "gtthms": |
| 284 |
$resp = $this->getThemes(); |
| 285 |
break; |
| 286 |
case "gtsym": |
| 287 |
$resp = $this->getSystemInfo(); |
| 288 |
break; |
| 289 |
case "gtwp": |
| 290 |
$resp = $this->getWpInfo(); |
| 291 |
break; |
| 292 |
case "gtallhdrs": |
| 293 |
$data = (function_exists('getallheaders')) ? getallheaders() : false; |
| 294 |
$resp = array("allhdrs" => $data); |
| 295 |
break; |
| 296 |
case "gtsvr": |
| 297 |
$resp = array("svr" => $_SERVER); |
| 298 |
break; |
| 299 |
case "getoption": |
| 300 |
$resp = array("option" => $this->settings->getOption($params['name'])); |
| 301 |
break; |
| 302 |
case "gtusrs": |
| 303 |
$full = false; |
| 304 |
if (array_key_exists('full', $params)) |
| 305 |
$full = true; |
| 306 |
$resp = $this->getUsers($full, $params['args']); |
| 307 |
break; |
| 308 |
case "gttrnsnt": |
| 309 |
$transient = $this->settings->getTransient($params['name']); |
| 310 |
if ($transient && array_key_exists('asarray', $params)) |
| 311 |
$transient = $this->objectToArray($transient); |
| 312 |
$resp = array("transient" => $transient); |
| 313 |
break; |
| 314 |
case "gthost": |
| 315 |
$resp = $this->getHostInfo(); |
| 316 |
break; |
| 317 |
case "gtplinfo": |
| 318 |
$args = array( |
| 319 |
'slug' => wp_unslash($params['slug']) |
| 320 |
); |
| 321 |
$action = $params['action']; |
| 322 |
$args = (object) $args; |
| 323 |
$args = apply_filters('plugins_api_args', $args, $action); |
| 324 |
$data = apply_filters('plugins_api', false, $action, $args); |
| 325 |
$resp = array("plugins_info" => $data); |
| 326 |
break; |
| 327 |
default: |
| 328 |
$resp = false; |
| 329 |
} |
| 330 |
return $resp; |
| 331 |
} |
| 332 |
} |
| 333 |
endif; |