PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.16.2
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.16.2
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / diagnostics.php
nitropack Last commit date
classes 1 year ago languages 2 years ago nitropack-sdk 1 year ago view 1 year ago advanced-cache.php 2 years ago batcache-compat.php 4 years ago constants.php 1 year ago diagnostics.php 2 years ago functions.php 1 year ago helpers.php 3 years ago main.php 1 year ago readme.txt 1 year ago uninstall.php 2 years ago wp-cli.php 2 years ago
diagnostics.php
219 lines
1 <?php
2
3 defined( 'ABSPATH' ) or die( 'Someone made a boo boo!' );
4
5 use \NitroPack\SDK\Api\ResponseStatus;
6
7 if (!function_exists('get_plugins')) {
8 require_once ABSPATH . 'wp-admin/includes/plugin.php';
9 }
10
11 $np_diag_functions = array(
12 'general-info-status' => 'npdiag_get_general_info',
13 'active-plugins-status' => 'npdiag_get_active_plugins',
14 'conflicting-plugins-status' => 'npdiag_get_conflicting_plugins',
15 'user-config-status' => 'npdiag_get_user_config',
16 'dir-info-status' => 'npdiag_get_dir_info',
17 'getexternalcache' => 'npdiag_detect_third_party_cache'
18
19 );
20
21 function npdiag_helper_trailingslashit($string) {
22 return rtrim( $string, '/\\' ) . '/';
23 }
24
25 function npdiag_compare_webhooks($nitro_sdk) {
26 try {
27 $siteConfig = nitropack_get_site_config();
28 if (!empty($siteConfig['siteId'])) {
29 $WHToken = nitropack_generate_webhook_token($siteConfig['siteId']);
30 $constructedWH = new \NitroPack\Url\Url(strtolower(get_home_url())) . '?nitroWebhook=config&token=' . $WHToken;
31 $storedWH = $nitro_sdk->getApi()->getWebhook("config");
32 $matchResult = ($constructedWH == $storedWH) ? __( 'OK', 'nitropack' ) : __( 'Warning: Webhooks do not match this site', 'nitropack' );
33 } else {
34 $debugMsg = empty($_SERVER["HTTP_HOST"]) ? "HTTP_HOST is not defined. " : "";
35 $debugMsg .= empty($_SERVER["REQUEST_URI"]) ? "REQUEST_URI is not defined. " : "";
36 $debugMsg .= empty($debugMsg) ? 'URL used to match config was: ' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : "";
37 $matchResult = __( 'Site config cannot be found, because ', 'nitropack' ) . $debugMsg;
38 }
39 return $matchResult;
40 } catch (\Exception $e) {
41 return $e->getMessage();
42 }
43 }
44
45 function npdiag_poll_api($nitro_sdk) {
46 $pollResult = array(
47 ResponseStatus::OK => __( 'OK', 'nitropack' ),
48 ResponseStatus::ACCEPTED => __( 'OK', 'nitropack' ),
49 ResponseStatus::BAD_REQUEST => __( 'Bad request.', 'nitropack' ),
50 ResponseStatus::PAYMENT_REQUIRED => __( 'Payment required. Please, contact NP support for details.', 'nitropack' ),
51 ResponseStatus::FORBIDDEN => __( 'Site disabled. Please, contact NP support for details.', 'nitropack' ),
52 ResponseStatus::NOT_FOUND => __( 'URL used for the API poll request returned 404. Please ignore this.', 'nitropack' ),
53 ResponseStatus::CONFLICT => __( 'Conflict. There is another operation, which prevents accepting optimization requests at the moment. Please, contact NP support for details.', 'nitropack' ),
54 ResponseStatus::RUNTIME_ERROR => __( 'Runtime error.', 'nitropack' ),
55 ResponseStatus::SERVICE_UNAVAILABLE => __( 'Service unavailable.', 'nitropack' ),
56 ResponseStatus::UNKNOWN => __( 'Unknown.', 'nitropack' )
57 );
58
59 try {
60 $referer = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '';
61 $apiResponseCode = $nitro_sdk->getApi()->getCache(get_home_url(), __( 'NitroPack Diagnostic Agent', 'nitropack' ), array(), false, 'default', $referer)->getStatus();
62 return $pollResult[$apiResponseCode];
63 } catch (\Exception $e) {
64 return 'Error: ' . $e->getMessage();
65 }
66
67 }
68
69 function npdiag_backlog_status($nitro_sdk) {
70 return $nitro_sdk->backlog->exists() ? 'Warning' : 'OK';
71 }
72
73 function npdiag_get_general_info() {
74 global $wp_version;
75 if (null !== $nitro = get_nitropack_sdk()) {
76 $probe_result = "OK";
77 try {
78 $nitro->fetchConfig();
79 } catch (\Exception $e) {
80 $probe_result = __( 'Error: ', 'nitropack' ) . $e->getMessage();
81 }
82 } else {
83 $probe_result = __( 'Error: Cannot get an SDK instance', 'nitropack' );
84 }
85
86 $third_party_residual_cache = npdiag_detect_third_party_cache();
87
88 $info = array(
89 'Nitro_WP_version' => !empty($wp_version) ? $wp_version : get_bloginfo('version'),
90 'Nitro_Version' => defined('NITROPACK_VERSION') ? NITROPACK_VERSION : __( 'Undefined', 'nitropack' ),
91 'Nitro_SDK_Connection' => $probe_result,
92 'Nitro_API_Polling' => $nitro ? npdiag_poll_api($nitro) : __( 'Error: Cannot get an SDK instance', 'nitropack' ),
93 'Nitro_SDK_Version' => defined('NitroPack\SDK\Nitropack::VERSION') ? NitroPack\SDK\Nitropack::VERSION : __( 'Undefined', 'nitropack' ),
94 'Nitro_WP_Cache' => defined('WP_CACHE') ? (WP_CACHE ? __( 'OK for drop-in', 'nitropack' ) : __( 'Turned off', 'nitropack' )) : __( 'Undefined', 'nitropack' ),
95 'Advanced_Cache_Version' => defined('NITROPACK_ADVANCED_CACHE_VERSION') ? NITROPACK_ADVANCED_CACHE_VERSION : __( 'Undefined', 'nitropack' ),
96 'Nitro_Absolute_Path' => defined('ABSPATH') ? ABSPATH : __( 'Undefined', 'nitropack' ),
97 'Nitro_Plugin_Directory' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__),
98 'Nitro_Data_Directory' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : __( 'Undefined', 'nitropack' ),
99 'Nitro_Plugin_Data_Directory' => defined('NITROPACK_PLUGIN_DATA_DIR') ? NITROPACK_PLUGIN_DATA_DIR : __( 'Undefined', 'nitropack' ),
100 'Nitro_Config_File' => defined('NITROPACK_CONFIG_FILE') ? NITROPACK_CONFIG_FILE : __( 'Undefined', 'nitropack' ),
101 'Nitro_Backlog_File_Status' => $nitro ? npdiag_backlog_status($nitro) : __( 'Error: Cannot get an SDK instance', 'nitropack' ),
102 'Nitro_Webhooks' => $nitro ? npdiag_compare_webhooks($nitro) : __( 'Error: Cannot get an SDK instance', 'nitropack' ),
103 'Nitro_Connectivity_Requirements' => nitropack_check_func_availability('stream_socket_client') ? __( 'OK', 'nitropack' ) : __( 'Warning: "stream_socket_client" function is disabled.', 'nitropack' ),
104 'Residual_Cache_Found_For' => $third_party_residual_cache,
105 );
106
107 if (defined("NITROPACK_VERSION") && defined("NITROPACK_ADVANCED_CACHE_VERSION") && NITROPACK_VERSION == NITROPACK_ADVANCED_CACHE_VERSION && nitropack_is_dropin_cache_allowed()) {
108 $info['Nitro_Cache_Method'] = 'drop-in';
109 } elseif ( defined('EZOIC_INTEGRATION_VERSION') ) {
110 $info['Nitro_Cache_Method'] = 'plugin-ezoic';
111 } else {
112 $info['Nitro_Cache_Method'] = 'plugin';
113 }
114
115 return $info;
116 }
117
118 function npdiag_get_active_plugins() {
119 if (is_admin()) {
120 $info = array();
121 $raw_installed_list = get_plugins();
122 $raw_active_list = get_option('active_plugins');
123 foreach ($raw_installed_list as $pkey => $pval) {
124 if ( in_array($pkey, $raw_active_list) ) {
125 $info[$pval['Name']] = $pval['Version'];
126 }
127 }
128 }
129
130 return $info;
131 }
132
133 function npdiag_get_user_config() {
134 if (defined('NITROPACK_CONFIG_FILE')) {
135 if (file_exists(NITROPACK_CONFIG_FILE)) {
136 $info = json_decode(file_get_contents(NITROPACK_CONFIG_FILE));
137 if (!$info) {
138 $info = __( 'Config found, but unable to get contents.', 'nitropack' );
139 }
140 } else {
141 $info = __( 'Config file not found.', 'nitropack' );
142 }
143 } else {
144 $info = __( 'Config file constant is not defined.', 'nitropack' );
145 }
146
147 return $info;
148 }
149
150 function npdiag_get_dir_info() {
151 $siteConfig = nitropack_get_site_config();
152 $siteID = $siteConfig['siteId'];
153 // DoI = Directories of Interest
154 $DoI = array(
155 'WP_Content_Dir_Writable' => defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : (defined('ABSPATH') ? ABSPATH . '/wp-content' : __( 'Undefined', 'nitropack' )),
156 'Nitro_Data_Dir_Writable' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack',
157 'Nitro_siteID_Dir_Writable' => defined('NITROPACK_DATA_DIR') ? NITROPACK_DATA_DIR . "/$siteID" : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . "nitropack/$siteID",
158 'Nitro_Plugin_Dir_Writable' => defined('NITROPACK_PLUGIN_DIR') ? NITROPACK_PLUGIN_DIR : dirname(__FILE__),
159 'Nitro_Plugin_Data_Dir_Writable' => defined('NITROPACK_PLUGIN_DATA_DIR') ? NITROPACK_PLUGIN_DATA_DIR : npdiag_helper_trailingslashit(WP_CONTENT_DIR) . 'nitropack',
160 );
161
162 $info = array();
163 foreach ($DoI as $doi_dir => $dpath) {
164 if (is_dir($dpath)) {
165 $info[$doi_dir] = is_writeable($dpath) ? true : false;
166 } else if (is_file($dpath)) {
167 $info[$doi_dir] = $dpath. __( ' is a file not a directory', 'nitropack' );
168 } else {
169 $info[$doi_dir] = __( 'Directory not found', 'nitropack' );
170 }
171 }
172
173 return $info;
174 }
175
176 function npdiag_get_conflicting_plugins() {
177 $info = nitropack_get_conflicting_plugins();
178 if ( !empty($info) ) {
179 return $info;
180 } else {
181 return $info = __( 'None detected', 'nitropack' );
182 }
183 }
184
185 function npdiag_detect_third_party_cache() {
186 $info = \NitroPack\Integration\Plugin\RC::detectThirdPartyCaches();
187 if ( !empty($info) ) {
188 return $info;
189 } else {
190 return $info = __( 'Not found', 'nitropack' );
191 }
192 }
193
194 function nitropack_generate_report() {
195 global $np_diag_functions;
196 nitropack_verify_ajax_nonce($_REQUEST);
197 try {
198 $ar = !empty($_POST["toggled"]) ? $_POST["toggled"] : NULL;
199 if ($ar !== NULL) {
200 $diag_data = array('report-time-stamp' => date("Y-m-d H:i:s"));
201 foreach ($ar as $func_name => $func_allowed) {
202 if ((boolean)$func_allowed) {
203 $diag_data[$func_name] = call_user_func($np_diag_functions[$func_name]);
204 }
205 }
206 $str = json_encode($diag_data, JSON_PRETTY_PRINT);
207 $filename = 'nitropack_diag_file.txt';
208 nitropack_header('Content-Disposition: attachment; filename="'.$filename.'"');
209 nitropack_header("Content-Type: text/plain");
210 nitropack_header("Content-Length: " . strlen($str));
211 echo $str;
212 exit;
213 }
214 } catch (\Exception $e) {
215 //exception handling here
216 }
217
218 }
219