PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 4.2.5
Jetpack – WP Security, Backup, Speed, & Growth v4.2.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / class.jetpack-debugger.php
class.jetpack-debugger.php
490 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Jetpack_Debugger {
4
5 private static function is_jetpack_support_open() {
6 try {
7 $url = add_query_arg( 'ver', JETPACK__VERSION, 'https://jetpack.com/is-support-open/' );
8 $response = wp_remote_request( esc_url_raw( $url ) );
9 if ( is_wp_error( $response ) ) {
10 return false;
11 }
12 $body = wp_remote_retrieve_body( $response );
13 $json = json_decode( $body );
14 return ( ( bool ) $json->is_support_open );
15 }
16 catch ( Exception $e ) {
17 return true;
18 }
19 }
20
21 static function seconds_to_time( $seconds ) {
22 $units = array(
23 "week" => 7*24*3600,
24 "day" => 24*3600,
25 "hour" => 3600,
26 "minute" => 60,
27 "second" => 1,
28 );
29 // specifically handle zero
30 if ( $seconds == 0 ) return "0 seconds";
31 $human_readable = "";
32 foreach ( $units as $name => $divisor ) {
33 if ( $quot = intval( $seconds / $divisor) ) {
34 $human_readable .= "$quot $name";
35 $human_readable .= ( abs( $quot ) > 1 ? "s" : "" ) . ", ";
36 $seconds -= $quot * $divisor;
37 }
38 }
39 return substr( $human_readable, 0, -2 );
40 }
41
42 public static function jetpack_increase_timeout() {
43 return 30; // seconds
44 }
45
46 public static function jetpack_debug_display_handler() {
47 if ( ! current_user_can( 'manage_options' ) )
48 wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
49
50 $current_user = wp_get_current_user();
51
52 $user_id = get_current_user_id();
53 $user_tokens = Jetpack_Options::get_option( 'user_tokens' );
54 if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
55 $user_token = $user_tokens[$user_id];
56 } else {
57 $user_token = '[this user has no token]';
58 }
59 unset( $user_tokens );
60
61 $debug_info = "\r\n";
62 foreach ( array(
63 'CLIENT_ID' => 'id',
64 'BLOG_TOKEN' => 'blog_token',
65 'MASTER_USER' => 'master_user',
66 'CERT' => 'fallback_no_verify_ssl_certs',
67 'TIME_DIFF' => 'time_diff',
68 'VERSION' => 'version',
69 'OLD_VERSION' => 'old_version',
70 'PUBLIC' => 'public',
71 ) as $label => $option_name ) {
72 $debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack_Options::get_option( $option_name ) );
73 }
74
75 $debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
76 $debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
77 $debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
78 $debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
79 $debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
80 $debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
81 $debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
82 $debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
83
84 $debug_info .= "\r\n";
85 require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
86 $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
87 $sync_statuses = $sync_module->get_status();
88 $human_readable_sync_status = array();
89 foreach( $sync_statuses as $sync_status => $sync_status_value ) {
90 $human_readable_sync_status[ $sync_status ] =
91 in_array( $sync_status, array( 'started', 'queue_finished', 'sent_started', 'finished' ) )
92 ? date( 'r', $sync_status_value ) : $sync_status_value ;
93 }
94
95 $debug_info .= "\r\n". sprintf( esc_html__( 'Jetpack Sync Full Status: `%1$s`', 'jetpack' ), print_r( $human_readable_sync_status, 1 ) );
96
97 $next_schedules = wp_next_scheduled( 'jetpack_sync_full' );
98 if( $next_schedules ) {
99 $debug_info .= "\r\n". sprintf( esc_html__( 'Next Jetpack Full Sync Schedule: `%1$s`', 'jetpack' ), date( 'r', $next_schedules ) );
100 } else {
101 $debug_info .= "\r\n". esc_html__( "Next Jetpack Full Sync Schedule: Not Scheduled", 'jetpack' );
102 }
103
104 require_once JETPACK__PLUGIN_DIR. 'sync/class.jetpack-sync-sender.php';
105
106 $queue = Jetpack_Sync_Sender::get_instance()->get_sync_queue();
107
108 $debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue size: %1$s', 'jetpack' ), $queue->size() );
109 $debug_info .= "\r\n". sprintf( esc_html__( 'Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $queue->lag() ) );
110
111 $full_sync_queue = Jetpack_Sync_Sender::get_instance()->get_full_sync_queue();
112
113 $debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue size: %1$s', 'jetpack' ), $full_sync_queue->size() );
114 $debug_info .= "\r\n". sprintf( esc_html__( 'Full Sync Queue lag: %1$s', 'jetpack' ), self::seconds_to_time( $full_sync_queue->lag() ) );
115
116 $debug_info .= "\r\n";
117
118 foreach ( array (
119 'HTTP_HOST',
120 'SERVER_PORT',
121 'HTTPS',
122 'GD_PHP_HANDLER',
123 'HTTP_AKAMAI_ORIGIN_HOP',
124 'HTTP_CF_CONNECTING_IP',
125 'HTTP_CLIENT_IP',
126 'HTTP_FASTLY_CLIENT_IP',
127 'HTTP_FORWARDED',
128 'HTTP_FORWARDED_FOR',
129 'HTTP_INCAP_CLIENT_IP',
130 'HTTP_TRUE_CLIENT_IP',
131 'HTTP_X_CLIENTIP',
132 'HTTP_X_CLUSTER_CLIENT_IP',
133 'HTTP_X_FORWARDED',
134 'HTTP_X_FORWARDED_FOR',
135 'HTTP_X_IP_TRAIL',
136 'HTTP_X_REAL_IP',
137 'HTTP_X_VARNISH',
138 'REMOTE_ADDR'
139 ) as $header ) {
140 if ( isset( $_SERVER[ $header ] ) ) {
141 $debug_info .= "\r\n" . esc_html( $header . ": " . $_SERVER[ $header ] );
142 }
143 }
144
145 $debug_info .= "\r\n" . esc_html( "PROTECT_TRUSTED_HEADER: " . json_encode( get_site_option( 'trusted_ip_header' ) ) );
146
147 $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
148 $debug_raw_info = '';
149
150
151 $tests = array();
152
153 $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
154 $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
155
156 $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
157 $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
158
159 $identity_crisis_message = '';
160 if ( $identity_crisis = Jetpack::check_identity_crisis( true ) ) {
161 foreach( $identity_crisis as $key => $value ) {
162 $identity_crisis_message .= sprintf( __( 'Your `%1$s` option is set up as `%2$s`, but your WordPress.com connection lists it as `%3$s`!', 'jetpack' ), $key, (string) get_option( $key ), $value ) . "\r\n";
163 }
164 $identity_crisis = new WP_Error( 'identity-crisis', $identity_crisis_message, $identity_crisis );
165 } else {
166 $identity_crisis = 'PASS';
167 }
168 $tests['IDENTITY_CRISIS']['result'] = $identity_crisis;
169 $tests['IDENTITY_CRISIS']['fail_message'] = esc_html__( 'Something has gotten mixed up in your Jetpack Connection!', 'jetpack' );
170
171 $self_xml_rpc_url = home_url( 'xmlrpc.php' );
172
173 $testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=' );
174
175 add_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
176
177 $tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
178 if ( is_wp_error( $tests['SELF']['result'] ) && 0 == strpos( $tests['SELF']['result']->get_error_message(), 'Operation timed out' ) ){
179 $tests['SELF']['fail_message'] = esc_html__( 'Your site did not get a response from our debugging service in the expected timeframe. If you are not experiencing other issues, this could be due to a slow connection between your site and our server.', 'jetpack' );
180 } else {
181 $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
182 }
183
184 remove_filter( 'http_request_timeout', array( 'Jetpack_Debugger', 'jetpack_increase_timeout' ) );
185
186 ?>
187 <div class="wrap">
188 <h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
189 <h3><?php _e( "Testing your site's compatibility with Jetpack...", 'jetpack' ); ?></h3>
190 <div class="jetpack-debug-test-container">
191 <?php
192 ob_start();
193 foreach ( $tests as $test_name => $test_info ) :
194 if ( 'PASS' !== $test_info['result'] && ( is_wp_error( $test_info['result'] ) ||
195 false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) ) ||
196 '200' != $response_code ) ) {
197 $debug_info .= $test_name . ": FAIL\r\n";
198 ?>
199 <div class="jetpack-test-error">
200 <p>
201 <a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
202 <span class="noticon noticon-collapse"></span>
203 </a>
204 </p>
205 <pre class="jetpack-test-details"><?php echo esc_html( $test_name ); ?>:
206 <?php echo esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
207 </div><?php
208 } else {
209 $debug_info .= $test_name . ": PASS\r\n";
210 }
211 $debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) );
212 ?>
213 <?php endforeach;
214 $html = ob_get_clean();
215
216 if ( '' == trim( $html ) ) {
217 echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
218 }
219 else {
220 echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
221 echo $html;
222 }
223 $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
224 ?>
225 </div>
226 <div class="entry-content">
227 <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
228 <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
229 <ol>
230 <li><b><em><?php esc_html_e( 'A known issue.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( 'Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s" target="_blank">Jetpack support pages</a> or <a href="%4$s" target="_blank">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/getting-started-with-jetpack/known-issues/', 'http://jetpack.com/support/', 'https://wordpress.org/support/plugin/jetpack' ); ?></li>
231 <li><b><em><?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?></em></b> <?php esc_html_e( "Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack' ); ?></li>
232 <li>
233 <b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b>
234 <?php
235 $default_theme = wp_get_theme( WP_DEFAULT_THEME );
236
237 if ( $default_theme->exists() ) {
238 echo esc_html( sprintf( __( "If your problem isn't known or caused by a plugin, try activating %s (the default WordPress theme).", 'jetpack' ), $default_theme->get( 'Name' ) ) );
239 } else {
240 esc_html_e( "If your problem isn't known or caused by a plugin, try activating the default WordPress theme.", 'jetpack' );
241 }
242 ?>
243 <?php esc_html_e( "If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?>
244 </li>
245 <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), site_url( 'xmlrpc.php' ) ); ?>
246 <ul>
247 <li>- <?php esc_html_e( "If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack' ); ?></li>
248 <li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
249 </ul>
250 </li>
251 </ol>
252 <?php if ( self::is_jetpack_support_open() ): ?>
253 <p class="jetpack-show-contact-form"><?php echo sprintf( __( 'If none of these help you find a solution, <a href="%s">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack' ), Jetpack::admin_url( array( 'page' => 'jetpack-debugger', 'contact' => true ) ) ); ?>
254 </p>
255 <?php endif; ?>
256 <?php if ( Jetpack::is_active() ) : ?>
257 <hr />
258 <div id="connected-user-details">
259 <p><?php printf( __( 'The primary connection is owned by <strong>%s</strong>\'s WordPress.com account.', 'jetpack' ), esc_html( Jetpack::get_master_user_email() ) ); ?></p>
260 </div>
261 <?php endif; ?>
262 </div>
263 <div id="contact-message" <?php if( ! isset( $_GET['contact'] ) ) {?> style="display:none" <?php } ?>>
264 <?php if ( self::is_jetpack_support_open() ): ?>
265 <form id="contactme" method="post" action="https://jetpack.com/contact-support/">
266 <input type="hidden" name="action" value="submit">
267 <input type="hidden" name="jetpack" value="needs-service">
268
269 <input type="hidden" name="contact_form" id="contact_form" value="1">
270 <input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
271 <?php
272 $subject_line = sprintf(
273 /* translators: %s is the URL of the site */
274 _x( 'from: %s Jetpack contact form', 'Support request email subject line', 'jetpack' ),
275 esc_attr( site_url() )
276 );
277
278 if ( Jetpack::is_development_version() ) {
279 $subject_line = 'BETA ' . $subject_line;
280 }
281
282 $subject_line_input = printf(
283 '<input type="hidden" name="subject" id="subject" value="%s"">',
284 $subject_line
285 );
286 ?>
287 <div class="formbox">
288 <label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
289 <textarea name="message" cols="40" rows="7" id="did"><?php echo ( isset( $_GET['note'] ) ? esc_textarea( $_GET['note'] ) : '' ); ?></textarea>
290 </div>
291
292 <div id="name_div" class="formbox">
293 <label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
294 <span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
295 <input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name, 'jetpack'); ?>" size="40">
296 </div>
297
298 <div id="email_div" class="formbox">
299 <label class="h" for="your_email"><?php esc_html_e( 'E-mail', 'jetpack' ); ?></label>
300 <span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
301 <input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email, 'jetpack'); ?>" size="40">
302 </div>
303
304 <div id="toggle_debug_form_info" class="formbox">
305 <p><?php _e( 'The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack' ); ?></p>
306 </div>
307
308 <div id="debug_info_form_div" class="formbox" style="display:none">
309 <label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
310 <textarea name="debug_info" cols="40" rows="7" id="debug_form_info"><?php echo esc_attr( $debug_info ); ?></textarea>
311 </div>
312
313 <div style="clear: both;"></div>
314
315 <div id="blog_div" class="formbox">
316 <div id="submit_div" class="contact-support">
317 <input type="submit" name="submit" class="button button-primary button-large" value="<?php esc_html_e( 'Submit &#187;', 'jetpack' ); ?>">
318 </div>
319 </div>
320 <div style="clear: both;"></div>
321 </form>
322 <?php endif; ?>
323 </div> <!-- contact-message, hidden by default. -->
324 <div id="toggle_debug_info"><a href="#"><?php _e( 'View Advanced Debug Results', 'jetpack' ); ?></a></div>
325 <div id="debug_info_div" style="display:none">
326 <h4><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></h4>
327 <div id="debug_info"><pre><?php echo esc_html( $debug_info ) ; ?></pre></div>
328 </div>
329 </div>
330 <?php
331 }
332
333 public static function jetpack_debug_admin_head() {
334 ?>
335 <style type="text/css">
336
337 .jetpack-debug-test-container {
338 margin-top: 20px;
339 margin-bottom: 30px;
340 }
341
342 .jetpack-tests-succed {
343 font-size: large;
344 color: #8BAB3E;
345 }
346
347 .jetpack-test-details {
348 margin: 4px 6px;
349 padding: 10px;
350 overflow: auto;
351 display: none;
352 }
353
354 .jetpack-test-error {
355 margin-bottom: 10px;
356 background: #FFEBE8;
357 border: solid 1px #C00;
358 border-radius: 3px;
359 }
360
361 .jetpack-test-error p {
362 margin: 0;
363 padding: 0;
364 }
365
366 .jetpack-test-error a.jetpack-test-heading {
367 padding: 4px 6px;
368 display: block;
369 text-decoration: none;
370 color: inherit;
371 }
372
373 .jetpack-test-error .noticon {
374 float: right;
375 }
376
377 form#contactme {
378 border: 1px solid #dfdfdf;
379 background: #FFF;
380 padding: 20px;
381 margin: 10px;
382 background-color: #F3F6F8;
383 font-size: 15px;
384 }
385
386 form#contactme label.h {
387 color: #444;
388 display: block;
389 font-weight: bold;
390 margin: 0 0 7px 10px;
391 text-shadow: 1px 1px 0 #fff;
392 }
393
394 .formbox {
395 margin: 0 0 25px 0;
396 }
397
398 .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea, #debug_info_div {
399 border: 1px solid #e5e5e5;
400 box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
401 color: #666;
402 font-size: 14px;
403 padding: 10px;
404 width: 97%;
405 }
406 #debug_info_div {
407 border-radius: 0;
408 margin-top: 16px;
409 background: #FFF;
410 padding: 16px;
411 }
412
413 .formbox span.errormsg {
414 margin: 0 0 10px 10px;
415 color: #d00;
416 display: none;
417 }
418
419 .formbox.error span.errormsg {
420 display: block;
421 }
422
423 #contact-message ul {
424 margin: 0 0 20px 10px;
425 }
426
427 #contact-message li {
428 margin: 0 0 10px 10px;
429 list-style: disc;
430 display: list-item;
431 }
432
433 #debug_info_div, #toggle_debug_info, #debug_info_div p {
434 font-size: 12px;
435 }
436
437 </style>
438 <script type="text/javascript">
439 jQuery( document ).ready( function($) {
440
441 $( '#debug_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
442 $( '#debug_form_info' ).prepend( 'jQuery version: ' + jQuery.fn.jquery + "\r\n" );
443
444 $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
445 $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
446 return false;
447 } );
448
449 $( '.jetpack-show-contact-form a' ).on( 'click', function() {
450 $( '#contact-message' ).slideToggle();
451 return false;
452 } );
453
454 $( '#toggle_debug_info a' ).on( 'click', function() {
455 $( '#debug_info_div' ).slideToggle();
456 return false;
457 } );
458
459 $( '#toggle_debug_form_info a' ).on( 'click', function() {
460 $( '#debug_info_form_div' ).slideToggle();
461 return false;
462 } );
463
464 $( 'form#contactme' ).on( "submit", function(e){
465 var form = $( this );
466 var message = form.find( '#did' );
467 var name = form.find( '#your_name' );
468 var email = form.find( '#your_email' )
469 var validation_error = false;
470 if( !name.val() ) {
471 name.parents( '.formbox' ).addClass( 'error' );
472 validation_error = true;
473 }
474 if( !email.val() ) {
475 email.parents( '.formbox' ).addClass( 'error' );
476 validation_error = true;
477 }
478 if ( validation_error ) {
479 return false;
480 }
481 message.val( message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_form_info').val() );
482 return true;
483 });
484
485 } );
486 </script>
487 <?php
488 }
489 }
490