cdn
7 months ago
data_structure
7 months ago
activation.cls.php
7 months ago
admin-display.cls.php
7 months ago
admin-settings.cls.php
7 months ago
admin.cls.php
7 months ago
api.cls.php
7 months ago
avatar.cls.php
7 months ago
base.cls.php
7 months ago
cdn.cls.php
7 months ago
cloud.cls.php
7 months ago
conf.cls.php
7 months ago
control.cls.php
7 months ago
core.cls.php
7 months ago
crawler-map.cls.php
7 months ago
crawler.cls.php
7 months ago
css.cls.php
7 months ago
data.cls.php
7 months ago
data.upgrade.func.php
7 months ago
db-optm.cls.php
7 months ago
debug2.cls.php
7 months ago
doc.cls.php
7 months ago
error.cls.php
7 months ago
esi.cls.php
7 months ago
file.cls.php
7 months ago
gui.cls.php
7 months ago
health.cls.php
7 months ago
htaccess.cls.php
7 months ago
img-optm.cls.php
7 months ago
import.cls.php
7 months ago
import.preset.cls.php
7 months ago
lang.cls.php
7 months ago
localization.cls.php
7 months ago
media.cls.php
7 months ago
metabox.cls.php
7 months ago
object-cache-wp.cls.php
7 months ago
object-cache.cls.php
7 months ago
object.lib.php
7 months ago
optimize.cls.php
7 months ago
optimizer.cls.php
7 months ago
placeholder.cls.php
7 months ago
purge.cls.php
7 months ago
report.cls.php
7 months ago
rest.cls.php
7 months ago
root.cls.php
7 months ago
router.cls.php
7 months ago
str.cls.php
7 months ago
tag.cls.php
7 months ago
task.cls.php
7 months ago
tool.cls.php
7 months ago
ucss.cls.php
7 months ago
utility.cls.php
7 months ago
vary.cls.php
7 months ago
vpi.cls.php
7 months ago
report.cls.php
269 lines
| 1 | <?php |
| 2 | // phpcs:ignoreFile |
| 3 | |
| 4 | /** |
| 5 | * The report class |
| 6 | * |
| 7 | * @since 1.1.0 |
| 8 | * @package LiteSpeed |
| 9 | */ |
| 10 | |
| 11 | namespace LiteSpeed; |
| 12 | |
| 13 | defined('WPINC') || exit(); |
| 14 | |
| 15 | class Report extends Base { |
| 16 | |
| 17 | const TYPE_SEND_REPORT = 'send_report'; |
| 18 | |
| 19 | /** |
| 20 | * Handle all request actions from main cls |
| 21 | * |
| 22 | * @since 1.6.5 |
| 23 | * @access public |
| 24 | */ |
| 25 | public function handler() { |
| 26 | $type = Router::verify_type(); |
| 27 | |
| 28 | switch ($type) { |
| 29 | case self::TYPE_SEND_REPORT: |
| 30 | $this->post_env(); |
| 31 | break; |
| 32 | |
| 33 | default: |
| 34 | break; |
| 35 | } |
| 36 | |
| 37 | Admin::redirect(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * post env report number to ls center server |
| 42 | * |
| 43 | * @since 1.6.5 |
| 44 | * @access public |
| 45 | */ |
| 46 | public function post_env() { |
| 47 | $report_con = $this->generate_environment_report(); |
| 48 | |
| 49 | // Generate link |
| 50 | $link = !empty($_POST['link']) ? esc_url($_POST['link']) : ''; |
| 51 | |
| 52 | $notes = !empty($_POST['notes']) ? esc_html($_POST['notes']) : ''; |
| 53 | |
| 54 | $php_info = !empty($_POST['attach_php']) ? esc_html($_POST['attach_php']) : ''; |
| 55 | $report_php = $php_info === '1' ? $this->generate_php_report() : ''; |
| 56 | |
| 57 | if ($report_php) { |
| 58 | $report_con .= "\nPHPINFO\n" . $report_php; |
| 59 | } |
| 60 | |
| 61 | $data = array( |
| 62 | 'env' => $report_con, |
| 63 | 'link' => $link, |
| 64 | 'notes' => $notes, |
| 65 | ); |
| 66 | |
| 67 | $json = Cloud::post(Cloud::API_REPORT, $data); |
| 68 | if (!is_array($json)) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | $num = !empty($json['num']) ? $json['num'] : '--'; |
| 73 | $summary = array( |
| 74 | 'num' => $num, |
| 75 | 'dateline' => time(), |
| 76 | ); |
| 77 | |
| 78 | self::save_summary($summary); |
| 79 | |
| 80 | return $num; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Gathers the PHP information. |
| 85 | * |
| 86 | * @since 7.0 |
| 87 | * @access public |
| 88 | */ |
| 89 | public function generate_php_report( $flags = INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES ) { |
| 90 | // INFO_ENVIRONMENT |
| 91 | $report = ''; |
| 92 | |
| 93 | ob_start(); |
| 94 | phpinfo($flags); |
| 95 | $report = ob_get_contents(); |
| 96 | ob_end_clean(); |
| 97 | |
| 98 | preg_match('%<style type="text/css">(.*?)</style>.*?<body>(.*?)</body>%s', $report, $report); |
| 99 | |
| 100 | return $report[2]; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Gathers the environment details and creates the report. |
| 105 | * Will write to the environment report file. |
| 106 | * |
| 107 | * @since 1.0.12 |
| 108 | * @access public |
| 109 | */ |
| 110 | public function generate_environment_report( $options = null ) { |
| 111 | global $wp_version, $_SERVER; |
| 112 | $frontend_htaccess = Htaccess::get_frontend_htaccess(); |
| 113 | $backend_htaccess = Htaccess::get_backend_htaccess(); |
| 114 | $paths = array( $frontend_htaccess ); |
| 115 | if ($frontend_htaccess != $backend_htaccess) { |
| 116 | $paths[] = $backend_htaccess; |
| 117 | } |
| 118 | |
| 119 | if (is_multisite()) { |
| 120 | $active_plugins = get_site_option('active_sitewide_plugins'); |
| 121 | if (!empty($active_plugins)) { |
| 122 | $active_plugins = array_keys($active_plugins); |
| 123 | } |
| 124 | } else { |
| 125 | $active_plugins = get_option('active_plugins'); |
| 126 | } |
| 127 | |
| 128 | if (function_exists('wp_get_theme')) { |
| 129 | $theme_obj = wp_get_theme(); |
| 130 | $active_theme = $theme_obj->get('Name'); |
| 131 | } else { |
| 132 | $active_theme = get_current_theme(); |
| 133 | } |
| 134 | |
| 135 | $extras = array( |
| 136 | 'wordpress version' => $wp_version, |
| 137 | 'siteurl' => get_option('siteurl'), |
| 138 | 'home' => get_option('home'), |
| 139 | 'home_url' => home_url(), |
| 140 | 'locale' => get_locale(), |
| 141 | 'active theme' => $active_theme, |
| 142 | ); |
| 143 | |
| 144 | $extras['active plugins'] = $active_plugins; |
| 145 | $extras['cloud'] = Cloud::get_summary(); |
| 146 | foreach (array( 'mini_html', 'pk_b64', 'sk_b64', 'cdn_dash', 'ips' ) as $v) { |
| 147 | if (!empty($extras['cloud'][$v])) { |
| 148 | unset($extras['cloud'][$v]); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (is_null($options)) { |
| 153 | $options = $this->get_options(true); |
| 154 | |
| 155 | if (is_multisite()) { |
| 156 | $options2 = $this->get_options(); |
| 157 | foreach ($options2 as $k => $v) { |
| 158 | if (isset($options[$k]) && $options[$k] !== $v) { |
| 159 | $options['[Overwritten] ' . $k] = $v; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if (!is_null($options) && is_multisite()) { |
| 166 | $blogs = Activation::get_network_ids(); |
| 167 | if (!empty($blogs)) { |
| 168 | $i = 0; |
| 169 | foreach ($blogs as $blog_id) { |
| 170 | if (++$i > 3) { |
| 171 | // Only log 3 subsites |
| 172 | break; |
| 173 | } |
| 174 | $opts = $this->cls('Conf')->load_options($blog_id, true); |
| 175 | if (isset($opts[self::O_CACHE])) { |
| 176 | $options['blog ' . $blog_id . ' radio select'] = $opts[self::O_CACHE]; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Security: Remove cf key in report |
| 183 | $secure_fields = array( self::O_CDN_CLOUDFLARE_KEY, self::O_OBJECT_PSWD ); |
| 184 | foreach ($secure_fields as $v) { |
| 185 | if (!empty($options[$v])) { |
| 186 | $options[$v] = str_repeat('*', strlen($options[$v])); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | $report = $this->build_environment_report($_SERVER, $options, $extras, $paths); |
| 191 | return $report; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Builds the environment report buffer with the given parameters |
| 196 | * |
| 197 | * @access private |
| 198 | */ |
| 199 | private function build_environment_report( $server, $options, $extras = array(), $htaccess_paths = array() ) { |
| 200 | $server_keys = array( |
| 201 | 'DOCUMENT_ROOT' => '', |
| 202 | 'SERVER_SOFTWARE' => '', |
| 203 | 'X-LSCACHE' => '', |
| 204 | 'HTTP_X_LSCACHE' => '', |
| 205 | ); |
| 206 | $server_vars = array_intersect_key($server, $server_keys); |
| 207 | $server_vars[] = 'LSWCP_TAG_PREFIX = ' . LSWCP_TAG_PREFIX; |
| 208 | |
| 209 | $server_vars = array_merge($server_vars, $this->cls('Base')->server_vars()); |
| 210 | |
| 211 | $buf = $this->_format_report_section('Server Variables', $server_vars); |
| 212 | |
| 213 | $buf .= $this->_format_report_section('WordPress Specific Extras', $extras); |
| 214 | |
| 215 | $buf .= $this->_format_report_section('LSCache Plugin Options', $options); |
| 216 | |
| 217 | if (empty($htaccess_paths)) { |
| 218 | return $buf; |
| 219 | } |
| 220 | |
| 221 | foreach ($htaccess_paths as $path) { |
| 222 | if (!file_exists($path) || !is_readable($path)) { |
| 223 | $buf .= $path . " does not exist or is not readable.\n"; |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | $content = file_get_contents($path); |
| 228 | if ($content === false) { |
| 229 | $buf .= $path . " returned false for file_get_contents.\n"; |
| 230 | continue; |
| 231 | } |
| 232 | $buf .= $path . " contents:\n" . $content . "\n\n"; |
| 233 | } |
| 234 | return $buf; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Creates a part of the environment report based on a section header and an array for the section parameters. |
| 239 | * |
| 240 | * @since 1.0.12 |
| 241 | * @access private |
| 242 | */ |
| 243 | private function _format_report_section( $section_header, $section ) { |
| 244 | $tab = ' '; // four spaces |
| 245 | |
| 246 | if (empty($section)) { |
| 247 | return 'No matching ' . $section_header . "\n\n"; |
| 248 | } |
| 249 | $buf = $section_header; |
| 250 | |
| 251 | foreach ($section as $k => $v) { |
| 252 | $buf .= "\n" . $tab; |
| 253 | |
| 254 | if (!is_numeric($k)) { |
| 255 | $buf .= $k . ' = '; |
| 256 | } |
| 257 | |
| 258 | if (!is_string($v)) { |
| 259 | $v = var_export($v, true); |
| 260 | } else { |
| 261 | $v = esc_html($v); |
| 262 | } |
| 263 | |
| 264 | $buf .= $v; |
| 265 | } |
| 266 | return $buf . "\n\n"; |
| 267 | } |
| 268 | } |
| 269 |