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