output_header(); $this->output_system_information(); $this->output_logs(); $this->output_footer(); ?>

get_debug_info(); ?>

🌐

  • =')): ?>

🖼️

⚡

  • = 256): ?>

⚙️

  • 50) { $plugin_count= '50+'; } echo esc_html($plugin_count.' installed'); ?>

get_log_list(); $log_list=new CompressX_Log_List_V2(); $log_list->set_log_list($list); $log_list->prepare_items(); $log_list->display(); ?>
GetSaveLogFolder(); $files = array(); $handler = opendir($dir); $regex = '#^compressx.*_log.txt#'; if ($handler !== false) { while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { if (is_dir($dir . $filename)) { continue; } else { if (preg_match($regex, $filename)) { $files[$filename] = $dir . $filename; } } } } if ($handler) { @closedir($handler); } } foreach ($files as $file) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Simple read operation for log file metadata $handle = @fopen($file, "r"); if ($handle) { $log_file['file_name'] = basename($file); if (preg_match('/compressx-(.*?)_/', basename($file), $matches)) { $id = $matches[0]; $id = substr($id, 0, strlen($id) - 1); $log_file['id'] = $id; } $log_file['path'] = $file; $log_file['size'] = filesize($file); $log_file['name'] = basename($file); $log_file['time'] = filemtime($file); $offset = get_option('gmt_offset'); $localtime = $log_file['time'] + $offset * 60 * 60; $log_file['date'] = gmdate('M-d-y H:i', $localtime); $line = fgets($handle); if ($line !== false) { $pos = strpos($line, 'Log created: '); if ($pos !== false) { $log_file['time'] = substr($line, $pos + strlen('Log created: ')); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing file opened above for log reading fclose($handle); $log_list[basename($file)] = $log_file; } } $log_list = $this->sort_list($log_list); return $log_list; } public function sort_list($list) { uasort($list, function ($a, $b) { if ($a['time'] > $b['time']) { return -1; } else if ($a['time'] === $b['time']) { return 0; } else { return 1; } }); return $list; } /** * Get filtered log list by date/time range * * @since 2.0.0 * @param string $start_date Start date * @param string $start_time Start time * @param string $end_date End date * @param string $end_time End time * @return array */ public function get_log_list_ex($start_date, $start_time, $end_date, $end_time) { if (empty($start_date)) { $start = 0; } else if (empty($start_time)) { $start = strtotime($start_date); } else { $start = strtotime($start_date . ' ' . $start_time); } if ($start > 0) { $offset = get_option('gmt_offset'); $start = $start - $offset * 60 * 60; } if (empty($end_date)) { $end = 0; } else if (empty($end_time)) { $end = strtotime($end_date); } else { $end = strtotime($end_date . ' ' . $end_time); } if ($end > 0) { $offset = get_option('gmt_offset'); $end = $end - $offset * 60 * 60; } $log_list = array(); $log = new CompressX_Log(); $dir = $log->GetSaveLogFolder(); $files = array(); $handler = opendir($dir); $regex = '#^compressx.*_log.txt#'; if ($handler !== false) { while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { if (is_dir($dir . $filename)) { continue; } else { if (preg_match($regex, $filename)) { $files[$filename] = $dir . $filename; } } } } if ($handler) @closedir($handler); } foreach ($files as $file) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Simple read operation for log file metadata $handle = @fopen($file, "r"); if ($handle) { $log_file['file_name'] = basename($file); if (preg_match('/compressx-(.*?)_/', basename($file), $matches)) { $id = $matches[0]; $id = substr($id, 0, strlen($id) - 1); $log_file['id'] = $id; } $log_file['path'] = $file; $log_file['size'] = filesize($file); $log_file['name'] = basename($file); /* $log_file['time'] = preg_replace('/[^0-9]/', '', basename($file)); $offset = get_option('gmt_offset'); $localtime = strtotime($log_file['time']) + $offset * 60 * 60; $log_file['date'] = gmdate('M-d-y H:i', $localtime);*/ $log_file['time'] = filemtime($file); $offset = get_option('gmt_offset'); $localtime = $log_file['time'] + $offset * 60 * 60; $log_file['date'] = gmdate('M-d-y H:i', $localtime); $line = fgets($handle); if ($line !== false) { $pos = strpos($line, 'Log created: '); if ($pos !== false) { $log_file['time'] = substr($line, $pos + strlen('Log created: ')); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing file opened above for log reading fclose($handle); if ($start > 0 && $end > 0) { if ($localtime >= $start && $localtime <= $end) { $log_list[basename($file)] = $log_file; } } else if ($start > 0) { if ($localtime >= $start) { $log_list[basename($file)] = $log_file; } } else if ($end > 0) { if ($localtime <= $end) { $log_list[basename($file)] = $log_file; } } else { $log_list[basename($file)] = $log_file; } } } $log_list = $this->sort_list($log_list); return $log_list; } private function is_log_file($file_name) { if (preg_match('/compressx_.*_log\.txt$/', $file_name)) { return true; } return false; } public function open_log() { global $compressx; $compressx->ajax_check_security('compressx-can-use-logs'); try { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above if (!isset($_POST['filename'])) { die(); } // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Nonce is verified in ajax_check_security above $file_name = sanitize_text_field(wp_unslash($_POST['filename'])); $loglist = $this->get_log_list(); if (!empty($loglist)) { if (isset($loglist[$file_name])) { $log = $loglist[$file_name]; } else { $ret['result'] = 'failed'; $ret['error'] = __('The log not found ', 'compressx') . $file_name; echo wp_json_encode($ret); die(); } $path = $log['path']; if (!file_exists($path)) { $ret['result'] = 'failed'; $ret['error'] = __('The log not found ', 'compressx') . $file_name; echo wp_json_encode($ret); die(); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Simple read operation for log display $file = fopen($path, 'r'); if (!$file) { $ret['result'] = 'failed'; $ret['error'] = __('Unable to open the log file.', 'compressx'); echo wp_json_encode($ret); die(); } $offset = get_option('gmt_offset'); $buffer = ''; $create = gmdate('Y-m-d', $log['time']) ; while (!feof($file)) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread -- Reading log file for display $buffer .= fread($file, 1024); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing file opened above fclose($file); $ret['create'] = $create; $ret['result'] = 'success'; $ret['data'] = $buffer; echo wp_json_encode($ret); die(); } else { $ret['result'] = 'failed'; $ret['error'] = 'The log not found.'; echo wp_json_encode($ret); die(); } } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); } die(); } public function download_log() { global $compressx; $compressx->ajax_check_security('compressx-can-use-logs'); try { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is verified in ajax_check_security above $file_name = sanitize_file_name($_GET['log']); $log = new CompressX_Log(); $path = $log->GetSaveLogFolder() . $file_name; if (!file_exists($path)) { die(); } if (session_id()) { session_write_close(); } $size = filesize($path); if (!headers_sent()) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $file_name . '"'); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $size); } ob_end_clean(); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Sending file to browser for download readfile($path); } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); } exit; } public function delete_log() { global $compressx; $compressx->ajax_check_security('compressx-can-use-logs'); try { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above if (!isset($_POST['filename'])) { die(); } // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Nonce is verified in ajax_check_security above $file_name = sanitize_text_field(wp_unslash($_POST['filename'])); $loglist = $this->get_log_list(); if (!empty($loglist)) { if (isset($loglist[$file_name])) { $log = $loglist[$file_name]; } else { $ret['result'] = 'failed'; $ret['error'] = __('The log not found ', 'compressx') . $file_name; echo wp_json_encode($ret); die(); } $path = $log['path']; @wp_delete_file($path); $ret['result'] = 'success'; echo wp_json_encode($ret); die(); } else { $ret['result'] = 'failed'; $ret['error'] = __('The log not found ', 'compressx'); echo wp_json_encode($ret); die(); } } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); } die(); } public function delete_all_log() { global $compressx; $compressx->ajax_check_security('compressx-can-use-logs'); try { $log = new CompressX_Log(); $dir = $log->GetSaveLogFolder(); $files = array(); $handler = opendir($dir); if ($handler !== false) { while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { if (is_dir($dir . $filename)) { continue; } else { if ($this->is_log_file($filename)) { @wp_delete_file($dir . $filename); } } } } if ($handler) { closedir($handler); } } $ret['result'] = 'success'; } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); $ret['result'] = 'failed'; $ret['error'] = $message; } echo wp_json_encode($ret); die(); } public function get_logs_list() { global $compressx; $compressx->ajax_check_security('compressx-can-use-logs'); if(isset($_POST['start_date'])) { $start_date=sanitize_key($_POST['start_date']); } else { $start_date=''; } if(isset($_POST['start_time'])) { $start_time=sanitize_key($_POST['start_time']); } else { $start_time=''; } if(isset($_POST['end_date'])) { $end_date=sanitize_key($_POST['end_date']); } else { $end_date=''; } if(isset($_POST['end_time'])) { $end_time=sanitize_key($_POST['end_time']); } else { $end_time=''; } if(isset($_POST['page'])) { $page=sanitize_key($_POST['page']); } else { $page=0; } $list=$this->get_log_list_ex($start_date,$start_time,$end_date,$end_time); $log_list=new CompressX_Log_List_V2(); $log_list->set_log_list($list,$page); $log_list->prepare_items(); ob_start(); $log_list->display(); $json['result'] = 'success'; $json['html'] = ob_get_clean(); echo wp_json_encode($json); die(); } public function get_debug_info() { global $wp_version; $debug_info = array(); $debug_info['home'] = $this->get_domain(); $debug_info['Server name'] = $_SERVER['SERVER_NAME']; $debug_info['Web Server'] = sanitize_text_field($_SERVER["SERVER_SOFTWARE"]); $debug_info['CompressX version'] = COMPRESSX_VERSION; $debug_info['Wordpress version'] = $wp_version; $debug_info['PHP version'] = phpversion(); if (!function_exists('gd_info')) { $debug_info['GD extension'] = __("GD extension is not installed or enabled.", 'compressx'); } else { $debug_info['GD extension'] = __("The GD extension has been properly installed.", 'compressx'); $info = gd_info(); $debug_info['GD Version'] = isset($info['GD Version']) ? $info['GD Version'] : ''; $debug_info['GD WebP Support'] = isset($info['WebP Support']) ? $info['WebP Support'] : false; $debug_info['GD AVIF Support'] = isset($info['AVIF Support']) ? $info['AVIF Support'] : false; } if (extension_loaded('imagick') && class_exists('\Imagick')) { $debug_info['Imagick extension'] = __("The imagick extension has been properly installed.", 'compressx'); $debug_info['Imagick Version'] = \Imagick::getVersion(); $debug_info['Imagick WebP Support'] = \Imagick::queryformats('WEBP') ? true : false; $debug_info['Imagick AVIF Support'] = \Imagick::queryformats('AVIF') ? true : false; } else { $debug_info['Imagick extension'] = __("Imagick extension is not installed or enabled.", 'compressx'); } $debug_info['active_plugins'] = get_option('active_plugins'); $debug_info['active_theme'] = wp_get_theme()->get_template(); $debug_info['memory_current'] = size_format(memory_get_usage(), 2); $debug_info['memory_peak'] = size_format(memory_get_peak_usage(), 2); $debug_info['memory_limit'] = ini_get('memory_limit'); include_once COMPRESSX_DIR . '/includes/class-compressx-rewrite-checker.php'; $test = new CompressX_Rewrite_Checker(); $result = $test->test_ex(); if ($result['result'] == 'success') { $debug_info['Rewrite rules test'] = 'success'; } else { $debug_info['Rewrite rules test'] = $result['error']; } $options = get_option('compressx_general_settings', array()); $debug_info['setting'] = $options; $quality_options = get_option('compressx_quality', array()); $converter_method = get_option('compressx_converter_method', false); $output_format_webp = get_option('compressx_output_format_webp', 1); $output_format_avif = get_option('compressx_output_format_avif', 1); $debug_info['setting']['quality'] = $quality_options; $debug_info['setting']['output_format_webp'] = $output_format_webp; $debug_info['setting']['output_format_avif'] = $output_format_avif; $debug_info['setting']['converter_method'] = $converter_method; $debug_info['setting'] = wp_json_encode($debug_info['setting']); return $debug_info; } public function get_domain() { global $wpdb; $home_url = home_url(); $db_home_url = home_url(); $home_url_sql = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name = %s", 'home')); foreach ($home_url_sql as $home) { $db_home_url = untrailingslashit($home->option_value); } if ($home_url === $db_home_url) { $domain = $home_url; } else { $domain = $db_home_url; } return strtolower($domain); } public function create_debug_package() { global $compressx; $compressx->ajax_check_security('compressx-can-use-system-info'); try { if (!class_exists('PclZip')) include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php'); $backup_path = "compressx"; $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_debug.zip'; if (!is_dir(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path)) { wp_mkdir_p(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating protection files @fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'index.html', 'x'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating htaccess protection file $tempfile = @fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . '.htaccess', 'x'); if ($tempfile) { $text = "deny from all"; // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite -- Writing htaccess protection fwrite($tempfile, $text); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing htaccess file fclose($tempfile); } } if (file_exists($path)) { @wp_delete_file($path); } $archive = new PclZip($path); $server_info = wp_json_encode($this->get_debug_info()); $server_file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_server_info.json'; if (file_exists($server_file_path)) { @wp_delete_file($server_file_path); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating temporary debug info file $server_file = fopen($server_file_path, 'x'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing temporary file fclose($server_file); file_put_contents($server_file_path, $server_info); if (!$archive->add($server_file_path, PCLZIP_OPT_REMOVE_ALL_PATH)) { exit; } @wp_delete_file($server_file_path); $log = new CompressX_Log(); $files = $log->get_logs(); if (!empty($files)) { if (!$archive->add($files, PCLZIP_OPT_REMOVE_ALL_PATH)) { exit; } } if (session_id()) session_write_close(); $size = filesize($path); if (!headers_sent()) { header('Content-Description: File Transfer'); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Cache-Control: must-revalidate'); header('Content-Length: ' . $size); header('Content-Transfer-Encoding: binary'); } ob_end_clean(); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- Sending debug package to browser for download readfile($path); @wp_delete_file($path); } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); die(); } exit; } public function send_debug_info() { global $compressx; $compressx->ajax_check_security('compressx-can-use-system-info'); try { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above if (!isset($_POST['user_mail']) || empty($_POST['user_mail'])) { $ret['result'] = 'failed'; $ret['error'] = __('User\'s email address is required.', 'compressx'); } else { $pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i'; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above if (!preg_match($pattern, $_POST['user_mail'])) { $ret['result'] = 'failed'; $ret['error'] = __('Please enter a valid email address.', 'compressx'); } else { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above $user_mail = sanitize_email($_POST['user_mail']); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is verified in ajax_check_security above $comment = sanitize_text_field($_POST['comment']); $ret = $this->_send_debug_info($user_mail, $comment); } } echo wp_json_encode($ret); die(); } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); die(); } } public function _send_debug_info($user_email, $comment) { $send_to = 'support@compressx.io'; $subject = 'Debug Information'; $body = '
User\'s email: ' . $user_email . '.
'; $body .= '
Comment: ' . $comment . '.
'; $headers = array('Content-Type: text/html; charset=UTF-8'); if (!class_exists('PclZip')) include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php'); $backup_path = "compressx"; $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_debug.zip'; if (!is_dir(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path)) { wp_mkdir_p(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating protection files @fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'index.html', 'x'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating htaccess protection file $tempfile = @fopen(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . '.htaccess', 'x'); if ($tempfile) { $text = "deny from all"; // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite -- Writing htaccess protection fwrite($tempfile, $text); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing htaccess file fclose($tempfile); } } if (file_exists($path)) { @wp_delete_file($path); } $archive = new PclZip($path); $server_info = wp_json_encode($this->get_debug_info()); $server_file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_server_info.json'; if (file_exists($server_file_path)) { @wp_delete_file($server_file_path); } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen -- Creating temporary debug info file $server_file = fopen($server_file_path, 'x'); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing temporary file fclose($server_file); file_put_contents($server_file_path, $server_info); $archive->add($server_file_path, PCLZIP_OPT_REMOVE_ALL_PATH); @wp_delete_file($server_file_path); $log = new CompressX_Log(); $files = $log->get_logs(); if (!empty($files)) { $archive->add($files, PCLZIP_OPT_REMOVE_ALL_PATH); } $attachments[] = $path; if (wp_mail($send_to, $subject, $body, $headers, $attachments) === false) { $ret['result'] = 'failed'; $ret['error'] = __('Unable to send email. Please check the configuration of email server.', 'compressx'); } else { $ret['result'] = 'success'; } @wp_delete_file($path); return $ret; } }